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 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 ("libcutLayerAverageFunctionObject.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 "volFieldsFwd.H"
88 #include "generatedCellZone.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 Structures
110 
111  //- Weight for a given cell and layer
112  struct weight
113  {
114  label celli, layeri;
115  scalar value;
116  };
117 
118 
119  // Private Data
120 
121  //- The set of cells to average
122  generatedCellZone zone_;
123 
124  //- Direction along which to plot
125  vector direction_;
126 
127  //- Name of the distance field along which to plot
128  word distanceName_;
129 
130  //- Number of layers
131  label nLayers_;
132 
133  //- Whether or not to interpolate
134  bool interpolate_;
135 
136  //- Fields to plot
137  wordList fields_;
138 
139  //- The direction over which to plot the results
140  coordSet::axisType axis_;
141 
142  //- File writer
143  autoPtr<setWriter> formatter_;
144 
145  //- Number of optimisation iterations. Default is 2.
146  label nOptimiseIter_;
147 
148  //- Weights
149  autoPtr<List<weight>> weights_;
150 
151  //- Layer distances. The distance of the layers' cut-planes to the
152  // origin, in the direction of the given vector. If interpolate is
153  // false, then the distance is taken to the middle of the layer.
154  autoPtr<scalarField> layerDistances_;
155 
156  //- Layer thicknesses. If interpolate is false, then this is the
157  // thickness of the layer that the plot point represents.
158  autoPtr<scalarField> layerThicknesses_;
159 
160  //- Layer positions. The average position of the layer.
161  autoPtr<pointField> layerPositions_;
162 
163 
164  // Private Member functions
165 
166  //- Return the output path
167  fileName outputPath() const;
168 
169  //- Calculate and return non-interpolating weights
170  List<weight> calcNonInterpolatingWeights
171  (
172  const scalarField& pointXs,
173  const scalarField& zoneCellMinXs,
174  const scalarField& zoneCellMaxXs,
175  const labelList& zoneCellMinOrder,
176  const scalarField& plotXs,
177  const bool normalise = true
178  ) const;
179 
180  //- Calculate and return interpolating weights
181  List<weight> calcInterpolatingWeights
182  (
183  const scalarField& pointXs,
184  const scalarField& zoneCellMinXs,
185  const scalarField& zoneCellMaxXs,
186  const labelList& zoneCellMinOrder,
187  const scalarField& plotXs,
188  const bool normalise = true
189  ) const;
190 
191  //- Calculate and return weights
192  List<weight> calcWeights
193  (
194  const scalarField& pointXs,
195  const scalarField& zoneCellMinXs,
196  const scalarField& zoneCellMaxXs,
197  const labelList& zoneCellMinOrder,
198  const scalarField& plotXs,
199  const bool normalise = true
200  ) const;
201 
202  //- Calculate and set the weights member data
203  void calcWeights();
204 
205  //- Construct plot values from cell values given a set of weights
206  template<class Type>
207  inline tmp<Field<Type>> applyWeights
208  (
209  const List<weight>& weights,
210  const VolInternalField<Type>& cellValues
211  ) const;
212 
213  //- Clear the cached weights
214  void clear();
215 
216 
217 public:
218 
219  //- Runtime type information
220  TypeName("cutLayerAverage");
221 
222 
223  // Constructors
224 
225  //- Construct from Time and dictionary
227  (
228  const word& name,
229  const Time& runTime,
230  const dictionary& dict
231  );
232 
233 
234  //- Destructor
235  virtual ~cutLayerAverage();
236 
237 
238  // Member Functions
239 
240  //- Read the cutLayerAverage data
241  virtual bool read(const dictionary&);
242 
243  //- Return the list of fields required
244  virtual wordList fields() const;
245 
246  //- Execute, currently does nothing
247  virtual bool execute();
248 
249  //- Write the cutLayerAverage
250  virtual bool write();
251 
252  //- Update for mesh point-motion
253  virtual void movePoints(const polyMesh&);
254 
255  //- Update topology using the given map
256  virtual void topoChange(const polyTopoChangeMap&);
257 
258  //- Update from another mesh using the given map
259  virtual void mapMesh(const polyMeshMap&);
260 
261  //- Redistribute or update using the given distribution map
262  virtual void distribute(const polyDistributionMap&);
263 };
264 
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 } // End namespace functionObjects
269 } // End namespace Foam
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 #endif
274 
275 // ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
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: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
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
typename VolField< Type >::Internal VolInternalField
Definition: volFieldsFwd.H:59
quaternion normalise(const quaternion &q)
Return the normalised (unit) quaternion of the given quaternion.
Definition: quaternionI.H:603
dictionary dict