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-2020 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 
192  // Protected Member Functions
193 
194  //- Clear old field groups
195  void clearFieldGroups();
196 
197  //- Classify field types, returns the number of fields
198  label classifyFields();
199 
200  //- Find cells and faces containing probes
201  virtual void findElements(const fvMesh& mesh);
202 
203  //- Classify field type and open/close file streams,
204  // returns number of fields to sample
205  label prepare();
206 
207 
208 private:
209 
210  //- Sample and write a particular volume field
211  template<class Type>
212  void sampleAndWrite
213  (
215  );
216 
217 
218  //- Sample and write a particular surface field
219  template<class Type>
220  void sampleAndWrite
221  (
223  );
224 
225  //- Sample and write all the fields of the given type
226  template<class Type>
227  void sampleAndWrite(const fieldGroup<Type>&);
228 
229  //- Sample and write all the surface fields of the given type
230  template<class Type>
231  void sampleAndWriteSurfaceFields(const fieldGroup<Type>&);
232 
233  //- No copy construct
234  probes(const probes&) = delete;
235 
236  //- No copy assignment
237  void operator=(const probes&) = delete;
238 
239 
240 public:
241 
242  //- Runtime type information
243  TypeName("probes");
244 
245 
246  // Constructors
247 
248  //- Construct from Time and dictionary
249  probes
250  (
251  const word& name,
252  const Time& runTime,
253  const dictionary& dict,
254  const bool loadFromFiles = false,
255  const bool readFields = true
256  );
257 
258 
259  //- Destructor
260  virtual ~probes() = default;
261 
262 
263  // Member Functions
264 
265  //- Return names of fields to probe
266  virtual const wordRes& fieldNames() const
267  {
268  return fieldSelection_;
269  }
270 
271  //- Return locations to probe
272  virtual const pointField& probeLocations() const
273  {
274  return *this;
275  }
276 
277  //- Return location for probe i
278  virtual const point& probe(const label i) const
279  {
280  return operator[](i);
281  }
282 
283  //- Cells to be probed (obtained from the locations)
284  const labelList& elements() const
285  {
286  return elementList_;
287  }
288 
289  //- Read the probes
290  virtual bool read(const dictionary&);
291 
292  //- Execute, currently does nothing
293  virtual bool execute();
294 
295  //- Sample and write
296  virtual bool write();
297 
298  //- Update for changes of mesh
299  virtual void updateMesh(const mapPolyMesh&);
300 
301  //- Update for changes of mesh
302  virtual void movePoints(const polyMesh&);
303 
304  //- Update for changes of mesh due to readUpdate
305  virtual void readUpdate(const polyMesh::readUpdateState state)
306  {}
307 
308  //- Sample a volume field at all locations
309  template<class Type>
310  tmp<Field<Type>> sample
311  (
313  ) const;
314 
315  //- Sample a single vol field on all sample locations
316  template<class Type>
317  tmp<Field<Type>> sample(const word& fieldName) const;
318 
319  //- Sample a single scalar field on all sample locations
320  template<class Type>
321  tmp<Field<Type>> sampleSurfaceFields(const word& fieldName) const;
322 
323  //- Sample a surface field at all locations
324  template<class Type>
325  tmp<Field<Type>> sample
326  (
328  ) const;
329 };
330 
331 
332 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
333 
334 } // End namespace Foam
335 
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
337 
338 #ifdef NoRepository
339  #include "probesTemplates.C"
340 #endif
341 
342 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
343 
344 #endif
345 
346 // ************************************************************************* //
Foam::probes::fieldNames
virtual const wordRes & fieldNames() const
Return names of fields to probe.
Definition: probes.H:265
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::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:62
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:67
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::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
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:283
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:121
Foam::probes::fieldGroup::fieldGroup
fieldGroup()
Construct null.
Definition: probes.H:127
surfaceMesh.H
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:83
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:277
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:271
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:35
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::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:304