Loading...
Searching...
No Matches
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-2025 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
30Description
31 Base class for sampling fields at specified locations and writing to file.
32 The locations are specified and determined in the derived class. The
33 sampling is done using the specified point probeModel class.
34
35SourceFiles
36 Probes.C
37 ProbesTemplates.C
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef Foam_Probes_H
42#define Foam_Probes_H
43
45#include "polyMesh.H"
46#include "HashPtrTable.H"
47#include "OFstream.H"
48#include "volFieldsFwd.H"
49#include "surfaceFieldsFwd.H"
50#include "probeModel.H"
51#include "IOobjectList.H"
52
53// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54
55namespace Foam
56{
57
58/*---------------------------------------------------------------------------*\
59 Class Probes Declaration
60\*---------------------------------------------------------------------------*/
61
62template<class ProbeType>
63class Probes
64:
66{
67protected:
68
69 // Protected Data
70
71 //- The specified point probeModel
72 ProbeType probeModel_;
73
74
75 // Protected Classes
76
77 //- Grouping of field names by GeometricField type
78 template<class GeoField>
79 struct fieldGroup : public DynamicList<word> {};
80
81
82 // Data Types
83
84 //- Local control for sampling actions
85 enum sampleActionType : unsigned
86 {
87 ACTION_NONE = 0,
91 };
92
93
94 // Protected Data
95
96 //- Load fields from files (not from objectRegistry)
97 bool loadFromFiles_;
98
99 //- Output verbosity
101
102 //- Perform sample actions on execute as well
103 bool onExecute_;
104
105 //- Requested names of fields to probe
107
108
109 // Calculated
111 //- Current list of field names selected for sampling
113
114 //- Categorized scalar/vector/tensor volume fields
115 fieldGroup<volScalarField> scalarFields_;
116 fieldGroup<volVectorField> vectorFields_;
117 fieldGroup<volSphericalTensorField> sphericalTensorFields_;
118 fieldGroup<volSymmTensorField> symmTensorFields_;
119 fieldGroup<volTensorField> tensorFields_;
120
121 //- Categorized scalar/vector/tensor surface fields
122 fieldGroup<surfaceScalarField> surfaceScalarFields_;
123 fieldGroup<surfaceVectorField> surfaceVectorFields_;
124 fieldGroup<surfaceSphericalTensorField> surfaceSphericalTensorFields_;
125 fieldGroup<surfaceSymmTensorField> surfaceSymmTensorFields_;
126 fieldGroup<surfaceTensorField> surfaceTensorFields_;
127
128 //- Current open files (non-empty on master only)
132 // Protected Member Functions
133
134 //- Classify field types, close/open file streams
135 // \return number of fields to sample
136 label prepare(unsigned request);
138 //- Get from registry or load from disk
139 template<class GeoField>
140 tmp<GeoField> getOrLoadField(const word& fieldName) const;
142 //- Store results: min/max/average/size
143 template<class Type>
144 void storeResults(const word& fieldName, const Field<Type>& values);
145
147private:
148
149 // Private Member Functions
150
151 //- Create new streams as required
152 void createProbeFiles(const wordList& fieldNames);
153
154 //- Write field values
155 template<class Type>
156 void writeValues
157 (
158 const word& fieldName,
159 const Field<Type>& values,
160 const scalar timeValue
161 );
163 //- Sample and store/write all applicable sampled fields
164 template<class GeoField>
165 void performAction
166 (
167 const fieldGroup<GeoField>& fieldNames, /* must be sorted */
168 unsigned request
169 );
170
171 //- Perform sampling action with store/write
172 bool performAction(unsigned request);
173
174
175public:
176
177 // Constructors
178
179 //- Construct from Time and dictionary
180 Probes
181 (
182 const word& name,
183 const Time& runTime,
184 const dictionary& dict,
185 const bool loadFromFiles = false,
186 const bool readFields = true
187 );
188
189
190 //- Destructor
191 virtual ~Probes() = default;
192
193
194 // Member Functions
195
196 //- Enable/disable verbose output
197 // \return old value
198 bool verbose(const bool on) noexcept;
199
200 //- Return names of fields to probe
201 virtual const wordRes& fieldNames() const noexcept
202 {
203 return fieldSelection_;
204 }
205
206 //- Return const reference to the point probeModel
207 const ProbeType& probeModel() const noexcept { return probeModel_; }
208
209 //- Read the settings from the dictionary
210 virtual bool read(const dictionary&);
211
212 //- Sample and store result if the sampleOnExecute is enabled.
213 virtual bool execute();
215 //- Sample and write
216 virtual bool write();
217
218 //- Update for changes of mesh due to readUpdate
219 virtual void readUpdate(const polyMesh::readUpdateState state)
220 {}
221};
222
223
224// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225
226} // End namespace Foam
228// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229
230#ifdef NoRepository
231 #include "Probes.C"
232#endif
233
234// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235
236#endif
238// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
constexpr DynamicList() noexcept
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
bool verbose(const bool on) noexcept
Enable/disable verbose output.
Definition Probes.C:386
HashPtrTable< OFstream > probeFilePtrs_
Definition Probes.H:146
patchFieldProbe probeModel_
Definition Probes.H:69
fieldGroup< surfaceSphericalTensorField > surfaceSphericalTensorFields_
Definition Probes.H:139
void storeResults(const word &fieldName, const Field< Type > &values)
Store results: min/max/average/size.
Definition Probes.C:335
virtual const wordRes & fieldNames() const noexcept
Definition Probes.H:242
fieldGroup< volSphericalTensorField > sphericalTensorFields_
Definition Probes.H:130
const ProbeType & probeModel() const noexcept
Return const reference to the point probeModel.
Definition Probes.H:250
label prepare(unsigned request)
Classify field types, close/open file streams.
Definition Probes.C:213
virtual void readUpdate(const polyMesh::readUpdateState state)
Update for changes of mesh due to readUpdate.
Definition Probes.H:270
fieldGroup< volScalarField > scalarFields_
Definition Probes.H:128
fieldGroup< surfaceSymmTensorField > surfaceSymmTensorFields_
Definition Probes.H:140
Probes(const word &name, const Time &runTime, const dictionary &dict, const bool loadFromFiles=false, const bool readFields=true)
Construct from Time and dictionary.
Definition Probes.C:362
fieldGroup< volVectorField > vectorFields_
Definition Probes.H:129
DynamicList< word > selectedFieldNames_
Definition Probes.H:123
fieldGroup< volSymmTensorField > symmTensorFields_
Definition Probes.H:131
virtual ~Probes()=default
Destructor.
fieldGroup< surfaceScalarField > surfaceScalarFields_
Definition Probes.H:137
fieldGroup< surfaceTensorField > surfaceTensorFields_
Definition Probes.H:141
fieldGroup< surfaceVectorField > surfaceVectorFields_
Definition Probes.H:138
tmp< GeoField > getOrLoadField(const word &fieldName) const
Get from registry or load from disk.
virtual bool execute()
Sample and store result if the sampleOnExecute is enabled.
Definition Probes.C:431
virtual bool write()
Sample and write.
Definition Probes.C:443
fieldGroup< volTensorField > tensorFields_
Definition Probes.H:132
sampleActionType
Local control for sampling actions.
Definition Probes.H:87
virtual bool read(const dictionary &)
Read the settings from the dictionary.
Definition Probes.C:395
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition polyMesh.H:92
A class for managing temporary objects.
Definition tmp.H:75
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
engineTime & runTime
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
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.
const direction noexcept
Definition scalarImpl.H:265
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
dictionary dict
Grouping of field names by GeometricField type.
Definition Probes.H:78
Forwards and collection of common volume field types.