CloudAverageField.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::CloudAverageField
26 
27 Description
28  A cloud field that is averaged and then interpolated back to the cloud. Uses
29  CloudDerivedField to provide flexible access and caching.
30 
31 See also
32  Foam::CloudDerivedField
33 
34 SourceFiles
35  CloudAverageField.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef CloudAverageField_H
40 #define CloudAverageField_H
41 
42 #include "CloudStateField.H"
43 #include "CloudDerivedField.H"
44 #include "LagrangianAverage.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 class fvMesh;
52 
53 /*---------------------------------------------------------------------------*\
54  Class CloudAverageField Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 template<class Type>
59 :
60  public CloudDerivedField<Type>
61 {
62  // Private Data
63 
64  //- The cell weight sum
65  const tmp<DimensionedField<scalar, fvMesh>> tcellWeightSum_;
66 
67  //- Reference to the weight state field
68  const CloudStateField<scalar>& weightState_;
69 
70  //- Reference to the weight derived field
71  const CloudDerivedField<scalar>& weightDerived_;
72 
73  //- Reference to the state field
74  const CloudStateField<Type>& weightPsiOrPsiState_;
75 
76  //- Reference to the derived field
77  const CloudDerivedField<Type>& weightPsiOrPsiDerived_;
78 
79  //- Averaging engine
80  mutable autoPtr<LagrangianAverage<Type>> psiAveragePtr_;
81 
82  //- Current state of the average
83  mutable enum class psiAverageState
84  {
85  removed,
86  complete,
87  cached
88  } psiAverageState_;
89 
90 
91  // Private Member Functions
92 
93  //- Run an operation on the averaging engine
94  template<class MethodWeightSum, class MethodNoWeightSum, class ... Args>
95  void op
96  (
97  MethodWeightSum,
98  MethodNoWeightSum,
99  const LagrangianSubMesh&,
100  const Args& ... args
101  ) const;
102 
103  //- Interpolate and return the result
104  tmp<LagrangianSubField<Type>> interpolate
105  (
106  const LagrangianModelRef&,
107  const LagrangianSubMesh&
108  ) const;
109 
110 
111 public:
112 
113  // Constructors
114 
115  //- Construct from a name, a cell weight sum and a derived field
117  (
118  const word& name,
119  const DimensionedField<scalar, fvMesh>& cellWeightSum,
120  const CloudDerivedField<Type>& weightPsi
121  );
122 
123 
124  // Member Functions
125 
126  //- Remove this sub-mesh from the average
127  void remove(const LagrangianSubMesh& subMesh);
128 
129  //- Add this sub-mesh to the average
130  void add(const LagrangianSubMesh& subMesh, const bool cache);
131 
132  //- Correct the average with values from the sub-mesh
133  void correct(const LagrangianSubMesh& subMesh, const bool cache);
134 
135  //- Reset
136  void reset();
137 };
138 
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
140 
141 } // End namespace Foam
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 #ifdef NoRepository
146  #include "CloudAverageField.C"
147 #endif
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 #endif
152 
153 // ************************************************************************* //
A cloud field that is averaged and then interpolated back to the cloud. Uses CloudDerivedField to pro...
void remove(const LagrangianSubMesh &subMesh)
Remove this sub-mesh from the average.
void add(const LagrangianSubMesh &subMesh, const bool cache)
Add this sub-mesh to the average.
CloudAverageField(const word &name, const DimensionedField< scalar, fvMesh > &cellWeightSum, const CloudDerivedField< Type > &weightPsi)
Construct from a name, a cell weight sum and a derived field.
void correct(const LagrangianSubMesh &subMesh, const bool cache)
Correct the average with values from the sub-mesh.
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.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
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
Namespace for OpenFOAM.
Foam::argList args(argc, argv)