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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "velocityGroup.H"
29 #include "sizeGroup.H"
30 #include "populationBalanceModel.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace diameterModels
39 {
40  defineTypeNameAndDebug(velocityGroup, 0);
41 
43  (
44  diameterModel,
45  velocityGroup,
46  dictionary
47  );
48 }
49 }
50 
51 
52 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
53 
54 Foam::tmp<Foam::volScalarField> Foam::diameterModels::velocityGroup::dsm() const
55 {
56  tmp<volScalarField> tInvDsm
57  (
59  (
60  "invDsm",
61  phase_.mesh(),
63  )
64  );
65 
66  volScalarField& invDsm = tInvDsm.ref();
67 
68  forAll(sizeGroups_, i)
69  {
70  const sizeGroup& fi = sizeGroups_[i];
71 
72  invDsm += fi/fi.d();
73  }
74 
75  return 1.0/tInvDsm;
76 }
77 
78 
80 Foam::diameterModels::velocityGroup::fSum() const
81 {
82  tmp<volScalarField> tsumSizeGroups
83  (
85  (
86  "sumSizeGroups",
87  phase_.mesh(),
88  dimensionedScalar("zero", dimless, 0)
89  )
90  );
91 
92  volScalarField& sumSizeGroups = tsumSizeGroups.ref();
93 
94  forAll(sizeGroups_, i)
95  {
96  sumSizeGroups += sizeGroups_[i];
97  }
98 
99  return tsumSizeGroups;
100 }
101 
102 
103 void Foam::diameterModels::velocityGroup::renormalize()
104 {
105  Info<< "Renormalizing sizeGroups for velocityGroup "
106  << phase_.name()
107  << endl;
108 
109  // Set negative values to zero
110  forAll(sizeGroups_, i)
111  {
112  sizeGroups_[i] *= pos(sizeGroups_[i]);
113  };
114 
115  forAll(sizeGroups_, i)
116  {
117  sizeGroups_[i] /= fSum_;
118  };
119 }
120 
121 
123 Foam::diameterModels::velocityGroup::mvconvection() const
124 {
125  tmp<fv::convectionScheme<Foam::scalar>> mvConvection
126  (
128  (
129  phase_.mesh(),
130  fields_,
131  phase_.alphaRhoPhi(),
132  phase_.mesh().divScheme
133  (
134  "div(" + phase_.alphaRhoPhi()().name() + ",f)"
135  )
136  )
137  );
138 
139  return mvConvection;
140 }
141 
142 
143 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
144 
146 (
147  const dictionary& diameterProperties,
148  const phaseModel& phase
149 )
150 :
151  diameterModel(diameterProperties, phase),
152  popBalName_(diameterProperties.lookup("populationBalance")),
153  f_
154  (
155  IOobject
156  (
158  (
159  "f",
161  (
162  phase.name(),
163  popBalName_
164  )
165  ),
166  phase.time().timeName(),
167  phase.mesh(),
170  ),
171  phase.mesh()
172  ),
173  formFactor_("formFactor", dimless, diameterProperties),
174  sizeGroups_
175  (
176  diameterProperties.lookup("sizeGroups"),
177  sizeGroup::iNew(phase, *this)
178  ),
179  fSum_
180  (
181  IOobject
182  (
184  (
185  "fsum",
187  (
188  phase.name(),
189  popBalName_
190  )
191  ),
192  phase.time().timeName(),
193  phase.mesh()
194  ),
195  fSum()
196  ),
197  d_
198  (
199  IOobject
200  (
202  phase.time().timeName(),
203  phase.mesh(),
206  ),
207  phase.mesh(),
209  ),
210  dmdt_
211  (
212  IOobject
213  (
214  IOobject::groupName("source", phase.name()),
215  phase.time().timeName(),
216  phase.mesh()
217  ),
218  phase.mesh(),
220  )
221 {
222  if
223  (
224  phase_.mesh().solverDict(popBalName_).lookupOrDefault<Switch>
225  (
226  "renormalizeAtRestart",
227  false
228  )
229  ||
230  phase_.mesh().solverDict(popBalName_).lookupOrDefault<Switch>
231  (
232  "renormalize",
233  false
234  )
235  )
236  {
237  renormalize();
238  }
239 
240  fSum_ = fSum();
241 
242  if
243  (
244  mag(1 - fSum_.weightedAverage(fSum_.mesh().V()).value()) >= 1e-5
245  || mag(1 - max(fSum_).value()) >= 1e-5
246  || mag(1 - min(fSum_).value()) >= 1e-5
247  )
248  {
250  << " Initial values of the sizeGroups belonging to velocityGroup "
251  << this->phase().name()
252  << " must add to" << nl << " unity. This condition might be"
253  << " violated due to wrong entries in the" << nl
254  << " velocityGroupCoeffs subdictionary or bad initial conditions in"
255  << " the startTime" << nl
256  << " directory. The sizeGroups can be renormalized at every"
257  << " timestep or at restart" << nl
258  << " only by setting the corresponding switch renormalize or"
259  << " renormalizeAtRestart" << nl
260  << " in the fvSolution subdictionary " << popBalName_ << "."
261  << " Note that boundary conditions are not" << nl << "renormalized."
262  << exit(FatalError);
263  }
264 
265  forAll(sizeGroups_, i)
266  {
267  fields_.add(sizeGroups_[i]);
268  }
269 
270  d_ = dsm();
271 }
272 
273 
274 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
275 
277 {}
278 
279 
280 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
281 
282 
284 {
285  mvConvection_ = mvconvection();
286 }
287 
288 
290 {
291  d_ = dsm();
292 
293  Info<< this->phase().name() << " Sauter mean diameter, min, max = "
294  << d_.weightedAverage(d_.mesh().V()).value()
295  << ' ' << min(d_).value()
296  << ' ' << max(d_).value()
297  << endl;
298 
299  fSum_ = fSum();
300 
301  Info<< phase_.name() << " sizeGroups-sum volume fraction, min, max = "
302  << fSum_.weightedAverage(phase_.mesh().V()).value()
303  << ' ' << min(fSum_).value()
304  << ' ' << max(fSum_).value()
305  << endl;
306 
307  if
308  (
309  phase_.mesh().solverDict(popBalName_).lookupOrDefault<Switch>
310  (
311  "renormalize",
312  false
313  )
314  )
315  {
316  renormalize();
317  }
318 }
319 
320 
323 {
325 
326  return true;
327 }
328 
329 
332 {
333  return d_;
334 }
335 
336 // ************************************************************************* //
Foam::diameterModels::defineTypeNameAndDebug
defineTypeNameAndDebug(constant, 0)
Foam::diameterModels::velocityGroup::velocityGroup
velocityGroup(const dictionary &diameterProperties, const phaseModel &phase)
Construct from components.
Definition: velocityGroup.C:146
populationBalanceModel.H
Foam::phaseModel
Single incompressible phase derived from the phase-fraction. Used as part of the multiPhaseMixture fo...
Definition: phaseModel.H:57
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:70
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:129
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:53
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:59
Foam::dimDensity
const dimensionSet dimDensity
Foam::diameterModels::velocityGroup::read
virtual bool read(const dictionary &diameterProperties)
Read diameterProperties dictionary.
Definition: velocityGroup.C:322
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:62
Foam::diameterModels::addToRunTimeSelectionTable
addToRunTimeSelectionTable(diameterModel, constant, dictionary)
Foam::diameterModel
A2stract 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:337
Foam::diameterModels::velocityGroup::~velocityGroup
virtual ~velocityGroup()
Destructor.
Definition: velocityGroup.C:276
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:290
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:54
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:73
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::diameterModels::velocityGroup::postSolve
void postSolve()
Corrections after populationBalanceModel::solve()
Definition: velocityGroup.C:289
sizeGroup.H
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
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:419
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:121
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:283
Foam::phaseModel::name
const word & name() const
Return the name of this phase.
Definition: phaseModel.C:94
Foam::diameterModels::velocityGroup::d
virtual tmp< volScalarField > d() const
Return the Sauter-mean diameter.
Definition: velocityGroup.C:331
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::nl
constexpr char nl
Definition: Ostream.H:372
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:718
Foam::IOobject::groupName
static word groupName(StringType name, const word &group)
Create dot-delimited name.group.
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::diameterModel::read
virtual bool read(const dictionary &phaseProperties)=0
Read phaseProperties dictionary.
Definition: diameterModel.C:64
Foam::IOobject::NO_READ
Definition: IOobject.H:123
zeroGradientFvPatchFields.H
Foam::IOobject::MUST_READ
Definition: IOobject.H:120
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177