CloudDerivedField.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::CloudDerivedField
26 
27 Description
28  A field derived from other state fields of the cloud. Stores and
29  virtualises a function or a method which generates the field. Caches the
30  result to prevent unnecessary re-evaluation during a calculation step.
31  Provides convenient access for a variety of contexts; i.e., full mesh,
32  sub-mesh and model.
33 
34 SourceFiles
35  CloudDerivedField.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef CloudDerivedField_H
40 #define CloudDerivedField_H
41 
42 #include "LagrangianMesh.H"
43 #include "LagrangianModelRef.H"
44 #include "LagrangianFieldsFwd.H"
45 #include "LagrangianSubFieldsFwd.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class CloudDerivedField Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 template<class Type>
58 {
59 protected:
60 
61  // Protected Classes
62 
63  //- Class to virtualise an evaluation procedure
64  class Functor;
65 
66  //- Class to store an evaluation function
67  template<class F>
68  class Function;
69 
70  //- Class to store an evaluation method
71  template<class C>
72  class Method;
73 
74  //- Class to convert the stored sub-all-field reference into a
75  // temporary Lagrangian field
76  class AllFieldToField;
77 
78 
79  // Protected Data
80 
81  //- The name. May be word::null, in which case the name is
82  // automatically generated by the field algebra.
83  const word name_;
84 
85 
86 private:
87 
88  // Private Data
89 
90  //- The function
91  const autoPtr<Functor> functorPtr_;
92 
93  //- The cached Lagrangian sub-all-field
94  mutable autoPtr<LagrangianSubField<Type>> psiAllPtr_;
95 
96  //- The cached Lagrangian sub-field
97  mutable autoPtr<LagrangianSubField<Type>> psiSubPtr_;
98 
99  //- Flag to indicate whether the sub-field is up to date
100  mutable bool psiSubUpToDate_;
101 
102  //- The index of the sub-mesh
103  mutable uint64_t psiSubMeshIndex_;
104 
105  //- The cached Lagrangian sub-sub-field
106  mutable autoPtr<LagrangianSubSubField<Type>> psiSubSubPtr_;
107 
108  //- Flag to indicate whether the sub-field is up to date
109  mutable bool psiSubSubUpToDate_;
110 
111  //- The index of the sub-sub-mesh
112  mutable uint64_t psiSubSubMeshIndex_;
113 
114 
115 public:
116 
117  // Constructors
118 
119  //- Construct from a name and a function
120  template<class F>
121  CloudDerivedField(const word& name, const F& f);
122 
123  //- Construct from a function
124  template<class F>
125  CloudDerivedField(const F& f);
126 
127  //- Construct from a name, class and a method
128  template<class C>
130  (
131  const word& name,
132  const C& c,
134  (
135  const LagrangianModelRef&,
136  const LagrangianSubMesh&
137  ) const
138  );
139 
140  //- Construct from a class and a method
141  template<class C>
143  (
144  const C& c,
146  (
147  const LagrangianModelRef&,
148  const LagrangianSubMesh&
149  ) const
150  );
151 
152  //- Disallow default bitwise copy construction
153  CloudDerivedField(const CloudDerivedField&) = delete;
154 
155 
156  // Member Functions
157 
158  //- Field name
159  const word& name() const;
160 
161  //- Compute and return an independent copy of the entire field
163  (
164  const LagrangianMesh& mesh
165  ) const;
166 
167  //- Access a part of the field
169 
170  //- Clear
171  void clear(const bool final);
172 
173 
174  // Member Operators
175 
176  //- Compute and return the entire field. This will be a slice of the
177  // cached sub-all-field, for which the lifetime is not guaranteed. If
178  // the result is being stored (e.g., by a function object) then this
179  // might not be appropriate, and the 'field' method should be used
180  // instead.
182  (
183  const LagrangianMesh& mesh
184  ) const;
185 
186  //- Compute and access a part of the field
187  const LagrangianSubField<Type>& operator()
188  (
189  const LagrangianSubMesh& subMesh
190  ) const;
191 
192  //- Compute and access a part of the field associated with a model
193  const LagrangianSubField<Type>& operator()
194  (
195  const LagrangianModelRef& model,
196  const LagrangianSubMesh& subMesh
197  ) const;
198 
199  //- Disallow default bitwise assignment
200  void operator=(const CloudDerivedField&) = delete;
201 };
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 } // End namespace Foam
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 #ifdef NoRepository
210  #include "CloudDerivedField.C"
211 #endif
212 
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 
215 #endif
216 
217 // ************************************************************************* //
Graphite solid properties.
Definition: C.H:51
Class to store an evaluation function.
Class to store an evaluation method.
A field derived from other state fields of the cloud. Stores and virtualises a function or a method w...
CloudDerivedField(const word &name, const F &f)
Construct from a name and a function.
void clear(const bool final)
Clear.
void operator=(const CloudDerivedField &)=delete
Disallow default bitwise assignment.
LagrangianSubSubField< Type > & ref(const LagrangianSubMesh &) const
Access a part of the field.
const word & name() const
Field name.
tmp< LagrangianInternalField< Type > > field(const LagrangianMesh &mesh) const
Compute and return an independent copy of the entire field.
const word name_
The name. May be word::null, in which case the name is.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Class containing Lagrangian geometry and topology.
Simple wrapper to provide an optional reference to a Lagrangian model.
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
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
const dimensionedScalar F
Faraday constant: default SI units: [C/mol].
const dimensionedScalar c
Speed of light in a vacuum.
Namespace for OpenFOAM.
labelList f(nPoints)