diff --git a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/DTRMParticle/DTRMParticle.H b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/DTRMParticle/DTRMParticle.H index 18dce5cf0c..1759de26cc 100644 --- a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/DTRMParticle/DTRMParticle.H +++ b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/DTRMParticle/DTRMParticle.H @@ -294,6 +294,18 @@ public: ); + // I-O + + //- Write individual parcel properties to stream + void writeProperties + ( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly = false + ) const; + + // Ostream Operator friend Ostream& operator<<(Ostream& os, const DTRMParticle& p); diff --git a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/DTRMParticle/DTRMParticleIO.C b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/DTRMParticle/DTRMParticleIO.C index 62272dc8e2..77592c7eae 100644 --- a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/DTRMParticle/DTRMParticleIO.C +++ b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/laserDTRM/DTRMParticle/DTRMParticleIO.C @@ -88,6 +88,31 @@ Foam::DTRMParticle::DTRMParticle } +void Foam::DTRMParticle::writeProperties +( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly +) const +{ + particle::writeProperties(os, filters, delim, namesOnly); + + #undef writeProp + #define writeProp(Name, Value) \ + particle::writeProperty(os, Name, Value, namesOnly, delim, filters) + + writeProp("p0", p0_); + writeProp("p1", p1_); + writeProp("I0", I0_); + writeProp("I", I_); + writeProp("dA", dA_); + writeProp("transmissiveId", transmissiveId_); + + #undef writeProp +} + + Foam::Ostream& Foam::operator<<(Ostream& os, const DTRMParticle& p) { if (os.format() == IOstream::ASCII) diff --git a/applications/solvers/multiphase/reactingEulerFoam/functionObjects/sizeDistribution/sizeDistribution.C b/applications/solvers/multiphase/reactingEulerFoam/functionObjects/sizeDistribution/sizeDistribution.C index ae7dd572ab..76f384a4cf 100644 --- a/applications/solvers/multiphase/reactingEulerFoam/functionObjects/sizeDistribution/sizeDistribution.C +++ b/applications/solvers/multiphase/reactingEulerFoam/functionObjects/sizeDistribution/sizeDistribution.C @@ -415,7 +415,7 @@ bool Foam::functionObjects::sizeDistribution::execute() bool Foam::functionObjects::sizeDistribution::write() { writeFileHeader(); - writeTime(file()); + writeCurrentTime(file()); Log << type() << " " << name() << " write" << nl; diff --git a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C index f29406b804..3453c1b814 100644 --- a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C +++ b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C @@ -153,19 +153,34 @@ Foam::Omanip Foam::functionObjects::writeFile::valueWidth // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +Foam::functionObjects::writeFile::writeFile(const writeFile& wf) +: + fileObr_(wf.fileObr_), + prefix_(wf.prefix_), + fileName_(wf.fileName_), + filePtr_(), + writePrecision_(wf.writePrecision_), + writeToFile_(wf.writeToFile_), + writtenHeader_(wf.writtenHeader_), + useUserTime_(wf.useUserTime_), + startTime_(wf.startTime_) +{} + + Foam::functionObjects::writeFile::writeFile ( const objectRegistry& obr, - const word& prefix, - const word& file + const fileName& prefix, + const word& name, + const bool writeToFile ) : fileObr_(obr), prefix_(prefix), - fileName_(file), + fileName_(name), filePtr_(), writePrecision_(IOstream::defaultPrecision()), - writeToFile_(true), + writeToFile_(writeToFile), writtenHeader_(false), useUserTime_(true), startTime_(obr.time().startTime().value()) @@ -175,12 +190,13 @@ Foam::functionObjects::writeFile::writeFile Foam::functionObjects::writeFile::writeFile ( const objectRegistry& obr, - const word& prefix, - const word& file, - const dictionary& dict + const fileName& prefix, + const word& name, + const dictionary& dict, + const bool writeToFile ) : - writeFile(obr, prefix, file) + writeFile(obr, prefix, name, writeToFile) { read(dict); @@ -200,7 +216,7 @@ bool Foam::functionObjects::writeFile::read(const dictionary& dict) // Only write on master writeToFile_ = - Pstream::master() && dict.lookupOrDefault("writeToFile", true); + Pstream::master() && dict.lookupOrDefault("writeToFile", writeToFile_); // Use user time, e.g. CA deg in preference to seconds useUserTime_ = dict.lookupOrDefault("useUserTime", true); @@ -275,7 +291,7 @@ void Foam::functionObjects::writeFile::writeHeader } -void Foam::functionObjects::writeFile::writeTime(Ostream& os) const +void Foam::functionObjects::writeFile::writeCurrentTime(Ostream& os) const { const scalar timeValue = ( diff --git a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H index b14855b789..3d5a99d839 100644 --- a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H +++ b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H @@ -68,7 +68,7 @@ protected: const objectRegistry& fileObr_; //- Prefix - const word prefix_; + const fileName prefix_; //- Name of file word fileName_; @@ -124,9 +124,6 @@ protected: Omanip valueWidth(const label offset = 0) const; - //- No copy construct - writeFile(const writeFile&) = delete; - //- No copy assignment void operator=(const writeFile&) = delete; @@ -143,8 +140,9 @@ public: writeFile ( const objectRegistry& obr, - const word& prefix, - const word& file = "undefined" + const fileName& prefix, + const word& name = "undefined", + const bool writeToFile = true ); //- Construct from objectRegistry, prefix, fileName @@ -152,11 +150,15 @@ public: writeFile ( const objectRegistry& obr, - const word& prefix, - const word& file, - const dictionary& dict + const fileName& prefix, + const word& name, + const dictionary& dict, + const bool writeToFile = true ); + //- Construct copy + writeFile(const writeFile& wf); + //- Destructor virtual ~writeFile() = default; @@ -186,7 +188,7 @@ public: virtual void writeHeader(Ostream& os, const string& str) const; //- Write the current time to stream - virtual void writeTime(Ostream& os) const; + virtual void writeCurrentTime(Ostream& os) const; //- Write a break marker to the stream virtual void writeBreak(Ostream& os) const; diff --git a/src/OpenFOAM/primitives/subModelBase/subModelBase.C b/src/OpenFOAM/primitives/subModelBase/subModelBase.C index b76e89a04e..a8d828a5f8 100644 --- a/src/OpenFOAM/primitives/subModelBase/subModelBase.C +++ b/src/OpenFOAM/primitives/subModelBase/subModelBase.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -169,6 +170,17 @@ bool Foam::subModelBase::writeTime() const } +Foam::fileName Foam::subModelBase::localPath() const +{ + if (modelName_ != word::null) + { + return modelName_; + } + + return baseName_; +} + + bool Foam::subModelBase::getModelDict ( const word& entryName, diff --git a/src/OpenFOAM/primitives/subModelBase/subModelBase.H b/src/OpenFOAM/primitives/subModelBase/subModelBase.H index 90ecac2989..7da05b41f2 100644 --- a/src/OpenFOAM/primitives/subModelBase/subModelBase.H +++ b/src/OpenFOAM/primitives/subModelBase/subModelBase.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -157,6 +158,9 @@ public: //- Flag to indicate when to write a property virtual bool writeTime() const; + //- Output directory + virtual fileName localPath() const; + // Edit diff --git a/src/functionObjects/field/blendingFactor/blendingFactor.C b/src/functionObjects/field/blendingFactor/blendingFactor.C index 4e2d28b14c..f1e656a046 100644 --- a/src/functionObjects/field/blendingFactor/blendingFactor.C +++ b/src/functionObjects/field/blendingFactor/blendingFactor.C @@ -174,7 +174,7 @@ bool Foam::functionObjects::blendingFactor::write() << " blended cells : " << nCellsBlended << nl << endl; - writeTime(file()); + writeCurrentTime(file()); file() << token::TAB << nCellsScheme1 diff --git a/src/functionObjects/field/continuityError/continuityError.C b/src/functionObjects/field/continuityError/continuityError.C index 07ff284a3e..36e40ac54b 100644 --- a/src/functionObjects/field/continuityError/continuityError.C +++ b/src/functionObjects/field/continuityError/continuityError.C @@ -121,7 +121,7 @@ bool Foam::functionObjects::continuityError::write() Ostream& os = file(); - writeTime(os); + writeCurrentTime(os); os << local << tab << global << tab diff --git a/src/functionObjects/field/fieldExtents/fieldExtentsTemplates.C b/src/functionObjects/field/fieldExtents/fieldExtentsTemplates.C index 2eb033f750..75b4689574 100644 --- a/src/functionObjects/field/fieldExtents/fieldExtentsTemplates.C +++ b/src/functionObjects/field/fieldExtents/fieldExtentsTemplates.C @@ -86,7 +86,7 @@ void Foam::functionObjects::fieldExtents::calcFieldExtents Log << "field: " << fieldName << nl; - writeTime(file()); + writeCurrentTime(file()); tmp tmask = calcMask(*fieldPtr); const volScalarField& mask = tmask(); diff --git a/src/functionObjects/field/fieldMinMax/fieldMinMax.C b/src/functionObjects/field/fieldMinMax/fieldMinMax.C index 465536eb3b..8ea69b49d2 100644 --- a/src/functionObjects/field/fieldMinMax/fieldMinMax.C +++ b/src/functionObjects/field/fieldMinMax/fieldMinMax.C @@ -152,7 +152,7 @@ bool Foam::functionObjects::fieldMinMax::write() { writeFileHeader(file()); - if (!location_) writeTime(file()); + if (!location_) writeCurrentTime(file()); Log << type() << " " << name() << " write:" << nl; for (const word& fieldName : fieldSet_.selectionNames()) diff --git a/src/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C b/src/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C index f11343b570..cdc9d0a5a9 100644 --- a/src/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C +++ b/src/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C @@ -50,7 +50,7 @@ void Foam::functionObjects::fieldMinMax::output if (location_) { - writeTime(file()); + writeCurrentTime(file); writeTabbed(file, fieldName); diff --git a/src/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.C b/src/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.C index a8bfa70f2c..55819728b4 100644 --- a/src/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.C +++ b/src/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.C @@ -160,7 +160,7 @@ bool Foam::functionObjects::fieldValues::fieldValueDelta::write() region1Ptr_->write(); region2Ptr_->write(); - writeTime(file()); + writeCurrentTime(file()); Log << type() << " " << name() << " write:" << endl; diff --git a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C index 43ff53629a..58b381e52e 100644 --- a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C +++ b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C @@ -992,7 +992,7 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::write() if (operation_ != opNone) { - writeTime(file()); + writeCurrentTime(file()); } if (writeArea_) diff --git a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.C b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.C index 08144db03a..3066f707e8 100644 --- a/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.C +++ b/src/functionObjects/field/fieldValues/volFieldValue/volFieldValue.C @@ -254,7 +254,7 @@ bool Foam::functionObjects::fieldValues::volFieldValue::write() if (Pstream::master()) { - writeTime(file()); + writeCurrentTime(file()); } // Only some operations need the cell volume diff --git a/src/functionObjects/field/momentum/momentum.C b/src/functionObjects/field/momentum/momentum.C index a6fe59032b..11950677f9 100644 --- a/src/functionObjects/field/momentum/momentum.C +++ b/src/functionObjects/field/momentum/momentum.C @@ -334,7 +334,7 @@ void Foam::functionObjects::momentum::writeValues(Ostream& os) if (writeToFile()) { - writeTime(os); + writeCurrentTime(os); os << tab << sumMomentum_; diff --git a/src/functionObjects/field/stabilityBlendingFactor/stabilityBlendingFactor.C b/src/functionObjects/field/stabilityBlendingFactor/stabilityBlendingFactor.C index cc158c5613..1767ab7314 100644 --- a/src/functionObjects/field/stabilityBlendingFactor/stabilityBlendingFactor.C +++ b/src/functionObjects/field/stabilityBlendingFactor/stabilityBlendingFactor.C @@ -728,7 +728,7 @@ bool Foam::functionObjects::stabilityBlendingFactor::write() if (writeToFile_) { - writeTime(file()); + writeCurrentTime(file()); file() << tab << nCellsScheme1 diff --git a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C index d5893f5717..cbb48b4a48 100644 --- a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C +++ b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C @@ -285,7 +285,7 @@ bool Foam::functionObjects::wallHeatFlux::write() if (Pstream::master()) { - writeTime(file()); + writeCurrentTime(file()); file() << token::TAB << pp.name() diff --git a/src/functionObjects/field/wallShearStress/wallShearStress.C b/src/functionObjects/field/wallShearStress/wallShearStress.C index aa9fd5eb71..ecc03916f3 100644 --- a/src/functionObjects/field/wallShearStress/wallShearStress.C +++ b/src/functionObjects/field/wallShearStress/wallShearStress.C @@ -245,7 +245,7 @@ bool Foam::functionObjects::wallShearStress::write() if (Pstream::master()) { - writeTime(file()); + writeCurrentTime(file()); file() << token::TAB << pp.name() diff --git a/src/functionObjects/field/yPlus/yPlus.C b/src/functionObjects/field/yPlus/yPlus.C index f4784b8fbd..324a0fe969 100644 --- a/src/functionObjects/field/yPlus/yPlus.C +++ b/src/functionObjects/field/yPlus/yPlus.C @@ -216,7 +216,7 @@ bool Foam::functionObjects::yPlus::write() << " y+ : min = " << minYplus << ", max = " << maxYplus << ", average = " << avgYplus << nl; - writeTime(file()); + writeCurrentTime(file()); file() << token::TAB << patch.name() << token::TAB << minYplus diff --git a/src/functionObjects/forces/forceCoeffs/forceCoeffs.C b/src/functionObjects/forces/forceCoeffs/forceCoeffs.C index 73709c0e06..e55aa3ef07 100644 --- a/src/functionObjects/forces/forceCoeffs/forceCoeffs.C +++ b/src/functionObjects/forces/forceCoeffs/forceCoeffs.C @@ -209,7 +209,7 @@ void Foam::functionObjects::forceCoeffs::writeBinData Ostream& os ) const { - writeTime(os); + writeCurrentTime(os); for (label bini = 0; bini < nBin_; ++bini) { @@ -411,7 +411,7 @@ bool Foam::functionObjects::forceCoeffs::execute() if (writeToFile()) { - writeTime(coeffFilePtr_()); + writeCurrentTime(coeffFilePtr_()); coeffFilePtr_() << tab << CdTot << tab << CsTot << tab << ClTot << tab << CmRollTot << tab << CmPitchTot << tab << CmYawTot diff --git a/src/functionObjects/forces/forces/forces.C b/src/functionObjects/forces/forces/forces.C index cb9480d811..750b3c560a 100644 --- a/src/functionObjects/forces/forces/forces.C +++ b/src/functionObjects/forces/forces/forces.C @@ -601,7 +601,7 @@ void Foam::functionObjects::forces::writeIntegratedForceMoment { Ostream& os = osPtr(); - writeTime(os); + writeCurrentTime(os); os << tab << total << tab << pressure @@ -668,7 +668,7 @@ void Foam::functionObjects::forces::writeBinnedForceMoment Ostream& os = osPtr(); - writeTime(os); + writeCurrentTime(os); forAll(f[0], i) { diff --git a/src/functionObjects/lagrangian/cloudInfo/cloudInfo.C b/src/functionObjects/lagrangian/cloudInfo/cloudInfo.C index 4a01445466..72e2524878 100644 --- a/src/functionObjects/lagrangian/cloudInfo/cloudInfo.C +++ b/src/functionObjects/lagrangian/cloudInfo/cloudInfo.C @@ -147,7 +147,7 @@ bool Foam::functionObjects::cloudInfo::write() { auto& os = files(cloudi); - writeTime(os); + writeCurrentTime(os); os << token::TAB << nTotParcels << token::TAB << totMass diff --git a/src/functionObjects/utilities/solverInfo/solverInfo.C b/src/functionObjects/utilities/solverInfo/solverInfo.C index 240cc0af68..07681805bd 100644 --- a/src/functionObjects/utilities/solverInfo/solverInfo.C +++ b/src/functionObjects/utilities/solverInfo/solverInfo.C @@ -182,7 +182,7 @@ bool Foam::functionObjects::solverInfo::execute() initialised_ = true; } - writeTime(file()); + writeCurrentTime(file()); for (const word& fieldName : fieldSet_.selectionNames()) { diff --git a/src/functionObjects/utilities/timeInfo/timeInfo.C b/src/functionObjects/utilities/timeInfo/timeInfo.C index 1b66352234..0498acc936 100644 --- a/src/functionObjects/utilities/timeInfo/timeInfo.C +++ b/src/functionObjects/utilities/timeInfo/timeInfo.C @@ -103,7 +103,7 @@ bool Foam::functionObjects::timeInfo::write() { if (Pstream::master()) { - writeTime(file()); + writeCurrentTime(file()); const scalar cpuTimeNow(time_.elapsedCpuTime()); const scalar clockTimeNow(time_.elapsedClockTime()); diff --git a/src/lagrangian/basic/injectedParticle/injectedParticle.H b/src/lagrangian/basic/injectedParticle/injectedParticle.H index 1aa4e22367..255450bbb1 100644 --- a/src/lagrangian/basic/injectedParticle/injectedParticle.H +++ b/src/lagrangian/basic/injectedParticle/injectedParticle.H @@ -219,6 +219,15 @@ public: //- Read fields static void readFields(Cloud& c); + //- Write individual parcel properties to stream + void writeProperties + ( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly + ) const; + //- Write fields static void writeFields(const Cloud& c); diff --git a/src/lagrangian/basic/injectedParticle/injectedParticleIO.C b/src/lagrangian/basic/injectedParticle/injectedParticleIO.C index 82b6c3f00e..f5b5eab9e5 100644 --- a/src/lagrangian/basic/injectedParticle/injectedParticleIO.C +++ b/src/lagrangian/basic/injectedParticle/injectedParticleIO.C @@ -172,6 +172,29 @@ void Foam::injectedParticle::writeFields(const Cloud& c) } +void Foam::injectedParticle::writeProperties +( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly +) const +{ + particle::writeProperties(os, filters, delim, namesOnly); + + #undef writeProp + #define writeProp(Name, Value) \ + particle::writeProperty(os, Name, Value, namesOnly, delim, filters) + + writeProp("tag", tag_); + writeProp("soi", soi_); + writeProp("d", d_); + writeProp("U", U_); + + #undef writeProp +} + + void Foam::injectedParticle::readObjects ( Cloud& c, diff --git a/src/lagrangian/basic/particle/particle.H b/src/lagrangian/basic/particle/particle.H index 4093a75d4a..3345be1fa1 100644 --- a/src/lagrangian/basic/particle/particle.H +++ b/src/lagrangian/basic/particle/particle.H @@ -666,6 +666,41 @@ public: // I-O + //- Write the name representation to stream + template + static void writePropertyName + ( + Ostream& os, + const word& name, + const word& delim + ); + + //- Write a named particle property to stream, + //- optionally filtered based on its name + template + static void writeProperty + ( + Ostream& os, + const word& name, + const Type& value, + const bool nameOnly, + const word& delim, + const wordRes& filters = wordRes::null() + ); + + //- Write a named particle property list to stream, + //- optionally filtered based on its name + template + static void writeProperty + ( + Ostream& os, + const word& name, + const Field& values, + const bool nameOnly, + const word& delim, + const wordRes& filters = wordRes::null() + ); + //- Read the fields associated with the owner cloud template static void readFields(TrackCloudType& c); @@ -674,6 +709,15 @@ public: template static void writeFields(const TrackCloudType& c); + //- Write individual particle properties to stream + void writeProperties + ( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly + ) const; + //- Read particle fields as objects from the obr registry template static void readObjects(CloudType& c, const objectRegistry& obr); diff --git a/src/lagrangian/basic/particle/particleIO.C b/src/lagrangian/basic/particle/particleIO.C index f59381c64f..bf8e9ac30a 100644 --- a/src/lagrangian/basic/particle/particleIO.C +++ b/src/lagrangian/basic/particle/particleIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -193,6 +193,32 @@ Foam::particle::particle } +void Foam::particle::writeProperties +( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly +) const +{ + #undef writeProp + #define writeProp(Name, Value) \ + particle::writeProperty(os, Name, Value, namesOnly, delim, filters) + + writeProp("coordinates", coordinates_); + writeProp("position", position()); + writeProp("celli", celli_); + writeProp("tetFacei", tetFacei_); + writeProp("tetPti", tetPti_); + writeProp("facei", facei_); + writeProp("stepFraction", stepFraction_); + writeProp("origProc", origProc_); + writeProp("origId", origId_); + + #undef writeProp +} + + void Foam::particle::writeCoordinates(Ostream& os) const { if (os.format() == IOstream::ASCII) diff --git a/src/lagrangian/basic/particle/particleTemplates.C b/src/lagrangian/basic/particle/particleTemplates.C index 259fca878f..d9f53e383e 100644 --- a/src/lagrangian/basic/particle/particleTemplates.C +++ b/src/lagrangian/basic/particle/particleTemplates.C @@ -40,6 +40,102 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +void Foam::particle::writePropertyName +( + Ostream& os, + const word& name, + const word& delim +) +{ + if (pTraits::nComponents == 1) + { + os << name; + } + else + { + os << '('; + for (int i = 0; i < pTraits::nComponents; ++i) + { + if (i) os << delim; + + os << name << Foam::name(i); + } + os << ')'; + } +} + + +template +void Foam::particle::writeProperty +( + Ostream& os, + const word& name, + const Type& value, + const bool nameOnly, + const word& delim, + const wordRes& filters +) +{ + if (!filters.empty() && !filters.match(name)) + { + return; + } + + os << delim; + if (nameOnly) + { + writePropertyName(os, name, delim); + } + else + { + os << value; + } +} + + +template +void Foam::particle::writeProperty +( + Ostream& os, + const word& name, + const Field& values, + const bool nameOnly, + const word& delim, + const wordRes& filters +) +{ + if (!filters.empty() && !filters.match(name)) + { + return; + } + + if (nameOnly) + { + os << delim; + os << "N("; + if (values.size()) + { + forAll(values, i) + { + if (i) os << delim; + const word tag(name + Foam::name(i)); + writePropertyName(os, tag, delim); + } + } + else + { + os << name; + } + os << ')'; + } + else + { + os << delim << values; + } +} + + template void Foam::particle::readFields(TrackCloudType& c) { diff --git a/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollidingParcel.H b/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollidingParcel.H index 073494859d..7741b6195f 100644 --- a/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollidingParcel.H +++ b/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollidingParcel.H @@ -323,6 +323,15 @@ public: template static void writeFields(const CloudType& c); + //- Write individual parcel properties to stream + void writeProperties + ( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly + ) const; + //- Read particle fields as objects from the obr registry template static void readObjects(CloudType& c, const objectRegistry& obr); diff --git a/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollidingParcelIO.C b/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollidingParcelIO.C index bce2bab1c4..9028e49c05 100644 --- a/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollidingParcelIO.C +++ b/src/lagrangian/intermediate/parcels/Templates/CollidingParcel/CollidingParcelIO.C @@ -291,6 +291,30 @@ void Foam::CollidingParcel::writeFields(const CloudType& c) } +template +void Foam::CollidingParcel::writeProperties +( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly +) const +{ + ParcelType::writeProperties(os, filters, delim, namesOnly); + + #undef writeProp + #define writeProp(Name, Value) \ + ParcelType::writeProperty(os, Name, Value, namesOnly, delim, filters) + + writeProp("f", f_); + writeProp("angularMomentum", angularMomentum_); + writeProp("torque", torque_); + //writeProp("collisionRecords", collisionRecords_); + + #undef writeProp +} + + template template void Foam::CollidingParcel::readObjects diff --git a/src/lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcel.H b/src/lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcel.H index e385816457..7b9b253394 100644 --- a/src/lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcel.H +++ b/src/lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcel.H @@ -659,6 +659,15 @@ public: template static void writeFields(const TrackCloudType& c); + //- Write individual parcel properties to stream + void writeProperties + ( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly = false + ) const; + //- Read particle fields as objects from the obr registry template static void readObjects(CloudType& c, const objectRegistry& obr); diff --git a/src/lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcelIO.C b/src/lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcelIO.C index ca6ef8d23a..ed15a3a492 100644 --- a/src/lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcelIO.C +++ b/src/lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcelIO.C @@ -266,6 +266,36 @@ void Foam::KinematicParcel::writeFields(const CloudType& c) } +template +void Foam::KinematicParcel::writeProperties +( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly +) const +{ + ParcelType::writeProperties(os, filters, delim, namesOnly); + + #undef writeProp + #define writeProp(Name, Value) \ + ParcelType::writeProperty(os, Name, Value, namesOnly, delim, filters) + + writeProp("active", active_); + writeProp("typeId", typeId_); + writeProp("nParticle", nParticle_); + writeProp("d", d_); + writeProp("dTarget", dTarget_); + writeProp("U", U_); + writeProp("rho", rho_); + writeProp("age", age_); + writeProp("tTurb", tTurb_); + writeProp("UTurb", UTurb_); + + #undef writeProp +} + + template template void Foam::KinematicParcel::readObjects diff --git a/src/lagrangian/intermediate/parcels/Templates/MPPICParcel/MPPICParcel.H b/src/lagrangian/intermediate/parcels/Templates/MPPICParcel/MPPICParcel.H index 873a6e0986..59cc4044fc 100644 --- a/src/lagrangian/intermediate/parcels/Templates/MPPICParcel/MPPICParcel.H +++ b/src/lagrangian/intermediate/parcels/Templates/MPPICParcel/MPPICParcel.H @@ -308,6 +308,15 @@ public: template static void writeFields(const CloudType& c); + //- Write individual parcel properties to stream + void writeProperties + ( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly = false + ) const; + //- Read particle fields as objects from the obr registry template static void readObjects(CloudType& c, const objectRegistry& obr); diff --git a/src/lagrangian/intermediate/parcels/Templates/MPPICParcel/MPPICParcelIO.C b/src/lagrangian/intermediate/parcels/Templates/MPPICParcel/MPPICParcelIO.C index da0eac818e..64daed8e00 100644 --- a/src/lagrangian/intermediate/parcels/Templates/MPPICParcel/MPPICParcelIO.C +++ b/src/lagrangian/intermediate/parcels/Templates/MPPICParcel/MPPICParcelIO.C @@ -133,6 +133,27 @@ void Foam::MPPICParcel::writeFields(const CloudType& c) } +template +void Foam::MPPICParcel::writeProperties +( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly +) const +{ + ParcelType::writeProperties(os, filters, delim, namesOnly); + + #undef writeProp + #define writeProp(Name, Value) \ + ParcelType::writeProperty(os, Name, Value, namesOnly, delim, filters) + + writeProp("UCorrect", UCorrect_); + + #undef writeProp +} + + template template void Foam::MPPICParcel::readObjects diff --git a/src/lagrangian/intermediate/parcels/Templates/ReactingHeterogeneousParcel/ReactingHeterogeneousParcel.H b/src/lagrangian/intermediate/parcels/Templates/ReactingHeterogeneousParcel/ReactingHeterogeneousParcel.H index 7973c580c2..82f55f5ce4 100644 --- a/src/lagrangian/intermediate/parcels/Templates/ReactingHeterogeneousParcel/ReactingHeterogeneousParcel.H +++ b/src/lagrangian/intermediate/parcels/Templates/ReactingHeterogeneousParcel/ReactingHeterogeneousParcel.H @@ -371,6 +371,15 @@ public: template static void writeFields(const CloudType& c); + //- Write individual parcel properties to stream + void writeProperties + ( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly + ) const; + //- Read particle fields as objects from the obr registry // - no composition template diff --git a/src/lagrangian/intermediate/parcels/Templates/ReactingHeterogeneousParcel/ReactingHeterogeneousParcelIO.C b/src/lagrangian/intermediate/parcels/Templates/ReactingHeterogeneousParcel/ReactingHeterogeneousParcelIO.C index 1d8206ceb9..16d3cfbf33 100644 --- a/src/lagrangian/intermediate/parcels/Templates/ReactingHeterogeneousParcel/ReactingHeterogeneousParcelIO.C +++ b/src/lagrangian/intermediate/parcels/Templates/ReactingHeterogeneousParcel/ReactingHeterogeneousParcelIO.C @@ -251,6 +251,28 @@ void Foam::ReactingHeterogeneousParcel::writeFields } +template +void Foam::ReactingHeterogeneousParcel::writeProperties +( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly +) const +{ + ParcelType::writeProperties(os, filters, delim, namesOnly); + + #undef writeProp + #define writeProp(Name, Value) \ + ParcelType::writeProperty(os, Name, Value, namesOnly, delim, filters) + + writeProp("F", F_); + writeProp("canCombust", canCombust_); + + #undef writeProp +} + + template template void Foam::ReactingHeterogeneousParcel::readObjects diff --git a/src/lagrangian/intermediate/parcels/Templates/ReactingMultiphaseParcel/ReactingMultiphaseParcel.H b/src/lagrangian/intermediate/parcels/Templates/ReactingMultiphaseParcel/ReactingMultiphaseParcel.H index 44e3e786f5..1595d9de27 100644 --- a/src/lagrangian/intermediate/parcels/Templates/ReactingMultiphaseParcel/ReactingMultiphaseParcel.H +++ b/src/lagrangian/intermediate/parcels/Templates/ReactingMultiphaseParcel/ReactingMultiphaseParcel.H @@ -462,6 +462,15 @@ public: template static void writeFields(const CloudType& c); + //- Write individual parcel properties to stream + void writeProperties + ( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly = false + ) const; + //- Read particle fields as objects from the obr registry // - no composition template diff --git a/src/lagrangian/intermediate/parcels/Templates/ReactingMultiphaseParcel/ReactingMultiphaseParcelIO.C b/src/lagrangian/intermediate/parcels/Templates/ReactingMultiphaseParcel/ReactingMultiphaseParcelIO.C index c42b7648c0..f3094d4cc5 100644 --- a/src/lagrangian/intermediate/parcels/Templates/ReactingMultiphaseParcel/ReactingMultiphaseParcelIO.C +++ b/src/lagrangian/intermediate/parcels/Templates/ReactingMultiphaseParcel/ReactingMultiphaseParcelIO.C @@ -282,6 +282,30 @@ void Foam::ReactingMultiphaseParcel::writeFields } +template +void Foam::ReactingMultiphaseParcel::writeProperties +( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly +) const +{ + ParcelType::writeProperties(os, filters, delim, namesOnly); + + #undef writeProp + #define writeProp(Name, Value) \ + ParcelType::writeProperty(os, Name, Value, namesOnly, delim, filters) + + writeProp("YGas", YGas_); + writeProp("YLiquid", YLiquid_); + writeProp("YSolid", YSolid_); + writeProp("canCombust", canCombust_); + + #undef writeProp +} + + template template void Foam::ReactingMultiphaseParcel::readObjects diff --git a/src/lagrangian/intermediate/parcels/Templates/ReactingParcel/ReactingParcel.H b/src/lagrangian/intermediate/parcels/Templates/ReactingParcel/ReactingParcel.H index 188479c4f6..6a4a61b647 100644 --- a/src/lagrangian/intermediate/parcels/Templates/ReactingParcel/ReactingParcel.H +++ b/src/lagrangian/intermediate/parcels/Templates/ReactingParcel/ReactingParcel.H @@ -414,6 +414,14 @@ public: template static void writeFields(const CloudType& c); + //- Write individual parcel properties to stream + void writeProperties + ( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly = false + ) const; //- Read particle fields as objects from the obr registry // - no composition diff --git a/src/lagrangian/intermediate/parcels/Templates/ReactingParcel/ReactingParcelIO.C b/src/lagrangian/intermediate/parcels/Templates/ReactingParcel/ReactingParcelIO.C index 9092291731..010598626f 100644 --- a/src/lagrangian/intermediate/parcels/Templates/ReactingParcel/ReactingParcelIO.C +++ b/src/lagrangian/intermediate/parcels/Templates/ReactingParcel/ReactingParcelIO.C @@ -231,6 +231,28 @@ void Foam::ReactingParcel::writeFields } +template +void Foam::ReactingParcel::writeProperties +( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly +) const +{ + ParcelType::writeProperties(os, filters, delim, namesOnly); + + #undef writeProp + #define writeProp(Name, Value) \ + ParcelType::writeProperty(os, Name, Value, namesOnly, delim, filters) + + writeProp("mass0", mass0_); + writeProp("Y", Y_); + + #undef writeProp +} + + template template void Foam::ReactingParcel::readObjects diff --git a/src/lagrangian/intermediate/parcels/Templates/ThermoParcel/ThermoParcel.H b/src/lagrangian/intermediate/parcels/Templates/ThermoParcel/ThermoParcel.H index adce067cce..dbbf70ffad 100644 --- a/src/lagrangian/intermediate/parcels/Templates/ThermoParcel/ThermoParcel.H +++ b/src/lagrangian/intermediate/parcels/Templates/ThermoParcel/ThermoParcel.H @@ -455,6 +455,15 @@ public: template static void writeFields(const CloudType& c); + //- Write individual parcel properties to stream + void writeProperties + ( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly = false + ) const; + //- Read particle fields as objects from the obr registry template static void readObjects(CloudType& c, const objectRegistry& obr); diff --git a/src/lagrangian/intermediate/parcels/Templates/ThermoParcel/ThermoParcelIO.C b/src/lagrangian/intermediate/parcels/Templates/ThermoParcel/ThermoParcelIO.C index a9a408aaa1..6cfb2efabf 100644 --- a/src/lagrangian/intermediate/parcels/Templates/ThermoParcel/ThermoParcelIO.C +++ b/src/lagrangian/intermediate/parcels/Templates/ThermoParcel/ThermoParcelIO.C @@ -138,6 +138,28 @@ void Foam::ThermoParcel::writeFields(const CloudType& c) } +template +void Foam::ThermoParcel::writeProperties +( + Ostream& os, + const wordRes& filters, + const word& delim, + const bool namesOnly +) const +{ + ParcelType::writeProperties(os, filters, delim, namesOnly); + + #undef writeProp + #define writeProp(Name, Value) \ + ParcelType::writeProperty(os, Name, Value, namesOnly, delim, filters) + + writeProp("T", T_); + writeProp("Cp", Cp_); + + #undef writeProp +} + + template template void Foam::ThermoParcel::readObjects diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/CloudFunctionObject/CloudFunctionObject.C b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/CloudFunctionObject/CloudFunctionObject.C index 4e05475139..ed89fc43e4 100644 --- a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/CloudFunctionObject/CloudFunctionObject.C +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/CloudFunctionObject/CloudFunctionObject.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2011-2019 OpenFOAM Foundation ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -66,9 +66,7 @@ Foam::CloudFunctionObject::CloudFunctionObject ( owner.mesh().time().globalPath() / functionObject::outputPrefix - / cloud::prefix - / owner.name() - / this->modelName() + / this->localPath() ); outputDir_.clean(); // Remove unneeded ".." diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.C b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.C index 5131443375..f391e78dc4 100644 --- a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.C +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.C @@ -40,15 +40,7 @@ Foam::label Foam::PatchPostProcessing::applyToPatch const label globalPatchi ) const { - forAll(patchIDs_, i) - { - if (patchIDs_[i] == globalPatchi) - { - return i; - } - } - - return -1; + return patchIDs_.find(globalPatchi); } @@ -100,7 +92,7 @@ void Foam::PatchPostProcessing::write() labelList indices(sortedOrder(globalTimes)); - string header("# Time currentProc " + parcelType::propertyList_); + string header("# Time currentProc " + header_); patchOutFile<< header.c_str() << nl; forAll(globalTimes, i) @@ -132,37 +124,40 @@ Foam::PatchPostProcessing::PatchPostProcessing : CloudFunctionObject(dict, owner, modelName, typeName), maxStoredParcels_(this->coeffDict().getScalar("maxStoredParcels")), + fields_(), patchIDs_(), times_(), - patchData_() + patchData_(), + header_() { - const wordList allPatchNames(owner.mesh().boundaryMesh().names()); - const wordReList patchNames(this->coeffDict().lookup("patches")); + // The "fields" filter is optional + this->coeffDict().readIfPresent("fields", fields_); - labelHashSet uniqIds; - for (const wordRe& re : patchNames) + // The "patches" are required + const wordRes patchMatcher(this->coeffDict().lookup("patches")); + + patchIDs_ = patchMatcher.matching(owner.mesh().boundaryMesh().names()); + + if (patchIDs_.empty()) { - labelList ids = findStrings(re, allPatchNames); - - if (ids.empty()) - { - WarningInFunction - << "Cannot find any patch names matching " << re - << endl; - } - - uniqIds.insert(ids); + WarningInFunction + << "No matching patches found: " + << flatOutput(patchMatcher) << nl; } - patchIDs_ = uniqIds.sortedToc(); - if (debug) { + Info<< "Post-process fields " + << flatOutput(fields_) << nl; + + Info<< "On patches ("; + for (const label patchi : patchIDs_) { - Info<< "Post-process patch " - << owner.mesh().boundaryMesh()[patchi].name() << endl; + Info<< ' ' << owner.mesh().boundaryMesh()[patchi].name(); } + + Info<< " )" << nl; } patchData_.setSize(patchIDs_.size()); @@ -178,9 +173,11 @@ Foam::PatchPostProcessing::PatchPostProcessing : CloudFunctionObject(ppm), maxStoredParcels_(ppm.maxStoredParcels_), + fields_(ppm.fields_), patchIDs_(ppm.patchIDs_), times_(ppm.times_), - patchData_(ppm.patchData_) + patchData_(ppm.patchData_), + header_(ppm.header_) {} @@ -197,12 +194,20 @@ void Foam::PatchPostProcessing::postPatch const label patchi = pp.index(); const label localPatchi = applyToPatch(patchi); + if (header_.empty()) + { + OStringStream data; + p.writeProperties(data, fields_, " ", true); + header_ = data.str(); + } + if (localPatchi != -1 && patchData_[localPatchi].size() < maxStoredParcels_) { times_[localPatchi].append(this->owner().time().value()); OStringStream data; - data<< Pstream::myProcNo() << ' ' << p; + data<< Pstream::myProcNo(); + p.writeProperties(data, fields_, " ", false); patchData_[localPatchi].append(data.str()); } diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.H b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.H index 065086e99c..4e1f6c4eb7 100644 --- a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.H +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -63,6 +64,9 @@ class PatchPostProcessing //- Maximum number of parcels to store - set as a scalar for I/O scalar maxStoredParcels_; + //- Field name filters + wordRes fields_; + //- List of patch indices to post-process labelList patchIDs_; @@ -72,6 +76,9 @@ class PatchPostProcessing //- List of output data per patch List> patchData_; + //- Field header + string header_; + // Private Member Functions diff --git a/src/lagrangian/intermediate/submodels/CloudSubModelBase.C b/src/lagrangian/intermediate/submodels/CloudSubModelBase.C index aaf1baee98..1203dff816 100644 --- a/src/lagrangian/intermediate/submodels/CloudSubModelBase.C +++ b/src/lagrangian/intermediate/submodels/CloudSubModelBase.C @@ -26,6 +26,7 @@ License \*---------------------------------------------------------------------------*/ #include "CloudSubModelBase.H" +#include "cloud.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -125,6 +126,18 @@ bool Foam::CloudSubModelBase::writeTime() const } +template +Foam::fileName Foam::CloudSubModelBase::localPath() const +{ + if (modelName_ != word::null) + { + return cloud::prefix/owner_.name()/modelName_; + } + + return cloud::prefix/owner_.name()/baseName_; +} + + template void Foam::CloudSubModelBase::write(Ostream& os) const { diff --git a/src/lagrangian/intermediate/submodels/CloudSubModelBase.H b/src/lagrangian/intermediate/submodels/CloudSubModelBase.H index 08b95195ce..500f4ddd49 100644 --- a/src/lagrangian/intermediate/submodels/CloudSubModelBase.H +++ b/src/lagrangian/intermediate/submodels/CloudSubModelBase.H @@ -109,6 +109,9 @@ public: //- Flag to indicate when to write a property virtual bool writeTime() const; + //- Output directory + virtual fileName localPath() const; + // Edit diff --git a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C index 6c2726b153..99cdf18c34 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C +++ b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2018 OpenCFD Ltd. + Copyright (C) 2015-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,6 +30,27 @@ License // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * // +template +void Foam::LocalInteraction::writeFileHeader(Ostream& os) +{ + PatchInteractionModel::writeFileHeader(os); + + forAll(nEscape_, patchi) + { + const word& patchName = patchData_[patchi].patchName(); + + forAll(nEscape_[patchi], injectori) + { + const word suffix = Foam::name(injectori); + this->writeTabbed(os, patchName + "_nEscape_" + suffix); + this->writeTabbed(os, patchName + "_massEscape_" + suffix); + this->writeTabbed(os, patchName + "_nStick_" + suffix); + this->writeTabbed(os, patchName + "_massStick_" + suffix); + } + } +} + + template Foam::LocalInteraction::LocalInteraction ( @@ -356,7 +377,7 @@ void Foam::LocalInteraction::info(Ostream& os) if (injIdToIndex_.size()) { - // Since injIdToIndex_ is a one-to-one mapping (starting as zero), + // Since injIdToIndex_ is a one-to-one mapping (starting at zero), // can simply invert it. labelList indexToInjector(injIdToIndex_.size()); forAllConstIters(injIdToIndex_, iter) @@ -364,34 +385,52 @@ void Foam::LocalInteraction::info(Ostream& os) indexToInjector[iter.val()] = iter.key(); } - forAll(patchData_, i) + forAll(patchData_, patchi) { - forAll(mpe[i], idx) + forAll(mpe[patchi], indexi) { - os << " Parcel fate: patch " << patchData_[i].patchName() + const word& patchName = patchData_[patchi].patchName(); + + os << " Parcel fate: patch " << patchName << " (number, mass)" << nl - << " - escape (injector " << indexToInjector[idx] - << " ) = " << npe[i][idx] - << ", " << mpe[i][idx] << nl - << " - stick (injector " << indexToInjector[idx] - << " ) = " << nps[i][idx] - << ", " << mps[i][idx] << nl; + << " - escape (injector " << indexToInjector[indexi] + << " ) = " << npe[patchi][indexi] + << ", " << mpe[patchi][indexi] << nl + << " - stick (injector " << indexToInjector[indexi] + << " ) = " << nps[patchi][indexi] + << ", " << mps[patchi][indexi] << nl; } } } else { - forAll(patchData_, i) + forAll(patchData_, patchi) { - os << " Parcel fate: patch " << patchData_[i].patchName() + const word& patchName = patchData_[patchi].patchName(); + + os << " Parcel fate: patch " << patchName << " (number, mass)" << nl << " - escape = " - << npe[i][0] << ", " << mpe[i][0] << nl + << npe[patchi][0] << ", " << mpe[patchi][0] << nl << " - stick = " - << nps[i][0] << ", " << mps[i][0] << nl; + << nps[patchi][0] << ", " << mps[patchi][0] << nl; } } + forAll(npe, patchi) + { + forAll(npe[patchi], injectori) + { + this->file() + << tab << npe[patchi][injectori] + << tab << mpe[patchi][injectori] + << tab << nps[patchi][injectori] + << tab << mps[patchi][injectori]; + } + } + + this->file() << endl; + if (this->writeTime()) { this->setModelProperty("nEscape", npe); diff --git a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H index ab022fcba2..80d23d1f28 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H +++ b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -61,19 +61,21 @@ class LocalInteraction //- List of participating patches const patchInteractionDataList patchData_; - // Bookkeeping for particle fates - //- Number of parcels escaped - List> nEscape_; + // Bookkeeping for particle fates - //- Mass of parcels escaped - List> massEscape_; + //- Number of parcels escaped + List> nEscape_; - //- Number of parcels stuck to patches - List> nStick_; + //- Mass of parcels escaped + List> massEscape_; + + //- Number of parcels stuck to patches + List> nStick_; + + //- Mass of parcels stuck to patches + List> massStick_; - //- Mass of parcels stuck to patches - List> massStick_; //- Flag to output data as fields bool writeFields_; @@ -89,6 +91,13 @@ class LocalInteraction autoPtr massStickPtr_; +protected: + + // Protected Member Functions + + //- Output file header information + virtual void writeFileHeader(Ostream& os); + public: diff --git a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/PatchInteractionModel/PatchInteractionModel.C b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/PatchInteractionModel/PatchInteractionModel.C index 17329eac4a..09925d58b0 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/PatchInteractionModel/PatchInteractionModel.C +++ b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/PatchInteractionModel/PatchInteractionModel.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016 OpenCFD Ltd. + Copyright (C) 2016-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,6 +40,20 @@ Foam::wordList Foam::PatchInteractionModel::interactionTypeNames_ }; +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template +void Foam::PatchInteractionModel::writeFileHeader(Ostream& os) +{ + this->writeHeader(os, "Particle patch interaction"); + this->writeHeaderValue(os, "Model", this->modelType()); + + this->writeCommented(os, "Time"); + this->writeTabbed(os, "escapedParcels"); + this->writeTabbed(os, "escapedMass"); +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template @@ -120,6 +134,7 @@ Foam::PatchInteractionModel::PatchInteractionModel ) : CloudSubModelBase(owner), + functionObjects::writeFile(owner, this->localPath(), typeName, false), UName_("unknown_U"), escapedParcels_(0), escapedMass_(0.0) @@ -135,6 +150,14 @@ Foam::PatchInteractionModel::PatchInteractionModel ) : CloudSubModelBase(owner, dict, typeName, type), + functionObjects::writeFile + ( + owner, + this->localPath(), + type, + this->coeffDict(), + false // Do not write by default + ), UName_(this->coeffDict().lookupOrDefault("U", word("U"))), escapedParcels_(0), escapedMass_(0.0) @@ -148,6 +171,7 @@ Foam::PatchInteractionModel::PatchInteractionModel ) : CloudSubModelBase(pim), + functionObjects::writeFile(pim), UName_(pim.UName_), escapedParcels_(pim.escapedParcels_), escapedMass_(pim.escapedMass_) @@ -170,7 +194,7 @@ void Foam::PatchInteractionModel::addToEscapedParcels ) { escapedMass_ += mass; - escapedParcels_++; + ++escapedParcels_; } @@ -191,6 +215,18 @@ void Foam::PatchInteractionModel::info(Ostream& os) << " - escape = " << escapedParcelsTotal << ", " << escapedMassTotal << endl; + if (!this->writtenHeader_) + { + this->writeFileHeader(this->file()); + this->writtenHeader_ = true; + this->file() << endl; + } + + this->writeCurrentTime(this->file()); + this->file() + << tab << escapedParcelsTotal << tab << escapedMassTotal; + + if (this->writeTime()) { this->setBaseProperty("escapedParcels", escapedParcelsTotal); diff --git a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/PatchInteractionModel/PatchInteractionModel.H b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/PatchInteractionModel/PatchInteractionModel.H index 67ed1daa22..73d7bb6c20 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/PatchInteractionModel/PatchInteractionModel.H +++ b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/PatchInteractionModel/PatchInteractionModel.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -48,6 +49,7 @@ SourceFiles #include "wallPolyPatch.H" #include "tetIndices.H" #include "CloudSubModelBase.H" +#include "writeFile.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -61,7 +63,8 @@ namespace Foam template class PatchInteractionModel : - public CloudSubModelBase + public CloudSubModelBase, + public functionObjects::writeFile { public: @@ -82,7 +85,7 @@ public: protected: - // Private data + // Protected data //- Name of velocity field - default = "U" const word UName_; @@ -97,6 +100,11 @@ protected: scalar escapedMass_; + // Protected Member Functions + + //- Output file header information + virtual void writeFileHeader(Ostream& os); + public: diff --git a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/StandardWallInteraction/StandardWallInteraction.C b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/StandardWallInteraction/StandardWallInteraction.C index 2512822bc1..efff7013ad 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/StandardWallInteraction/StandardWallInteraction.C +++ b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/StandardWallInteraction/StandardWallInteraction.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2018 OpenCFD Ltd. + Copyright (C) 2015-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,6 +28,29 @@ License #include "StandardWallInteraction.H" +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template +void Foam::StandardWallInteraction::writeFileHeader(Ostream& os) +{ + PatchInteractionModel::writeFileHeader(os); + + forAll(nEscape_, patchi) + { + const word& patchName = mesh_.boundary()[patchi].name(); + + forAll(nEscape_[patchi], injectori) + { + const word suffix = Foam::name(injectori); + this->writeTabbed(os, patchName + "_nEscape_" + suffix); + this->writeTabbed(os, patchName + "_massEscape_" + suffix); + this->writeTabbed(os, patchName + "_nStick_" + suffix); + this->writeTabbed(os, patchName + "_massStick_" + suffix); + } + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -51,8 +74,8 @@ Foam::StandardWallInteraction::StandardWallInteraction massStick_(nEscape_.size()), injIdToIndex_() { - const bool outputByInjectorId - = this->coeffDict().lookupOrDefault("outputByInjectorId", false); + const bool outputByInjectorId = + this->coeffDict().lookupOrDefault("outputByInjectorId", false); switch (interactionType_) { @@ -277,33 +300,48 @@ void Foam::StandardWallInteraction::info(Ostream& os) indexToInjector[iter.val()] = iter.key(); } - forAll(npe, i) + forAll(npe, patchi) { - forAll(mpe[i], idx) + forAll(mpe[patchi], indexi) { - os << " Parcel fate: patch " << mesh_.boundary()[i].name() + const word& patchName = mesh_.boundary()[patchi].name() ; + + os << " Parcel fate: patch " << patchName << " (number, mass)" << nl - << " - escape (injector " << indexToInjector[idx] - << ") = " << npe[i][idx] - << ", " << mpe[i][idx] << nl - << " - stick (injector " << indexToInjector[idx] - << ") = " << nps[i][idx] - << ", " << mps[i][idx] << nl; + << " - escape (injector " << indexToInjector[indexi] + << ") = " << npe[patchi][indexi] + << ", " << mpe[patchi][indexi] << nl + << " - stick (injector " << indexToInjector[indexi] + << ") = " << nps[patchi][indexi] + << ", " << mps[patchi][indexi] << nl; + + this->file() + << tab << npe[patchi][indexi] << tab << mpe[patchi][indexi] + << tab << nps[patchi][indexi] << tab << mps[patchi][indexi]; } } + + this->file() << endl; } else { - forAll(npe, i) + forAll(npe, patchi) { - os << " Parcel fate: patch (number, mass) " - << mesh_.boundary()[i].name() << nl - << " - escape = " - << npe[i][0] << ", " << mpe[i][0] << nl - << " - stick = " - << nps[i][0] << ", " << mps[i][0] << nl; + const word& patchName = mesh_.boundary()[patchi].name(); + os << " Parcel fate: patch (number, mass) " + << patchName << nl + << " - escape = " + << npe[patchi][0] << ", " << mpe[patchi][0] << nl + << " - stick = " + << nps[patchi][0] << ", " << mps[patchi][0] << nl; + + this->file() + << tab << npe[patchi][0] << tab << mpe[patchi][0] + << tab << nps[patchi][0] << tab << mps[patchi][0]; } + + this->file() << endl; } if (this->writeTime()) diff --git a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/StandardWallInteraction/StandardWallInteraction.H b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/StandardWallInteraction/StandardWallInteraction.H index 7096df2ed6..71178cd36b 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/StandardWallInteraction/StandardWallInteraction.H +++ b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/StandardWallInteraction/StandardWallInteraction.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -85,19 +85,21 @@ protected: //- Restitution coefficient scalar mu_; - // Bookkeeping for particle fates - //- Number of parcels escaped - List> nEscape_; + // Bookkeeping for particle fates - //- Mass of parcels escaped - List> massEscape_; + //- Number of parcels escaped + List> nEscape_; - //- Number of parcels stuck to patches - List> nStick_; + //- Mass of parcels escaped + List> massEscape_; + + //- Number of parcels stuck to patches + List> nStick_; + + //- Mass of parcels stuck to patches + List> massStick_; - //- Mass of parcels stuck to patches - List> massStick_; //- Flag to output escaped/mass particles sorted by injectorID bool outputByInjectorId_; @@ -107,6 +109,12 @@ protected: Map