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();
175 label numValuesChanged = 0;
178 if (fieldMask.
empty())
181 numValuesChanged =
output.size();
183 output.primitiveFieldRef() = evaluated;
187 auto&
internal =
output.primitiveFieldRef();
193 internal[idx] = evaluated[idx];
200 forAll(evaluated.boundaryField(), patchi)
202 auto& pf =
output.boundaryFieldRef()[patchi];
204 if (pf.patch().coupled())
206 pf == evaluated.boundaryField()[patchi];
215 if (numValuesChanged == numTotal)
221 Info<<
"Set " << numValuesChanged <<
" of ";
223 Info<< numTotal <<
" values" <<
endl;
225 if (ctrl.hasDimensions)
227 Info<<
"Setting dimensions to " << dims <<
endl;
228 output.dimensions().reset(dims);
238 output.writeObject(ctrl.streamOpt,
true);
248 const word& fieldName,
255 const setExprFieldsControl& ctrl
262 Info<<
"Set new field: " << fieldName;
278 <<
"Field '" << fieldName
279 <<
"' 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[])
506 "Write in ASCII format instead of the controlDict setting" 512 "Alternative dictionary for setExprFieldsDict" 516 "Evaluate but do not write" 520 "Additional verbosity",
527 "Specify field or fields to preload. Eg, 'T' or '(p T U)'",
534 "The field to create/overwrite" 535 " (command-line operation)",
542 "The expression to evaluate" 543 " (command-line operation)",
550 "The field mask (logical condition) when to apply the expression" 551 " (command-line operation)",
559 "The dimensions for created fields" 560 " (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");
779 if (ctrl.hasDimensions)
798 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;
826 ctrl.debugParsing =
args.
found(
"debug-parser");
827 ctrl.cacheVariables = !
args.
found(
"no-variable-caching");
832 ctrl.correctPatches = !
args.
found(
"noCorrectPatches");
833 ctrl.correctBCs =
args.
found(
"correctResultBoundaryFields");
840 if (ctrl.createNew && ctrl.keepPatches)
843 <<
"Cannot specify both 'create' and 'keepPatches'" 851 "correctResultBoundaryFields",
864 "fieldMask", {{
"condition", 2106}},
902 <<
"No command-line or dictionary??" <<
nl <<
endl
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry data stream. FatalIOError if not found, or not a stream. ...
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
word fieldGeoType(const expressions::FieldAssociation geoType)
bool readEntry(const word &keyword, const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ)
Read/expand entry with dictionary variables, and strip any embedded C/C++ comments from the input...
virtual const fileName & name() const
The name of the stream.
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.
A simple field-loader, as per the readFields function object.
label retain(const HashTable< AnyType, Key, AnyHash > &other)
Retain table entries given by keys of the other hash-table.
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if List is empty (ie, size() is zero)
const word dictName("faMeshDefinition")
Ostream & endl(Ostream &os)
Add newline and flush stream.
A traits class, which is primarily used for primitives and vector-space.
List< T > getList(const label index) const
Get a List of values from the argument at index.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
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.
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
Generic GeometricField class.
A simple container for options an IOstream can normally have.
Ignore writing from objectRegistry::writeObject()
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
static void doCorrectBoundaryConditions(bool correctBCs, VolumeField< Type > &field)
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.
#define doLocalCode(FieldType, Variable)
bool start()
Called at the start of the time-loop.
bool allowFunctionObjects() const
The controlDict 'functions' entry is allowed to be used.
void trim()
Inplace trim leading and trailing whitespace.
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
#define forAll(list, i)
Loop across all elements in list.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
const keyType & keyword() const noexcept
Return keyword.
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
surfacesMesh setField(triSurfaceToAgglom)
const functionObjectList & functionObjects() const noexcept
Return the list of function objects.
Operations involving expressions.
A class for handling words, derived from Foam::string.
static void addDryRunOption(const string &usage, bool advanced=false)
Enable a 'dry-run' bool option, with usage information.
const Time & time() const noexcept
Return time registry.
int dryRun() const noexcept
Return the dry-run flag.
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)
String evaluation with specified (positive, non-zero) field width.
A variant of Foam::string with expansion of dictionary variables into a comma-separated form...
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
ITstream lookup(const word &optName) const
Return an input stream from the named option.
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (respects is_globalIOobject trait) and check its info.
static void addVerboseOption(const string &usage="", bool advanced=false)
Enable a 'verbose' bool option, with usage information.
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
const word & constant() const noexcept
Return constant name.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
bool readListIfPresent(const word &optName, List< T > &list) const
If named option is present, get a List of values treating a single entry like a list of size 1...
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options and also set the runTime to the first i...
const entry * findCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option matchOpt) const
Find and return an entry pointer if present, or return a nullptr, using any compatibility names if ne...
bool readIfPresent(const word &entryName, const dictionary &dict)
Update the dimensions from dictionary entry. FatalIOError if it is found and the number of tokens is ...
const word & headerClassName() const noexcept
Return name of the class name read from header.
T get(const label index) const
Get a value from the argument at index.
static bool checking() noexcept
True if dimension checking is enabled (the usual default)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Mesh data needed to do the Finite Volume discretisation.
const HashTable< string > & options() const noexcept
Return options.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
messageStream Info
Information stream (stdout output on master, null elsewhere)
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
static Ostream & output(Ostream &os, const IntRange< T > &range)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
IOstreamOption::streamFormat writeFormat() const noexcept
Get write stream format.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
Foam::argList args(argc, argv)
bool execute(const UList< word > &fieldNames)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Driver for volume, surface, point field expressions.
int verbose() const noexcept
Return the verbose flag.
Do not request registration (bool: false)
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.
bool found(const word &optName) const
Return true if the named option is found.
An input stream of tokens.
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
A keyword and a list of tokens is an 'entry'.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
static constexpr const zero Zero
Global zero (0)