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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::probes
29
30Group
31 grpUtilitiesFunctionObjects
32
33Description
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 (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
87SourceFiles
88 probes.C
89 probesTemplates.C
90
91\*---------------------------------------------------------------------------*/
92
93#ifndef Foam_probes_H
94#define Foam_probes_H
95
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
109namespace Foam
110{
111
112// Forward Declarations
113class Time;
114class objectRegistry;
115class dictionary;
116class fvMesh;
117class mapPolyMesh;
118
119/*---------------------------------------------------------------------------*\
120 Class probes Declaration
121\*---------------------------------------------------------------------------*/
122
123class probes
124:
125 public functionObjects::fvMeshFunctionObject,
126 public pointField
127{
128protected:
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_;
158
159 //- Include probes that were not found (default: true)
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
216
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);
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);
233private:
234
235 // Private Member Functions
236
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,
245 const Field<Type>& values,
246 const scalar timeValue
247 );
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);
259
260 //- No copy construct
261 probes(const probes&) = delete;
262
263 //- No copy assignment
264 void operator=(const probes&) = delete;
266public:
267
268 //- Runtime type information
269 TypeName("probes");
270
271
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>
344
345 //- Sample a surface field at all locations
346 template<class Type>
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// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
Minimal example by using system/controlDict.functions:
Generic GeometricField class.
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
Definition: HashPtrTable.H:68
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
T & operator[](const label i)
Return element of UList.
Definition: UListI.H:299
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const word & name() const noexcept
Return the name of this functionObject.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:162
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:91
Set of locations to sample.
Definition: probes.H:166
word samplePointScheme_
Interpolation/sample scheme to obtain values at the points.
Definition: probes.H:212
bool verbose(const bool on) noexcept
Enable/disable verbose output.
Definition: probes.C:394
bool includeOutOfBounds_
Include probes that were not found (default: true)
Definition: probes.H:199
HashPtrTable< OFstream > probeFilePtrs_
Current open files (non-empty on master only)
Definition: probes.H:245
fieldGroup< surfaceSphericalTensorField > surfaceSphericalTensorFields_
Definition: probes.H:230
tmp< Field< Type > > sample(const SurfaceField< Type > &) const
Sample a surface field at all locations.
const labelList & elements() const noexcept
Cells to be probed (obtained from the locations)
Definition: probes.H:353
void storeResults(const word &fieldName, const Field< Type > &values)
Store results: min/max/average/size.
virtual const wordRes & fieldNames() const noexcept
Return names of fields to probe.
Definition: probes.H:335
virtual const pointField & probeLocations() const noexcept
Return locations to probe.
Definition: probes.H:341
labelList processor_
Processor holding the cell or face (-1 if point not found.
Definition: probes.H:242
fieldGroup< volSphericalTensorField > sphericalTensorFields_
Definition: probes.H:223
label prepare(unsigned request)
Classify field types, close/open file streams.
Definition: probes.C:279
pointField oldPoints_
Original probes location (only used for patchProbes)
Definition: probes.H:251
virtual void findElements(const fvMesh &mesh)
Find cells and faces containing probes.
Definition: probes.C:163
TypeName("probes")
Runtime type information.
virtual void readUpdate(const polyMesh::readUpdateState state)
Update for changes of mesh due to readUpdate.
Definition: probes.H:374
fieldGroup< volScalarField > scalarFields_
Categorized scalar/vector/tensor volume fields.
Definition: probes.H:221
fieldGroup< surfaceSymmTensorField > surfaceSymmTensorFields_
Definition: probes.H:231
bool loadFromFiles_
Load fields from files (not from objectRegistry)
Definition: probes.H:191
fieldGroup< volVectorField > vectorFields_
Definition: probes.H:222
DynamicList< word > selectedFieldNames_
Current list of field names selected for sampling.
Definition: probes.H:218
fieldGroup< volSymmTensorField > symmTensorFields_
Definition: probes.H:224
labelList elementList_
Cells to be probed (obtained from the locations)
Definition: probes.H:235
fieldGroup< surfaceScalarField > surfaceScalarFields_
Categorized scalar/vector/tensor surface fields.
Definition: probes.H:228
fieldGroup< surfaceTensorField > surfaceTensorFields_
Definition: probes.H:232
bool verbose_
Output verbosity.
Definition: probes.H:202
bool fixedLocations_
Fixed locations (default: true)
Definition: probes.H:196
virtual void movePoints(const polyMesh &)
Update for changes of mesh.
Definition: probes.C:563
wordRes fieldSelection_
Requested names of fields to probe.
Definition: probes.H:208
fieldGroup< surfaceVectorField > surfaceVectorFields_
Definition: probes.H:229
virtual ~probes()=default
Destructor.
tmp< GeoField > getOrLoadField(const word &fieldName) const
Get from registry or load from disk.
labelList patchIDList_
Patch IDs on which the new probes are located (for patchProbes)
Definition: probes.H:248
tmp< Field< Type > > sample(const word &fieldName) const
Sample a volume field at all locations.
tmp< Field< Type > > sampleSurfaceField(const word &fieldName) const
Sample a surface field at all locations.
labelList faceList_
Faces to be probed.
Definition: probes.H:238
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition: probes.C:472
bool onExecute_
Perform sample actions on execute as well.
Definition: probes.H:205
virtual const point & probe(const label i) const
Return location for probe i.
Definition: probes.H:347
virtual bool execute()
Sample and store result if the sampleOnExecute is enabled.
Definition: probes.C:455
virtual bool write()
Sample and write.
Definition: probes.C:466
fieldGroup< volTensorField > tensorFields_
Definition: probes.H:225
tmp< Field< Type > > sample(const VolumeField< Type > &) const
Sample a volume field at all locations.
sampleActionType
Local control for sampling actions.
Definition: probes.H:180
@ ACTION_WRITE
Definition: probes.H:182
@ ACTION_ALL
Definition: probes.H:184
@ ACTION_NONE
Definition: probes.H:181
@ ACTION_STORE
Definition: probes.H:183
virtual bool read(const dictionary &)
Read the probes.
Definition: probes.C:402
A class for managing temporary objects.
Definition: tmp.H:65
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
engineTime & runTime
Namespace for OpenFOAM.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
const direction noexcept
Definition: Scalar.H:223
dictionary dict
Grouping of field names by GeometricField type.
Definition: probes.H:173
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73