populationBalance.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) 2017-2026 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 
26 #include "populationBalance.H"
28 #include "populationBalanceModel.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace diameterModels
35 {
38 
39  // Backwards compatible lookup as "velocityGroup"
41  (
44  dictionary,
45  velocityGroup
46  );
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 (
55  const dictionary& diameterProperties,
56  const phaseModel& phase
57 )
58 :
59  diameterModel(diameterProperties, phase),
60  popBalName_(diameterProperties.lookup("populationBalance")),
61  popBalPtr_(nullptr),
62  nGroups_(diameterProperties.lookup<label>("nGroups")),
63  iFirst_(-1),
64  d_
65  (
66  IOobject
67  (
68  IOobject::groupName("d", phase.name()),
69  phase.time().name(),
70  phase.mesh(),
71  IOobject::NO_READ,
72  IOobject::AUTO_WRITE
73  ),
74  phase.mesh(),
75  dimensionedScalar("d", dimLength, NaN)
76  )
77 {}
78 
79 
80 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
81 
83 {}
84 
85 
86 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
87 
90 {
91  if (popBalPtr_ == nullptr)
92  {
93  popBalPtr_ =
94  &phase().mesh().lookupObject<populationBalanceModel>(popBalName_);
95  }
96 
97  return *popBalPtr_;
98 }
99 
100 
102 {
103  if (iFirst_ == -1)
104  {
105  const UPtrList<const populationBalance>& uniqueDiameters =
106  popBal().uniqueDiameters();
107 
108  // Determine the unique phase index within the population balance
109  label uniquePhasei = -1;
110  forAll(uniqueDiameters, uniquePhasej)
111  {
112  if (&uniqueDiameters[uniquePhasej] == this)
113  {
114  uniquePhasei = uniquePhasej;
115  break;
116  }
117  }
118 
119  // If this is the first unique phase, then the first group of this
120  // phase is the first of the entire population balance. Otherwise it is
121  // the group immediately after those in the previous unique phase.
122  iFirst_ =
123  uniquePhasei == 0
124  ? 0
125  : uniqueDiameters[uniquePhasei - 1].iLast() + 1;
126  }
127 
128  return iFirst_;
129 }
130 
131 
134 {
135  return d_;
136 }
137 
138 
141 {
142  tmp<volScalarField> tsumFiAbyV
143  (
145  (
146  "sumFiAbyV",
147  phase().mesh(),
149  )
150  );
151  volScalarField& sumFiAbyV = tsumFiAbyV.ref();
152 
153  const populationBalanceModel& popBal = this->popBal();
154 
155  for (label i = iFirst(); i <= iLast(); ++ i)
156  {
157  sumFiAbyV += popBal.f(i)*popBal.a(i)/popBal.v(i);
158  }
159 
160  return phase()*tsumFiAbyV;
161 }
162 
163 
166 {
169  (
170  "sumFi",
171  phase().mesh(),
173  );
174  volScalarField::Internal& sumFi = tsumFi.ref();
175 
176  const populationBalanceModel& popBal = this->popBal();
177 
178  for (label i = iFirst(); i <= iLast(); ++ i)
179  {
180  sumFi += popBal.f(i)();
181  }
182 
183  return tsumFi;
184 }
185 
186 
188 {
189  const populationBalanceModel& popBal = this->popBal();
190 
191  if (popBal.solveOnFinalIterOnly() && !popBal.fluid().pimple().finalIter())
192  {
193  return;
194  }
195 
196  tmp<volScalarField> tsumFi
197  (
199  (
200  "sumFi",
201  phase().mesh(),
203  )
204  );
205  tmp<volScalarField> tsumFiAbyV
206  (
208  (
209  "sumFiAbyV",
210  phase().mesh(),
212  )
213  );
214  volScalarField& sumFi = tsumFi.ref();
215  volScalarField& sumFiAbyV = tsumFiAbyV.ref();
216 
217  for (label i = iFirst(); i <= iLast(); ++ i)
218  {
219  sumFi += max(popBal.f(i), rootVSmall);
220  sumFiAbyV += max(popBal.f(i), rootVSmall)*popBal.a(i)/popBal.v(i);
221  }
222 
223  d_ = 6*sumFi/tsumFiAbyV;
224 
225  Info<< indent << phase().name() << " min/Sauter-mean/max diameter = "
226  << min(d_).value() << '/' << d_.weightedAverage(d_.mesh().V()).value()
227  << '/' << max(d_).value() << endl;
228 }
229 
230 
232 (
233  const dictionary& diameterProperties
234 )
235 {
236  return true;
237 }
238 
239 
240 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
static tmp< DimensionedField< Type, GeoMesh, PrimitiveField > > New(const word &name, const GeoMesh &mesh, const dimensionSet &, const PrimitiveField< Type > &)
Return a temporary field constructed from name, mesh,.
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,.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.H:297
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:66
Abstract base-class for dispersed-phase particle diameter models.
Definition: diameterModel.H:52
virtual bool read()
Read diameter properties dictionary.
Definition: diameterModel.C:62
This diameter model computes the diameter from multiple size group diameters and fractions provided b...
virtual void correct()
Correct the model.
populationBalance(const dictionary &diameterProperties, const phaseModel &phase)
Construct from dictionary and phase.
label iFirst() const
Return the index of the first group of this phase.
virtual tmp< volScalarField > d() const
Get the diameter field.
const populationBalanceModel & popBal() const
Return the populationBalance this populationBalance belongs to.
virtual tmp< volScalarField > Av() const
Get the surface area per unit volume field.
tmp< volScalarField::Internal > fSum() const
...
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
const pimpleNoLoopControl & pimple() const
Return pimpleNoLoopControl.
Definition: phaseSystemI.H:97
bool finalIter() const
Flag to indicate the final iteration.
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 dimensionedScalar & v(const label i) const
Access the representative volumes diameters of a group.
const phaseSystem & fluid() const
Return reference to the phaseSystem.
bool solveOnFinalIterOnly() const
Solve on final pimple iteration only.
const fvMesh & mesh() const
Return reference to the mesh.
tmp< volScalarField > a(const label i) const
Return the representative surface area of the group.
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
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
addNamedToRunTimeSelectionTable(diameterModel, populationBalance, dictionary, velocityGroup)
addToRunTimeSelectionTable(diameterModel, constant, dictionary)
defineTypeNameAndDebug(constant, 0)
const dimensionSet time
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
const dimensionSet & dimless
Definition: dimensions.C:138
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
void inv(pointPatchField< tensor > &, const pointPatchField< tensor > &)
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:243
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.