CarrierField.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::CarrierField
26 
27 Description
28  A field interpolated from the carrier to the cloud. Uses CloudDerivedField
29  to provide flexible access and caching.
30 
31 See also
32  Foam::CloudDerivedField
33 
34 SourceFiles
35  CarrierField.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef CarrierField_H
40 #define CarrierField_H
41 
42 #include "CloudDerivedField.H"
43 #include "interpolation.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class CarrierFieldBase Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 template<class Type>
55 class CarrierFieldBase
56 :
57  public CloudDerivedField<Type>
58 {
59  // Private Classes
60 
61  //- Class to virtualise an evaluation procedure
62  class Functor;
63 
64  //- Class to store an evaluation function
65  template<class F>
66  class Function;
67 
68 
69  // Private Data
70 
71  //- The function
72  const autoPtr<Functor> functorPtr_;
73 
74  //- Field reference or cache
75  mutable tmp<VolField<Type>> tpsi_;
76 
77  //- Interpolation engine
78  mutable autoPtr<interpolation<Type>> psiInterpolationPtr_;
79 
80  //- Old-time interpolation engine
81  mutable autoPtr<interpolation<Type>> psi0InterpolationPtr_;
82 
83 
84  // Private Member Functions
85 
86  //- Interpolate and return the result
88  (
89  const LagrangianModelRef&,
90  const LagrangianSubMesh& subMesh
91  ) const;
92 
93 
94 protected:
95 
96  // Protected Member Functions
97 
98  //- Return whether or not to interpolate in time as well as space
99  bool useOldTime(const LagrangianMesh&) const;
100 
101  //- Return the interpolation engine
103  (
104  const LagrangianMesh&
105  ) const;
106 
107  //- Return the old-time interpolation engine
109  (
110  const LagrangianMesh&
111  ) const;
112 
113 
114 public:
115 
116  // Constructors
117 
118  //- Construct from a reference to a carrier field
120 
121  //- Construct from a name and a reference to a carrier field
122  CarrierFieldBase(const word& name, const VolField<Type>&);
123 
124  //- Construct from a name and an evaluation function
125  template<class F>
126  CarrierFieldBase(const word& name, const F& f);
127 
128 
129  // Member Functions
130 
131  //- Access the carrier field
132  const VolField<Type>& psi() const;
133 
134  //- Reset
135  void reset(const bool initial);
136 };
137 
138 
139 /*---------------------------------------------------------------------------*\
140  Class CarrierFieldGradBase Declaration
141 \*---------------------------------------------------------------------------*/
142 
143 template<class Type>
145 :
146  public CarrierFieldBase<Type>
147 {
148  // Private Type Definitions
149 
150  //- The gradient type
151  typedef typename outerProduct<Type, vector>::type GradType;
152 
153 
154  // Private Member Functions
155 
156  //- Interpolate the gradient and return the result
157  tmp<LagrangianSubField<GradType>> interpolateGrad
158  (
159  const LagrangianModelRef&,
160  const LagrangianSubMesh& subMesh
161  ) const;
162 
163 
164 public:
165 
166  // Constructors
167 
168  //- Construct from arguments passed to the base class
169  template<class ... Args>
170  CarrierFieldGradBase(const Args& ... args);
171 
172 
173  // Public Data
174 
175  // The gradient derived field
177 
178 
179  // Member Functions
180 
181  //- Reset
182  void reset(const bool initial);
183 };
184 
185 
186 /*---------------------------------------------------------------------------*\
187  Typedef CarrierFieldBaseOrGradBase Declaration
188 \*---------------------------------------------------------------------------*/
189 
190 template<class Type>
192  typename std::conditional
193  <
194  (pTraits<Type>::rank > 1),
197  >::type;
198 
199 
200 /*---------------------------------------------------------------------------*\
201  Class CarrierField Declaration
202 \*---------------------------------------------------------------------------*/
203 
204 template<class Type>
205 class CarrierField
206 :
207  public CarrierFieldBaseOrGradBase<Type>
208 {
209  // Private Type Definitions
210 
211  //- The base class
213 
214 
215 public:
216 
217  // Constructors
218 
219  //- Inherit constructors
220  using Base::Base;
221 };
222 
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 } // End namespace Foam
227 
228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 
230 #ifdef NoRepository
231  #include "CarrierField.C"
232 #endif
233 
234 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 
236 #endif
237 
238 // ************************************************************************* //
Class to store an evaluation function.
Definition: CarrierField.C:67
const VolField< Type > & psi() const
Access the carrier field.
Definition: CarrierField.C:360
bool useOldTime(const LagrangianMesh &) const
Return whether or not to interpolate in time as well as space.
Definition: CarrierField.C:251
const interpolation< Type > & psi0Interpolation(const LagrangianMesh &) const
Return the old-time interpolation engine.
Definition: CarrierField.C:285
void reset(const bool initial)
Reset.
Definition: CarrierField.C:372
CarrierFieldBase(const VolField< Type > &)
Construct from a reference to a carrier field.
Definition: CarrierField.C:306
const interpolation< Type > & psiInterpolation(const LagrangianMesh &) const
Return the interpolation engine.
Definition: CarrierField.C:265
void reset(const bool initial)
Reset.
Definition: CarrierField.C:395
CarrierFieldGradBase(const Args &... args)
Construct from arguments passed to the base class.
Definition: CarrierField.C:350
CloudDerivedField< GradType > grad
Definition: CarrierField.H:175
A field interpolated from the carrier to the cloud. Uses CloudDerivedField to provide flexible access...
Definition: CarrierField.H:207
A field derived from other state fields of the cloud. Stores and virtualises a function or a method w...
const word & name() const
Field name.
Generic GeometricField class.
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
Abstract base class for interpolation.
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:90
Traits class for primitives.
Definition: pTraits.H:53
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
const dimensionedScalar F
Faraday constant: default SI units: [C/mol].
static tmp< SurfaceField< Type > > interpolate(const VolField< Type > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
Namespace for OpenFOAM.
typename std::conditional<(pTraits< Type >::rank > 1), CarrierFieldBase< Type >, CarrierFieldGradBase< Type > >::type CarrierFieldBaseOrGradBase
Definition: CarrierField.H:196
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
labelList f(nPoints)
Foam::argList args(argc, argv)