cutLayerAverage.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::functionObjects::cutLayerAverage
26 
27 Description
28  This function object writes graphs of cell values, volume-averaged in
29  planes perpendicular to a given direction or in contours of a given
30  distance field. It adaptively grades the distribution of graph points to
31  match the resolution of the mesh.
32 
33  Unlike the \c layerAverage function, this function does not require the
34  mesh to be of any specific structure. This function will cut cells that
35  span multiple layers in order to distribute their contributions between the
36  layers. The cutting process has an expense associated with it and the point
37  grading is calculated iteratively and is somewhat approximate.
38 
39  Example of function object specification:
40  \verbatim
41  cutLayerAverage1
42  {
43  type cutLayerAverage;
44  libs ("libfieldFunctionObjects.so");
45 
46  writeControl writeTime;
47  writeInterval 1;
48 
49  direction (1 0 0);
50  nPoints 100;
51  interpolate no;
52 
53  fields (p U);
54 
55  axis x;
56  setFormat raw;
57  }
58  \endverbatim
59 
60 Usage
61  \table
62  Property | Description | Required | Default value
63  type | type name: cutLayerAverage | yes |
64  cellZone | The name of the cell zone | yes |
65  direction | Axis along which to plot | if distance not specified |
66  distance | Distance field along which to plot \\
67  | if direction not specified |
68  nPoints | Number of points in the plot | yes |
69  interpolate | Do linear interpolation | no | false
70  fields | Fields to plot values of | yes |
71  axis | Component of the position to plot against | yes |
72  setFormat | Format of the output file | yes |
73  \endtable
74 
75 See also
76  Foam::functionObjects::layerAverage
77 
78 SourceFiles
79  cutLayerAverage.C
80 
81 \*---------------------------------------------------------------------------*/
82 
83 #ifndef cutLayerAverage_H
84 #define cutLayerAverage_H
85 
86 #include "fvMeshFunctionObject.H"
87 #include "generatedCellZone.H"
88 #include "cutPlot.H"
89 #include "setWriter.H"
90 
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92 
93 namespace Foam
94 {
95 
96 class polyPatch;
97 
98 namespace functionObjects
99 {
100 
101 /*---------------------------------------------------------------------------*\
102  Class cutLayerAverage Declaration
103 \*---------------------------------------------------------------------------*/
104 
105 class cutLayerAverage
106 :
107  public fvMeshFunctionObject
108 {
109  // Private Data
110 
111  //- The set of cells to average
112  generatedCellZone zone_;
113 
114  //- Direction along which to plot
115  vector direction_;
116 
117  //- Name of the distance field along which to plot
118  word distanceName_;
119 
120  //- Number of layers
121  label nLayers_;
122 
123  //- Whether or not to interpolate
124  bool interpolate_;
125 
126  //- Fields to plot
127  wordList fields_;
128 
129  //- The direction over which to plot the results
130  coordSet::axisType axis_;
131 
132  //- File writer
133  autoPtr<setWriter> formatter_;
134 
135  //- Number of optimisation iterations. Default is 2.
136  label nOptimiseIter_;
137 
138  //- Weights
139  autoPtr<List<cutPlot::weight>> weights_;
140 
141  //- Layer distances. The distance of the layers' cut-planes to the
142  // origin, in the direction of the given vector. If interpolate is
143  // false, then the distance is taken to the middle of the layer.
144  autoPtr<scalarField> layerDistances_;
145 
146  //- Layer thicknesses. If interpolate is false, then this is the
147  // thickness of the layer that the plot point represents.
148  autoPtr<scalarField> layerThicknesses_;
149 
150  //- Layer positions. The average position of the layer.
151  autoPtr<pointField> layerPositions_;
152 
153 
154  // Private Member functions
155 
156  //- Return the output path
157  fileName outputPath() const;
158 
159  //- Calculate and set the weights member data
160  void calcWeights();
161 
162  //- Clear the cached weights
163  void clear();
164 
165 
166 public:
167 
168  //- Runtime type information
169  TypeName("cutLayerAverage");
170 
171 
172  // Constructors
173 
174  //- Construct from Time and dictionary
176  (
177  const word& name,
178  const Time& runTime,
179  const dictionary& dict
180  );
181 
182 
183  //- Destructor
184  virtual ~cutLayerAverage();
185 
186 
187  // Member Functions
188 
189  //- Read the cutLayerAverage data
190  virtual bool read(const dictionary&);
191 
192  //- Return the list of fields required
193  virtual wordList fields() const;
194 
195  //- Execute, currently does nothing
196  virtual bool execute();
197 
198  //- Write the cutLayerAverage
199  virtual bool write();
200 
201  //- Update for mesh point-motion
202  virtual void movePoints(const polyMesh&);
203 
204  //- Update topology using the given map
205  virtual void topoChange(const polyTopoChangeMap&);
206 
207  //- Update from another mesh using the given map
208  virtual void mapMesh(const polyMeshMap&);
209 
210  //- Redistribute or update using the given distribution map
211  virtual void distribute(const polyDistributionMap&);
212 };
213 
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 } // End namespace functionObjects
218 } // End namespace Foam
219 
220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 
222 #endif
223 
224 // ************************************************************************* //
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
A class for handling file names.
Definition: fileName.H:82
const word & name() const
Return the name of this functionObject.
TypeName("cutLayerAverage")
Runtime type information.
virtual wordList fields() const
Return the list of fields required.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
cutLayerAverage(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual bool execute()
Execute, currently does nothing.
virtual bool write()
Write the cutLayerAverage.
virtual bool read(const dictionary &)
Read the cutLayerAverage data.
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:78
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
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
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
dictionary dict