cloud.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 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::cloud
26 
27 Description
28  Base class for clouds. Provides a basic evolution algorithm, models, and a
29  database for caching derived and average fields to avoid unnecessary
30  re-calculation.
31 
32 SourceFiles
33  cloud.C
34  cloudTemplates.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef cloud_H
39 #define cloud_H
40 
41 #include "LagrangianModels.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 template<class Type>
49 class CloudStateField;
50 
51 template<class Type>
52 class CloudDerivedField;
53 
54 template<class Type>
55 class CloudAverageField;
56 
57 /*---------------------------------------------------------------------------*\
58  Class cloud Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 class cloud
62 :
63  public regIOobject
64 {
65 private:
66 
67  // Private Data
68 
69  //- Reference to the mesh
70  LagrangianMesh& mesh_;
71 
72  //- The demand-driven Lagrangian models pointer
73  mutable Foam::LagrangianModels* LagrangianModelsPtr_;
74 
75  //- State fields
76  #define DECLARE_STATE_FIELDS(Type, nullArg) \
77  mutable PtrList<CloudStateField<Type>> \
78  CAT3(state, CAPITALIZE(Type), Fields_);
79  FOR_ALL_FIELD_TYPES(DECLARE_STATE_FIELDS);
80  #undef DECLARE_STATE_FIELDS
81 
82  //- Derived fields
83  #define DECLARE_DERIVED_FIELDS(Type, nullArg) \
84  mutable PtrList<CloudDerivedField<Type>> \
85  CAT3(derived, CAPITALIZE(Type), Fields_);
86  FOR_ALL_FIELD_TYPES(DECLARE_DERIVED_FIELDS);
87  #undef DECLARE_DERIVED_FIELDS
88 
89  //- Average fields
90  #define DECLARE_AVERAGE_FIELDS(Type, nullArg) \
91  mutable PtrList<CloudAverageField<Type>> \
92  CAT3(average, CAPITALIZE(Type), Fields_);
93  FOR_ALL_FIELD_TYPES(DECLARE_AVERAGE_FIELDS);
94  #undef DECLARE_AVERAGE_FIELDS
95 
96  //- Retained state labels
97  autoPtr<LagrangianLabelDynamicField> statePtr_;
98 
99  //- Cell length scale
100  scalarField cellLengthScaleVf_;
101 
102 
103  // Private Member Functions
104 
105  //- Construct and store the Lagrangian mesh, and return a reference
106  static LagrangianMesh& mesh
107  (
108  const polyMesh& pMesh,
109  const word& name,
112  );
113 
114  //- Access the state fields. Only specialisations are defined.
115  template<class Type>
116  PtrList<CloudStateField<Type>>& stateFields() const;
117 
118  //- Clear the state fields
119  void clearStateFields();
120 
121  //- Access the derived fields. Only specialisations are defined.
122  template<class Type>
123  PtrList<CloudDerivedField<Type>>& derivedFields() const;
124 
125  //- Clear the derived fields
126  void clearDerivedFields(const bool final);
127 
128  //- Access the average fields. Only specialisations are defined.
129  template<class Type>
130  PtrList<CloudAverageField<Type>>& averageFields() const;
131 
132  //- Remove values from a sub mesh from the average fields
133  void removeFromAverageFields(const LagrangianSubMesh&);
134 
135  //- Add values from a sub mesh into the average fields
136  void addToAverageFields(const LagrangianSubMesh&, const bool final);
137 
138  //- Correct values from a sub mesh in the average fields
139  void correctAverageFields(const LagrangianSubMesh&, const bool final);
140 
141  //- Clear the average fields
142  void clearAverageFields();
143 
144  //- Reset the average fields
145  void resetAverageFields();
146 
147  //- Return the IO for the retained state labels
148  IOobject stateIo(const IOobject::readOption) const;
149 
150  //- Read and return the retained state labels, if the file exists,
151  // otherwise return an empty pointer
152  autoPtr<LagrangianLabelDynamicField> readStates() const;
153 
154  //- Return the retained state enumerations, if they are available,
155  // otherwise return an empty pointer
156  autoPtr<List<LagrangianState>> initialStates() const;
157 
158  //- Clear the retained state labels
159  void clearStates();
160 
161  //- Store the retained state labels if necessary
162  bool storeStates();
163 
164  //- Store the retained state labels for the given sub-mesh
165  void storeStates(const LagrangianSubMesh& subMesh);
166 
167  //- Calculate the cell length scale for the given sub-mesh
168  tmp<LagrangianSubScalarField> cellLengthScale
169  (
170  const LagrangianSubMesh& subMesh
171  ) const;
172 
173  //- Track through the mesh
174  void track
175  (
176  LagrangianSubScalarSubField& fraction,
177  const scalar maxTimeStepFraction,
178  const scalar maxCellLengthScaleFraction
179  );
180 
181  //- Dummy write for regIOobject
182  virtual bool writeData(Ostream&) const;
183 
184 
185 protected:
186 
187  // Protected Member Functions
188 
189  //- Initialisation hook
190  virtual void initialise(const bool predict);
191 
192  //- Partition hook
193  virtual void partition();
194 
195  //- Return the acceleration with which to do second-order tracking
197  (
198  const LagrangianSubMesh&
199  ) const = 0;
200 
201  //- Do we need to re-calculate particles that are modified?
202  virtual bool reCalculateModified() = 0;
203 
204  //- Update the cloud properties
205  virtual void calculate
206  (
207  const LagrangianSubScalarField& deltaT,
208  const bool final
209  );
210 
211 
212 public:
213 
214  // Public Static Data
215 
216  //- Run-time type information
217  TypeName("cloud");
218 
219 
220  // Public Data
221 
222  //- Context in which this cloud is used
224 
225  //- Tracking method
226  const enum trackingType { linear, parabolic } tracking;
227 
228  //- Velocity
230 
231 
232  //- Declare run-time constructor selection table
234  (
235  autoPtr,
236  cloud,
237  polyMesh,
238  (const polyMesh& mesh, const word& name, const contextType context),
239  (mesh, name, context)
240  );
241 
242 
243  // Constructors
244 
245  //- Construct from a mesh and a name
246  cloud
247  (
248  const polyMesh& mesh,
249  const word& name,
250  const contextType context,
253  );
254 
255  //- Disallow default bitwise copy construction
256  cloud(const cloud&) = delete;
257 
258 
259  //- Selector
260  static autoPtr<cloud> New
261  (
262  const polyMesh& mesh,
263  const word& name,
264  const word& type
265  );
266 
267 
268  //- Destructor
269  virtual ~cloud();
270 
271 
272  // Member Functions
273 
274  // Access
275 
276  //- Access the mesh
277  inline const LagrangianMesh& mesh() const
278  {
279  return mesh_;
280  }
281 
282  //- Lookup the cloud associated with a mesh
283  static const Foam::cloud& lookup(const LagrangianMesh& mesh);
284 
285  //- Access the models
287 
288 
289  // Fields
290 
291  //- Add/get a state field to/from the cache
292  template<class Type, class ... Args>
294  (
295  const Args& ... args
296  ) const;
297 
298  //- Add/get a derived field to/from the cache
299  template<class Type, class ... Args>
301  (
302  const Args& ... args
303  ) const;
304 
305  //- Add/get an average field to/from the cache
306  template<class Type, class ... Args>
308  (
309  const Args& ... args
310  ) const;
311 
312 
313  // Evolution
314 
315  //- Solve the cloud's evolution over the current time-step
316  virtual void solve();
317 
318 
319  // Mesh changes
320 
321  //- Store the positions for use during mapping
322  virtual void storePosition();
323 
324  //- Update for mesh motion
325  virtual void movePoints(const polyMesh&);
326 
327  //- Update topology using the given map
328  virtual void topoChange(const polyTopoChangeMap&);
329 
330  //- Update from another mesh using the given map
331  virtual void mapMesh(const polyMeshMap&);
332 
333  //- Redistribute or update using the given distribution map
334  virtual void distribute(const polyDistributionMap&);
335 
336 
337  // Member Operators
338 
339  //- Disallow default bitwise assignment
340  void operator=(const LagrangianMesh&) = delete;
341 };
342 
343 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
344 
345 } // End namespace Foam
346 
347 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
348 
349 #ifdef NoRepository
350  #include "cloudTemplates.C"
351 #endif
352 
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
354 
355 #endif
356 
357 // ************************************************************************* //
#define DECLARE_STATE_FIELDS(Type, nullArg)
State fields.
Definition: cloud.H:75
#define DECLARE_AVERAGE_FIELDS(Type, nullArg)
Average fields.
Definition: cloud.H:89
#define DECLARE_DERIVED_FIELDS(Type, nullArg)
Derived fields.
Definition: cloud.H:82
A cloud field that is averaged and then interpolated back to the cloud. Uses CloudDerivedField to pro...
A field derived from other state fields of the cloud. Stores and virtualises a function or a method w...
A field which is stored as part of the state of the cloud. This is a light wrapper around a dynamic L...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
readOption
Enumeration defining the read options.
Definition: IOobject.H:117
IOobject(const word &name, const fileName &instance, const objectRegistry &registry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true)
Construct from name, instance, registry, io options.
Definition: IOobject.C:164
const word & name() const
Return name.
Definition: IOobject.H:307
writeOption
Enumeration defining the write options.
Definition: IOobject.H:126
Class containing Lagrangian geometry and topology.
List of Lagrangian models, constructed as a (Lagrangian) mesh object. Provides similar functions to t...
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Base class for clouds. Provides a basic evolution algorithm, models, and a database for caching deriv...
Definition: cloud.H:63
CloudStateField< Type > & stateField(const Args &... args) const
Add/get a state field to/from the cache.
declareRunTimeSelectionTable(autoPtr, cloud, polyMesh,(const polyMesh &mesh, const word &name, const contextType context),(mesh, name, context))
Declare run-time constructor selection table.
contextType
Context in which this cloud is used.
Definition: cloud.H:222
@ unknown
Definition: cloud.H:222
@ functionObject
Definition: cloud.H:222
CloudStateField< vector > & U
Velocity.
Definition: cloud.H:228
virtual void initialise(const bool predict)
Initialisation hook.
Definition: cloud.C:476
cloud(const polyMesh &mesh, const word &name, const contextType context, const IOobject::readOption readOption=IOobject::READ_IF_PRESENT, const IOobject::writeOption writeOption=IOobject::AUTO_WRITE)
Construct from a mesh and a name.
Definition: cloud.C:512
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: cloud.C:931
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: cloud.C:947
TypeName("cloud")
Run-time type information.
const CloudDerivedField< Type > & derivedField(const Args &... args) const
Add/get a derived field to/from the cache.
virtual void storePosition()
Store the positions for use during mapping.
Definition: cloud.C:919
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: cloud.C:939
Foam::LagrangianModels & LagrangianModels() const
Access the models.
Definition: cloud.C:623
static autoPtr< cloud > New(const polyMesh &mesh, const word &name, const word &type)
Selector.
Definition: cloud.C:562
virtual void movePoints(const polyMesh &)
Update for mesh motion.
Definition: cloud.C:925
const CloudAverageField< Type > & averageField(const Args &... args) const
Add/get an average field to/from the cache.
enum Foam::cloud::contextType context
trackingType
Tracking method.
Definition: cloud.H:225
@ linear
Definition: cloud.H:225
@ parabolic
Definition: cloud.H:225
static const Foam::cloud & lookup(const LagrangianMesh &mesh)
Lookup the cloud associated with a mesh.
Definition: cloud.C:617
virtual ~cloud()
Destructor.
Definition: cloud.C:611
virtual tmp< LagrangianSubVectorField > dUdt(const LagrangianSubMesh &) const =0
Return the acceleration with which to do second-order tracking.
void operator=(const LagrangianMesh &)=delete
Disallow default bitwise assignment.
enum Foam::cloud::trackingType tracking
virtual void partition()
Partition hook.
Definition: cloud.C:484
virtual bool reCalculateModified()=0
Do we need to re-calculate particles that are modified?
virtual void calculate(const LagrangianSubScalarField &deltaT, const bool final)
Update the cloud properties.
Definition: cloud.C:493
const LagrangianMesh & mesh() const
Access the mesh.
Definition: cloud.H:276
virtual void solve()
Solve the cloud's evolution over the current time-step.
Definition: cloud.C:634
Finite volume model abstract base class.
Definition: fvModel.H:60
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
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
LagrangianSubSubField< scalar > LagrangianSubScalarSubField
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
Foam::argList args(argc, argv)