From deeb27896cff54f818707d08927993e26d64bbf3 Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Mon, 9 Dec 2019 22:31:09 +0000 Subject: [PATCH] ENH: Added option to write particle patch interactions to file File writing is off by default; to activate, add to the patch interaction model coeff dictionary writeToFile yes; --- .../LocalInteraction/LocalInteraction.C | 69 +++++++++++++---- .../LocalInteraction/LocalInteraction.H | 29 ++++--- .../PatchInteractionModel.C | 40 +++++++++- .../PatchInteractionModel.H | 12 ++- .../StandardWallInteraction.C | 76 ++++++++++++++----- .../StandardWallInteraction.H | 28 ++++--- .../filter/constant/reactingCloud1Properties | 2 + 7 files changed, 198 insertions(+), 58 deletions(-) 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