From 271c8c8c6e75f5d13d7a1d46d7402df3fba9cb60 Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Tue, 29 Nov 2016 14:56:48 +0000 Subject: [PATCH] ENH: Added new extractEulerianParticles function object Generates discrete particle data from multiphase calculations by interrogating the phase fraction field at a faceZone. Data is written in raw form, i.e. per particle collected, with as an optional binned distribution --- src/functionObjects/field/Make/files | 2 + src/functionObjects/field/Make/options | 15 +- .../eulerianParticle/eulerianParticle.C | 104 ++ .../eulerianParticle/eulerianParticle.H | 155 +++ .../eulerianParticleTemplates.C | 88 ++ .../extractEulerianParticles.C | 893 ++++++++++++++++++ .../extractEulerianParticles.H | 346 +++++++ .../extractEulerianParticlesTemplates.C | 56 ++ 8 files changed, 1654 insertions(+), 5 deletions(-) create mode 100644 src/functionObjects/field/extractEulerianParticles/eulerianParticle/eulerianParticle.C create mode 100644 src/functionObjects/field/extractEulerianParticles/eulerianParticle/eulerianParticle.H create mode 100644 src/functionObjects/field/extractEulerianParticles/eulerianParticle/eulerianParticleTemplates.C create mode 100644 src/functionObjects/field/extractEulerianParticles/extractEulerianParticles/extractEulerianParticles.C create mode 100644 src/functionObjects/field/extractEulerianParticles/extractEulerianParticles/extractEulerianParticles.H create mode 100644 src/functionObjects/field/extractEulerianParticles/extractEulerianParticles/extractEulerianParticlesTemplates.C diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files index e8e4f79e4e..b4bbed1442 100644 --- a/src/functionObjects/field/Make/files +++ b/src/functionObjects/field/Make/files @@ -72,6 +72,8 @@ externalCoupled/externalCoupled.C externalCoupled/externalCoupledMixed/externalCoupledMixedFvPatchFields.C externalCoupled/externalCoupledTemperatureMixed/externalCoupledTemperatureMixedFvPatchScalarField.C +extractEulerianParticles/extractEulerianParticles/extractEulerianParticles.C + ddt2/ddt2.C zeroGradient/zeroGradient.C diff --git a/src/functionObjects/field/Make/options b/src/functionObjects/field/Make/options index ea32eb29ff..efaea7c1b8 100644 --- a/src/functionObjects/field/Make/options +++ b/src/functionObjects/field/Make/options @@ -2,6 +2,7 @@ EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \ + -I$(LIB_SRC)/lagrangian/distributionModels/lnInclude \ -I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/sampling/lnInclude \ -I$(LIB_SRC)/surfMesh/lnInclude \ @@ -19,18 +20,22 @@ EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/sampling/lnInclude \ - -I$(LIB_SRC)/surfMesh/lnInclude + -I$(LIB_SRC)/surfMesh/lnInclude \ + -I$(LIB_SRC)/fvAgglomerationMethods/pairPatchAgglomeration/lnInclude LIB_LIBS = \ -lfiniteVolume \ + -lmeshTools \ + -llagrangian \ + -ldistributionModels \ + -lsampling \ + -lsurfMesh \ -lfluidThermophysicalModels \ -lincompressibleTransportModels \ -lturbulenceModels \ -lcompressibleTransportModels \ -lincompressibleTurbulenceModels \ -lcompressibleTurbulenceModels \ - -lmeshTools \ - -lsampling \ - -lsurfMesh \ -lchemistryModel \ - -lreactionThermophysicalModels + -lreactionThermophysicalModels \ + -lpairPatchAgglomeration diff --git a/src/functionObjects/field/extractEulerianParticles/eulerianParticle/eulerianParticle.C b/src/functionObjects/field/extractEulerianParticles/eulerianParticle/eulerianParticle.C new file mode 100644 index 0000000000..8bc18a3ce3 --- /dev/null +++ b/src/functionObjects/field/extractEulerianParticles/eulerianParticle/eulerianParticle.C @@ -0,0 +1,104 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +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 "eulerianParticle.H" +#include "mathematicalConstants.H" + +using namespace Foam::constant; + +// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::eulerianParticle::eulerianParticle() +: + globalFaceIHit(-1), + VC(vector::zero), + VU(vector::zero), + V(0), + time(0), + timeIndex(0) +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +Foam::Ostream& Foam::operator<<(Ostream& os, const eulerianParticle& p) +{ + os << p.globalFaceIHit << token::SPACE + << p.VC << token::SPACE + << p.VU << token::SPACE + << p.V << token::SPACE + << p.time << token::SPACE + << p.timeIndex; + + return os; +} + + +Foam::Istream& Foam::operator>>(Istream& is, eulerianParticle& p) +{ + is >> p.globalFaceIHit + >> p.VC + >> p.VU + >> p.V + >> p.time + >> p.timeIndex; + + return is; +} + + +void Foam::functionObjects::eulerianParticle::write(Ostream& os) const +{ + scalar pDiameter = cbrt(6*V/constant::mathematical::pi); + vector U = VU/(V + ROOTVSMALL); + vector C = VC/(V + ROOTVSMALL); + + os << time << token::SPACE + << globalFaceIHit << token::SPACE + << C << token::SPACE + << pDiameter << token::SPACE + << U << token::SPACE + << endl; +} + + +Foam::dictionary Foam::functionObjects::eulerianParticle::writeDict() const +{ + scalar pDiameter = cbrt(6*V/constant::mathematical::pi); + vector U = VU/(V + ROOTVSMALL); + vector C = VC/(V + ROOTVSMALL); + + dictionary dict; + dict.add("time", time); + dict.add("meshFace", globalFaceIHit); + dict.add("position", C); + dict.add("diameter", pDiameter); + dict.add("U", U); + + return dict; +} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/extractEulerianParticles/eulerianParticle/eulerianParticle.H b/src/functionObjects/field/extractEulerianParticles/eulerianParticle/eulerianParticle.H new file mode 100644 index 0000000000..e5d4bfc2b4 --- /dev/null +++ b/src/functionObjects/field/extractEulerianParticles/eulerianParticle/eulerianParticle.H @@ -0,0 +1,155 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +Class + Foam::eulerianParticle + +Description + Lightweight class to store particle data derived from VOF calculations, + with special handling for input, output and parallel reduction. + +SourceFiles + eulerianParticle.H + eulerianParticle.C + eulerianParticleTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_eulerianParticle_H +#define functionObjects_eulerianParticle_H + +#include "label.H" +#include "scalar.H" +#include "vector.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +// Forward declaration of classes +class Istream; +class Ostream; + +namespace functionObjects +{ + class eulerianParticle; +} + +// Forward declaration of friend functions and operators +Istream& operator>>(Istream&, functionObjects::eulerianParticle&); +Ostream& operator<<(Ostream&, const functionObjects::eulerianParticle&); + +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class eulerianParticle Declaration +\*---------------------------------------------------------------------------*/ + +class eulerianParticle +{ + +public: + + // Public data + + //- Index of face in faceZone that this particle hits. Also used to + // identify the index of the coarse face of the surface agglomeration + // Note: value of -1 used to indicate that the particle has not + // been initialised + label globalFaceIHit; + + //- Volume multiplied by face centres [m4] + vector VC; + + //- Volume multiplied by velocity [m4/s] + vector VU; + + //- Volume [m3] + scalar V; + + //- Injection time - set at collection [s] + scalar time; + + //- Index of last output time + label timeIndex; + + + //- Constructor + eulerianParticle(); + + + // Public Member Functions + + //- Write to stream + void write(Ostream& os) const; + + //- Write to dictionary + Foam::dictionary writeDict() const; + + + // Operators + + friend bool operator== + ( + const eulerianParticle& a, + const eulerianParticle& b + ) + { + return + a.globalFaceIHit == b.globalFaceIHit + && a.VC == b.VC + && a.VU == b.VU + && a.V == b.V + && a.time == b.time + && a.timeIndex == b.timeIndex; + } + + friend bool operator!= + ( + const eulerianParticle& a, + const eulerianParticle& b + ) + { + return !(a == b); + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "eulerianParticleTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/functionObjects/field/extractEulerianParticles/eulerianParticle/eulerianParticleTemplates.C b/src/functionObjects/field/extractEulerianParticles/eulerianParticle/eulerianParticleTemplates.C new file mode 100644 index 0000000000..d0fbee15fe --- /dev/null +++ b/src/functionObjects/field/extractEulerianParticles/eulerianParticle/eulerianParticleTemplates.C @@ -0,0 +1,88 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +\*---------------------------------------------------------------------------*/ + +namespace Foam +{ +namespace functionObjects +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +class sumParticleOp +{ + public: + eulerianParticle operator() + ( + const eulerianParticle& p0, + const eulerianParticle& p1 + ) const + { + if ((p0.globalFaceIHit != -1) && (p1.globalFaceIHit == -1)) + { + return p0; + } + else if ((p0.globalFaceIHit == -1) && (p1.globalFaceIHit != -1)) + { + return p1; + } + else if ((p0.globalFaceIHit != -1) && (p1.globalFaceIHit != -1)) + { + // Choose particle with the largest collected volume and + // accumulate total volume + if (p0.V > p1.V) + { + eulerianParticle p = p0; + p.V = p0.V + p1.V; + p.VC = p0.VC + p1.VC; + p.VU = p0.VU + p1.VU; + return p; + } + else + { + eulerianParticle p = p1; + p.V = p0.V + p1.V; + p.VC = p0.VC + p1.VC; + p.VU = p0.VU + p1.VU; + return p; + } + } + else + { + eulerianParticle p; + return p; + } + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// ************************************************************************* // diff --git a/src/functionObjects/field/extractEulerianParticles/extractEulerianParticles/extractEulerianParticles.C b/src/functionObjects/field/extractEulerianParticles/extractEulerianParticles/extractEulerianParticles.C new file mode 100644 index 0000000000..60821e8092 --- /dev/null +++ b/src/functionObjects/field/extractEulerianParticles/extractEulerianParticles/extractEulerianParticles.C @@ -0,0 +1,893 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +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 "extractEulerianParticles.H" +#include "regionSplit2D.H" +#include "mathematicalConstants.H" +#include "volFields.H" +#include "surfaceFields.H" +#include "surfaceInterpolate.H" +#include "pairPatchAgglomeration.H" +#include "emptyPolyPatch.H" +#include "coupledPolyPatch.H" +#include "binned.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(extractEulerianParticles, 0); + + addToRunTimeSelectionTable + ( + functionObject, + extractEulerianParticles, + dictionary + ); +} +} + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +Foam::fileName +Foam::functionObjects::extractEulerianParticles::dictBaseFileDir() const +{ + fileName baseDir(".."); // = obr_.time().path(); + + if (Pstream::parRun()) + { + // Put in undecomposed case (Note: gives problems for + // distributed data running) + baseDir = baseDir/".."/"postProcessing"; + } + else + { + baseDir = baseDir/"postProcessing"; + } + + return baseDir; +} + + +void Foam::functionObjects::extractEulerianParticles::checkFaceZone() +{ + DebugInFunction << endl; + + zoneID_ = mesh_.faceZones().findZoneID(faceZoneName_); + if (zoneID_ == -1) + { + FatalErrorInFunction + << "Unable to find faceZone " << faceZoneName_ + << ". Available faceZones are: " + << exit(FatalError); + } + + const faceZone& fz = mesh_.faceZones()[zoneID_]; + const label nFaces = fz.size(); + const label allFaces = returnReduce(nFaces, sumOp