LagrangianModel.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::LagrangianModel
26 
27 Description
28  Base class for Lagrangian models
29 
30 SourceFiles
31  LagrangianModelI.H
32  LagrangianModel.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef LagrangianModel_H
37 #define LagrangianModel_H
38 
39 #include "LagrangianEqn.H"
40 #include "LagrangianModelM.H"
41 #include "stateModel.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 class LagrangianMesh;
49 class polyTopoChangeMap;
50 class polyMeshMap;
51 class polyDistributionMap;
52 
53 /*---------------------------------------------------------------------------*\
54  Class LagrangianModel Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 class LagrangianModel
58 :
59  public stateModel
60 {
61 public:
62 
63  // Public Enumerations
64 
65  //- Enumeration of the types of instantaneous modification
66  enum class modification : label
67  {
68  change = 0,
69  remove = 1
70  };
71 
72 
73  // Public Type Definitions
74 
75  //- Class containing an element-index and a modification-enumeration
77 
78 
79 private:
80 
81  // Private Data
82 
83  //- Model name
84  const word name_;
85 
86  //- Reference to the mesh
87  const LagrangianMesh& mesh_;
88 
89 
90 protected:
91 
92  // Protected Member Functions
93 
94  //- Add a source term to an equation
95  template<class Type>
96  void addSupType
97  (
98  const LagrangianSubScalarField& deltaT,
99  const LagrangianSubSubField<Type>& field,
101  ) const;
102 
103  //- Add a source term to a volume or mass-weighted equation
104  template<class Type>
105  void addSupType
106  (
107  const LagrangianSubScalarField& deltaT,
108  const LagrangianSubScalarSubField& vOrM,
109  const LagrangianSubSubField<Type>& field,
111  ) const;
112 
113 
114 public:
115 
116  //- Runtime type information
117  TypeName("LagrangianModel");
118 
119 
120  //- Declare run-time constructor selection table
122  (
123  autoPtr,
125  dictionary,
126  (
127  const word& name,
128  const LagrangianMesh& mesh,
129  const dictionary& modelDict,
130  const dictionary& stateDict
131  ),
132  (name, mesh, modelDict, stateDict)
133  );
134 
135 
136  // Static Member Functions
137 
138  //- Return the name of the field associated with a source term
139  template<class AlphaRhoFieldType, class ... AlphaRhoFieldTypes>
140  static word fieldName
141  (
142  const AlphaRhoFieldType& alphaRhoField,
143  const AlphaRhoFieldTypes& ... alphaRhoFields
144  );
145 
146  //- Return the name of the field associated with a source term (base
147  // condition for the above)
148  template
149  <
150  class Type,
151  class GeoMesh,
152  template<class> class PrimitiveField
153  >
154  static const word& fieldName
155  (
157  );
158 
159  //- Return the name of the field associated with a source term (base
160  // condition for the above)
161  template
162  <
163  class Type,
164  class GeoMesh,
165  template<class> class PrimitiveField
166  >
167  static const word& fieldName
168  (
170  );
171 
172  //- Return the name of the field associated with a source term (base
173  // condition for the above)
174  template
175  <
176  class Type,
177  template<class> class PrimitiveField
178  >
179  static word fieldName
180  (
182  );
183 
184  //- Return the name of the product of the fields associated with a
185  // source term
186  template<class AlphaRhoFieldType, class ... AlphaRhoFieldTypes>
187  static word fieldsName
188  (
189  const AlphaRhoFieldType& alphaRhoField,
190  const AlphaRhoFieldTypes& ... alphaRhoFields
191  );
192 
193  //- Return the name of the product of the fields associated with a
194  // source term (base condition for the above)
195  template<class AlphaRhoFieldType>
196  static word fieldsName(const AlphaRhoFieldType& alphaRhoField);
197 
198 
199  // Constructors
200 
201  //- Construct from components
203  (
204  const word& name,
205  const LagrangianMesh& mesh
206  );
207 
208  //- Disallow default bitwise copy construction
209  LagrangianModel(const LagrangianModel&) = delete;
210 
211  //- Clone
213  {
215  return autoPtr<LagrangianModel>(nullptr);
216  }
217 
218  //- List construction class
219  class iNew
220  {
221  const word& name_;
222 
223  const LagrangianMesh& mesh_;
224 
225  public:
226 
227  iNew(const word& name, const LagrangianMesh& mesh)
228  :
229  name_(name),
230  mesh_(mesh)
231  {}
232 
234  {
236  (
237  LagrangianModel::New(name_, mesh_, dictionary(is))
238  );
239  }
240  };
241 
242 
243  //- Selector
245  (
246  const word& name,
247  const LagrangianMesh& mesh,
248  const dictionary& modelDict
249  );
250 
251 
252  //- Destructor
253  virtual ~LagrangianModel();
254 
255 
256  // Member Functions
257 
258  // Access
259 
260  //- The source name
261  inline const word& name() const;
262 
263  //- The database
264  inline const objectRegistry& db() const;
265 
266  //- Return time
267  inline const Time& time() const;
268 
269  //- The mesh
270  inline const LagrangianMesh& mesh() const;
271 
272 
273  // Checks
274 
275  //- Return the list of fields for which the LagrangianModel adds
276  // source term to the transport equation
277  virtual wordList addSupFields() const;
278 
279  //- Return true if the LagrangianModel adds a source term to the
280  // given field's transport equation
281  virtual bool addsSupToField
282  (
283  const word& fieldName,
284  const word& eqnFieldName
285  ) const = 0;
286 
287  //- Return true if the LagrangianModels adds a source term to the
288  // given field's transport equation
289  template
290  <
291  class Type,
292  template<class> class PrimitiveField,
293  template<class> class PrimitiveEqnField
294  >
295  bool addsSupToField
296  (
299  ) const;
300 
301 
302  //- Do post construction steps which require access to other models
303  virtual void postConstruct();
304 
305  //- Correct the LagrangianModel
306  virtual void correct();
307 
308  //- Identify elements in the Lagrangian mesh which are to be
309  // instantaneously modified or removed
310  virtual void preModify
311  (
312  const LagrangianMesh& mesh,
313  DynamicList<elementModification>& elementModifications
314  ) const;
315 
316  //- Instantaneously modify and/or create and remove elements in the
317  // Lagrangian mesh
318  virtual LagrangianSubMesh modify
319  (
321  const LagrangianSubMesh& modifiedMesh
322  ) const;
323 
324  //- Solve equations and/or update continually changing properties
325  virtual void calculate
326  (
327  const LagrangianSubScalarField& deltaT,
328  const bool final
329  );
330 
331 
332  // Sources
333 
334  //- Hook before source evaluation
335  virtual void preAddSup
336  (
337  const LagrangianSubScalarField& deltaT,
338  const bool final
339  );
340 
341  //- Add a fractional source term
342  virtual void addSup
343  (
344  const LagrangianSubScalarField& deltaT,
346  ) const;
347 
348  //- Add a source term to an equation
350 
351  //- Add a source term to a volume or mass-weighted equation
353 
354  //- Hook after source evaluation
355  virtual void postAddSup
356  (
357  const LagrangianSubScalarField& deltaT,
358  const bool final
359  );
360 
361 
362  // Mesh changes
363 
364  //- Update topology using the given map
365  virtual void topoChange(const polyTopoChangeMap&);
366 
367  //- Update from another mesh using the given map
368  virtual void mapMesh(const polyMeshMap&);
369 
370  //- Redistribute or update using the given distribution map
371  virtual void distribute(const polyDistributionMap&);
372 
373 
374  // IO
375 
376  //- Read dictionary
377  virtual bool read(const dictionary& modelDict);
378 
379  //- Write data
380  virtual bool write(const bool write) const;
381 
382 
383  // Member Operators
384 
385  //- Disallow default bitwise assignment
386  void operator=(const LagrangianModel&) = delete;
387 };
388 
389 
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 
392 } // End namespace Foam
393 
394 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
395 
396 #include "LagrangianModelI.H"
397 
398 #ifdef NoRepository
399  #include "LagrangianModelTemplates.C"
400 #endif
401 
402 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
403 
404 #endif
405 
406 // ************************************************************************* //
#define DEFINE_LAGRANGIAN_MODEL_ADD_V_OR_M_FIELD_SUP(Type, nullArg)
#define DEFINE_LAGRANGIAN_MODEL_ADD_FIELD_SUP(Type, nullArg)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
Generic GeometricField class.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
This class stores the coefficients of a Lagrangian equation, and facilitates solving that equation an...
Definition: LagrangianEqn.H:56
Class to hold element-group indices, and associate the group.
Class containing Lagrangian geometry and topology.
List construction class.
iNew(const word &name, const LagrangianMesh &mesh)
autoPtr< LagrangianModel > operator()(Istream &is) const
Base class for Lagrangian models.
virtual ~LagrangianModel()
Destructor.
virtual void addSup(const LagrangianSubScalarField &deltaT, LagrangianEqn< scalar > &eqn) const
Add a fractional source term.
virtual wordList addSupFields() const
Return the list of fields for which the LagrangianModel adds.
const Time & time() const
Return time.
virtual void postConstruct()
Do post construction steps which require access to other models.
modification
Enumeration of the types of instantaneous modification.
void addSupType(const LagrangianSubScalarField &deltaT, const LagrangianSubSubField< Type > &field, LagrangianEqn< Type > &eqn) const
Add a source term to an equation.
virtual void preModify(const LagrangianMesh &mesh, DynamicList< elementModification > &elementModifications) const
Identify elements in the Lagrangian mesh which are to be.
virtual void correct()
Correct the LagrangianModel.
declareRunTimeSelectionTable(autoPtr, LagrangianModel, dictionary,(const word &name, const LagrangianMesh &mesh, const dictionary &modelDict, const dictionary &stateDict),(name, mesh, modelDict, stateDict))
Declare run-time constructor selection table.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual bool addsSupToField(const word &fieldName, const word &eqnFieldName) const =0
Return true if the LagrangianModel adds a source term to the.
const objectRegistry & db() const
The database.
TypeName("LagrangianModel")
Runtime type information.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
autoPtr< LagrangianModel > clone() const
Clone.
virtual bool read(const dictionary &modelDict)
Read dictionary.
static word fieldsName(const AlphaRhoFieldType &alphaRhoField, const AlphaRhoFieldTypes &... alphaRhoFields)
Return the name of the product of the fields associated with a.
const LagrangianMesh & mesh() const
The mesh.
virtual bool write(const bool write) const
Write data.
LagrangianModel(const word &name, const LagrangianMesh &mesh)
Construct from components.
virtual void preAddSup(const LagrangianSubScalarField &deltaT, const bool final)
Hook before source evaluation.
virtual LagrangianSubMesh modify(LagrangianMesh &mesh, const LagrangianSubMesh &modifiedMesh) const
Instantaneously modify and/or create and remove elements in the.
static word fieldName(const AlphaRhoFieldType &alphaRhoField, const AlphaRhoFieldTypes &... alphaRhoFields)
Return the name of the field associated with a source term.
const word & name() const
The source name.
LagrangianMesh::elementGroup< modification > elementModification
Class containing an element-index and a modification-enumeration.
virtual void postAddSup(const LagrangianSubScalarField &deltaT, const bool final)
Add a source term to an equation.
virtual void calculate(const LagrangianSubScalarField &deltaT, const bool final)
Solve equations and/or update continually changing properties.
static autoPtr< LagrangianModel > New(const word &name, const LagrangianMesh &mesh, const dictionary &modelDict)
Selector.
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Registry of regIOobjects.
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.
Base class for models with state.
Definition: stateModel.H:49
static dictionary stateDict(const word &name, const objectRegistry &db)
Construct and return the state dictionary for reading.
Definition: stateModel.C:137
A class for handling words, derived from string.
Definition: word.H:63
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
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
FOR_ALL_FIELD_TYPES(makeDimensionedPointFieldFunctions)