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-2022 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 writeTime;
50  writeInterval 1;
51 
52  // Fields to be probed
53  fields (U "p.*");
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  Entries:
76  \table
77  Property | Description | Required | Default
78  type | Type-name: probes | yes |
79  probeLocations | Probe locations | yes |
80  fields | word/regex list of fields to sample | yes |
81  interpolationScheme | scheme to obtain values | no | cell
82  fixedLocations | Do not recalculate cells if mesh moves | no | true
83  includeOutOfBounds | Include out-of-bounds locations | no | true
84  sampleOnExecute | Sample on execution and store results | no | false
85  \endtable
86 
87 SourceFiles
88  probes.C
89  probesTemplates.C
90 
91 \*---------------------------------------------------------------------------*/
92 
93 #ifndef Foam_probes_H
94 #define Foam_probes_H
95 
96 #include "fvMeshFunctionObject.H"
97 #include "HashPtrTable.H"
98 #include "OFstream.H"
99 #include "polyMesh.H"
100 #include "pointField.H"
101 #include "volFieldsFwd.H"
102 #include "surfaceFieldsFwd.H"
103 #include "surfaceMesh.H"
104 #include "wordRes.H"
105 #include "IOobjectList.H"
106 
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
109 namespace Foam
110 {
111 
112 // Forward Declarations
113 class Time;
114 class objectRegistry;
115 class dictionary;
116 class fvMesh;
117 class mapPolyMesh;
118 
119 /*---------------------------------------------------------------------------*\
120  Class probes Declaration
121 \*---------------------------------------------------------------------------*/
122 
123 class probes
124 :
125  public functionObjects::fvMeshFunctionObject,
126  public pointField
127 {
128 protected:
129 
130  // Protected Classes
131 
132  //- Grouping of field names by GeometricField type
133  template<class GeoField>
134  struct fieldGroup : public DynamicList<word> {};
135 
136 
137  // Data Types
138 
139  //- Local control for sampling actions
140  enum sampleActionType : unsigned
141  {
142  ACTION_NONE = 0,
143  ACTION_WRITE = 0x1,
144  ACTION_STORE = 0x2,
145  ACTION_ALL = 0xF
146  };
147 
148 
149  // Protected Data
150 
151  //- Load fields from files (not from objectRegistry)
152  bool loadFromFiles_;
153 
154  //- Fixed locations (default: true)
155  // Note: set to false for moving mesh calculations where locations
156  // should move with the mesh
157  bool fixedLocations_;
159  //- Include probes that were not found (default: true)
160  bool includeOutOfBounds_;
161 
162  //- Output verbosity
163  bool verbose_;
164 
165  //- Perform sample actions on execute as well
166  bool onExecute_;
167 
168  //- Requested names of fields to probe
170 
171  //- Interpolation/sample scheme to obtain values at the points
172  // Note: only possible when fixedLocations_ is true
174 
175 
176  // Calculated
177 
178  //- Current list of field names selected for sampling
180 
181  //- Categorized scalar/vector/tensor volume fields
187 
188  //- Categorized scalar/vector/tensor surface fields
194 
195  //- Cells to be probed (obtained from the locations)
197 
198  //- Faces to be probed
200 
201  //- Processor holding the cell or face (-1 if point not found
202  // on any processor)
204 
205  //- Current open files (non-empty on master only)
207 
208  //- Patch IDs on which the new probes are located (for patchProbes)
210 
211  //- Original probes location (only used for patchProbes)
213 
214 
215  // Protected Member Functions
217  //- Find cells and faces containing probes
218  virtual void findElements(const fvMesh& mesh);
219 
220  //- Classify field types, close/open file streams
221  // \return number of fields to sample
222  label prepare(unsigned request);
223 
224  //- Get from registry or load from disk
225  template<class GeoField>
226  tmp<GeoField> getOrLoadField(const word& fieldName) const;
227 
228  //- Store results: min/max/average/size
229  template<class Type>
230  void storeResults(const word& fieldName, const Field<Type>& values);
231 
232 
233 private:
234 
235  // Private Member Functions
237  //- Create new streams as required
238  void createProbeFiles(const wordList& fieldNames);
239 
240  //- Write field values
241  template<class Type>
242  void writeValues
243  (
244  const word& fieldName,
246  const scalar timeValue
247  );
248 
249  //- Sample and store/write all applicable sampled fields
250  template<class GeoField>
251  void performAction
252  (
253  const fieldGroup<GeoField>& fieldNames, /* must be sorted */
254  unsigned request
255  );
256 
257  //- Perform sampling action with store/write
258  bool performAction(unsigned request);
260  //- No copy construct
261  probes(const probes&) = delete;
262 
263  //- No copy assignment
264  void operator=(const probes&) = delete;
265 
266 public:
267 
268  //- Runtime type information
269  TypeName("probes");
270 
272  // Constructors
273 
274  //- Construct from Time and dictionary
275  probes
276  (
277  const word& name,
278  const Time& runTime,
279  const dictionary& dict,
280  const bool loadFromFiles = false,
281  const bool readFields = true
282  );
283 
284 
285  //- Destructor
286  virtual ~probes() = default;
287 
288 
289  // Member Functions
290 
291  //- Enable/disable verbose output
292  // \return old value
293  bool verbose(const bool on) noexcept;
294 
295  //- Return names of fields to probe
296  virtual const wordRes& fieldNames() const noexcept
297  {
298  return fieldSelection_;
299  }
300 
301  //- Return locations to probe
302  virtual const pointField& probeLocations() const noexcept
303  {
304  return *this;
305  }
306 
307  //- Return location for probe i
308  virtual const point& probe(const label i) const
309  {
310  return operator[](i);
311  }
312 
313  //- Cells to be probed (obtained from the locations)
314  const labelList& elements() const noexcept
315  {
316  return elementList_;
317  }
318 
319  //- Read the probes
320  virtual bool read(const dictionary&);
321 
322  //- Sample and store result if the sampleOnExecute is enabled.
323  virtual bool execute();
324 
325  //- Sample and write
326  virtual bool write();
327 
328  //- Update for changes of mesh
329  virtual void updateMesh(const mapPolyMesh&);
330 
331  //- Update for changes of mesh
332  virtual void movePoints(const polyMesh&);
333 
334  //- Update for changes of mesh due to readUpdate
335  virtual void readUpdate(const polyMesh::readUpdateState state)
336  {}
337 
338 
339  // Sampling
340 
341  //- Sample a volume field at all locations
342  template<class Type>
343  tmp<Field<Type>> sample(const VolumeField<Type>&) const;
344 
345  //- Sample a surface field at all locations
346  template<class Type>
347  tmp<Field<Type>> sample(const SurfaceField<Type>&) const;
348 
349  //- Sample a volume field at all locations
350  template<class Type>
351  tmp<Field<Type>> sample(const word& fieldName) const;
352 
353  //- Sample a surface field at all locations
354  template<class Type>
355  tmp<Field<Type>> sampleSurfaceField(const word& fieldName) const;
356 };
357 
358 
359 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
360 
361 } // End namespace Foam
362 
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 
365 #ifdef NoRepository
366  #include "probesTemplates.C"
367 #endif
368 
369 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
370 
371 #endif
372 
373 // ************************************************************************* //
bool fixedLocations_
Fixed locations (default: true)
Definition: probes.H:201
fieldGroup< volSymmTensorField > symmTensorFields_
Definition: probes.H:244
dictionary dict
fieldGroup< volTensorField > tensorFields_
Definition: probes.H:245
virtual bool write()
Sample and write.
Definition: probes.C:456
virtual const point & probe(const label i) const
Return location for probe i.
Definition: probes.H:418
fieldGroup< volSphericalTensorField > sphericalTensorFields_
Definition: probes.H:243
Grouping of field names by GeometricField type.
Definition: probes.H:171
Forwards and collection of common volume field types.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
pointField oldPoints_
Original probes location (only used for patchProbes)
Definition: probes.H:286
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition: probes.C:462
virtual bool execute()
Sample and store result if the sampleOnExecute is enabled.
Definition: probes.C:445
TypeName("probes")
Runtime type information.
virtual ~probes()=default
Destructor.
virtual const wordRes & fieldNames() const noexcept
Return names of fields to probe.
Definition: probes.H:402
Set of locations to sample.
Definition: probes.H:158
engineTime & runTime
virtual void readUpdate(const polyMesh::readUpdateState state)
Update for changes of mesh due to readUpdate.
Definition: probes.H:459
tmp< GeoField > getOrLoadField(const word &fieldName) const
Get from registry or load from disk.
fieldGroup< surfaceTensorField > surfaceTensorFields_
Definition: probes.H:254
labelList processor_
Processor holding the cell or face (-1 if point not found.
Definition: probes.H:271
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers...
Definition: HashPtrTable.H:51
tmp< Field< Type > > sampleSurfaceField(const word &fieldName) const
Sample a surface field at all locations.
sampleActionType
Local control for sampling actions.
Definition: probes.H:179
DynamicList< word > selectedFieldNames_
Current list of field names selected for sampling.
Definition: probes.H:236
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
fieldGroup< surfaceVectorField > surfaceVectorFields_
Definition: probes.H:251
const word & name() const noexcept
Return the name of this functionObject.
label prepare(unsigned request)
Classify field types, close/open file streams.
Definition: probes.C:269
T & operator[](const label i)
Return element of UList.
Definition: UListI.H:361
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
labelList faceList_
Faces to be probed.
Definition: probes.H:264
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
virtual const pointField & probeLocations() const noexcept
Return locations to probe.
Definition: probes.H:410
dynamicFvMesh & mesh
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const NameMatchPredicate &selectedFields, DynamicList< regIOobject *> &storedObjects)
Read the selected GeometricFields of the templated type and store on the objectRegistry.
A class for handling words, derived from Foam::string.
Definition: word.H:63
wordRes fieldSelection_
Requested names of fields to probe.
Definition: probes.H:221
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
fieldGroup< surfaceSphericalTensorField > surfaceSphericalTensorFields_
Definition: probes.H:252
const direction noexcept
Definition: Scalar.H:258
bool includeOutOfBounds_
Include probes that were not found (default: true)
Definition: probes.H:206
fieldGroup< volScalarField > scalarFields_
Categorized scalar/vector/tensor volume fields.
Definition: probes.H:241
HashPtrTable< OFstream > probeFilePtrs_
Current open files (non-empty on master only)
Definition: probes.H:276
virtual void movePoints(const polyMesh &)
Update for changes of mesh.
Definition: probes.C:553
bool verbose_
Output verbosity.
Definition: probes.H:211
vector point
Point is a vector.
Definition: point.H:37
bool verbose(const bool on) noexcept
Enable/disable verbose output.
Definition: probes.C:384
bool loadFromFiles_
Load fields from files (not from objectRegistry)
Definition: probes.H:193
word samplePointScheme_
Interpolation/sample scheme to obtain values at the points.
Definition: probes.H:228
void storeResults(const word &fieldName, const Field< Type > &values)
Store results: min/max/average/size.
const labelList & elements() const noexcept
Cells to be probed (obtained from the locations)
Definition: probes.H:426
virtual void findElements(const fvMesh &mesh)
Find cells and faces containing probes.
Definition: probes.C:153
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
labelList elementList_
Cells to be probed (obtained from the locations)
Definition: probes.H:259
virtual bool read(const dictionary &)
Read the probes.
Definition: probes.C:392
tmp< Field< Type > > sample(const VolumeField< Type > &) const
Sample a volume field at all locations.
fieldGroup< surfaceScalarField > surfaceScalarFields_
Categorized scalar/vector/tensor surface fields.
Definition: probes.H:250
fieldGroup< volVectorField > vectorFields_
Definition: probes.H:242
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:90
List< label > labelList
A List of labels.
Definition: List.H:62
A class for managing temporary objects.
Definition: HashPtrTable.H:50
bool onExecute_
Perform sample actions on execute as well.
Definition: probes.H:216
fieldGroup< surfaceSymmTensorField > surfaceSymmTensorFields_
Definition: probes.H:253
labelList patchIDList_
Patch IDs on which the new probes are located (for patchProbes)
Definition: probes.H:281
Namespace for OpenFOAM.