Go to the documentation of this file.
74 struct setExprFieldsControl
88 void doCorrectBoundaryConditions
96 Info<<
"Correcting boundary conditions: " <<
field.name() <<
nl;
97 field.correctBoundaryConditions();
103 void doCorrectBoundaryConditions
111 Info<<
"Correcting boundary conditions: " <<
field.name() <<
nl;
112 field.correctBoundaryConditions();
118 void doCorrectBoundaryConditions
126 template<
class GeoField,
class Mesh>
129 const word& fieldName,
131 const GeoField& result,
136 const setExprFieldsControl& ctrl
139 Info<<
"setField(" << fieldName <<
"): "
189 output[celli] = result[celli];
198 forAll(result.boundaryField(), patchi)
200 auto& pf =
output.boundaryFieldRef()[patchi];
202 if (pf.patch().coupled())
204 pf == result.boundaryField()[patchi];
209 if (setCells == totalCells)
215 Info<<
"Set " << setCells <<
" of ";
217 Info<< totalCells <<
" cells" <<
endl;
220 doCorrectBoundaryConditions(ctrl.correctBCs,
output);
222 if (ctrl.useDimension)
224 Info<<
"Setting dimension to " << dims <<
endl;
225 output.dimensions().reset(dims);
243 const word& fieldName,
250 const setExprFieldsControl& ctrl
257 Info<<
"Set new field: " << fieldName;
271 oldFieldType = io.headerClassName();
273 if (oldFieldType == IOobject::typeName)
276 <<
"Field " << fieldName <<
" is "
278 <<
". Seems that it does not exist. Use 'create'"
283 Info<<
"Modify field: " << fieldName
284 <<
" (type " << oldFieldType <<
')';
288 <<
"Expression:" <<
nl
290 << expression.c_str() <<
nl
292 <<
"Condition:" <<
nl
294 << condition.c_str() <<
nl
297 if (ctrl.keepPatches)
299 Info<<
"Keeping patches unaltered" <<
endl;
301 else if (!valuePatches.empty())
304 <<
" to fixed value" <<
endl;
315 driver.readDict(
dict);
317 if (ctrl.debugParsing)
319 Info<<
"Parsing expression: " << expression <<
"\nand condition "
320 << condition <<
nl <<
endl;
321 driver.setDebugging(
true,
true);
325 driver.clearVariables();
329 bool evaluatedCondition =
false;
333 if (condition.size() && condition !=
"true")
335 if (ctrl.debugParsing)
337 Info<<
"Parsing condition:" << condition <<
endl;
340 driver.parse(condition);
341 if (ctrl.debugParsing)
348 bool goodCond =
true;
356 conditionField = ptr->internalField();
366 conditionField = ptr->internalField();
377 conditionField = ptr->internalField();
388 goodCond = goodCond && driver.isLogical();
393 <<
" condition: " << condition
394 <<
" does not evaluate to a logical expression: "
395 << driver.resultType() <<
nl
397 <<
"contents: " << conditionField
402 if (ctrl.debugParsing)
404 Info<<
"Condition evaluates to "
405 << conditionField <<
nl;
408 evaluatedCondition =
true;
411 if (ctrl.debugParsing)
413 Info<<
"Parsing expression:" << expression <<
endl;
416 driver.parse(expression);
418 if (ctrl.debugParsing)
423 if (evaluatedCondition)
425 if (conditionDataType != driver.fieldAssociation())
428 <<
"Mismatch between condition geometric type ("
429 << fieldGeoType(conditionDataType) <<
") and" <<
nl
430 <<
"expression geometric type ("
431 << fieldGeoType(driver.fieldAssociation()) <<
')' <<
nl
433 <<
"Expression: " << expression <<
nl
434 <<
"Condition: " << condition <<
nl
440 if (!ctrl.createNew && driver.resultType() != oldFieldType)
443 <<
"Inconsistent types: " << fieldName <<
" is "
445 <<
" but the expression evaluates to "
446 << driver.resultType()
450 Info<<
"Dispatch ... " << driver.resultType() <<
nl;
452 #undef setFieldDispatch
453 #define setFieldDispatch(FieldType) \
456 const auto* ptr = driver.isResultType<FieldType>(); \
488 #undef setFieldDispatch
489 #define setFieldDispatch(FieldType) \
492 const auto* ptr = driver.isResultType<FieldType>(); \
501 pointMesh::New(mesh), \
518 #undef setFieldDispatch
523 <<
"Expression evaluates to an unsupported type: "
524 << driver.resultType() <<
nl <<
nl
525 <<
"Expression " << expression <<
nl <<
endl
532 int main(
int argc,
char *argv[])
543 "Alternative dictionary for setExprFieldsDict"
549 "Evaluate but do not write"
555 "Additional verbosity",
563 "The field to overwrite command-line operation)",
570 "The expression to evaluate (command-line operation)",
577 "The logical condition when to apply the expression"
578 " (command-line operation)",
585 "The dimensions to apply for created fields"
586 " (command-line operation)",
592 "Additional debugging information",
598 "Disable caching of expression variables",
604 "Create a new field (command-line operation)",
610 "Leave patches unaltered"
611 " (command-line operation)",
618 "A list of patches that receive a fixed value"
619 " (command-line operation)",
625 "(command-line operation)",
638 "correctResultBoundaryFields",
649 const bool dryrun =
args.
found(
"dry-run");
650 const bool verbose =
args.
found(
"verbose");
656 if (times.size() < 1)
673 const bool useCommandArgs =
args.
found(
"field");
680 <<
"Cannot specify both dictionary and command-line arguments"
688 <<
"Cannot specify both 'create' and 'keepPatches'" <<
nl
698 "create",
"keepPatches",
"valuePatches",
699 "dimension",
"condition",
"expression"
704 if (!badOptions.empty())
707 <<
"Using a dictionary. Cannot specify command options:" <<
nl
726 if (
args.
found(
"dummy-phi") && !dummyPhi)
728 Info<<
"Adding a dummy phi" <<
endl;
756 Info<<
"Using command-line options for "
757 << fieldName <<
nl <<
endl;
759 setExprFieldsControl ctrl;
761 ctrl.dryRun = dryrun;
762 ctrl.debugParsing =
args.
found(
"debug-parser");
763 ctrl.cacheVariables = !
args.
found(
"no-variable-caching");
766 ctrl.keepPatches =
args.
found(
"keepPatches");
767 ctrl.correctPatches = !
args.
found(
"noCorrectPatches");
768 ctrl.correctBCs =
args.
found(
"correctResultBoundaryFields");
769 ctrl.useDimension =
args.
found(
"dimension");
786 if (ctrl.useDimension)
805 else if (exprDictPtr)
812 for (
const entry& dEntry : actions)
814 if (!dEntry.isDict())
816 Info<<
"Ignore non-dictionary entry: "
817 << dEntry.keyword() <<
nl;
823 setExprFieldsControl ctrl;
825 ctrl.dryRun = dryrun;
826 ctrl.debugParsing =
args.
found(
"debug-parser");
827 ctrl.cacheVariables = !
args.
found(
"no-variable-caching");
831 ctrl.correctPatches = !
args.
found(
"noCorrectPatches");
832 ctrl.correctBCs =
args.
found(
"correctResultBoundaryFields");
834 if (ctrl.createNew && ctrl.keepPatches)
837 <<
"Cannot specify both 'create' and 'keepPatches'"
845 "correctResultBoundaryFields",
854 dict.
get<
string>(
"expression"),
870 ctrl.useDimension =
dict.
found(
"dimension");
873 if (ctrl.useDimension)
881 if (verbose && !timei)
904 <<
"No command-line or dictionary??" <<
nl <<
endl
int debug
Static debugging option.
A keyword and a list of tokens is an 'entry'.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
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)
A class for managing temporary objects.
static constexpr const zero Zero
Global zero (0)
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (uses typeFilePath to find file) and check its info.
const Time & time() const
Return time.
Driver for volume, surface, point field expressions.
static word timeName(const scalar t, const int precision=precision_)
const word dictName("blockMeshDict")
const HashTable< string > & options() const
Return options.
const functionObjectList & functionObjects() const
Return the list of function objects.
Ostream & endl(Ostream &os)
Add newline and flush stream.
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Dimension set for the base types.
label retain(const HashTable< AnyType, Key, AnyHash > &other)
Retain table entries given by keys of the other hash-table.
T get(const label index) const
Get a value from the argument at index.
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
bool start()
Called at the start of the time-loop.
#define forAll(list, i)
Loop across all elements in list.
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
FieldAssociation
The field association for patch expressions (mutually exclusive)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
ITstream lookup(const word &optName) const
Return an input stream from the named option.
An input stream of tokens.
messageStream Info
Information stream (uses stdout - output is on the master only)
FieldAssociation
The field association for volume expressions (mutually exclusive)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
virtual const fileName & name() const
Return the name of the stream.
surfacesMesh setField(triSurfaceToAgglom)
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Convert [0-1] values (usually scalars) as false/true.
Generic dimensioned Type class.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Mesh data needed to do the Finite Volume discretisation.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
errorManipArg< error, int > exit(error &err, const int errNo=1)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
Traits class for primitives.
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
List< T > getList(const label index) const
Get a List of values from the argument at index.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
static instantList select0(Time &runTime, const argList &args)
const word & constant() const
Return constant name.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Foam::argList args(argc, argv)
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
string evaluate(const std::string &s, size_t pos=0, size_t len=std::string::npos)
Operations involving expressions.
bool found(const word &optName) const
Return true if the named option is found.