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  :
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
Definition: probes.H:269
TypeName
#define TypeName(TypeNameString)
Definition: typeInfo.H:71
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::probes::sphericalTensorFields_
fieldGroup< sphericalTensor > sphericalTensorFields_
Definition: probes.H:162
volFieldsFwd.H
wordRes.H
Foam::probes::symmTensorFields_
fieldGroup< symmTensor > symmTensorFields_
Definition: probes.H:163
Foam::probes::patchIDList_
labelList patchIDList_
Definition: probes.H:189
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::probes::tensorFields_
fieldGroup< tensor > tensorFields_
Definition: probes.H:164
probesTemplates.C
Foam::probes::scalarFields_
fieldGroup< scalar > scalarFields_
Definition: probes.H:160
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:57
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:51
Foam::read
bool read(const char *buf, int32_t &val)
Definition: int32.H:125
Foam::functionObjects::stateFunctionObject
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: stateFunctionObject.H:65
Foam::probes::loadFromFiles_
bool loadFromFiles_
Definition: probes.H:136
Foam::probes::fieldSelection_
wordRes fieldSelection_
Definition: probes.H:142
Foam::probes::fixedLocations_
bool fixedLocations_
Definition: probes.H:147
Foam::probes::surfaceVectorFields_
fieldGroup< vector > surfaceVectorFields_
Definition: probes.H:168
polyMesh.H
Foam::probes::fieldGroup
Definition: probes.H:117
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
OFstream.H
Foam::probes::surfaceSphericalTensorFields_
fieldGroup< sphericalTensor > surfaceSphericalTensorFields_
Definition: probes.H:169
Foam::probes::mesh_
const fvMesh & mesh_
Definition: probes.H:133
Foam::Field
Generic templated field type.
Definition: Field.H:59
Foam::probes::probeFilePtrs_
HashPtrTable< OFstream > probeFilePtrs_
Definition: probes.H:184
Foam::probes::includeOutOfBounds_
bool includeOutOfBounds_
Definition: probes.H:154
Foam::probes::faceList_
labelList faceList_
Definition: probes.H:177
Foam::probes::elements
const labelList & elements() const
Definition: probes.H:287
Foam::probes::elementList_
labelList elementList_
Definition: probes.H:174
Foam::probes
Set of locations to sample.
Definition: probes.H:106
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:119
Foam::probes::oldPoints_
pointField oldPoints_
Definition: probes.H:192
Foam::probes::fieldGroup::fieldGroup
fieldGroup()
Definition: probes.H:123
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:170
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:81
Foam
Definition: atmBoundaryLayer.C:26
Foam::probes::vectorFields_
fieldGroup< vector > vectorFields_
Definition: probes.H:161
Foam::polyMesh::readUpdateState
readUpdateState
Definition: polyMesh.H:86
pointField.H
Foam::probes::surfaceScalarFields_
fieldGroup< scalar > surfaceScalarFields_
Definition: probes.H:167
Foam::probes::probe
virtual const point & probe(const label i) const
Definition: probes.H:281
Foam::probes::surfaceTensorFields_
fieldGroup< tensor > surfaceTensorFields_
Definition: probes.H:171
Foam::probes::probeLocations
virtual const pointField & probeLocations() const
Definition: probes.H:275
Foam::HashPtrTable
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
Definition: HashPtrTable.H:50
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:58
HashPtrTable.H
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:47
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:151
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Definition: foamVtkOutputTemplates.C:29
Foam::functionObjects
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows by prod...
Definition: ObukhovLength.C:34
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::probes::interpolationScheme_
word interpolationScheme_
Definition: probes.H:151
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:49
Foam::probes::readUpdate
virtual void readUpdate(const polyMesh::readUpdateState state)
Definition: probes.H:308
sample
Minimal example by using system/controlDict.functions:
Foam::probes::processor_
labelList processor_
Definition: probes.H:181