probes.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::probes
29 
30 Group
31  grpUtilitiesFunctionObjects
32 
33 Description
34  Set of locations to sample.
35 
36  Call write() to sample and write files.
37 
38  Example of function object specification:
39  \verbatim
40  probes
41  {
42  type probes;
43  libs (sampling);
44 
45  // Name of the directory for probe data
46  name probes;
47 
48  // Write at same frequency as fields
49  writeControl outputTime;
50  writeInterval 1;
51 
52  // Fields to be probed
53  fields (p U);
54 
55  // Optional: do not recalculate cells if mesh moves
56  fixedLocations false;
57 
58  // Optional: interpolation scheme to use (default is cell)
59  interpolationScheme cellPoint;
60 
61  probeLocations
62  (
63  ( 1e-06 0 0.01 ) // at inlet
64  (0.21 -0.20999 0.01) // at outlet1
65  (0.21 0.20999 0.01) // at outlet2
66  (0.21 0 0.01) // at central block
67  );
68 
69  // Optional: filter out points that haven't been found. Default
70  // is to include them (with value -VGREAT)
71  includeOutOfBounds true;
72  }
73  \endverbatim
74 
75 SourceFiles
76  probes.C
77 
78 \*---------------------------------------------------------------------------*/
79 
80 #ifndef probes_H
81 #define probes_H
82 
83 #include "stateFunctionObject.H"
84 #include "HashPtrTable.H"
85 #include "OFstream.H"
86 #include "polyMesh.H"
87 #include "pointField.H"
88 #include "volFieldsFwd.H"
89 #include "surfaceFieldsFwd.H"
90 #include "surfaceMesh.H"
91 #include "wordRes.H"
92 
93 using namespace Foam::functionObjects;
94 
95 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
96 
97 namespace Foam
98 {
99 
100 // Forward declaration of classes
101 class Time;
102 class objectRegistry;
103 class dictionary;
104 class fvMesh;
105 class mapPolyMesh;
106 
107 /*---------------------------------------------------------------------------*\
108  Class probes Declaration
109 \*---------------------------------------------------------------------------*/
110 
111 class probes
112 :
113  public stateFunctionObject,
114  public pointField
115 {
116 protected:
117 
118  // Protected classes
119 
120  //- Class used for grouping field types
121  template<class Type>
122  class fieldGroup
123  :
124  public DynamicList<word>
125  {
126  public:
127  //- Construct null
128  fieldGroup()
129  :
130  DynamicList<word>(0)
131  {}
132  };
133 
134 
135  // Protected data
136 
137  //- Const reference to fvMesh
138  const fvMesh& mesh_;
139 
140  //- Load fields from files (not from objectRegistry)
141  bool loadFromFiles_;
142 
143 
144  // Read from dictionary
145 
146  //- Names of fields to probe
147  wordRes fieldSelection_;
148 
149  //- Fixed locations, default = yes
150  // Note: set to false for moving mesh calculations where locations
151  // should move with the mesh
152  bool fixedLocations_;
153 
154  //- Interpolation scheme name
155  // Note: only possible when fixedLocations_ is true
156  word interpolationScheme_;
157 
158  //- Include probes that were not found
159  bool includeOutOfBounds_;
160 
161 
162  // Calculated
163 
164  //- Categorized scalar/vector/tensor vol fields
165  fieldGroup<scalar> scalarFields_;
166  fieldGroup<vector> vectorFields_;
167  fieldGroup<sphericalTensor> sphericalTensorFields_;
168  fieldGroup<symmTensor> symmTensorFields_;
169  fieldGroup<tensor> tensorFields_;
170 
171  //- Categorized scalar/vector/tensor surf fields
172  fieldGroup<scalar> surfaceScalarFields_;
173  fieldGroup<vector> surfaceVectorFields_;
174  fieldGroup<sphericalTensor> surfaceSphericalTensorFields_;
175  fieldGroup<symmTensor> surfaceSymmTensorFields_;
176  fieldGroup<tensor> surfaceTensorFields_;
177 
178  //- Cells to be probed (obtained from the locations)
179  labelList elementList_;
180 
181  //- Faces to be probed
182  labelList faceList_;
183 
184  //- Processor holding the cell or face (-1 if point not found
185  // on any processor)
186  labelList processor_;
187 
188  //- Current open files
189  HashPtrTable<OFstream> probeFilePtrs_;
190 
191  // Additional fields for patchProbes
192 
193  //- Patch IDs on which the new probes are located
194  labelList patchIDList_;
195 
196  //- Original probes location (only used for patchProbes)
197  pointField oldPoints_;
198 
199 
200  // Protected Member Functions
201 
202  //- Clear old field groups
203  void clearFieldGroups();
204 
205  //- Classify field types, returns the number of fields
206  label classifyFields();
207 
208  //- Find cells and faces containing probes
209  virtual void findElements(const fvMesh& mesh);
210 
211  //- Classify field type and open/close file streams,
212  // returns number of fields to sample
213  label prepare();
214 
215 
216 private:
217 
218  //- Sample and write a particular volume field
219  template<class Type>
220  void sampleAndWrite
221  (
223  );
224 
225 
226  //- Sample and write a particular surface field
227  template<class Type>
228  void sampleAndWrite
229  (
231  );
232 
233  //- Sample and write all the fields of the given type
234  template<class Type>
235  void sampleAndWrite(const fieldGroup<Type>&);
236 
237  //- Sample and write all the surface fields of the given type
238  template<class Type>
239  void sampleAndWriteSurfaceFields(const fieldGroup<Type>&);
240 
241  //- No copy construct
242  probes(const probes&) = delete;
243 
244  //- No copy assignment
245  void operator=(const probes&) = delete;
246 
247 
248 public:
249 
250  //- Runtime type information
251  TypeName("probes");
252 
253 
254  // Constructors
255 
256  //- Construct from Time and dictionary
257  probes
258  (
259  const word& name,
260  const Time& runTime,
261  const dictionary& dict,
262  const bool loadFromFiles = false,
263  const bool readFields = true
264  );
265 
266 
267  //- Destructor
268  virtual ~probes() = default;
269 
270 
271  // Member Functions
272 
273  //- Return names of fields to probe
274  virtual const wordRes& fieldNames() const
275  {
276  return fieldSelection_;
277  }
278 
279  //- Return locations to probe
280  virtual const pointField& probeLocations() const
281  {
282  return *this;
283  }
284 
285  //- Return location for probe i
286  virtual const point& probe(const label i) const
287  {
288  return operator[](i);
289  }
290 
291  //- Cells to be probed (obtained from the locations)
292  const labelList& elements() const
293  {
294  return elementList_;
295  }
296 
297  //- Read the probes
298  virtual bool read(const dictionary&);
299 
300  //- Execute, currently does nothing
301  virtual bool execute();
302 
303  //- Sample and write
304  virtual bool write();
305 
306  //- Update for changes of mesh
307  virtual void updateMesh(const mapPolyMesh&);
308 
309  //- Update for changes of mesh
310  virtual void movePoints(const polyMesh&);
311 
312  //- Update for changes of mesh due to readUpdate
313  virtual void readUpdate(const polyMesh::readUpdateState state)
314  {}
315 
316  //- Sample a volume field at all locations
317  template<class Type>
319  (
321  ) const;
322 
323  //- Sample a single vol field on all sample locations
324  template<class Type>
325  tmp<Field<Type>> sample(const word& fieldName) const;
326 
327  //- Sample a single scalar field on all sample locations
328  template<class Type>
329  tmp<Field<Type>> sampleSurfaceFields(const word& fieldName) const;
330 
331  //- Sample a surface field at all locations
332  template<class Type>
334  (
336  ) const;
337 };
338 
339 
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 
342 } // End namespace Foam
343 
344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345 
346 #ifdef NoRepository
347  #include "probesTemplates.C"
348 #endif
349 
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
351 
352 #endif
353 
354 // ************************************************************************* //
Foam::probes::fieldNames
virtual const wordRes & fieldNames() const
Return names of fields to probe.
Definition: probes.H:273
TypeName
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::probes::sphericalTensorFields_
fieldGroup< sphericalTensor > sphericalTensorFields_
Definition: probes.H:166
volFieldsFwd.H
wordRes.H
Foam::probes::symmTensorFields_
fieldGroup< symmTensor > symmTensorFields_
Definition: probes.H:167
Foam::probes::patchIDList_
labelList patchIDList_
Patch IDs on which the new probes are located.
Definition: probes.H:193
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::probes::tensorFields_
fieldGroup< tensor > tensorFields_
Definition: probes.H:168
probesTemplates.C
Foam::probes::scalarFields_
fieldGroup< scalar > scalarFields_
Categorized scalar/vector/tensor vol fields.
Definition: probes.H:164
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::functionObjects::stateFunctionObject
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: stateFunctionObject.H:69
Foam::probes::loadFromFiles_
bool loadFromFiles_
Load fields from files (not from objectRegistry)
Definition: probes.H:140
Foam::probes::fieldSelection_
wordRes fieldSelection_
Names of fields to probe.
Definition: probes.H:146
Foam::probes::surfaceVectorFields_
fieldGroup< vector > surfaceVectorFields_
Definition: probes.H:172
polyMesh.H
Foam::probes::fieldGroup
Class used for grouping field types.
Definition: probes.H:121
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
OFstream.H
Foam::probes::surfaceSphericalTensorFields_
fieldGroup< sphericalTensor > surfaceSphericalTensorFields_
Definition: probes.H:173
Foam::probes::mesh_
const fvMesh & mesh_
Const reference to fvMesh.
Definition: probes.H:137
Foam::Field< vector >
Foam::probes::probeFilePtrs_
HashPtrTable< OFstream > probeFilePtrs_
Current open files.
Definition: probes.H:188
Foam::probes::includeOutOfBounds_
bool includeOutOfBounds_
Include probes that were not found.
Definition: probes.H:158
Foam::probes::faceList_
labelList faceList_
Faces to be probed.
Definition: probes.H:181
Foam::probes::elements
const labelList & elements() const
Cells to be probed (obtained from the locations)
Definition: probes.H:291
Foam::probes::elementList_
labelList elementList_
Cells to be probed (obtained from the locations)
Definition: probes.H:178
Foam::probes
Set of locations to sample.
Definition: probes.H:110
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::probes::oldPoints_
pointField oldPoints_
Original probes location (only used for patchProbes)
Definition: probes.H:196
Foam::probes::fieldGroup::fieldGroup
fieldGroup()
Construct null.
Definition: probes.H:127
surfaceMesh.H
fieldNames
const wordRes fieldNames(propsDict.getOrDefault< wordRes >("fields", wordRes()))
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::probes::surfaceSymmTensorFields_
fieldGroup< symmTensor > surfaceSymmTensorFields_
Definition: probes.H:174
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::probes::vectorFields_
fieldGroup< vector > vectorFields_
Definition: probes.H:165
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:90
pointField.H
Foam::probes::surfaceScalarFields_
fieldGroup< scalar > surfaceScalarFields_
Categorized scalar/vector/tensor surf fields.
Definition: probes.H:171
Foam::probes::probe
virtual const point & probe(const label i) const
Return location for probe i.
Definition: probes.H:285
Foam::probes::surfaceTensorFields_
fieldGroup< tensor > surfaceTensorFields_
Definition: probes.H:175
Foam::probes::probeLocations
virtual const pointField & probeLocations() const
Return locations to probe.
Definition: probes.H:279
Foam::HashPtrTable
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
Definition: HashPtrTable.H:54
Foam::Vector< scalar >
Foam::List< label >
HashPtrTable.H
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
surfaceFieldsFwd.H
stateFunctionObject.H
Foam::functionObjects::readFields
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition: readFields.H:155
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::functionObjects
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows by prod...
Definition: ObukhovLength.C:41
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::probes::readUpdate
virtual void readUpdate(const polyMesh::readUpdateState state)
Update for changes of mesh due to readUpdate.
Definition: probes.H:312
sample
Minimal example by using system/controlDict.functions: