patchCutLayerAverage.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) 2022-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::patchCutLayerAverage
26 
27 Description
28  This function object writes graphs of patch face values, area-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  Example of function object specification:
34  \verbatim
35  patchCutLayerAverage1
36  {
37  type patchCutLayerAverage;
38  libs ("libpatchCutLayerAverageFunctionObject.so");
39 
40  writeControl writeTime;
41  writeInterval 1;
42 
43  patch lowerWall;
44  direction (1 0 0);
45  nPoints 100;
46  interpolate no;
47 
48  fields (p U);
49 
50  axis x;
51  setFormat raw;
52  }
53  \endverbatim
54 
55 Usage
56  \table
57  Property | Description | Required | Default value
58  type | type name: patchCutLayerAverage | yes |
59  patch | Name of the patch | yes |
60  direction | Axis along which to plot | if distance not specified |
61  distance | Distance field along which to plot \\
62  | if direction not specified |
63  nPoints | Number of points in the plot | yes |
64  interpolate | Do linear interpolation | no | false
65  fields | Fields to plot values of | yes |
66  axis | Component of the position to plot against | yes |
67  setFormat | Format of the output file | yes |
68  \endtable
69 
70 SourceFiles
71  patchCutLayerAverage.C
72 
73 \*---------------------------------------------------------------------------*/
74 
75 #ifndef patchCutLayerAverage_H
76 #define patchCutLayerAverage_H
77 
78 #include "fvMeshFunctionObject.H"
79 #include "vector.H"
80 #include "setWriter.H"
81 
82 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
83 
84 namespace Foam
85 {
86 
87 class polyPatch;
88 
89 namespace functionObjects
90 {
91 
92 /*---------------------------------------------------------------------------*\
93  Class patchCutLayerAverage Declaration
94 \*---------------------------------------------------------------------------*/
95 
96 class patchCutLayerAverage
97 :
98  public fvMeshFunctionObject
99 {
100  // Private Structures
101 
102  //- Weight for a given face and layer
103  struct weight
104  {
105  label facei, layeri;
106  scalar value;
107  };
108 
109 
110  // Private Data
111 
112  //- Name of the patch
113  word patchName_;
114 
115  //- Direction along which to plot
116  vector direction_;
117 
118  //- Name of the distance field along which to plot
119  word distanceName_;
120 
121  //- Number of layers
122  label nLayers_;
123 
124  //- Whether or not to interpolate
125  bool interpolate_;
126 
127  //- Fields to plot
128  wordList fields_;
129 
130  //- The direction over which to plot the results
131  coordSet::axisType axis_;
132 
133  //- File writer
134  autoPtr<setWriter> formatter_;
135 
136  //- Number of optimisation iterations. Default is 2.
137  label nOptimiseIter_;
138 
139  //- Weights
140  autoPtr<List<weight>> weights_;
141 
142  //- Layer distances. The distance of the layers' cut-planes to the
143  // origin, in the direction of the given vector. If interpolate is
144  // false, then the distance is taken to the middle of the layer.
145  autoPtr<scalarField> layerDistances_;
146 
147  //- Layer thicknesses. If interpolate is false, then this is the
148  // thickness of the layer that the plot point represents.
149  autoPtr<scalarField> layerThicknesses_;
150 
151  //- Layer positions. The average position of the layer.
152  autoPtr<pointField> layerPositions_;
153 
154 
155  // Private Member functions
156 
157  //- Return the output path
158  fileName outputPath() const;
159 
160  //- Calculate and return non-interpolating weights
161  List<weight> calcNonInterpolatingWeights
162  (
163  const scalarField& pointXs,
164  const scalarField& faceMinXs,
165  const scalarField& faceMaxXs,
166  const labelList& faceMinOrder,
167  const scalarField& plotXs,
168  const bool normalise = true
169  ) const;
170 
171  //- Calculate and return interpolating weights
172  List<weight> calcInterpolatingWeights
173  (
174  const scalarField& pointXs,
175  const scalarField& faceMinXs,
176  const scalarField& faceMaxXs,
177  const labelList& faceMinOrder,
178  const scalarField& plotXs,
179  const bool normalise = true
180  ) const;
181 
182  //- Calculate and return weights
183  List<weight> calcWeights
184  (
185  const scalarField& pointXs,
186  const scalarField& faceMinXs,
187  const scalarField& faceMaxXs,
188  const labelList& faceMinOrder,
189  const scalarField& plotXs,
190  const bool normalise = true
191  ) const;
192 
193  //- Calculate and set the weights member data
194  void calcWeights();
195 
196  //- Construct plot values from face values given a set of weights
197  template<class Type>
198  inline tmp<Field<Type>> applyWeights
199  (
200  const List<weight>& weights,
201  const Field<Type>& faceValues
202  ) const;
203 
204  //- Clear the cached weights
205  void clear();
206 
207 
208 public:
209 
210  //- Runtime type information
211  TypeName("patchCutLayerAverage");
212 
213 
214  // Constructors
215 
216  //- Construct from Time and dictionary
218  (
219  const word& name,
220  const Time& runTime,
221  const dictionary& dict
222  );
223 
224 
225  //- Destructor
226  virtual ~patchCutLayerAverage();
227 
228 
229  // Member Functions
230 
231  //- Read the patchCutLayerAverage data
232  virtual bool read(const dictionary&);
233 
234  //- Return the list of fields required
235  virtual wordList fields() const;
236 
237  //- Execute, currently does nothing
238  virtual bool execute();
239 
240  //- Write the patchCutLayerAverage
241  virtual bool write();
242 
243  //- Update for mesh point-motion
244  virtual void movePoints(const polyMesh&);
245 
246  //- Update topology using the given map
247  virtual void topoChange(const polyTopoChangeMap&);
248 
249  //- Update from another mesh using the given map
250  virtual void mapMesh(const polyMeshMap&);
251 
252  //- Redistribute or update using the given distribution map
253  virtual void distribute(const polyDistributionMap&);
254 };
255 
256 
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 
259 } // End namespace functionObjects
260 } // End namespace Foam
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 #endif
265 
266 // ************************************************************************* //
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.
patchCutLayerAverage(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
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.
TypeName("patchCutLayerAverage")
Runtime type information.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
virtual bool execute()
Execute, currently does nothing.
virtual bool write()
Write the patchCutLayerAverage.
virtual bool read(const dictionary &)
Read the patchCutLayerAverage 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
quaternion normalise(const quaternion &q)
Return the normalised (unit) quaternion of the given quaternion.
Definition: quaternionI.H:603
dictionary dict