LagrangianModels.H
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 Class
25  Foam::LagrangianModels
26 
27 Description
28  List of Lagrangian models, constructed as a (Lagrangian) mesh object.
29  Provides similar functions to the models themselves and forwards them to
30  each model in turn. This is the high level model interface used by clouds
31  when constructing their injections and transport equations.
32 
33 SourceFiles
34  LagrangianModels.C
35  LagrangianModelsTemplates.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef LagrangianModels_H
40 #define LagrangianModels_H
41 
42 #include "LagrangianModel.H"
43 #include "PtrListDictionary.H"
44 #include "DemandDrivenMeshObject.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class LagrangianModels Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class LagrangianModels
56 :
58  <
59  LagrangianMesh,
60  TopoChangeableMeshObject,
61  LagrangianModels,
62  IOdictionary
63  >,
64  public PtrListDictionary<LagrangianModel>
65 {
66  // Private Data
67 
68  //- Time index to check that all defined sources have been applied
69  mutable label checkTimeIndex_;
70 
71  //- Sets of the fields that have had sources added by the
72  // LagrangianModels
73  mutable PtrList<wordHashSet> addSupFields_;
74 
75 
76  // Private Member Functions
77 
78  //- Create IO object for an optional LagrangianModels file
79  IOobject io(const LagrangianMesh& mesh) const;
80 
81  //- Helper for modelTypeFieldSourceTypes. Inserts the field source type
82  // into to the table if the model is of the required type.
83  template<class ... ModelAndFieldSourceTypes>
84  struct modelTypeFieldSourceType;
85 
86  //- Check that all LagrangianModels have been applied
87  void checkApplied() const;
88 
89  //- Return a source for an equation
90  template
91  <
92  class Type,
93  template<class> class PrimitiveField,
94  class ... AlphaRhoFieldTypes
95  >
96  tmp<LagrangianEqn<Type>> sourceTerm
97  (
99  const LagrangianSubScalarField& deltaT,
100  const AlphaRhoFieldTypes& ... alphaRhoFields
101  ) const;
102 
103 
104 protected:
105 
106  //- Let the mesh object use the protected constructors
107  friend class DemandDrivenMeshObject;
108 
109  // Protected Constructors
110 
111  //- Construct for a mesh
112  explicit LagrangianModels(const LagrangianMesh& mesh);
113 
114 
115 public:
116 
117  //- Runtime type information
118  TypeName("LagrangianModels");
119 
120 
121  // Constructors
122 
123  //- Disallow default bitwise copy construction
124  LagrangianModels(const LagrangianModels&) = delete;
125 
126  //- Inherit the base New method
128  <
133  >::New;
134 
135 
136  //- Destructor
137  virtual ~LagrangianModels();
138 
139 
140  // Member Functions
141 
142  // Checks
143 
144  //- Return true if the LagrangianModels adds a source term to the
145  // given field's transport equation
146  bool addsSupToField(const word& fieldName) const;
147 
148  //- Return true if the LagrangianModels adds a source term to the
149  // given field's transport equation
150  bool addsSupToField
151  (
152  const word& fieldName,
153  const word& eqnFieldName
154  ) const;
155 
156  //- Return true if the LagrangianModels adds a source term to the
157  // given field's transport equation
158  template<class Type, template<class> class PrimitiveField>
159  bool addsSupToField
160  (
162  ) const;
163 
164  //- Return true if the LagrangianModels adds a source term to the
165  // given field's transport equation
166  template
167  <
168  class Type,
169  template<class> class PrimitiveField,
170  template<class> class PrimitiveEqnField
171  >
172  bool addsSupToField
173  (
176  ) const;
177 
178 
179  //- Correct the LagrangianModels
180  void correct();
181 
182  //- Identify elements in the Lagrangian mesh which are to be
183  // instantaneously modified and put them in contiguous groups
185 
186  //- Instantaneously modify and/or create and remove elements in the
187  // Lagrangian mesh
189  (
191  const LagrangianSubMesh& modifiedMesh
192  ) const;
193 
194  //- Solve equations and/or update continually changing properties
195  void calculate
196  (
197  const LagrangianSubScalarField& deltaT,
198  const bool final
199  );
200 
201  //- Return a table of field source types that are chosen to match given
202  // model types. So, e.g., a zero field source for every injection
203  // model. Useful for programmatically constructing fields. Template
204  // arguments should alternate between model and field types; i.e.,
205  // model-type-1, field-source-type-1, model-type-2,
206  // field-source-type-2, model-type-3, ...
207  template<class ... ModelAndFieldSourceTypes>
209 
210 
211  // Sources
212 
213  //- Hook before source evaluation
214  virtual void preSource
215  (
216  const LagrangianSubScalarField& deltaT,
217  const bool final
218  );
219 
220  //- Return the fractional source
222  (
223  const LagrangianSubScalarField& deltaT
224  ) const;
225 
226  //- Return source for an equation
227  template<class Type, template<class> class PrimitiveField>
229  (
230  const LagrangianSubScalarField& deltaT,
232  ) const;
233 
234  //- Return source for an equation
235  template
236  <
237  class Type,
238  template<class> class PrimitiveField,
239  template<class> class PrimitiveEqnField
240  >
242  (
243  const LagrangianSubScalarField& deltaT,
246  ) const;
247 
248  //- Return source for a volume or mass-weighted equation
249  template<class Type, template<class> class PrimitiveField>
251  (
252  const LagrangianSubScalarField& deltaT,
255  ) const;
256 
257  //- Return source for a volume or mass-weighted equation
258  template
259  <
260  class Type,
261  template<class> class PrimitiveField,
262  template<class> class PrimitiveEqnField
263  >
265  (
266  const LagrangianSubScalarField& deltaT,
270  ) const;
271 
272  //- Hook after source evaluation
273  virtual void postSource
274  (
275  const LagrangianSubScalarField& deltaT,
276  const bool final
277  );
278 
279 
280  // Mesh changes
281 
282  //- Update for mesh motion. Only for mesh object. Does nothing.
283  // Lagrangian evolves continuously across the range of mesh
284  // motion, so no instantaneous update is needed.
285  virtual bool movePoints();
286 
287  //- Update topology using the given map
288  virtual void topoChange(const polyTopoChangeMap&);
289 
290  //- Update from another mesh using the given map
291  virtual void mapMesh(const polyMeshMap&);
292 
293  //- Redistribute or update using the given distribution map
294  virtual void distribute(const polyDistributionMap&);
295 
296 
297  // IO
298 
299  //- Read the LagrangianModels dictionary if it has changed
300  // and update the models
301  virtual bool read();
302 
303  //- Write the LagrangianModels
304  virtual bool writeObject
305  (
309  const bool write
310  ) const;
311 
312 
313  // Member Operators
314 
315  //- Inherit the PtrListDictionary index operators
317 
318  //- Inherit the PtrListDictionary size function
320 
321  //- Disallow default bitwise assignment
322  void operator=(const LagrangianModels&) = delete;
323 };
324 
325 
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327 
328 //- Trait for obtaining global status
329 template<>
331 {
332  static const bool global = true;
333 };
334 
335 
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
337 
338 #ifdef NoRepository
339  #include "LagrangianModelsTemplates.C"
340 #endif
341 
342 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
343 
344 } // End namespace Foam
345 
346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
347 
348 #endif
349 
350 // ************************************************************************* //
Templated abstract base-class for demand-driven mesh objects used to automate their allocation to the...
static LagrangianModels & New(const word &name, const LagrangianMesh &mesh)
Construct and return the named DemandDrivenMeshObject.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
An STL-conforming hash table.
Definition: HashTable.H:127
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Version number type.
Definition: IOstream.H:97
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
Class containing Lagrangian geometry and topology.
List of Lagrangian models, constructed as a (Lagrangian) mesh object. Provides similar functions to t...
virtual bool movePoints()
Update for mesh motion. Only for mesh object. Does nothing.
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write) const
Write the LagrangianModels.
void operator=(const LagrangianModels &)=delete
Disallow default bitwise assignment.
void correct()
Correct the LagrangianModels.
tmp< LagrangianEqn< scalar > > source(const LagrangianSubScalarField &deltaT) const
Return the fractional source.
HashTable< word > modelTypeFieldSourceTypes() const
Return a table of field source types that are chosen to match given.
virtual void postSource(const LagrangianSubScalarField &deltaT, const bool final)
Hook after source evaluation.
virtual ~LagrangianModels()
Destructor.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
TypeName("LagrangianModels")
Runtime type information.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual void preSource(const LagrangianSubScalarField &deltaT, const bool final)
Hook before source evaluation.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
LagrangianSubMesh preModify(LagrangianMesh &mesh) const
Identify elements in the Lagrangian mesh which are to be.
tmp< LagrangianEqn< Type > > sourceProxy(const LagrangianSubScalarField &deltaT, const LagrangianSubField< Type, PrimitiveField > &field, const LagrangianSubField< Type, PrimitiveEqnField > &eqnField) const
Return source for an equation.
LagrangianSubMesh modify(LagrangianMesh &mesh, const LagrangianSubMesh &modifiedMesh) const
Instantaneously modify and/or create and remove elements in the.
bool addsSupToField(const word &fieldName) const
Return true if the LagrangianModels adds a source term to the.
void calculate(const LagrangianSubScalarField &deltaT, const bool final)
Solve equations and/or update continually changing properties.
LagrangianModels(const LagrangianMesh &mesh)
Construct for a mesh.
virtual bool read()
Read the LagrangianModels dictionary if it has changed.
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
Template dictionary class which manages the storage associated with it.
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
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:214
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.
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
Trait for obtaining global status.
Definition: IOobject.H:518
static const bool global
Definition: IOobject.H:519