populationBalanceSetSizeDistribution.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2024-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 #include "distribution.H"
29 #include "populationBalance.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
39  (
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
52 (
53  const word& name,
54  const Time& runTime,
55  const dictionary& dict
56 )
57 :
58  fvMeshFunctionObject(name, runTime, dict),
59  popBalName_(dict.lookupOrDefault("populationBalance", word::null)),
60  phaseName_(dict.lookupOrDefault("phase", word::null)),
61  distribution_
62  (
63  distribution::New(dimLength, dict.subDict("distribution"), 3, -1)
64  )
65 {
66  const bool havePopBal = popBalName_ != word::null;
67  const bool havePhase = phaseName_ != word::null;
68  if (havePopBal == havePhase)
69  {
71  << (havePopBal ? "both" : "neither") << " of keywords "
72  << "populationBalance " << (havePopBal ? "and" : "or")
73  << " phase defined in dictionary " << dict.name()
74  << exit(FatalIOError);
75  }
76 
77  read(dict);
78 }
79 
80 
81 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
82 
85 {}
86 
87 
88 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 
91 {
92  return true;
93 }
94 
95 
97 {
99  {
101  << "The " << typeName << " function cannot be executed at run-time"
102  << endl;
103 
104  return false;
105  }
106 
107  Info<< nl << indent << name() << token::COLON << endl << incrIndent;
108 
109  if (popBalName_ != word::null)
110  {
111  populationBalanceModel& popBal =
112  obr_.lookupObjectRef<populationBalanceModel>(popBalName_);
113 
115 
116  // Set the group fractions for the population balance
117  forAll(popBal.fs(), i)
118  {
119  volScalarField& fi = popBal.f(i);
120 
121  fi == popBal.etaV(i, distribution_());
122 
123  Info<< indent << "Writing " << fi.name() << endl;
124 
125  fi.write();
126 
127  diameterPtrs.insert
128  (
129  popBal.phases()[i].name(),
130  &popBal.diameters()[i]
131  );
132  }
133 
134  // Set the volume fractions if there are multiple phases in this
135  // population balance
136  if (diameterPtrs.size() > 1)
137  {
138  tmp<volScalarField> talphas =
140  (
141  IOobject::groupName("alpha", popBal.name()),
142  mesh(),
143  dimensionedScalar(dimless, scalar(0))
144  );
145  volScalarField& alphas = talphas.ref();
146 
148  (
150  diameterPtrs,
151  iter
152  )
153  {
154  alphas += iter()->phase();
155  }
156 
158  (
160  diameterPtrs,
161  iter
162  )
163  {
165  const_cast<phaseModel&>(iter()->phase());
166 
167  const label i0 = iter()->iFirst();
168  const label i1 = iter()->iLast();
169 
170  alpha == popBal.etaV(labelPair(i0, i1), distribution_)*alphas;
171 
172  Info<< indent << "Writing " << alpha.name() << endl;
173 
174  alpha.write();
175  }
176  }
177  }
178  else
179  {
181  refCast<diameterModels::populationBalance>
182  (
183  obr_.lookupObjectRef<phaseSystem>
184  (
186  ).phases()[phaseName_].diameter()
187  );
188 
189  populationBalanceModel& popBal =
190  obr_.lookupObjectRef<populationBalanceModel>(diameter.popBalName());
191 
192  // Set the group fractions for this phase
193  for (label i = diameter.iFirst(); i <= diameter.iLast(); ++ i)
194  {
195  volScalarField& fi = popBal.f(i);
196 
197  fi == popBal.etaV(i, distribution_());
198 
199  Info<< indent << "Writing " << fi.name() << endl;
200 
201  fi.write();
202  }
203  }
204 
205  Info<< decrIndent;
206 
207  return true;
208 }
209 
210 
211 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
Macros for easy insertion into run-time selection tables.
Generic GeometricField class.
static tmp< GeometricField< Type, GeoMesh, PrimitiveField > > New(const word &name, const Internal &, const PtrList< Patch > &, const HashPtrTable< Source > &=HashPtrTable< Source >())
Return a temporary field constructed from name,.
An STL-conforming hash table.
Definition: HashTable.H:127
const word & name() const
Return name.
Definition: IOobject.H:307
static word groupName(Name name, const word &group)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
This diameter model computes the diameter from multiple size group diameters and fractions provided b...
label iLast() const
Return the index of the last group of this phase.
label iFirst() const
Return the index of the first group of this phase.
const word & popBalName() const
Return name of populationBalance this populationBalance belongs to.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Base class for statistical distributions.
Definition: distribution.H:76
Abstract base-class for Time/database functionObjects.
static bool postProcess
Global post-processing mode switch.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
virtual bool read(const dictionary &)
Read optional controls.
Sets the population balance size distribution by overwriting the values in the group fraction fields ...
populationBalanceSetSizeDistribution(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual bool write()
Calculate and write the group fraction fields.
Class to represent a system of phases.
Definition: phaseSystem.H:74
static const word propertiesName
Default name of the phase properties dictionary.
Definition: phaseSystem.H:252
const phaseModelList & phases() const
Return the phase models.
Definition: phaseSystemI.H:104
Model for tracking the evolution of a dispersed phase size distribution due to coalescence (synonymou...
const volScalarField & f(const label i) const
Access a group fraction.
const UPtrList< const diameterModels::populationBalance > & diameters() const
Access the list of diameter models associated with each group.
dimensionedScalar etaV(const label i, const dimensionedScalar &v) const
Return the volume allocation coefficient for a single volume.
const UPtrList< const phaseModel > & phases() const
Access the list of phases associated with each group.
const PtrList< volScalarField > & fs() const
Access the group fractions.
virtual bool write(const bool write=true) const
Write using setting from DB.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
#define WarningInFunction
Report a warning using Foam::Warning.
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, dictionary)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Pair< label > labelPair
Label pair.
Definition: labelPair.H:48
const dimensionSet & dimless
Definition: dimensions.C:138
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:272
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
const dimensionSet & dimLength
Definition: dimensions.C:141
messageStream Info
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:265
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:243
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
static const char nl
Definition: Ostream.H:297
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dictionary dict