velocityGroup.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017-2019 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "velocityGroup.H"
30 #include "sizeGroup.H"
31 #include "populationBalanceModel.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace diameterModels
40 {
41  defineTypeNameAndDebug(velocityGroup, 0);
42 
44  (
45  diameterModel,
46  velocityGroup,
47  dictionary
48  );
49 }
50 }
51 
52 
53 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
54 
55 Foam::tmp<Foam::volScalarField> Foam::diameterModels::velocityGroup::dsm() const
56 {
57  tmp<volScalarField> tInvDsm
58  (
60  (
61  "invDsm",
62  phase_.mesh(),
64  )
65  );
66 
67  volScalarField& invDsm = tInvDsm.ref();
68 
69  forAll(sizeGroups_, i)
70  {
71  const sizeGroup& fi = sizeGroups_[i];
72 
73  invDsm += fi/fi.d();
74  }
75 
76  return 1.0/tInvDsm;
77 }
78 
79 
81 Foam::diameterModels::velocityGroup::fSum() const
82 {
83  tmp<volScalarField> tsumSizeGroups
84  (
86  (
87  "sumSizeGroups",
88  phase_.mesh(),
89  dimensionedScalar("zero", dimless, 0)
90  )
91  );
92 
93  volScalarField& sumSizeGroups = tsumSizeGroups.ref();
94 
95  forAll(sizeGroups_, i)
96  {
97  sumSizeGroups += sizeGroups_[i];
98  }
99 
100  return tsumSizeGroups;
101 }
102 
103 
104 void Foam::diameterModels::velocityGroup::renormalize()
105 {
106  Info<< "Renormalizing sizeGroups for velocityGroup "
107  << phase_.name()
108  << endl;
109 
110  // Set negative values to zero
111  forAll(sizeGroups_, i)
112  {
113  sizeGroups_[i] *= pos(sizeGroups_[i]);
114  };
115 
116  forAll(sizeGroups_, i)
117  {
118  sizeGroups_[i] /= fSum_;
119  };
120 }
121 
122 
124 Foam::diameterModels::velocityGroup::mvconvection() const
125 {
126  tmp<fv::convectionScheme<Foam::scalar>> mvConvection
127  (
129  (
130  phase_.mesh(),
131  fields_,
132  phase_.alphaRhoPhi(),
133  phase_.mesh().divScheme
134  (
135  "div(" + phase_.alphaRhoPhi()().name() + ",f)"
136  )
137  )
138  );
139 
140  return mvConvection;
141 }
142 
143 
144 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
145 
147 (
148  const dictionary& diameterProperties,
149  const phaseModel& phase
150 )
151 :
152  diameterModel(diameterProperties, phase),
153  popBalName_(diameterProperties.lookup("populationBalance")),
154  f_
155  (
156  IOobject
157  (
159  (
160  "f",
162  (
163  phase.name(),
164  popBalName_
165  )
166  ),
167  phase.time().timeName(),
168  phase.mesh(),
171  ),
172  phase.mesh()
173  ),
174  formFactor_("formFactor", dimless, diameterProperties),
175  sizeGroups_
176  (
177  diameterProperties.lookup("sizeGroups"),
178  sizeGroup::iNew(phase, *this)
179  ),
180  fSum_
181  (
182  IOobject
183  (
185  (
186  "fsum",
188  (
189  phase.name(),
190  popBalName_
191  )
192  ),
193  phase.time().timeName(),
194  phase.mesh()
195  ),
196  fSum()
197  ),
198  d_
199  (
200  IOobject
201  (
203  phase.time().timeName(),
204  phase.mesh(),
207  ),
208  phase.mesh(),
210  ),
211  dmdt_
212  (
213  IOobject
214  (
215  IOobject::groupName("source", phase.name()),
216  phase.time().timeName(),
217  phase.mesh()
218  ),
219  phase.mesh(),
221  )
222 {
223  if
224  (
225  phase_.mesh().solverDict(popBalName_).getOrDefault<Switch>
226  (
227  "renormalizeAtRestart",
228  false
229  )
230  ||
231  phase_.mesh().solverDict(popBalName_).getOrDefault<Switch>
232  (
233  "renormalize",
234  false
235  )
236  )
237  {
238  renormalize();
239  }
240 
241  fSum_ = fSum();
242 
243  if
244  (
245  mag(1 - fSum_.weightedAverage(fSum_.mesh().V()).value()) >= 1e-5
246  || mag(1 - max(fSum_).value()) >= 1e-5
247  || mag(1 - min(fSum_).value()) >= 1e-5
248  )
249  {
251  << " Initial values of the sizeGroups belonging to velocityGroup "
252  << this->phase().name()
253  << " must add to" << nl << " unity. This condition might be"
254  << " violated due to wrong entries in the" << nl
255  << " velocityGroupCoeffs subdictionary or bad initial conditions in"
256  << " the startTime" << nl
257  << " directory. The sizeGroups can be renormalized at every"
258  << " timestep or at restart" << nl
259  << " only by setting the corresponding switch renormalize or"
260  << " renormalizeAtRestart" << nl
261  << " in the fvSolution subdictionary " << popBalName_ << "."
262  << " Note that boundary conditions are not" << nl << "renormalized."
263  << exit(FatalError);
264  }
265 
266  forAll(sizeGroups_, i)
267  {
268  fields_.add(sizeGroups_[i]);
269  }
270 
271  d_ = dsm();
272 }
273 
274 
275 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
276 
278 {}
279 
280 
281 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
282 
283 
285 {
286  mvConvection_ = mvconvection();
287 }
288 
289 
291 {
292  d_ = dsm();
293 
294  Info<< this->phase().name() << " Sauter mean diameter, min, max = "
295  << d_.weightedAverage(d_.mesh().V()).value()
296  << ' ' << min(d_).value()
297  << ' ' << max(d_).value()
298  << endl;
299 
300  fSum_ = fSum();
301 
302  Info<< phase_.name() << " sizeGroups-sum volume fraction, min, max = "
303  << fSum_.weightedAverage(phase_.mesh().V()).value()
304  << ' ' << min(fSum_).value()
305  << ' ' << max(fSum_).value()
306  << endl;
307 
308  if
309  (
310  phase_.mesh().solverDict(popBalName_).getOrDefault<Switch>
311  (
312  "renormalize",
313  false
314  )
315  )
316  {
317  renormalize();
318  }
319 }
320 
321 
324 {
326 
327  return true;
328 }
329 
330 
333 {
334  return d_;
335 }
336 
337 // ************************************************************************* //
Foam::diameterModels::velocityGroup::velocityGroup
velocityGroup(const dictionary &diameterProperties, const phaseModel &phase)
Construct from components.
Definition: velocityGroup.C:147
populationBalanceModel.H
Foam::phaseModel
Single incompressible phase derived from the phase-fraction. Used as part of the multiPhaseMixture fo...
Definition: phaseModel.H:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:77
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:52
Foam::phase
Single incompressible phase derived from the phase-fraction. Used as part of the multiPhaseMixture fo...
Definition: phase.H:54
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::dimDensity
const dimensionSet dimDensity
Foam::diameterModels::velocityGroup::read
virtual bool read(const dictionary &diameterProperties)
Read diameterProperties dictionary.
Definition: velocityGroup.C:323
Foam::fv::convectionScheme::New
static tmp< convectionScheme< Type > > New(const fvMesh &mesh, const surfaceScalarField &faceFlux, Istream &schemeData)
Return a pointer to a new convectionScheme created on freestore.
Definition: convectionScheme.C:61
Foam::phaseProperties
Helper class to manage multi-specie phase properties.
Definition: phaseProperties.H:60
Foam::diameterModel
Abstract base-class for dispersed-phase particle diameter models.
Definition: diameterModel.H:53
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::diameterModels::velocityGroup::~velocityGroup
virtual ~velocityGroup()
Destructor.
Definition: velocityGroup.C:277
velocityGroup.H
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::GeometricField< scalar, fvPatchField, volMesh >::New
static tmp< GeometricField< scalar, fvPatchField, volMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &ds, const word &patchFieldType=fvPatchField< scalar >::calculatedType())
Return tmp field from name, mesh, dimensions and patch type.
Definition: GeometricFieldNew.C:34
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:53
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:73
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::diameterModels::velocityGroup::postSolve
void postSolve()
Corrections after populationBalanceModel::solve()
Definition: velocityGroup.C:290
Foam::diameterModels::defineTypeNameAndDebug
defineTypeNameAndDebug(constant, 0)
sizeGroup.H
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:42
mvConvection
tmp< fv::convectionScheme< scalar > > mvConvection(fv::convectionScheme< scalar >::New(mesh, fields, phi, mesh.divScheme("div(phi,Yi_h)")))
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::dictionary::lookup
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:386
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::phase::name
const word & name() const
Definition: phase.H:111
Foam::diameterModel::phase_
const phaseModel & phase_
Definition: diameterModel.H:61
Foam::diameterModels::velocityGroup::preSolve
void preSolve()
Corrections before populationBalanceModel::solve()
Definition: velocityGroup.C:284
Foam::phaseModel::name
const word & name() const
Definition: phaseModel.H:140
Foam::diameterModels::velocityGroup::d
virtual tmp< volScalarField > d() const
Return the Sauter-mean diameter.
Definition: velocityGroup.C:332
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::diameterModels::sizeGroup::iNew
Return a pointer to a new sizeGroup created on freestore.
Definition: sizeGroup.H:136
Foam::GeometricField::ref
Internal & ref(const bool updateAccessTime=true)
Return a reference to the dimensioned internal field.
Definition: GeometricField.C:749
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::diameterModel::read
virtual bool read(const dictionary &phaseProperties)=0
Read phaseProperties dictionary.
Definition: diameterModel.C:96
Foam::IOobject::groupName
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
Foam::diameterModels::addToRunTimeSelectionTable
addToRunTimeSelectionTable(diameterModel, constant, dictionary)
Foam::IOobject::NO_READ
Definition: IOobject.H:188
zeroGradientFvPatchFields.H
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition: dimensionSets.C:189
Foam::IOobject::MUST_READ
Definition: IOobject.H:185
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177