multicomponentLagrangianThermo.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) 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 "LagrangianFieldsFwd.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
35 }
36 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 (
42  const dictionary& dict,
43  const speciesTable& species,
44  const LagrangianMesh& mesh,
45  const word& phaseName
46 )
47 :
48  defaultSpecieName_
49  (
50  species.size()
51  ? dict.lookup<word>("defaultSpecie")
52  : "undefined"
53  ),
54  defaultSpeciei_
55  (
56  species.size()
57  ? species[defaultSpecieName_]
58  : -1
59  ),
60  Y_(species.size())
61 {
63 
64  bool Yset = false;
65 
66  // Read the species' mass fractions
67  forAll(species, i)
68  {
70  (
72  mesh.time().name(),
73  mesh,
75  );
76 
77  if (io.headerOk())
78  {
79  Y_.set
80  (
81  i,
83  (
84  IOobject
85  (
87  mesh.time().name(),
88  mesh,
91  ),
92  mesh
93  )
94  );
95 
96  Yset = true;
97  }
98  else
99  {
100  if (!Ydefault.valid())
101  {
102  Ydefault = new LagrangianScalarField
103  (
104  IOobject
105  (
106  IOobject::groupName("Ydefault", phaseName),
107  mesh.time().name(),
108  mesh,
111  ),
112  mesh
113  );
114  }
115 
116  Y_.set
117  (
118  i,
120  (
121  IOobject
122  (
124  mesh.time().name(),
125  mesh,
128  ),
129  Ydefault()
130  )
131  );
132  }
133  }
134 
135  // If the mass fractions have been specified check and normalise
136  if (Yset)
137  {
138  // Scale the mass fractions so that they sum to one in case the input is
139  // not exact
141  (
143  (
145  Y_[0]
146  )
147  );
148  LagrangianScalarField& Yt = tYt.ref();
149 
150  for (label i = 1; i < Y_.size(); ++ i)
151  {
152  Yt += Y_[i];
153  }
154 
155  if (min(Yt.primitiveField()) == 0 && max(Yt.primitiveField()) == 0)
156  {
158  << "Sum of specie mass fractions = 0"
159  << exit(FatalError);
160  }
161 
162  if (min(Yt.primitiveField()) < 0.999)
163  {
165  << "Min sum of specie mass fractions "
166  << min(Yt.primitiveField())
167  << " < 0.999"
168  << exit(FatalError);
169  }
170 
171  if (max(Yt.primitiveField()) > 1.001)
172  {
174  << "Max sum of specie mass fractions "
175  << max(Yt.primitiveField())
176  << " > 1.001"
177  << exit(FatalError);
178  }
179 
180  forAll(Y_, i)
181  {
182  Y_[i] /= Yt;
183  }
184  }
185 }
186 
187 
188 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
189 
192 (
193  const LagrangianMesh& mesh,
194  const word& phaseName
195 )
196 {
197  return
198  basicLagrangianThermo::New<multicomponentLagrangianThermo>
199  (
200  mesh,
201  phaseName
202  );
203 }
204 
205 
206 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
207 
209 {}
210 
211 
213 {}
214 
215 
216 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
217 
220 {
221  return defaultSpeciei_;
222 }
223 
224 
227 {
228  return Y_;
229 }
230 
231 
234 {
235  return Y_;
236 }
237 
238 
240 (
241  const LagrangianSubMesh& subMesh
242 )
243 {
244  if (defaultSpeciei_ == -1 || !species().size()) return;
245 
247  (
249  (
251  subMesh,
253  )
254  );
255  LagrangianSubScalarField& Yt = tYt.ref();
256 
257  forAll(Y(), i)
258  {
259  if (i == defaultSpeciei_) continue;
260 
261  LagrangianSubScalarSubField subYi(subMesh.sub(Y_[i]));
262  subYi = max(subYi, scalar(0));
263  Yt += subYi;
264  }
265 
266  LagrangianSubScalarSubField subYdefault(subMesh.sub(Y_[defaultSpeciei_]));
267  subYdefault = max(scalar(1) - Yt, scalar(0));
268 }
269 
270 
271 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
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.
const Internal::FieldType & primitiveField() const
Return a const-reference to the primitive field.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
static word groupName(Name name, const word &group)
Class containing Lagrangian geometry and topology.
const Time & time() const
Return time.
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
word sub(const word &fieldName) const
Return the name of a field corresponding to this sub-mesh.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
virtual const LagrangianMesh & mesh() const =0
Access the mesh.
virtual const word & phaseName() const =0
Access the phase name.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const word & name() const
Return const reference to name.
A wordList with hashed indices for faster lookup by name.
virtual label defaultSpecie() const
The index of the default specie.
virtual PtrList< LagrangianScalarDynamicField > & Y()
Access the mass-fraction fields.
virtual void normaliseY(const LagrangianSubMesh &)
Normalise the mass fractions within the given sub-mesh by.
PtrList< LagrangianScalarDynamicField > Y_
Species mass fractions.
implementation(const dictionary &, const speciesTable &, const LagrangianMesh &, const word &)
Construct from dictionary, mesh and phase name.
Base-class for multicomponent Lagrangian thermodynamic models.
virtual const speciesTable & species() const =0
Return the table of species.
virtual PtrList< LagrangianScalarDynamicField > & Y()=0
Access the mass-fraction fields.
static autoPtr< multicomponentLagrangianThermo > New(const LagrangianMesh &mesh, const word &phaseName=word::null)
Select a multicomponent thermo.
A class for managing temporary objects.
Definition: tmp.H:55
bool valid() const
Is this temporary object valid,.
Definition: tmpI.H:183
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
Templated form of IOobject providing type information for file reading and header type checking.
Definition: IOobject.H:545
bool headerOk()
Read header (uses typeGlobalFile to find file) and check.
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
LagrangianField< scalar > LagrangianScalarField
defineRunTimeSelectionTable(fvConstraint, dictionary)
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
error FatalError
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dictionary dict