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