From 2a64d98d0211d9045fe342f703294648f6760a1f Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin Date: Fri, 14 Aug 2020 12:50:15 +0100 Subject: [PATCH] ENH: PatchParticleHistogram: add a new cloud FO Computes a histogram for the distribution of particle diameters and corresponding number of particles hitting on a given list of patches. A minimal example by using `constant/reactingCloud1Properties.cloudFunctions`: ``` patchParticleHistogram1 { // Mandatory entries (unmodifiable) type patchParticleHistogram; patches ( ... ); nBins 10; min 0.1; max 10.0; maxStoredParcels 20; } ``` --- .../include/makeParcelCloudFunctionObjects.H | 3 + .../makeReactingParcelCloudFunctionObjects.H | 2 + .../PatchParticleHistogram.C | 254 ++++++++++++++++++ .../PatchParticleHistogram.H | 222 +++++++++++++++ .../filter/constant/reactingCloud1Properties | 14 + 5 files changed, 495 insertions(+) create mode 100644 src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchParticleHistogram/PatchParticleHistogram.C create mode 100644 src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchParticleHistogram/PatchParticleHistogram.H diff --git a/src/lagrangian/intermediate/parcels/include/makeParcelCloudFunctionObjects.H b/src/lagrangian/intermediate/parcels/include/makeParcelCloudFunctionObjects.H index 4615278aa0..ed6c4f6bf9 100644 --- a/src/lagrangian/intermediate/parcels/include/makeParcelCloudFunctionObjects.H +++ b/src/lagrangian/intermediate/parcels/include/makeParcelCloudFunctionObjects.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2018 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,6 +38,7 @@ License #include "ParticleTrap.H" #include "PatchCollisionDensity.H" #include "PatchPostProcessing.H" +#include "PatchParticleHistogram.H" #include "RemoveParcels.H" #include "VoidFraction.H" @@ -53,6 +55,7 @@ License makeCloudFunctionObjectType(ParticleTrap, CloudType); \ makeCloudFunctionObjectType(PatchCollisionDensity, CloudType); \ makeCloudFunctionObjectType(PatchPostProcessing, CloudType); \ + makeCloudFunctionObjectType(PatchParticleHistogram, CloudType); \ makeCloudFunctionObjectType(RemoveParcels, CloudType); \ makeCloudFunctionObjectType(VoidFraction, CloudType); diff --git a/src/lagrangian/intermediate/parcels/include/makeReactingParcelCloudFunctionObjects.H b/src/lagrangian/intermediate/parcels/include/makeReactingParcelCloudFunctionObjects.H index a11f3de2e2..dd45507c68 100644 --- a/src/lagrangian/intermediate/parcels/include/makeReactingParcelCloudFunctionObjects.H +++ b/src/lagrangian/intermediate/parcels/include/makeReactingParcelCloudFunctionObjects.H @@ -38,6 +38,7 @@ License #include "ParticleTrap.H" #include "PatchCollisionDensity.H" #include "PatchPostProcessing.H" +#include "PatchParticleHistogram.H" #include "RemoveParcels.H" #include "VoidFraction.H" #include "WeberNumberReacting.H" @@ -55,6 +56,7 @@ License makeCloudFunctionObjectType(ParticleTrap, CloudType); \ makeCloudFunctionObjectType(PatchCollisionDensity, CloudType); \ makeCloudFunctionObjectType(PatchPostProcessing, CloudType); \ + makeCloudFunctionObjectType(PatchParticleHistogram, CloudType); \ makeCloudFunctionObjectType(RemoveParcels, CloudType); \ makeCloudFunctionObjectType(VoidFraction, CloudType); \ makeCloudFunctionObjectType(WeberNumberReacting, CloudType); diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchParticleHistogram/PatchParticleHistogram.C b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchParticleHistogram/PatchParticleHistogram.C new file mode 100644 index 0000000000..d60f1723dc --- /dev/null +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchParticleHistogram/PatchParticleHistogram.C @@ -0,0 +1,254 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2020 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "PatchParticleHistogram.H" +#include "Pstream.H" +#include "stringListOps.H" +#include "ListOps.H" +#include "ListListOps.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +Foam::label Foam::PatchParticleHistogram::applyToPatch +( + const label globalPatchi +) const +{ + return patchIDs_.find(globalPatchi); +} + + +// * * * * * * * * * * * * * protected Member Functions * * * * * * * * * * // + +template +void Foam::PatchParticleHistogram::write() +{ + forAll(times_, i) + { + List> procTimes(Pstream::nProcs()); + procTimes[Pstream::myProcNo()] = times_[i]; + Pstream::gatherList(procTimes); + + List> procDiameters(Pstream::nProcs()); + procDiameters[Pstream::myProcNo()] = patchDiameters_[i]; + Pstream::gatherList(procDiameters); + + List> procParticles(Pstream::nProcs()); + procParticles[Pstream::myProcNo()] = patchParticles_[i]; + Pstream::gatherList(procParticles); + + if (Pstream::master()) + { + const fvMesh& mesh = this->owner().mesh(); + + mkDir(this->writeTimeDir()); + + const word& patchName = mesh.boundaryMesh()[patchIDs_[i]].name(); + + OFstream patchOutFile + ( + this->writeTimeDir()/patchName + ".post", + IOstream::ASCII, + IOstream::currentVersion, + mesh.time().writeCompression() + ); + + List globalTimes; + globalTimes = ListListOps::combine> + ( + procTimes, + accessOp>() + ); + + List globalDiameters; + globalDiameters = ListListOps::combine> + ( + procDiameters, + accessOp>() + ); + + List globalParticles; + globalParticles = ListListOps::combine> + ( + procParticles, + accessOp>() + ); + + // Compute histogram + List nParticles(nBins_, Zero); + forAll(globalDiameters, j) + { + const label bini = (globalDiameters[j] - min_)/delta_; + if (bini >= 0 && bini < nBins_) + { + nParticles[bini] += globalParticles[j]; + nParticlesCumulative_[i][bini] += globalParticles[j]; + } + } + + patchOutFile + << "# nBin=" << nBins_ + << "; min=" << min_ + << "; max=" << max_ << nl + << "# d nParticles nParticlesCumulative" + << endl; + + forAll(nParticles, j) + { + patchOutFile + << binEdges_[j] + << "-" + << binEdges_[j + 1] + << " " + << nParticles[j] + << " " + << nParticlesCumulative_[i][j] + << nl; + } + } + + times_[i].clearStorage(); + patchDiameters_[i].clearStorage(); + patchParticles_[i].clearStorage(); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::PatchParticleHistogram::PatchParticleHistogram +( + const dictionary& dict, + CloudType& owner, + const word& modelName +) +: + CloudFunctionObject(dict, owner, modelName, typeName), + nBins_(dict.getCheck