parcel.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 "parcel.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 {
46 }
47 namespace functionObjects
48 {
50 }
51 }
52 
53 
54 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
55 
57 (
58  const LagrangianSubMesh& subMesh
59 ) const
60 {
61  const LagrangianSubScalarSubField& m = this->m.ref(subMesh);
62  const LagrangianSubVectorSubField& U = this->U.ref(subMesh);
63 
64  return
68 }
69 
70 
72 {
73  const bool dUdt = tracking == trackingType::parabolic;
74 
75  const LagrangianSubMesh subMesh = this->mesh().subNone();
76 
77  LagrangianSubScalarSubField& number = this->number.ref(subMesh);
78  LagrangianSubScalarSubField& m = this->m.ref(subMesh);
79  LagrangianSubScalarSubField& e = this->e.ref(subMesh);
80  LagrangianSubVectorSubField& U = this->U.ref(subMesh);
81 
82  bool result = false;
83 
84  if (LagrangianModels().addsSupToField(word::null))
85  {
86  result = Lagrangianm::initDdt(dimless, number) || result;
87  }
88 
89  if (LagrangianModels().addsSupToField(m))
90  {
91  result = Lagrangianm::initDdt(dimless, m, dUdt) || result;
92 
93  if (context == cloud::contextType::fvModel)
94  {
95  result = initPsicDdt(m, rhoc) || result;
96  if (hasPhase())
97  {
98  result = initPsicDdt(m, rhocPhase) || result;
99  }
100  }
101  }
102 
103  {
104  result = Lagrangianm::initDdt(dimMass, e, dUdt) || result;
105 
106  if (context == cloud::contextType::fvModel)
107  {
108  if (hasThermoc())
109  {
110  result = initPsicDdt(m, hec) || result;
111  }
112  if (hasThermocPhase() && &hecPhase != &hec)
113  {
114  result = initPsicDdt(m, hecPhase) || result;
115  }
116  }
117  }
118 
119  {
120  result = Lagrangianm::initDdt(dimMass, U, dUdt) || result;
121 
122  if (context == cloud::contextType::fvModel)
123  {
124  result = initPsicDdt(m, Uc) || result;
125  if (hasPhase() && &UcPhase != &Uc)
126  {
127  result = initPsicDdt(m, UcPhase) || result;
128  }
129  }
130  }
131 
132  return result;
133 }
134 
135 
137 (
138  const LagrangianSubScalarField& deltaT,
139  const bool final
140 )
141 {
142  const LagrangianSubMesh& subMesh = deltaT.mesh();
143 
144  LagrangianSubScalarSubField& number = this->number.ref(subMesh);
145  LagrangianSubScalarSubField& m = this->m.ref(subMesh);
146  const LagrangianSubScalarSubField& rho = this->rho(subMesh);
147  LagrangianSubScalarSubField& e = this->e.ref(subMesh);
148  LagrangianSubVectorSubField& U = this->U.ref(subMesh);
149 
150  // Update the pressure
151  thermo().correctPressure(subMesh);
152 
153  // Evaluate the fractional source
154  LagrangianEqn<scalar> oneEqn(LagrangianModels().source(deltaT));
155 
156  // Initialise a unity fractional change in number (i.e., no change)
157  oneOrTmp<LagrangianSubScalarField> numberByNumber0;
158 
159  // Solve the number equation if a model provides a fractional source
160  if (oneEqn.valid())
161  {
162  LagrangianEqn<scalar> numberEqn
163  (
164  Lagrangianm::Ddt(deltaT, number)
165  ==
166  oneEqn
167  );
168 
169  numberEqn.solve(final);
170 
171  // Set the fractional change in number
172  numberByNumber0 = number/number.oldTime();
173 
174  // Correct the fractional source
175  oneEqn *= numberByNumber0();
176  }
177 
178  // Solve the mass equation if a model provides a mass source
179  if (LagrangianModels().addsSupToField(m))
180  {
182  (
183  Lagrangianm::Ddt(deltaT, m)
184  + oneEqn
185  ==
186  numberByNumber0()*LagrangianModels().source(deltaT, m)
187  );
188 
189  mEqn.solve(final);
190 
191  // Correct the diameter for the change in mass, assuming the density
192  // remains constant
194 
195  // Calculate mass exchanges with the carrier
196  if (context == cloud::contextType::fvModel && final)
197  {
198  carrierEqn(rhoc) += number*psicEqn(deltaT, m, rhoc);
199  if (hasPhase())
200  {
201  carrierEqn(rhocPhase) += number*psicEqn(deltaT, m, rhocPhase);
202  }
203  }
204  }
205 
206  // Solve the energy equation
207  {
209  (
210  Lagrangianm::Ddt(deltaT, m, e)
211  + m*oneEqn
212  ==
213  numberByNumber0()*LagrangianModels().source(deltaT, m, e)
214  );
215 
216  eEqn.solve(final);
217 
218  // Update the thermodynamic model
219  thermo().correct(subMesh);
220 
221  // Correct the diameter for changes in density
223 
224  // Calculate energy exchanges with the carrier
225  if (context == cloud::contextType::fvModel && final)
226  {
227  if (hasThermoc())
228  {
229  carrierEqn(hec) += number*psicEqn(deltaT, m, e, hec);
230  }
231  if (hasThermocPhase() && &hecPhase != &hec)
232  {
233  carrierEqn(hecPhase) += number*psicEqn(deltaT, m, e, hecPhase);
234  }
235  }
236  }
237 
238  // Solve the momentum equation
239  {
241  (
242  Lagrangianm::Ddt(deltaT, m, U)
243  + m*oneEqn
244  ==
245  numberByNumber0*LagrangianModels().source(deltaT, m, U)
246  );
247 
248  UEqn.solve(final);
249 
250  // Calculate momentum exchanges with the carrier
251  if (context == cloud::contextType::fvModel && final)
252  {
253  carrierEqn(Uc) += number*psicEqn(deltaT, m, U, Uc);
254  if (hasPhase() && &UcPhase != &Uc)
255  {
256  carrierEqn(UcPhase) += number*psicEqn(deltaT, m, U, UcPhase);
257  }
258  }
259  }
260 }
261 
262 
264 {
267 }
268 
269 
270 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
271 
273 (
275  const contextType context,
276  const dictionary& dict
277 )
278 :
279  cloud(mesh, context),
280  carried(*this, dict),
281  grouped(static_cast<const cloud&>(*this)),
282  spherical(static_cast<const cloud&>(*this)),
283  thermal(*this, *this, *this),
284  coupledToThermalFluid(*this, *this, *this),
285  sphericalCoupled(*this, *this, *this, *this),
286  massiveCoupledToFluid(*this, *this, *this)
287 {
288  thermo().initialise();
289 
291 }
292 
293 
294 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
295 
297 {}
298 
299 
300 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
301 
302 void Foam::clouds::parcel::solve(const bool initial, const bool final)
303 {
304  // Pre-solve operations ...
308 
309  // Solve
310  cloud::solve(initial, final);
311 
312  // Post-solve operations ...
313 }
314 
315 
316 // ************************************************************************* //
Functions for calculating the time derivative for a Lagrangian equation.
Functions for calculating the time derivative for a Lagrangian equation.
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 thermodynamic modelling, grouped into parcels.
Definition: parcel.H:64
virtual void solve(const bool initial, const bool final)
Solve the cloud's evolution over the current time-step.
Definition: parcel.C:302
virtual bool reCalculateModified()
Do we need to re-calculate particles that are modified?
Definition: parcel.C:71
virtual tmp< LagrangianSubVectorField > dUdt(const LagrangianSubMesh &) const
Return the acceleration with which to do second-order tracking.
Definition: parcel.C:57
parcel(LagrangianMesh &mesh, const contextType context, const dictionary &dict)
Construct from a mesh and context.
Definition: parcel.C:273
virtual ~parcel()
Destructor.
Definition: parcel.C:296
virtual void partition()
Partition hook.
Definition: parcel.C:263
virtual void calculate(const LagrangianSubScalarField &deltaT, const bool final)
Update the cloud properties.
Definition: parcel.C:137
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
Base class for clouds with thermodynamic modelling.
Definition: thermal.H:56
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
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
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
fluidMulticomponentThermo & thermo
Definition: createFields.H:15