multicomponentParcel.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) 2025-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 "multicomponentParcel.H"
27 #include "cloud_fvModel.H"
28 #include "cloud_functionObject.H"
29 #include "LagrangiancDdt.H"
30 #include "LagrangianmDdt.H"
31 #include "oneOrTmp.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace clouds
39 {
42 }
43 namespace fv
44 {
45  makeCloudFvModel(multicomponentParcel);
46 }
47 namespace functionObjects
48 {
49  makeCloudFunctionObject(multicomponentParcel);
50 }
51 }
52 
53 
54 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
55 
58 (
59  const LagrangianSubMesh& subMesh
60 ) const
61 {
62  const LagrangianSubScalarSubField& m = this->m.ref(subMesh);
63  const LagrangianSubVectorSubField& U = this->U.ref(subMesh);
64 
65  return
69 }
70 
71 
73 {
74  const bool dUdt = tracking == trackingType::parabolic;
75 
76  const LagrangianSubMesh subMesh = this->mesh().subNone();
77 
78  LagrangianSubScalarSubField& number = this->number.ref(subMesh);
79  LagrangianSubScalarSubField& m = this->m.ref(subMesh);
80  LagrangianSubScalarSubField& e = this->e.ref(subMesh);
81  LagrangianSubVectorSubField& U = this->U.ref(subMesh);
82 
83  bool result = false;
84 
85  if (LagrangianModels().addsSupToField(word::null))
86  {
87  result = Lagrangianm::initDdt(dimless, number) || result;
88  }
89 
90  if (LagrangianModels().addsSupToField(m))
91  {
92  result = Lagrangianm::initDdt(dimless, m, dUdt) || result;
93 
94  if (context == cloud::contextType::fvModel)
95  {
96  result = initPsicDdt(m, rhoc) || result;
97  if (hasPhase())
98  {
99  result = initPsicDdt(m, rhocPhase) || result;
100  }
101  }
102  }
103 
104  {
105  forAll(this->Y, i)
106  {
107  LagrangianSubScalarSubField& Yi = this->Y[i].ref(subMesh);
108 
109  result = Lagrangianm::initDdt(dimMass, Yi, dUdt) || result;
110  }
111 
112  if (context == cloud::contextType::fvModel)
113  {
114  forAll(this->Y, i)
115  {
116  const label ic = iToic[i];
117  if (ic != -1)
118  {
119  result = initPsicDdt(m, Yc[ic]) || result;
120  }
121  if (hasPhase())
122  {
123  const label icPhase = iToicPhase[i];
124  if (icPhase != -1 && &YcPhase[icPhase] != &Yc[ic])
125  {
126  result = initPsicDdt(m, YcPhase[icPhase]) || result;
127  }
128  }
129  }
130  }
131  }
132 
133  {
134  result = Lagrangianm::initDdt(dimMass, e, dUdt) || result;
135 
136  if (context == cloud::contextType::fvModel)
137  {
138  if (hasThermoc())
139  {
140  result = initPsicDdt(m, hec) || result;
141  }
142  if (hasThermocPhase() && &hecPhase != &hec)
143  {
144  result = initPsicDdt(m, hecPhase) || result;
145  }
146  }
147  }
148 
149  {
150  result = Lagrangianm::initDdt(dimMass, U, dUdt) || result;
151 
152  if (context == cloud::contextType::fvModel)
153  {
154  result = initPsicDdt(m, Uc) || result;
155  if (hasPhase() && &UcPhase != &Uc)
156  {
157  result = initPsicDdt(m, UcPhase) || result;
158  }
159  }
160  }
161 
162  return result;
163 }
164 
165 
167 (
168  const LagrangianSubScalarField& deltaT,
169  const bool final
170 )
171 {
172  const LagrangianSubMesh& subMesh = deltaT.mesh();
173 
174  LagrangianSubScalarSubField& number = this->number.ref(subMesh);
175  LagrangianSubScalarSubField& m = this->m.ref(subMesh);
176  const LagrangianSubScalarSubField& rho = this->rho(subMesh);
177  LagrangianSubScalarSubField& e = this->e.ref(subMesh);
178  LagrangianSubVectorSubField& U = this->U.ref(subMesh);
179 
180  // Update the pressure
181  thermo().correctPressure(subMesh);
182 
183  // Evaluate the fractional source
184  LagrangianEqn<scalar> oneEqn(LagrangianModels().source(deltaT));
185 
186  // Initialise a unity fractional change in number (i.e., no change)
187  oneOrTmp<LagrangianSubScalarField> numberByNumber0;
188 
189  // Solve the number equation if a model provides a fractional source
190  if (oneEqn.valid())
191  {
192  LagrangianEqn<scalar> numberEqn
193  (
194  Lagrangianm::Ddt(deltaT, number)
195  ==
196  oneEqn
197  );
198 
199  numberEqn.solve(final);
200 
201  // Set the fractional change in number
202  numberByNumber0 = number/number.oldTime();
203 
204  // Correct the fractional source
205  oneEqn *= numberByNumber0();
206  }
207 
208  // Solve the mass equation if a model provides a mass source
209  if (LagrangianModels().addsSupToField(m))
210  {
212  (
213  Lagrangianm::Ddt(deltaT, m)
214  + oneEqn
215  ==
216  numberByNumber0()*LagrangianModels().source(deltaT, m)
217  );
218 
219  mEqn.solve(final);
220 
221  // Correct the diameter for the change in mass, assuming the density
222  // remains constant
224 
225  // Calculate mass exchanges with the carrier
226  if (context == cloud::contextType::fvModel && final)
227  {
228  carrierEqn(rhoc) += number*psicEqn(deltaT, m, rhoc);
229  if (hasPhase())
230  {
231  carrierEqn(rhocPhase) += number*psicEqn(deltaT, m, rhocPhase);
232  }
233  }
234  }
235 
236  // Solve the species fraction equations
237  {
239  this->thermo<multicomponentLagrangianThermo>();
240 
241  forAll(this->Y, i)
242  {
243  if (i == thermo.defaultSpecie()) continue;
244 
245  LagrangianSubScalarSubField& Yi = this->Y[i].ref(subMesh);
246 
248  (
249  Lagrangianm::Ddt(deltaT, m, Yi)
250  + m*oneEqn
251  ==
252  numberByNumber0()*LagrangianModels().source(deltaT, m, Yi)
253  );
254 
255  YiEqn.solve(final);
256  }
257 
258  // Ensure the species fractions sum to one
259  thermo.normaliseY(subMesh);
260 
261  // Calculate specie exchanges with the carrier
262  if (context == cloud::contextType::fvModel && final)
263  {
264  forAll(this->Y, i)
265  {
266  const label ic = iToic[i];
267  if (ic != -1)
268  {
269  carrierEqn(Yc[ic]) +=
270  number*psicEqn(deltaT, m, e, Yc[ic]);
271  }
272  if (hasPhase())
273  {
274  const label icPhase = iToicPhase[i];
275  if (icPhase != -1 && &YcPhase[icPhase] != &Yc[ic])
276  {
277  carrierEqn(YcPhase[icPhase]) +=
278  number*psicEqn(deltaT, m, e, YcPhase[icPhase]);
279  }
280  }
281  }
282  }
283  }
284 
285  // Solve the energy equation
286  {
288  (
289  Lagrangianm::Ddt(deltaT, m, e)
290  + m*oneEqn
291  ==
292  numberByNumber0()*LagrangianModels().source(deltaT, m, e)
293  );
294 
295  eEqn.solve(final);
296 
297  // Update the thermodynamic model
298  thermo().correct(subMesh);
299 
300  // Correct the diameter for changes in density
302 
303  // Calculate energy exchanges with the carrier
304  if (context == cloud::contextType::fvModel && final)
305  {
306  if (hasThermoc())
307  {
308  carrierEqn(hec) += number*psicEqn(deltaT, m, e, hec);
309  }
310  if (hasThermocPhase() && &hecPhase != &hec)
311  {
312  carrierEqn(hecPhase) += number*psicEqn(deltaT, m, e, hecPhase);
313  }
314  }
315  }
316 
317  // Solve the momentum equation
318  {
320  (
321  Lagrangianm::Ddt(deltaT, m, U)
322  + m*oneEqn
323  ==
324  numberByNumber0*LagrangianModels().source(deltaT, m, U)
325  );
326 
327  UEqn.solve(final);
328 
329  // Calculate momentum exchanges with the carrier
330  if (context == cloud::contextType::fvModel && final)
331  {
332  carrierEqn(Uc) += number*psicEqn(deltaT, m, U, Uc);
333  if (hasPhase() && &UcPhase != &Uc)
334  {
335  carrierEqn(UcPhase) += number*psicEqn(deltaT, m, U, UcPhase);
336  }
337  }
338  }
339 }
340 
341 
343 {
346 }
347 
348 
349 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
350 
352 (
354  const contextType context,
355  const dictionary& dict
356 )
357 :
358  cloud(mesh, context),
359  carried(*this, dict),
360  grouped(static_cast<const cloud&>(*this)),
361  spherical(static_cast<const cloud&>(*this)),
362  multicomponentThermal(*this, *this, *this),
363  coupledToThermalFluid(*this, *this, *this),
364  sphericalCoupled(*this, *this, *this, *this),
365  massiveCoupledToFluid(*this, *this, *this)
366 {
367  thermo().initialise();
368 
370 }
371 
372 
373 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
374 
376 {}
377 
378 
379 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
380 
382 (
383  const bool initial,
384  const bool final
385 )
386 {
387  // Pre-solve operations ...
391 
392  // Solve
393  cloud::solve(initial, final);
394 
395  // Post-solve operations ...
396 }
397 
398 
399 // ************************************************************************* //
Functions for calculating the time derivative for a Lagrangian equation.
Functions for calculating the time derivative for a Lagrangian equation.
#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...
const GeoMesh & mesh() const
Return mesh.
This class stores the coefficients of a Lagrangian equation, and facilitates solving that equation an...
Definition: LagrangianEqn.H:56
void solve(const bool final)
Solve.
bool valid() const
Determine whether this matrix has any valid coefficients.
Class containing Lagrangian geometry and topology.
List of Lagrangian models, constructed as a (Lagrangian) mesh object. Provides similar functions to t...
bool addsSupToField(const word &fieldName) const
Return true if the LagrangianModels adds a source term to the.
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
const Field0Type & oldTime() const
Return the old-time field.
Definition: OldTimeField.C:322
Base class for clouds. Provides a basic evolution algorithm, models, and a database for caching deriv...
Definition: cloud.H:61
contextType
Context in which this cloud is used.
Definition: cloud.H:203
virtual void solve(const bool initial, const bool final)
Solve the cloud's evolution over the current time-step.
Definition: cloud.C:608
Foam::LagrangianModels & LagrangianModels() const
Access the models.
Definition: cloud.C:597
virtual void partition()
Partition hook.
Definition: cloud.C:450
CloudStateField< vector > U
Velocity.
Definition: cloud.H:209
Base class for clouds which are carried by a fluid.
Definition: carried.H:57
void clearCarrierFields()
Clear the carrier fields.
Definition: carried.C:115
void resetCarrierFields(const bool initial)
Reset the carrier fields.
Definition: carried.C:132
void updateCarrier()
Update the cached carrier fields.
Base class for clouds which are coupled to a fluid with a thermodynamic model.
void clearCarrierEqns()
Clear the carrier equations.
Definition: coupled.C:110
Base class for clouds in which particles are grouped into parcels.
Definition: grouped.H:51
Base class for clouds of massive particles which are coupled to a fluid.
const CloudDerivedField< scalar > & m
Mass.
Definition: massive.H:78
Cloud with spherical particles with multicomponent thermodynamic modelling, grouped into parcels.
virtual void solve(const bool initial, const bool final)
Solve the cloud's evolution over the current time-step.
virtual bool reCalculateModified()
Do we need to re-calculate particles that are modified?
virtual tmp< LagrangianSubVectorField > dUdt(const LagrangianSubMesh &) const
Return the acceleration with which to do second-order tracking.
multicomponentParcel(LagrangianMesh &mesh, const contextType context, const dictionary &dict)
Construct from a mesh and context.
virtual void partition()
Partition hook.
virtual void calculate(const LagrangianSubScalarField &deltaT, const bool final)
Update the cloud properties.
Base class for clouds with multicomponent thermodynamic modelling.
Base class for clouds of spherical particles which are coupled to a carrier.
Base class for clouds with spherical particles.
Definition: spherical.H:53
void correct(const LagrangianSubScalarSubField &v)
Correct the shape to match the given volume.
Definition: spherical.C:90
const Thermo & thermo(const Args &... args) const
Get a reference to the thermodynamic model of a given type.
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 multicomponent Lagrangian thermodynamic models.
Variant type that either contains and behaves as tmp object or represents a value of one....
Definition: oneOrTmp.H:53
A class for managing temporary objects.
Definition: tmp.H:55
static const word null
An empty word.
Definition: word.H:78
fvVectorMatrix & UEqn
Definition: UEqn.H:11
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
U
Definition: pEqn.H:72
rho
Definition: pEqn.H:1
tmp< LagrangianSubField< Type > > Ddt(const LagrangianSubSubField< Type > &psi)
Return the instantaneous time-derivative.
tmp< LagrangianEqn< Type > > Ddt(const LagrangianSubScalarField &deltaT, LagrangianSubSubField< Type > &psi)
Return the time-derivative matrix.
bool initDdt(const dimensionSet &mDims, const LagrangianSubSubField< Type > &psi, const bool instantaneousDdt=false)
Initialise time-derivative information. Registers fields used to.
addToRunTimeSelectionTable(cloud, dynamicParcel, LagrangianMesh)
defineTypeNameAndDebug(carried, 0)
makeCloudFunctionObject(dynamicParcel)
makeCloudFvModel(dynamicParcel)
Namespace for OpenFOAM.
const doubleScalar e
Definition: doubleScalar.H:106
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
const dimensionSet & dimMass
Definition: dimensions.C:140
tmp< DimensionedField< Type, GeoMesh, SubField > > toSubField(const DimensionedField< Type, GeoMesh, Field > &)
Return a temporary sub-field from a reference to a field.
labelList fv(nPoints)
dictionary dict
PtrList< volScalarField > & Y
fluidMulticomponentThermo & thermo
Definition: createFields.H:15