Go to the documentation of this file.
41 namespace functionObjects
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();
131 template<
class FieldType>
137 Log <<
" Reading " << io.
name()
138 <<
" (" << FieldType::typeName <<
')' <<
endl;
140 mesh_.objectRegistry::store(
new FieldType(io,
mesh_));
157 loadAndStore<VolFieldType>(io)
159 || loadAndStore<SurfaceFieldType>(io)
171 for (
const word& fieldName : fieldSet_)
174 const auto* ptr = mesh_.cfindObject<
regIOobject>(fieldName);
181 << ptr->name() <<
" (" << ptr->type()
182 <<
") already in database" <<
endl;
190 mesh_.time().timeName(),
202 loadField<scalar>(io)
203 || loadField<vector>(io)
204 || loadField<sphericalTensor>(io)
205 || loadField<symmTensor>(io)
206 || loadField<tensor>(io)
217 <<
"readFields : failed to load " << fieldName <<
endl;
225 template<
class GeoField>
229 const GeoField& evaluated,
233 label numValuesChanged = 0;
236 if (fieldMask.empty())
239 numValuesChanged =
output.size();
241 output.primitiveFieldRef() = evaluated;
245 auto&
internal =
output.primitiveFieldRef();
251 internal[idx] = evaluated[idx];
258 forAll(evaluated.boundaryField(), patchi)
260 auto& pf =
output.boundaryFieldRef()[patchi];
262 if (pf.patch().coupled())
264 pf == evaluated.boundaryField()[patchi];
270 if (action_ == actionType::opModify &&
log)
276 if (numValuesChanged == numTotal)
282 Info<< numValuesChanged <<
" of ";
284 Info<< numTotal <<
" values (field: "
291 output.dimensions().reset(dimensions_);
305 const bool loadFromFiles
315 action_(actionType::opNew),
318 hasDimensions_(
false),
319 loadFromFiles_(loadFromFiles)
337 case actionType::opNone:
341 case actionType::opNew:
343 return scopedName(fieldName_);
345 case actionType::opModify:
359 action_ = actionNames_.getOrDefault(
"action",
dict, actionType::opNew);
361 fieldName_ =
dict.get<
word>(
"field");
362 const word fldName = fieldName();
365 <<
" action = " << actionNames_[action_] <<
nl
366 <<
" field = " << fldName <<
nl;
371 preloadFields_.clear();
372 dict.readIfPresent(
"readFields", preloadFields_);
376 case actionType::opNone:
381 case actionType::opModify:
384 maskExpr_.readEntry(
"fieldMask",
dict,
false);
387 case actionType::opNew:
390 valueExpr_.readEntry(
"expression",
dict);
395 autowrite_ =
dict.getOrDefault(
"autowrite",
false);
396 store_ =
dict.getOrDefault(
"autowrite",
true);
400 hasDimensions_ = dimensions_.readEntry(
"dimensions",
dict,
false);
402 if (action_ == actionType::opNew)
406 Log <<
" no 'dimensions' : treat '" << fldName
407 <<
"' as dimensionless" <<
endl;
413 hasDimensions_ =
false;
417 if (action_ == actionType::opNone)
419 driver_.reset(
nullptr);
428 driver_->setSearchBehaviour
442 driver_->readDict(dict_);
452 if (!driver_ || action_ == actionType::opNone)
458 const word fldName = fieldName();
462 loadFields(preloadFields_);
465 if (action_ == actionType::opModify && loadFromFiles_)
470 auto& driver = *driver_;
474 auto* regIOobjectPtr = mesh_.getObjectPtr<
regIOobject>(fldName);
476 if (action_ == actionType::opModify && !regIOobjectPtr)
481 <<
" missing-field: " << fldName <<
nl
491 (action_ == actionType::opModify)
492 && maskExpr_.size() && maskExpr_ !=
"true" && maskExpr_ !=
"1"
500 driver.parse(maskExpr_);
502 if (driver.isLogical())
504 auto& result = driver.result();
505 if (result.is_bool())
507 fieldMask = result.getResult<
bool>();
508 maskFieldAssoc = driver.fieldAssociation();
514 driver.clearResult();
521 <<
"field-mask: " << maskExpr_
522 <<
" does not evaluate to a logical expression: "
523 << driver.resultType() <<
nl
525 <<
"contents: " << fieldMask
534 bool applied =
false;
538 driver.clearVariables();
540 driver.parse(valueExpr_);
542 if (evalFieldMask && maskFieldAssoc != driver.fieldAssociation())
545 <<
"Mismatch between field-mask geometric type ("
547 <<
"expression geometric type ("
550 <<
"Expression: " << valueExpr_ <<
nl
551 <<
"Field-mask: " << maskExpr_ <<
nl
560 toutputField.
reset(driver.dupZeroField());
564 toutputField->rename(fldName);
575 regIOobjectPtr = toutputField.
get();
579 if (toutputField->checkIn() && toutputField->store())
585 regIOobjectPtr = mesh_.getObjectPtr<
regIOobject>(fldName);
597 <<
" missing-field: " << fldName <<
nl
613 switch (driver.fieldAssociation())
616 #define doLocalCode(GeoField) \
619 auto* outPtr = dynamic_cast<GeoField*>(regIOobjectPtr); \
620 const auto* ptr = driver.isResultType<GeoField>(); \
624 applied = setField(*outPtr, *ptr, fieldMask); \
668 driver.clearResult();
675 <<
type() <<
' ' << this->
name() <<
": Failed to apply "
676 << actionNames_[action_] <<
" for " << fldName
686 return performAction(
false);
692 return performAction(
true);
Defines the attributes of an object for which implicit objectRegistry management is supported,...
virtual bool read(const dictionary &dict)
Read the data.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static Ostream & output(Ostream &os, const IntRange< T > &range)
A class for handling words, derived from Foam::string.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
virtual ~fvExpressionField()
Destructor.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Driver for volume, surface, point field expressions.
bool loadAndStore(const IOobject &io)
Attempt load from io, store on database if successful.
bool loadField(const IOobject &io)
Forward to loadAndStore for supported types.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const word & headerClassName() const noexcept
Return name of the class name read from header.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
#define forAll(list, i)
Loop across all elements in list.
word fieldGeoType(const expressions::FieldAssociation geoType)
List< word > wordList
A List of words.
static const Enum< actionType > actionNames_
Action type names.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
searchControls
Search/caching controls.
Search disk (eg, standalone app)
messageStream Info
Information stream (stdout output on master, null elsewhere)
static void doCorrectBoundaryConditions(bool correctBCs, GeometricField< Type, fvPatchField, volMesh > &field)
T * release() noexcept
Release ownership and return the pointer.
T * get() noexcept
Return pointer to managed object without nullptr checking.
virtual const fileName & name() const
Return the name of the stream.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
virtual bool read(const dictionary &dict)
Read optional controls.
virtual word fieldName() const
Qualified/unqualified field name (depends on action)
Macros for easy insertion into run-time selection tables.
bool performAction(bool doWrite)
This boundary condition is not designed to be evaluated; it is assmued that the value is assigned via...
bool setField(GeoField &output, const GeoField &evaluated, const boolField &cond)
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 Time and dictionary.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void reset(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
const word & name() const noexcept
Return name.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
const TargetType * isA(const Type &t)
Check if dynamic_cast to TargetType is possible.
Search registry before disk.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define DebugInfo
Report an information message using Foam::Info.
virtual bool write()
Write.
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
const fvMesh & mesh_
Reference to the fvMesh.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
defineTypeNameAndDebug(ObukhovLength, 0)
static const word null
An empty word.
virtual bool execute()
Execute.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Computes the natural logarithm of an input volScalarField.
actionType
Action type enumeration.
#define WarningInFunction
Report a warning using Foam::Warning.
#define doLocalCode(GeoField)
The field association for mesh (patch/volume) values.