layerAverage.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) 2011-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::functionObjects::layerAverage
26 
27 Description
28  This function object writes graphs of cell values, volume-averaged in
29  the layers of cells in the mesh.
30 
31  The layers are defined by a set of patches or zones. Between these patches
32  and/or zones the mesh must be perfectly layered; i.e., every cell must be a
33  prism for which the base polygon is topologically similar to the
34  corresponding face on the patch or zone. If the mesh is not layered in this
35  way, then consider using the \c cutLayerAverage function instead.
36 
37  Patches can be used to define the start of the layers and hence the
38  beginning of the graph. E.g.:
39 
40  \verbatim
41  Patch
42  <--|| 1 | 2 | 3 | ...
43  ||---------+---------+---------+----
44  <--|| 1 | 2 | 3 | ...
45  ||---------+---------+---------+----
46  <--|| 1 | 2 | 3 | ...
47  \endverbatim
48 
49  Zones can define either the start or the end of the layers, depending on
50  the zones' orientations. Layers will be enumerated in the same way as for a
51  patch; i.e., they will number outwards in a direction opposite to the
52  zone's normal direction. If two zones (or a zone and a patch) overlap then
53  the one in front (relative to the zones' orientations) defines the start of
54  the layers and the one behind defines the end of the layers. If two zones
55  overlap and have opposing orientations then an error will be generated.
56 
57  \verbatim
58  Zone A Zone B
59  ... | <--|| 1 | 2 | 3 <--|| | ...
60  ----+-------||---------+---------+---------||-------+----
61  ... | <--|| 1 | 2 | 3 <--|| | ...
62  ----+-------||---------+---------+---------||-------+----
63  ... | <--|| 1 | 2 | 3 <--|| | ...
64  \endverbatim
65 
66  Example of function object specification:
67  \verbatim
68  layerAverage1
69  {
70  type layerAverage;
71  libs ("libfieldFunctionObjects.so");
72 
73  writeControl writeTime;
74 
75  setFormat raw;
76 
77  patches (bottom);
78  zones (quarterPlane threeQuartersPlane);
79 
80  axis y;
81 
82  symmetric true;
83 
84  fields (pMean pPrime2Mean UMean UPrime2Mean k);
85  }
86  \endverbatim
87 
88 Usage
89  \table
90  Property | Description | Required | Default value
91  type | Type name: layerAverage | yes |
92  setFormat | Output plotting format | yes |
93  patch | Patch that layers extrude from | no |
94  patches | Patches that layers extrude from | no | ()
95  zones | Face zones that the layers extrude from | no | ()
96  axis | Component of the position to plot against | yes |
97  symmetric | Is the geometry symmetric around the centre layer? \\
98  | no | false
99  fields | Fields to average and plot | yes |
100  weightField | Field with which to weight the average | no | none
101  weightFields | Fields with which to weight the average | no | ()
102  \endtable
103 
104 See also
105  Foam::functionObjects::cutLayerAverage
106 
107 SourceFiles
108  layerAverage.C
109  layerAverageTemplates.C
110 
111 \*---------------------------------------------------------------------------*/
112 
113 #ifndef layerAverage_H
114 #define layerAverage_H
115 
116 #include "fvMeshFunctionObject.H"
117 #include "setWriter.H"
118 #include "boolList.H"
119 #include "volFields.H"
120 
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
122 
123 namespace Foam
124 {
125 namespace functionObjects
126 {
127 
128 /*---------------------------------------------------------------------------*\
129  Class layerAverage Declaration
130 \*---------------------------------------------------------------------------*/
131 
132 class layerAverage
133 :
134  public fvMeshFunctionObject
135 {
136  // Private Data
137 
138  //- Patches which form the start of the layers
139  labelList patchIndices_;
140 
141  //- Zones which form the start of the layers
142  labelList zoneIndices_;
143 
144  //- Is the case symmetric?
145  bool symmetric_;
146 
147  //- The direction over which to plot the results
148  coordSet::axisType axis_;
149 
150  //- Per cell the global layer
151  label nLayers_;
152 
153  //- Per cell the global layer
154  labelList cellLayer_;
155 
156  //- Per global layer the volume
157  scalarField layerVolume_;
158 
159  //- The average centre of each layer
160  pointField layerCentre_;
161 
162  //- Fields to average
163  wordList fields_;
164 
165  //- Fields with which to weight the averages
166  wordList weightFields_;
167 
168  //- Set formatter
169  autoPtr<setWriter> formatter_;
170 
171 
172  // Private Member Functions
173 
174  //- Create the layer information, the sort map, and the scalar axis
175  void calcLayers();
176 
177  //- Calculate and return the weight field, or a null pointer if there
178  // are no weight fields
179  tmp<VolInternalField<scalar>> weight() const;
180 
181  //- Return the coefficient to multiply onto symmetric values
182  template<class T>
183  T symmetricCoeff() const;
184 
185  //- Sum field per layer
186  template<class T>
187  tmp<Field<T>> sum(const VolInternalField<T>& cellField) const;
188 
189  //- Average a field per layer
190  template<class T>
191  tmp<Field<T>> average
192  (
193  const tmp<VolInternalField<scalar>>& cellWeight,
194  const tmp<Field<scalar>>& layerWeight,
195  const VolInternalField<T>& cellField
196  ) const;
197 
198 
199 public:
200 
201  //- Runtime type information
202  TypeName("layerAverage");
203 
204 
205  // Constructors
206 
207  //- Construct from Time and dictionary
209  (
210  const word& name,
211  const Time& runTime,
212  const dictionary& dict
213  );
214 
215  //- Disallow default bitwise copy construction
216  layerAverage(const layerAverage&) = delete;
217 
218 
219  //- Destructor
220  virtual ~layerAverage();
221 
222 
223  // Member Functions
224 
225  //- Read the field average data
226  virtual bool read(const dictionary&);
227 
228  //- Return the list of fields required
229  virtual wordList fields() const;
230 
231  //- Do nothing
232  virtual bool execute();
233 
234  //- Calculate and write the graphs
235  virtual bool write();
236 
237  //- Update for mesh point-motion
238  virtual void movePoints(const polyMesh&);
239 
240  //- Update topology using the given map
241  virtual void topoChange(const polyTopoChangeMap&);
242 
243  //- Update from another mesh using the given map
244  virtual void mapMesh(const polyMeshMap&);
245 
246  //- Redistribute or update using the given distribution map
247  virtual void distribute(const polyDistributionMap&);
248 
249 
250  // Member Operators
251 
252  //- Disallow default bitwise assignment
253  void operator=(const layerAverage&) = delete;
254 };
255 
256 
257 template<>
258 vector layerAverage::symmetricCoeff<vector>() const;
259 
260 template<>
261 symmTensor layerAverage::symmetricCoeff<symmTensor>() const;
262 
263 template<>
264 tensor layerAverage::symmetricCoeff<tensor>() const;
265 
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 } // End namespace functionObjects
270 } // End namespace Foam
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 #ifdef NoRepository
275  #include "layerAverageTemplates.C"
276 #endif
277 
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 
280 #endif
281 
282 // ************************************************************************* //
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
axisType
Enumeration defining the output format for coordinates.
Definition: coordSet.H:58
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const word & name() const
Return the name of this functionObject.
This function object writes graphs of cell values, volume-averaged in the layers of cells in the mesh...
Definition: layerAverage.H:188
virtual wordList fields() const
Return the list of fields required.
Definition: layerAverage.C:287
void operator=(const layerAverage &)=delete
Disallow default bitwise assignment.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: layerAverage.C:410
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: layerAverage.C:433
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: layerAverage.C:422
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
Definition: layerAverage.C:399
layerAverage(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: layerAverage.C:219
TypeName("layerAverage")
Runtime type information.
virtual bool execute()
Do nothing.
Definition: layerAverage.C:295
virtual bool write()
Calculate and write the graphs.
Definition: layerAverage.C:301
virtual ~layerAverage()
Destructor.
Definition: layerAverage.C:233
virtual bool read(const dictionary &)
Read the field average data.
Definition: layerAverage.C:239
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
void T(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1)
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
typename VolField< Type >::Internal VolInternalField
Definition: volFieldsFwd.H:59
dictionary dict