55 { actionType::opNone,
"none" },
56 { actionType::opNew,
"new" },
57 { actionType::opModify,
"modify" },
89 field.correctBoundaryConditions();
92 for (
auto& pf :
field.boundaryFieldRef())
96 pf = pf.patchInternalField();
113 field.correctBoundaryConditions();
131template<
class FieldType>
134 if (
io.isHeaderClass<FieldType>())
137 Log <<
" Reading " <<
io.name()
138 <<
" (" << FieldType::typeName <<
')' <<
endl;
167 for (
const word& fieldName : fieldSet_)
170 const auto* ptr = mesh_.cfindObject<
regIOobject>(fieldName);
177 << ptr->name() <<
" (" << ptr->type()
178 <<
") already in database" <<
endl;
186 mesh_.time().timeName(),
197 loadField<scalar>(
io)
198 || loadField<vector>(
io)
199 || loadField<sphericalTensor>(
io)
200 || loadField<symmTensor>(
io)
201 || loadField<tensor>(
io)
212 <<
"readFields : failed to load " << fieldName <<
endl;
220template<
class GeoField>
224 const GeoField& evaluated,
228 label numValuesChanged = 0;
231 if (fieldMask.
empty())
234 numValuesChanged = output.size();
236 output.primitiveFieldRef() = evaluated;
240 auto& internal = output.primitiveFieldRef();
246 internal[idx] = evaluated[idx];
253 forAll(evaluated.boundaryField(), patchi)
255 auto& pf = output.boundaryFieldRef()[patchi];
257 if (pf.patch().coupled())
259 pf == evaluated.boundaryField()[patchi];
265 if (action_ == actionType::opModify &&
log)
267 const label numTotal =
returnReduce(output.size(), sumOp<label>());
268 reduce(numValuesChanged, sumOp<label>());
271 if (numValuesChanged == numTotal)
277 Info<< numValuesChanged <<
" of ";
279 Info<< numTotal <<
" values (field: "
280 << output.name() <<
')' <<
nl <<
endl;
286 output.dimensions().reset(dimensions_);
300 const bool loadFromFiles
310 action_(actionType::opNew),
313 hasDimensions_(false),
314 loadFromFiles_(loadFromFiles)
332 case actionType::opNone:
336 case actionType::opNew:
338 return scopedName(fieldName_);
340 case actionType::opModify:
354 action_ = actionNames_.getOrDefault(
"action",
dict, actionType::opNew);
356 fieldName_ =
dict.get<word>(
"field");
357 const word fldName = fieldName();
360 <<
" action = " << actionNames_[action_] <<
nl
361 <<
" field = " << fldName <<
nl;
366 preloadFields_.clear();
367 dict.readIfPresent(
"readFields", preloadFields_);
371 case actionType::opNone:
376 case actionType::opModify:
379 maskExpr_.readIfPresent(
"fieldMask",
dict);
382 case actionType::opNew:
385 valueExpr_.readEntry(
"expression",
dict);
390 autowrite_ =
dict.getOrDefault(
"autowrite",
false);
391 store_ =
dict.getOrDefault(
"store",
true);
395 hasDimensions_ = dimensions_.readIfPresent(
"dimensions",
dict);
397 if (action_ == actionType::opNew)
401 Log <<
" no 'dimensions' : treat '" << fldName
402 <<
"' as dimensionless" <<
endl;
408 hasDimensions_ =
false;
412 if (action_ == actionType::opNone)
414 driver_.reset(
nullptr);
423 driver_->setSearchBehaviour
447 if (!driver_ || action_ == actionType::opNone)
453 const word fldName = fieldName();
457 loadFields(preloadFields_);
460 if (action_ == actionType::opModify && loadFromFiles_)
465 auto& driver = *driver_;
469 auto* regIOobjectPtr = mesh_.getObjectPtr<regIOobject>(fldName);
471 if (action_ == actionType::opModify && !regIOobjectPtr)
476 <<
" missing-field: " << fldName <<
nl
486 (action_ == actionType::opModify)
487 && maskExpr_.size() && maskExpr_ !=
"true" && maskExpr_ !=
"1"
495 driver.parse(maskExpr_);
497 if (driver.isLogical())
499 auto& result = driver.result();
500 if (result.is_bool())
502 fieldMask = result.getResult<
bool>();
503 maskFieldAssoc = driver.fieldAssociation();
509 driver.clearResult();
511 evalFieldMask = (maskFieldAssoc != FieldAssociation::NO_DATA);
516 <<
"field-mask: " << maskExpr_
517 <<
" does not evaluate to a logical expression: "
518 << driver.resultType() <<
nl
520 <<
"contents: " << fieldMask
529 bool applied =
false;
530 autoPtr<regIOobject> toutputField;
533 driver.clearVariables();
535 driver.parse(valueExpr_);
537 if (evalFieldMask && maskFieldAssoc != driver.fieldAssociation())
540 <<
"Mismatch between field-mask geometric type ("
542 <<
"expression geometric type ("
545 <<
"Expression: " << valueExpr_ <<
nl
546 <<
"Field-mask: " << maskExpr_ <<
nl
555 toutputField.reset(driver.dupZeroField());
559 toutputField->rename(fldName);
570 regIOobjectPtr = toutputField.get();
574 if (toutputField->checkIn() && toutputField->store())
577 toutputField.release();
580 regIOobjectPtr = mesh_.getObjectPtr<regIOobject>(fldName);
592 <<
" missing-field: " << fldName <<
nl
608 switch (driver.fieldAssociation())
611 #define doLocalCode(GeoField) \
614 auto* outPtr = dynamic_cast<GeoField*>(regIOobjectPtr); \
615 const auto* ptr = driver.isResultType<GeoField>(); \
619 applied = setField(*outPtr, *ptr, fieldMask); \
628 case FieldAssociation::VOLUME_DATA:
637 case FieldAssociation::FACE_DATA:
646 case FieldAssociation::POINT_DATA:
663 driver.clearResult();
670 <<
type() <<
' ' << this->
name() <<
": Failed to apply "
671 << actionNames_[action_] <<
" for " << fldName
687 return performAction(
true);
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
bool empty() const noexcept
True if List is empty (ie, size() is zero).
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
T * get() noexcept
Return pointer to managed object without nullptr checking.
T * release() noexcept
Release ownership and return the pointer.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
This boundary condition is not designed to be evaluated; it is assumed that the value is assigned via...
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
The field association for mesh (patch/volume) values.
searchControls
Search/caching controls.
@ SEARCH_REGISTRY
Search registry before disk.
@ SEARCH_FILES
Search disk (eg, standalone app).
Abstract base-class for Time/database function objects.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
word scopedName(const word &name) const
Return a scoped (prefixed) name.
Function object that generates or modifies a field based on expressions.
expressions::exprString maskExpr_
The field-mask expression (modify mode).
bool setField(GeoField &output, const GeoField &evaluated, const boolField &cond)
Sets the values of the output field based on a condition.
autoPtr< expressions::volumeExprDriver > driver_
bool performAction(bool doWrite)
Execute the requested action.
dimensionSet dimensions_
Dimensions for new field.
virtual ~fvExpressionField()
Destructor.
dictionary dict_
The context dictionary.
bool loadFromFiles_
Load fields from files (not from objectRegistry).
bool autowrite_
Set AUTO_WRITE for new field.
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
word fieldName_
Name of the field.
bool hasDimensions_
True if dimensions_ should be used (creation).
bool loadAndStore(const IOobject &io)
Attempt load from io, store on database if successful.
static const Enum< actionType > actionNames_
Action type names.
bool store_
Store calculated field.
actionType
Action type enumeration.
@ opModify
Modify existing field.
@ opNew
Create/overwrite field (default).
label loadFields(const UList< word > &fieldSet_)
Attempt to load specified fields.
fvExpressionField(const word &name, const Time &runTime, const dictionary &dict, const bool loadFromFiles=false)
Construct from name, Time and dictionary.
virtual bool execute()
Execute the function-object operations.
virtual word fieldName() const
Qualified/unqualified field name (depends on action).
expressions::exprString valueExpr_
Expression to evaluate.
wordList preloadFields_
Names fields to preload.
virtual bool write()
Write the function-object results.
actionType action_
Operation mode.
bool loadField(const IOobject &io)
Forward to loadAndStore for supported types.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const fvMesh & mesh_
Reference to the fvMesh.
fvMeshFunctionObject(const fvMeshFunctionObject &)=delete
No copy construct.
Computes the natural logarithm of an input volScalarField.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
bool store()
Register object with its registry and transfer ownership to the registry.
A class for handling words, derived from Foam::string.
static const word null
An empty word.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define doLocalCode(FieldType, Variable)
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
volumeExpr::parseDriver volumeExprDriver
Typedef for volumeExpr parseDriver.
@ VOLUME_DATA
Volume data.
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
List< word > wordList
List of word.
GeometricField< vector, fvPatchField, volMesh > volVectorField
GeometricField< Type, fvPatchField, volMesh > VolumeField
A volume field for a given type.
GeometricField< tensor, pointPatchField, pointMesh > pointTensorField
bool read(const char *buf, int32_t &val)
Same as readInt32.
GeometricField< scalar, pointPatchField, pointMesh > pointScalarField
GeometricField< sphericalTensor, pointPatchField, pointMesh > pointSphericalTensorField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Field< bool > boolField
Specialisation of Field<T> for bool.
messageStream Info
Information stream (stdout output on master, null elsewhere).
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
GeometricField< symmTensor, pointPatchField, pointMesh > pointSymmTensorField
Ostream & endl(Ostream &os)
Add newline and flush stream.
GeometricField< tensor, fvPatchField, volMesh > volTensorField
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
GeometricField< tensor, fvsPatchField, surfaceMesh > surfaceTensorField
GeometricField< sphericalTensor, fvPatchField, volMesh > volSphericalTensorField
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
GeometricField< sphericalTensor, fvsPatchField, surfaceMesh > surfaceSphericalTensorField
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
static void doCorrectBoundaryConditions(bool correctBCs, VolumeField< Type > &field)
GeometricField< Type, pointPatchField, pointMesh > PointField
A point field for a given type.
word fieldGeoType(const expressions::FieldAssociation geoType)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
errorManipArg< error, int > exit(error &err, const int errNo=1)
GeometricField< symmTensor, fvsPatchField, surfaceMesh > surfaceSymmTensorField
GeometricField< Type, fvsPatchField, surfaceMesh > SurfaceField
A (volume) surface field for a given type.
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.