38template<
class ProbeType>
39void Foam::Probes<ProbeType>::createProbeFiles(
const wordList& fieldNames)
43 bool needsNewFiles =
false;
44 for (
const word& fieldName : fieldNames)
46 if (!probeFilePtrs_.found(fieldName))
53 if (needsNewFiles && Pstream::master())
56 <<
"Probing fields: " << fieldNames <<
nl
57 <<
"Probing locations: " << probeModel_.probeLocations() <<
nl
65 mesh_.time().globalPath()
66 / functionObject::outputPrefix
67 /
name()/mesh_.regionName()
69 / mesh_.time().timeName(mesh_.time().startTime().value())
76 for (
const word& fieldName : fieldNames)
78 if (probeFilePtrs_.found(fieldName))
84 auto osPtr = autoPtr<OFstream>::New(probeDir/fieldName);
90 <<
"Cannot open probe output file: " <<
os.name() <<
nl
94 probeFilePtrs_.insert(fieldName, osPtr);
98 const unsigned int width(IOstream::defaultPrecision() + 7);
99 os.setf(std::ios_base::left);
101 const pointField& probeLocs = probeModel_.probeLocations();
102 const labelList& processors = probeModel_.processors();
103 const labelList& patchIDList = probeModel_.patchIDList();
104 const pointField& oldPoints = probeModel_.oldPoints();
108 os <<
"# Probe " << probei <<
' ' << probeLocs[probei];
110 if (processors[probei] == -1)
112 os <<
" # Not Found";
114 else if (probei < patchIDList.size())
116 const label patchi = patchIDList[probei];
119 const polyBoundaryMesh& bm = mesh_.boundaryMesh();
122 patchi < bm.nNonProcessor()
123 || processors[probei] == Pstream::myProcNo()
126 os <<
" at patch " << bm[patchi].name();
128 os <<
" with a distance of "
129 <<
mag(probeLocs[probei]-oldPoints[probei])
130 <<
" m to the original point "
131 << oldPoints[probei];
138 os <<
setw(width) <<
"# Time";
142 if (probeModel_.includeOutOfBounds() || processors[probei] != -1)
144 os <<
' ' <<
setw(width) << probei;
153template<
class ProbeType>
155void Foam::Probes<ProbeType>::writeValues
157 const word& fieldName,
158 const Field<Type>& values,
159 const scalar timeValue
162 if (Pstream::master())
164 const unsigned int width(IOstream::defaultPrecision() + 7);
165 OFstream&
os = *probeFilePtrs_[fieldName];
167 os <<
setw(width) << timeValue;
171 const bool includeOutOfBounds = probeModel_.includeOutOfBounds();
172 const labelList& procs = probeModel_.processors();
175 if (includeOutOfBounds || procs[probei] != -1)
179 os <<
' ' <<
setw(width) << buf.str().data();
187template<
class ProbeType>
188template<
class GeoField>
189void Foam::Probes<ProbeType>::performAction
191 const fieldGroup<GeoField>& fieldNames,
195 for (
const word& fieldName : fieldNames)
197 tmp<GeoField> tfield = getOrLoadField<GeoField>(fieldName);
201 const auto&
field = tfield();
202 const scalar timeValue =
field.time().timeOutputValue();
204 Field<typename GeoField::value_type>
207 this->storeResults(fieldName, values);
208 if (request & ACTION_WRITE)
210 this->writeValues(fieldName, values, timeValue);
219template<
class ProbeType>
223 HashTable<wordHashSet> selected =
226 ? IOobjectList(mesh_, mesh_.time().timeName()).classes(fieldSelection_)
227 : mesh_.classes(fieldSelection_)
235 #define doLocalCode(InputType, Target) \
238 const auto iter = selected.cfind(InputType::typeName); \
242 Target.append(iter.val().sortedToc()); \
243 nFields += Target.size(); \
249 doLocalCode(volSphericalTensorField, sphericalTensorFields_);
250 doLocalCode(volSymmTensorField, symmTensorFields_);
253 doLocalCode(surfaceScalarField, surfaceScalarFields_);
254 doLocalCode(surfaceVectorField, surfaceVectorFields_);
255 doLocalCode(surfaceSphericalTensorField, surfaceSphericalTensorFields_);
256 doLocalCode(surfaceSymmTensorField, surfaceSymmTensorFields_);
257 doLocalCode(surfaceTensorField, surfaceTensorFields_);
264 if (Pstream::master())
267 currentFields.insert(scalarFields_);
268 currentFields.insert(vectorFields_);
269 currentFields.insert(sphericalTensorFields_);
270 currentFields.insert(symmTensorFields_);
271 currentFields.insert(tensorFields_);
273 currentFields.insert(surfaceScalarFields_);
274 currentFields.insert(surfaceVectorFields_);
275 currentFields.insert(surfaceSphericalTensorFields_);
276 currentFields.insert(surfaceSymmTensorFields_);
277 currentFields.insert(surfaceTensorFields_);
280 <<
"Probing fields: " << currentFields <<
nl
281 <<
"Probing locations: " << probeModel_.probeLocations() <<
nl
287 if (!currentFields.erase(iter.key()))
289 DebugInfo<<
"close probe stream: " << iter()->name() <<
endl;
291 probeFilePtrs_.remove(iter);
295 if ((request & ACTION_WRITE) && !currentFields.empty())
297 createProbeFiles(currentFields.sortedToc());
305template<
class ProbeType>
306template<
class GeoField>
309 const word& fieldName
321 mesh_.time().timeName(),
332 tfield.
cref(mesh_.cfindObject<GeoField>(fieldName));
339template<
class ProbeType>
343 const word& fieldName,
348 const Type avgVal =
average(values);
350 this->setResult(
"average(" + fieldName +
")", avgVal);
351 this->setResult(
"min(" + fieldName +
")",
limits.min());
352 this->setResult(
"max(" + fieldName +
")",
limits.max());
353 this->setResult(
"size(" + fieldName +
")", values.size());
358 <<
" avg: " << avgVal <<
nl
367template<
class ProbeType>
373 const bool loadFromFiles,
374 const bool readFields
378 probeModel_(mesh_,
dict),
379 loadFromFiles_(loadFromFiles),
392template<
class ProbeType>
401template<
class ProbeType>
404 dict.readEntry(
"fields", fieldSelection_);
406 verbose_ =
dict.getOrDefault(
"verbose",
false);
407 onExecute_ =
dict.getOrDefault(
"sampleOnExecute",
false);
410 prepare(ACTION_NONE);
416template<
class ProbeType>
417bool Foam::Probes<ProbeType>::performAction(
unsigned request)
419 if (!probeModel_.empty() && request && prepare(request))
421 performAction(scalarFields_, request);
422 performAction(vectorFields_, request);
423 performAction(sphericalTensorFields_, request);
424 performAction(symmTensorFields_, request);
425 performAction(tensorFields_, request);
427 performAction(surfaceScalarFields_, request);
428 performAction(surfaceVectorFields_, request);
429 performAction(surfaceSphericalTensorFields_, request);
430 performAction(surfaceSymmTensorFields_, request);
437template<
class ProbeType>
442 return performAction(ACTION_ALL & ~ACTION_WRITE);
449template<
class ProbeType>
452 return performAction(ACTION_ALL);
Istream and Ostream manipulators taking arguments.
#define doLocalCode(InputType, Target)
Input/output streams with (internal or external) character storage.
Macros for easy insertion into run-time selection tables.
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
A HashTable similar to std::unordered_map.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
bool empty() const noexcept
True if the hash table is empty.
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable,...
HashTable< wordHashSet > classes() const
A summary hash of classes used and their associated object names.
@ NO_REGISTER
Do not request registration (bool: false).
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
A min/max value pair with additional methods. In addition to conveniently storing values,...
bool verbose(const bool on) noexcept
Enable/disable verbose output.
HashPtrTable< OFstream > probeFilePtrs_
Current open files (non-empty on master only).
ProbeType probeModel_
The specified point probeModel.
fieldGroup< surfaceSphericalTensorField > surfaceSphericalTensorFields_
void storeResults(const word &fieldName, const Field< Type > &values)
Store results: min/max/average/size.
fieldGroup< volSphericalTensorField > sphericalTensorFields_
label prepare(unsigned request)
Classify field types, close/open file streams.
fieldGroup< volScalarField > scalarFields_
Categorized scalar/vector/tensor volume fields.
fieldGroup< surfaceSymmTensorField > surfaceSymmTensorFields_
Probes(const word &name, const Time &runTime, const dictionary &dict, const bool loadFromFiles=false, const bool readFields=true)
Construct from Time and dictionary.
bool loadFromFiles_
Load fields from files (not from objectRegistry).
fieldGroup< volVectorField > vectorFields_
fieldGroup< volSymmTensorField > symmTensorFields_
fieldGroup< surfaceScalarField > surfaceScalarFields_
Categorized scalar/vector/tensor surface fields.
fieldGroup< surfaceTensorField > surfaceTensorFields_
bool verbose_
Output verbosity.
wordRes fieldSelection_
Requested names of fields to probe.
fieldGroup< surfaceVectorField > surfaceVectorFields_
tmp< GeoField > getOrLoadField(const word &fieldName) const
Get from registry or load from disk.
bool onExecute_
Perform sample actions on execute as well.
virtual bool execute()
Sample and store result if the sampleOnExecute is enabled.
virtual bool write()
Sample and write.
fieldGroup< volTensorField > tensorFields_
virtual bool read(const dictionary &)
Read the settings from the dictionary.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const fvMesh & mesh_
Reference to the fvMesh.
fvMeshFunctionObject(const fvMeshFunctionObject &)=delete
No copy construct.
void setResult(const word &entryName, const Type &value)
Add result.
A class for managing temporary objects.
T & emplace(Args &&... args)
Reset with emplace construction. Return reference to the new content.
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
A class for handling words, derived from Foam::string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
#define DebugInfo
Report an information message using Foam::Info.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
GeometricField< vector, fvPatchField, volMesh > volVectorField
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
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.
List< label > labelList
A List of labels.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
messageStream Info
Information stream (stdout output on master, null elsewhere).
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Omanip< int > setw(const int i)
Ostream & endl(Ostream &os)
Add newline and flush stream.
GeometricField< tensor, fvPatchField, volMesh > volTensorField
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
GeometricField< tensor, fvsPatchField, surfaceMesh > surfaceTensorField
GeometricField< sphericalTensor, fvPatchField, volMesh > volSphericalTensorField
GeometricField< sphericalTensor, fvsPatchField, surfaceMesh > surfaceSphericalTensorField
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &f1, const label comm)
GeometricField< symmTensor, fvsPatchField, surfaceMesh > surfaceSymmTensorField
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.
#define forAllIters(container, iter)
Iterate across all elements in the container object.