41 namespace functionObjects
55 { actionType::opNone,
"none" },
56 { actionType::opNew,
"new" },
57 { actionType::opModify,
"modify" },
83 VolumeField<Type>&
field 89 field.correctBoundaryConditions();
92 for (
auto& pf :
field.boundaryFieldRef())
94 if (
isA<calculatedFvPatchField<Type>>(pf))
96 pf = pf.patchInternalField();
107 PointField<Type>&
field 122 SurfaceField<Type>&
field 131 template<
class FieldType>
134 if (
io.isHeaderClass<FieldType>())
137 Log <<
" Reading " <<
io.name()
138 <<
" (" << FieldType::typeName <<
')' <<
endl;
162 const UList<word>& fieldSet_
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(),
194 io.typeHeaderOk<regIOobject>(
false)
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;
220 template<
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)
268 reduce(numValuesChanged, sumOp<label>());
271 if (numValuesChanged == numTotal)
277 Info<< numValuesChanged <<
" of ";
279 Info<< numTotal <<
" values (field: " 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
437 driver_->readDict(dict_);
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)
475 <<
type() <<
' ' << this->
name() <<
':' << nl
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();
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);
591 <<
type() <<
' ' << this->
name() <<
':' << nl
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); \ 663 driver.clearResult();
670 <<
type() <<
' ' << this->
name() <<
": Failed to apply " 671 << actionNames_[action_] <<
" for " << fldName
681 return performAction(
false);
687 return performAction(
true);
actionType
Action type enumeration.
bool setField(GeoField &output, const GeoField &evaluated, const boolField &cond)
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
word fieldGeoType(const expressions::FieldAssociation geoType)
defineTypeNameAndDebug(ObukhovLength, 0)
virtual word fieldName() const
Qualified/unqualified field name (depends on action)
virtual const fileName & name() const
The name of the stream.
Search registry before disk.
dimensionedScalar log(const dimensionedScalar &ds)
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
The field association for mesh (patch/volume) values.
bool loadField(const IOobject &io)
Forward to loadAndStore for supported types.
GeometricField< tensor, fvPatchField, volMesh > volTensorField
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if List is empty (ie, size() is zero)
virtual bool write()
Write.
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
GeometricField< sphericalTensor, fvsPatchField, surfaceMesh > surfaceSphericalTensorField
Ostream & endl(Ostream &os)
Add newline and flush stream.
label loadFields(const UList< word > &fieldSet_)
Attempt to load specified fields.
bool store()
Register object with its registry and transfer ownership to the registry.
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
Generic GeometricField class.
virtual bool execute()
Execute.
Ignore writing from objectRegistry::writeObject()
static void doCorrectBoundaryConditions(bool correctBCs, VolumeField< Type > &field)
GeometricField< vector, fvPatchField, volMesh > volVectorField
virtual ~fvExpressionField()
Destructor.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
GeometricField< sphericalTensor, fvPatchField, volMesh > volSphericalTensorField
Macros for easy insertion into run-time selection tables.
GeometricField< tensor, pointPatchField, pointMesh > pointTensorField
bool read(const char *buf, int32_t &val)
Same as readInt32.
#define forAll(list, i)
Loop across all elements in list.
searchControls
Search/caching controls.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Field< bool > boolField
Specialisation of Field<T> for bool.
#define doLocalCode(GeoField)
bool performAction(bool doWrite)
GeometricField< symmTensor, fvsPatchField, surfaceMesh > surfaceSymmTensorField
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
volumeExpr::parseDriver volumeExprDriver
Typedef for volumeExpr parseDriver.
A class for handling words, derived from Foam::string.
GeometricField< tensor, fvsPatchField, surfaceMesh > surfaceTensorField
static const word null
An empty word.
GeometricField< scalar, pointPatchField, pointMesh > pointScalarField
#define DebugInfo
Report an information message using Foam::Info.
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Search disk (eg, standalone app)
bool loadAndStore(const IOobject &io)
Attempt load from io, store on database if successful.
GeometricField< sphericalTensor, pointPatchField, pointMesh > pointSphericalTensorField
List< word > wordList
List of word.
#define WarningInFunction
Report a warning using Foam::Warning.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Automatically write from objectRegistry::writeObject()
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool read(const dictionary &dict)
Read optional controls.
static Ostream & output(Ostream &os, const IntRange< T > &range)
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
virtual bool read(const dictionary &dict)
Read the data.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Defines the attributes of an object for which implicit objectRegistry management is supported...
static const Enum< actionType > actionNames_
Action type names.
GeometricField< symmTensor, pointPatchField, pointMesh > pointSymmTensorField
fvExpressionField(const word &name, const Time &runTime, const dictionary &dict, const bool loadFromFiles=false)
Construct from Time and dictionary.
const fvMesh & mesh_
Reference to the fvMesh.
void reduce(T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) using linear/tree communication schedule.