Go to the documentation of this file.
51 #include "readFields.H"
72 struct setExprFieldsControl
95 Info<<
"Correcting boundary conditions: " <<
field.name() <<
nl;
96 field.correctBoundaryConditions();
110 Info<<
"Correcting boundary conditions: " <<
field.name() <<
nl;
111 field.correctBoundaryConditions();
125 template<
class GeoField>
128 const word& fieldName,
129 const GeoField& evaluated,
134 const setExprFieldsControl& ctrl
137 Info<<
"setField(" << fieldName <<
"): "
140 const auto&
mesh = evaluated.mesh();
174 label numValuesChanged = 0;
177 if (fieldMask.empty())
180 numValuesChanged =
output.size();
182 output.primitiveFieldRef() = evaluated;
186 auto&
internal =
output.primitiveFieldRef();
192 internal[idx] = evaluated[idx];
199 forAll(evaluated.boundaryField(), patchi)
201 auto& pf =
output.boundaryFieldRef()[patchi];
203 if (pf.patch().coupled())
205 pf == evaluated.boundaryField()[patchi];
214 if (numValuesChanged == numTotal)
220 Info<<
"Set " << numValuesChanged <<
" of ";
222 Info<< numTotal <<
" values" <<
endl;
224 if (ctrl.hasDimensions)
226 Info<<
"Setting dimensions to " << dims <<
endl;
227 output.dimensions().reset(dims);
237 output.writeObject(ctrl.streamOpt,
true);
247 const word& fieldName,
254 const setExprFieldsControl& ctrl
261 Info<<
"Set new field: " << fieldName;
275 oldFieldType = io.headerClassName();
277 if (oldFieldType == IOobject::typeName)
280 <<
"Field " << fieldName <<
"(type: " << oldFieldType
281 <<
") seems to be missing. Use 'create'" <<
nl
285 Info<<
"Modify field: " << fieldName
286 <<
" (type " << oldFieldType <<
')';
291 <<
"Expression:" <<
nl
293 << valueExpr_.c_str() <<
nl
297 (maskExpr_.size() && maskExpr_ !=
"true" && maskExpr_ !=
"1");
301 Info<<
"field-mask:" <<
nl
303 << maskExpr_.c_str() <<
nl
307 if (ctrl.keepPatches)
309 Info<<
"Keeping patches unaltered" <<
endl;
311 else if (!valuePatches.empty())
314 <<
" to fixed value" <<
endl;
321 driver.setCaching(ctrl.cacheVariables);
323 driver.readDict(
dict);
325 if (ctrl.debugParsing)
327 Info<<
"Parsing expression: " << valueExpr_ <<
"\nand field-mask "
328 << maskExpr_ <<
nl <<
endl;
329 driver.setDebugging(
true,
true);
333 driver.clearVariables();
343 if (ctrl.debugParsing)
345 Info<<
"Parsing field-mask:" << maskExpr_ <<
endl;
348 driver.parse(maskExpr_);
349 if (ctrl.debugParsing)
354 if (driver.isLogical())
356 auto& result = driver.result();
357 if (result.is_bool())
359 fieldMask = result.getResult<
bool>();
360 maskFieldAssoc = driver.fieldAssociation();
366 driver.clearResult();
373 <<
" mask: " << maskExpr_
374 <<
" does not evaluate to a logical expression: "
375 << driver.resultType() <<
nl
377 <<
"contents: " << fieldMask
382 if (ctrl.debugParsing)
384 Info<<
"Field-mask evaluates to "
389 if (ctrl.debugParsing)
391 Info<<
"Parsing expression:" << valueExpr_ <<
endl;
394 driver.parse(valueExpr_);
396 if (ctrl.debugParsing)
401 if (evalFieldMask && maskFieldAssoc != driver.fieldAssociation())
404 <<
"Mismatch between field-mask geometric type ("
406 <<
"expression geometric type ("
409 <<
"expression: " << valueExpr_ <<
nl
410 <<
"field-mask: " << maskExpr_ <<
nl
415 if (!oldFieldType.empty() && driver.resultType() != oldFieldType)
418 <<
"Inconsistent types: " << fieldName <<
" is "
420 <<
" but the expression evaluates to "
421 << driver.resultType()
425 Info<<
"Dispatch ... " << driver.resultType() <<
nl;
428 bool applied =
false;
429 switch (driver.fieldAssociation())
432 #define doLocalCode(GeoField) \
434 const auto* ptr = driver.isResultType<GeoField>(); \
485 <<
"Expression evaluates to an unsupported type: "
486 << driver.resultType() <<
nl <<
nl
487 <<
"Expression " << valueExpr_ <<
nl <<
endl
495 int main(
int argc,
char *argv[])
505 "Write in ASCII format instead of the controlDict setting"
511 "Alternative dictionary for setExprFieldsDict"
515 "Evaluate but do not write"
519 "Additional verbosity",
526 "Specify field or fields to preload. Eg, 'T' or '(p T U)'",
533 "The field to create/overwrite"
534 " (command-line operation)",
541 "The expression to evaluate"
542 " (command-line operation)",
549 "The field mask (logical condition) when to apply the expression"
550 " (command-line operation)",
558 "The dimensions for created fields"
559 " (command-line operation)",
567 "Additional debugging information",
573 "Disable caching of expression variables",
580 " (command-line operation)",
586 "Leave patches unaltered"
587 " (command-line operation)",
594 "A list of patches that receive a fixed value"
595 " (command-line operation)",
601 "Provide a zero phi field"
602 " (command-line operation)",
615 "correctResultBoundaryFields",
633 <<
"No times selected." <<
nl
648 const bool useCommandArgs =
args.
found(
"field");
652 bool fatalCombination =
false;
656 fatalCombination =
true;
658 <<
"Cannot specify both dictionary and command-line arguments"
664 fatalCombination =
true;
666 <<
"Cannot specify both 'create' and 'keepPatches'" <<
nl
672 fatalCombination =
true;
674 <<
"Missing mandatory 'expression' option'" <<
nl
677 if (fatalCombination)
689 "create",
"keepPatches",
"value-patches",
690 "field-mask",
"expression",
"dimensions"
694 if (!badOptions.empty())
698 <<
"Using a dictionary. Cannot specify these options:" <<
nl
723 if (
args.
found(
"dummy-phi") && !dummyPhi)
725 Info<<
"Adding a dummy phi" <<
endl;
753 Info<<
"Using command-line options for "
754 << fieldName <<
nl <<
endl;
756 setExprFieldsControl ctrl;
759 ctrl.debugParsing =
args.
found(
"debug-parser");
760 ctrl.cacheVariables = !
args.
found(
"no-variable-caching");
763 ctrl.keepPatches =
args.
found(
"keepPatches");
764 ctrl.correctPatches = !
args.
found(
"noCorrectPatches");
765 ctrl.correctBCs =
args.
found(
"correctResultBoundaryFields");
766 ctrl.hasDimensions =
args.
found(
"dimensions");
783 if (ctrl.hasDimensions)
802 else if (exprDictPtr)
816 for (
const entry& dEntry : actions)
818 if (!dEntry.isDict())
820 Info<<
"Ignore non-dictionary entry: "
821 << dEntry.keyword() <<
nl;
827 setExprFieldsControl ctrl;
830 ctrl.debugParsing =
args.
found(
"debug-parser");
831 ctrl.cacheVariables = !
args.
found(
"no-variable-caching");
836 ctrl.correctPatches = !
args.
found(
"noCorrectPatches");
837 ctrl.correctBCs =
args.
found(
"correctResultBoundaryFields");
844 if (ctrl.createNew && ctrl.keepPatches)
847 <<
"Cannot specify both 'create' and 'keepPatches'"
855 "correctResultBoundaryFields",
875 "fieldMask", {{
"condition", 2106}},
890 "dimensions", {{
"dimension", 2012}},
897 ctrl.hasDimensions =
bool(dimPtr);
923 <<
"No command-line or dictionary??" <<
nl <<
endl
A keyword and a list of tokens is an 'entry'.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Defines the attributes of an object for which implicit objectRegistry management is supported,...
static exprString getEntry(const word &keyword, const dictionary &dict, const bool stripComments=true)
static Ostream & output(Ostream &os, const IntRange< T > &range)
A class for handling words, derived from Foam::string.
virtual ITstream & stream() const =0
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
virtual const objectRegistry & thisDb() const
IOstream::streamFormat writeFormat() const
const word dictName("faMeshDefinition")
Driver for volume, surface, point field expressions.
static word timeName(const scalar t, const int precision=precision_)
const functionObjectList & functionObjects() const
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
const keyType & keyword() const noexcept
bool readListIfPresent(const word &optName, List< T > &list) const
Ostream & endl(Ostream &os)
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
A HashTable with keys but without contents that is similar to std::unordered_set.
@ VOLUME_DATA
Volume data.
T get(const label index) const
bool readIfPresent(const word &optName, T &val) const
#define doLocalCode(GeoField)
static const dictionary null
word fieldGeoType(const expressions::FieldAssociation geoType)
virtual readUpdateState readUpdate()
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
static void noFunctionObjects(bool addWithOption=false)
virtual const fileName & name() const
ITstream lookup(const word &optName) const
int dryRun() const noexcept
An input stream of tokens.
static void doCorrectBoundaryConditions(bool correctBCs, GeometricField< Type, fvPatchField, volMesh > &field)
The IOstreamOption is a simple container for options an IOstream can normally have.
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,...
int verbose() const noexcept
Generic dimensioned Type class.
Mesh data needed to do the Finite Volume discretisation.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
const HashTable< string > & options() const noexcept
static void addDryRunOption(const string &usage, bool advanced=false)
errorManipArg< error, int > exit(error &err, const int errNo=1)
bool readEntry(const word &keyword, const dictionary &dict, bool mandatory=true, const bool stripComments=true)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
void reset(autoPtr< T > &&other) noexcept
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
@ ASCII
"ascii" (normal default)
#define FatalErrorInFunction
bool execute(const UList< word > &fieldNames)
static void addOptions(const bool constant=true, const bool withZero=false)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
A traits class, which is primarily used for primitives.
virtual void setTime(const Time &t)
static tmp< T > New(Args &&... args)
List< T > getList(const label index) const
A simple field-loader, as per the readFields function object.
#define FatalIOErrorInFunction(ios)
static instantList select0(Time &runTime, const argList &args)
const entry * findCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option) const
const word & constant() const
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Generic GeometricField class.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Foam::argList args(argc, argv)
static bool checking() noexcept
const Time & time() const noexcept
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
static void addVerboseOption(const string &usage, bool advanced=false)
Operations involving expressions.
bool found(const word &optName) const
The field association for mesh (patch/volume) values.
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)