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 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 private:
80 
81  // Private Data
82 
83  //- The name. May be null, in which case the name is automatically
84  // generated by the field algebra.
85  const word& name_;
86 
87  //- The function
88  const autoPtr<Functor> functorPtr_;
89 
90  //- The cached Lagrangian sub-all-field
91  mutable autoPtr<LagrangianSubField<Type>> psiAllPtr_;
92 
93  //- The cached Lagrangian sub-field
94  mutable autoPtr<LagrangianSubField<Type>> psiSubPtr_;
95 
96  //- Flag to indicate whether the sub-field is up to date
97  mutable bool psiSubUpToDate_;
98 
99  //- The index of the sub-mesh
100  mutable label psiSubMeshIndex_;
101 
102  //- The cached Lagrangian sub-sub-field
103  mutable autoPtr<LagrangianSubSubField<Type>> psiSubSubPtr_;
104 
105  //- Flag to indicate whether the sub-field is up to date
106  mutable bool psiSubSubUpToDate_;
107 
108  //- The index of the sub-sub-mesh
109  mutable label psiSubSubMeshIndex_;
110 
111 
112 public:
113 
114  // Constructors
115 
116  //- Construct from a name and a function
117  template<class F>
118  CloudDerivedField(const word& name, const F& f);
119 
120  //- Construct from a function
121  template<class F>
122  CloudDerivedField(const F& f);
123 
124  //- Construct from a name, class and a method
125  template<class C>
127  (
128  const word& name,
129  const C& c,
131  (
132  const LagrangianModelRef&,
133  const LagrangianSubMesh&
134  ) const
135  );
136 
137  //- Construct from a class and a method
138  template<class C>
140  (
141  const C& c,
143  (
144  const LagrangianModelRef&,
145  const LagrangianSubMesh&
146  ) const
147  );
148 
149  //- Disallow default bitwise copy construction
150  CloudDerivedField(const CloudDerivedField&) = delete;
151 
152 
153  // Member Functions
154 
155  //- Compute and return an independent copy of the entire field
157  (
158  const LagrangianMesh& mesh
159  ) const;
160 
161  //- Access a part of the field
163 
164  //- Clear
165  void clear(const bool final);
166 
167 
168  // Member Operators
169 
170  //- Compute and return the entire field. This will be a slice of the
171  // cached sub-all-field, for which the lifetime is not guaranteed. If
172  // the result is being stored (e.g., by a function object) then this
173  // might not be appropriate, and the 'field' method should be used
174  // instead.
176  (
177  const LagrangianMesh& mesh
178  ) const;
179 
180  //- Compute and access a part of the field
181  const LagrangianSubField<Type>& operator()
182  (
183  const LagrangianSubMesh& subMesh
184  ) const;
185 
186  //- Compute and access a part of the field associated with a model
187  const LagrangianSubField<Type>& operator()
188  (
189  const LagrangianModelRef& model,
190  const LagrangianSubMesh& subMesh
191  ) const;
192 
193  //- Disallow default bitwise assignment
194  void operator=(const CloudDerivedField&) = delete;
195 };
196 
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 
199 } // End namespace Foam
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 #ifdef NoRepository
204  #include "CloudDerivedField.C"
205 #endif
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 #endif
210 
211 // ************************************************************************* //
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.
tmp< LagrangianInternalField< Type > > field(const LagrangianMesh &mesh) const
Compute and return an independent copy of the entire field.
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:62
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.
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
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
labelList f(nPoints)