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 #include "CloudStateField.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 template<class Type>
50 class CloudDerivedField;
51 
52 template<class Type>
53 class CloudAverageField;
54 
55 /*---------------------------------------------------------------------------*\
56  Class cloud Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 class cloud
60 :
61  public regIOobject
62 {
63 private:
64 
65  // Private Data
66 
67  //- Reference to the mesh
68  LagrangianMesh& mesh_;
69 
70  //- The demand-driven Lagrangian models pointer
71  mutable Foam::LagrangianModels* LagrangianModelsPtr_;
72 
73  //- Derived fields
74  #define DECLARE_DERIVED_FIELDS(Type, nullArg) \
75  mutable PtrList<CloudDerivedField<Type>> \
76  CAT3(derived, CAPITALIZE(Type), Fields_);
77  FOR_ALL_FIELD_TYPES(DECLARE_DERIVED_FIELDS);
78  #undef DECLARE_DERIVED_FIELDS
79 
80  //- Average fields
81  #define DECLARE_AVERAGE_FIELDS(Type, nullArg) \
82  mutable PtrList<CloudAverageField<Type>> \
83  CAT3(average, CAPITALIZE(Type), Fields_);
84  FOR_ALL_FIELD_TYPES(DECLARE_AVERAGE_FIELDS);
85  #undef DECLARE_AVERAGE_FIELDS
86 
87  //- Retained state labels
88  autoPtr<LagrangianLabelDynamicField> statePtr_;
89 
90  //- Cell length scale
91  scalarField cellLengthScaleVf_;
92 
93 
94  // Private Member Functions
95 
96  //- Construct and store the Lagrangian mesh, and return a reference
97  static LagrangianMesh& mesh
98  (
99  const polyMesh& pMesh,
100  const word& name,
103  );
104 
105  //- Access the derived fields. Only specialisations are defined.
106  template<class Type>
107  PtrList<CloudDerivedField<Type>>& derivedFields() const;
108 
109  //- Clear the derived fields
110  void clearDerivedFields(const bool final);
111 
112  //- Access the average fields. Only specialisations are defined.
113  template<class Type>
114  PtrList<CloudAverageField<Type>>& averageFields() const;
115 
116  //- Remove values from a sub mesh from the average fields
117  void removeFromAverageFields(const LagrangianSubMesh&);
118 
119  //- Add values from a sub mesh into the average fields
120  void addToAverageFields(const LagrangianSubMesh&, const bool final);
121 
122  //- Correct values from a sub mesh in the average fields
123  void correctAverageFields(const LagrangianSubMesh&, const bool final);
124 
125  //- Clear the average fields
126  void clearAverageFields();
127 
128  //- Reset the average fields
129  void resetAverageFields();
130 
131  //- Return the IO for the retained state labels
132  IOobject stateIo(const IOobject::readOption) const;
133 
134  //- Read and return the retained state labels, if the file exists,
135  // otherwise return an empty pointer
136  autoPtr<LagrangianLabelDynamicField> readStates() const;
137 
138  //- Return the retained state enumerations, if they are available,
139  // otherwise return an empty pointer
140  autoPtr<List<LagrangianState>> initialStates() const;
141 
142  //- Clear the retained state labels
143  void clearStates();
144 
145  //- Store the retained state labels if necessary
146  bool storeStates();
147 
148  //- Store the retained state labels for the given sub-mesh
149  void storeStates(const LagrangianSubMesh& subMesh);
150 
151  //- Calculate the cell length scale for the given sub-mesh
152  tmp<LagrangianSubScalarField> cellLengthScale
153  (
154  const LagrangianSubMesh& subMesh
155  ) const;
156 
157  //- Track through the mesh
158  void track
159  (
161  const scalar maxTimeStepFraction,
162  const scalar maxCellLengthScaleFraction
163  );
164 
165  //- Dummy write for regIOobject
166  virtual bool writeData(Ostream&) const;
167 
168 
169 protected:
170 
171  // Protected Member Functions
172 
173  //- Return the acceleration with which to do second-order tracking
175  (
176  const LagrangianSubMesh&
177  ) const = 0;
178 
179  //- Do we need to re-calculate particles that are modified?
180  virtual bool reCalculateModified() = 0;
181 
182  //- Update the cloud properties
183  virtual void calculate
184  (
185  const LagrangianSubScalarField& deltaT,
186  const bool final
187  ) = 0;
188 
189  //- Partition hook
190  virtual void partition();
191 
192 
193 public:
194 
195  // Public Static Data
196 
197  //- Run-time type information
198  TypeName("cloud");
199 
200 
201  // Public Data
202 
203  //- Context in which this cloud is used
205 
206  //- Tracking method
207  const enum trackingType { linear, parabolic } tracking;
208 
209  //- Velocity
211 
212 
213  //- Declare run-time constructor selection table
215  (
216  autoPtr,
217  cloud,
219  (
221  const contextType context,
222  const dictionary& dict
223  ),
224  (mesh, context, dict)
225  );
226 
227 
228  // Constructors
229 
230  //- Construct from a mesh and context. Reads the velocity field.
232 
233  //- Construct from a mesh, context and a specified velocity field
234  cloud
235  (
237  const contextType context,
239  );
240 
241  //- Disallow default bitwise copy construction
242  cloud(const cloud&) = delete;
243 
244 
245  //- Selectors
246 
247  //- Select given the type name
248  static autoPtr<cloud> New
249  (
250  const polyMesh& mesh,
251  const word& name,
252  const contextType context,
253  const dictionary& dict,
254  const word& type,
257  );
258 
259  //- Select given the type class
260  template<class Type>
261  static autoPtr<Type> New
262  (
263  const polyMesh& pMesh,
264  const word& name,
265  const contextType context,
266  const dictionary& dict,
269  );
270 
271 
272  //- Destructor
273  virtual ~cloud();
274 
275 
276  // Member Functions
277 
278  // Access
279 
280  //- Access the mesh
281  inline const LagrangianMesh& mesh() const
282  {
283  return mesh_;
284  }
285 
286  //- Lookup the cloud associated with a mesh
287  static const Foam::cloud& lookup(const LagrangianMesh& mesh);
288 
289  //- Access the models
291 
292 
293  // Fields
294 
295  //- Add/get a derived field to/from the cache
296  template<class Type, class ... Args>
298  (
299  const Args& ... args
300  ) const;
301 
302  //- Add/get an average field to/from the cache
303  template<class Type, class ... Args>
305  (
306  const Args& ... args
307  ) const;
308 
309 
310  // Evolution
311 
312  //- Solve the cloud's evolution over the current time-step
313  virtual void solve(const bool initial, const bool final);
314 
315 
316  // Mesh changes
317 
318  //- Store the positions for use during mapping
319  virtual void storePosition();
320 
321  //- Update for mesh motion
322  virtual void movePoints(const polyMesh&);
323 
324  //- Update topology using the given map
325  virtual void topoChange(const polyTopoChangeMap&);
326 
327  //- Update from another mesh using the given map
328  virtual void mapMesh(const polyMeshMap&);
329 
330  //- Redistribute or update using the given distribution map
331  virtual void distribute(const polyDistributionMap&);
332 
333 
334  // Member Operators
335 
336  //- Disallow default bitwise assignment
337  void operator=(const LagrangianMesh&) = delete;
338 };
339 
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 
342 } // End namespace Foam
343 
344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345 
346 #ifdef NoRepository
347  #include "cloudTemplates.C"
348 #endif
349 
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
351 
352 #endif
353 
354 // ************************************************************************* //
#define DECLARE_AVERAGE_FIELDS(Type, nullArg)
Average fields.
Definition: cloud.H:80
#define DECLARE_DERIVED_FIELDS(Type, nullArg)
Derived fields.
Definition: cloud.H:73
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:61
contextType
Context in which this cloud is used.
Definition: cloud.H:203
@ unknown
Definition: cloud.H:203
@ functionObject
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
static autoPtr< cloud > New(const polyMesh &mesh, const word &name, const contextType context, const dictionary &dict, const word &type, const IOobject::readOption readOption=IOobject::READ_IF_PRESENT, const IOobject::writeOption writeOption=IOobject::AUTO_WRITE)
Selectors.
Definition: cloud.C:524
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: cloud.C:879
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: cloud.C:895
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:867
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: cloud.C:887
virtual void calculate(const LagrangianSubScalarField &deltaT, const bool final)=0
Update the cloud properties.
Foam::LagrangianModels & LagrangianModels() const
Access the models.
Definition: cloud.C:597
virtual void movePoints(const polyMesh &)
Update for mesh motion.
Definition: cloud.C:873
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:206
@ linear
Definition: cloud.H:206
@ parabolic
Definition: cloud.H:206
static const Foam::cloud & lookup(const LagrangianMesh &mesh)
Lookup the cloud associated with a mesh.
Definition: cloud.C:591
virtual ~cloud()
Destructor.
Definition: cloud.C:585
declareRunTimeSelectionTable(autoPtr, cloud, LagrangianMesh,(LagrangianMesh &mesh, const contextType context, const dictionary &dict),(mesh, context, dict))
Declare run-time constructor selection table.
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:450
virtual bool reCalculateModified()=0
Do we need to re-calculate particles that are modified?
cloud(LagrangianMesh &mesh, const contextType context)
Construct from a mesh and context. Reads the velocity field.
Definition: cloud.C:468
const LagrangianMesh & mesh() const
Access the mesh.
Definition: cloud.H:280
CloudStateField< vector > U
Velocity.
Definition: cloud.H:209
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
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:78
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:63
const unitSet fraction
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
dictionary dict
Foam::argList args(argc, argv)