LagrangianAverage.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::LagrangianAverage
26 
27 Description
28  Base class for methods of local-averaging of Lagrangian properties
29 
30 SourceFiles
31  LagrangianAverage.C
32  LagrangianAverages.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef LagrangianAverage_H
37 #define LagrangianAverage_H
38 
39 #include "dimensionSet.H"
40 #include "LagrangianFieldsFwd.H"
41 #include "LagrangianSubFieldsFwd.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 template<class Type>
49 class LagrangianAverage;
50 
51 template<class CellMesh, class Type>
53 {
55 };
56 
57 template<class Type>
59 {
60  // No definition. SFINAE then resolves the New templates below.
61 };
62 
63 /*---------------------------------------------------------------------------*\
64  Class LagrangianAverage Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 template<class Type>
69 {
70  // Private Data
71 
72  //- The name of the result
73  const word name_;
74 
75  //- Reference to the mesh
76  const LagrangianMesh& mesh_;
77 
78  //- Dimensions of the result
79  const dimensionSet dimensions_;
80 
81 
82  // Private Member Functions
83 
84  //- Interpolate into a sub-field, where possible. Calling code deals
85  // with default values where no elements are available to interpolate.
86  virtual void interpolate(LagrangianSubField<Type>& result) const = 0;
87 
88 
89 public:
90 
91  //- Runtime type information
92  TypeName("LagrangianAverage");
93 
94 
95  //- Declare run-time constructor selection tables
97  (
98  autoPtr,
100  dictionary,
101  (
102  const word& name,
103  const LagrangianMesh& mesh,
104  const dimensionSet& dimensions,
105  const Field<scalar>& cellWeightSum
106  ),
107  (name, mesh, dimensions, cellWeightSum)
108  );
109 
110 
111  // Constructors
112 
113  //- Construct with a name, for a mesh and with given dimensions
115  (
116  const word& name,
117  const LagrangianMesh& mesh,
118  const dimensionSet& dimensions
119  );
120 
121 
122  // Selectors
123 
124  //- Select to average a field
125  template<template<class> class WeightPF, template<class> class PsiPF>
127  (
128  const word& type,
129  const word& name,
132  );
133 
134  //- Select to average a field with a given cell weight sum
135  template<class CellMesh, template<class> class WeightPsiPF>
137  (
138  const word& type,
139  const word& name,
140  const DimensionedField<scalar, CellMesh>& cellWeightSum,
142  );
143 
144 
145  //- Destructor
146  virtual ~LagrangianAverage();
147 
148 
149  // Member Functions
150 
151  //- Remove weighted values from the average
152  virtual void remove
153  (
154  const LagrangianSubSubField<scalar>& weight,
156  ) = 0;
157 
158  //- Remove values from the average
159  void remove(const LagrangianSubSubField<Type>& weightPsi);
160 
161  //- Add weighted values to the average
162  virtual void add
163  (
164  const LagrangianSubSubField<scalar>& weight,
166  const bool cache
167  ) = 0;
168 
169  //- Add values to the average
170  void add
171  (
172  const LagrangianSubSubField<Type>& weightPsi,
173  const bool cache
174  );
175 
176  //- Correct weighted values in the average
177  virtual void correct
178  (
179  const LagrangianSubSubField<scalar>& weight,
181  const bool cache
182  ) = 0;
183 
184  //- Correct values in the average
185  void correct
186  (
187  const LagrangianSubSubField<Type>& weightPsi,
188  const bool cache
189  );
190 
191  //- Interpolate to a sub-mesh
192  tmp<LagrangianSubField<Type>> interpolate
193  (
194  const LagrangianSubMesh& subMesh
195  ) const;
196 
197 
198  // Member Operators
199 
200  //- Disallow default bitwise assignment
201  void operator=(const LagrangianAverage<Type>&) = delete;
202 };
203 
204 
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 } // End namespace Foam
208 
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 
211 #ifdef NoRepository
212  #include "LagrangianAverage.C"
213 #endif
214 
215 
216 #define defineLagrangianAverage(Type, nullArg) \
217  \
218  namespace Foam \
219  { \
220  typedef LagrangianAverage<Type> Type##Average; \
221  \
222  defineNamedTemplateTypeNameAndDebug \
223  ( \
224  Type##Average, \
225  0 \
226  ); \
227  \
228  defineTemplateRunTimeSelectionTable \
229  ( \
230  Type##Average, \
231  dictionary \
232  ); \
233  }
234 
235 
236 #define makeLagrangianAverage(Type, AverageType) \
237  \
238  namespace Foam \
239  { \
240  typedef LagrangianAverage<Type> Type##Average; \
241  \
242  namespace LagrangianAverages \
243  { \
244  typedef AverageType<Type> Type##AverageType; \
245  \
246  defineNamedTemplateTypeNameAndDebug \
247  ( \
248  Type##AverageType, \
249  0 \
250  ); \
251  \
252  addToRunTimeSelectionTable \
253  ( \
254  Type##Average, \
255  Type##AverageType, \
256  dictionary \
257  ); \
258  } \
259  }
260 
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 #endif
265 
266 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Basic Lagrangian averaging process in which values are averaged in the cells and then interpolated as...
virtual void correct(const LagrangianSubSubField< scalar > &weight, const LagrangianSubSubField< Type > &psi, const bool cache)=0
Correct weighted values in the average.
LagrangianAverage(const word &name, const LagrangianMesh &mesh, const dimensionSet &dimensions)
Construct with a name, for a mesh and with given dimensions.
virtual void add(const LagrangianSubSubField< scalar > &weight, const LagrangianSubSubField< Type > &psi, const bool cache)=0
Add weighted values to the average.
virtual void remove(const LagrangianSubSubField< scalar > &weight, const LagrangianSubSubField< Type > &psi)=0
Remove weighted values from the average.
virtual ~LagrangianAverage()
Destructor.
static autoPtr< LagrangianAverage< Type > > New(const word &type, const word &name, const DimensionedField< scalar, LagrangianMesh, WeightPF > &weight, const DimensionedField< Type, LagrangianMesh, PsiPF > &psi)
Select to average a field.
declareRunTimeSelectionTable(autoPtr, LagrangianAverage, dictionary,(const word &name, const LagrangianMesh &mesh, const dimensionSet &dimensions, const Field< scalar > &cellWeightSum),(name, mesh, dimensions, cellWeightSum))
Declare run-time constructor selection tables.
void operator=(const LagrangianAverage< Type > &)=delete
Disallow default bitwise assignment.
TypeName("LagrangianAverage")
Runtime type information.
Class containing Lagrangian geometry and topology.
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 list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Dimension set for the base types.
Definition: dimensionSet.H:125
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 volScalarField & psi
Namespace for OpenFOAM.
const HashTable< dimensionSet > & dimensions()
Get the table of dimension sets.
Definition: dimensionSets.C:96
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
autoPtr< LagrangianAverage< Type > > type