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;
277 <<
"Field '" << fieldName
278 <<
"' seems to be missing. Use 'create'" <<
nl 284 Info<<
"Modify field: " << fieldName
285 <<
" (type: " << oldFieldType <<
')';
290 <<
"Expression:" <<
nl 292 << valueExpr_.c_str() <<
nl 296 (maskExpr_.size() && maskExpr_ !=
"true" && maskExpr_ !=
"1");
300 Info<<
"field-mask:" <<
nl 302 << maskExpr_.c_str() <<
nl 306 if (ctrl.keepPatches)
308 Info<<
"Keeping patches unaltered" <<
endl;
310 else if (!valuePatches.
empty())
313 <<
" to fixed value" <<
endl;
320 driver.setCaching(ctrl.cacheVariables);
322 driver.readDict(
dict);
324 if (ctrl.debugParsing)
326 Info<<
"Parsing expression: " << valueExpr_ <<
"\nand field-mask " 327 << maskExpr_ <<
nl <<
endl;
328 driver.setDebugging(
true,
true);
332 driver.clearVariables();
342 if (ctrl.debugParsing)
344 Info<<
"Parsing field-mask:" << maskExpr_ <<
endl;
347 driver.parse(maskExpr_);
348 if (ctrl.debugParsing)
353 if (driver.isLogical())
355 auto& result = driver.result();
356 if (result.is_bool())
358 fieldMask = result.getResult<
bool>();
359 maskFieldAssoc = driver.fieldAssociation();
365 driver.clearResult();
372 <<
" mask: " << maskExpr_
373 <<
" does not evaluate to a logical expression: " 374 << driver.resultType() <<
nl 376 <<
"contents: " << fieldMask
381 if (ctrl.debugParsing)
383 Info<<
"Field-mask evaluates to " 388 if (ctrl.debugParsing)
390 Info<<
"Parsing expression:" << valueExpr_ <<
endl;
393 driver.parse(valueExpr_);
395 if (ctrl.debugParsing)
400 if (evalFieldMask && maskFieldAssoc != driver.fieldAssociation())
403 <<
"Mismatch between field-mask geometric type (" 405 <<
"expression geometric type (" 408 <<
"expression: " << valueExpr_ <<
nl 409 <<
"field-mask: " << maskExpr_ <<
nl 414 if (!oldFieldType.empty() && driver.resultType() != oldFieldType)
417 <<
"Inconsistent types: " << fieldName <<
" is " 419 <<
" but the expression evaluates to " 420 << driver.resultType()
424 Info<<
"Dispatch ... " << driver.resultType() <<
nl;
427 bool applied =
false;
428 switch (driver.fieldAssociation())
431 #define doLocalCode(GeoField) \ 433 const auto* ptr = driver.isResultType<GeoField>(); \ 484 <<
"Expression evaluates to an unsupported type: " 485 << driver.resultType() <<
nl <<
nl 486 <<
"Expression " << valueExpr_ <<
nl <<
endl 494 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)",
566 "Additional debugging information",
572 "Disable caching of expression variables",
579 " (command-line operation)",
585 "Leave patches unaltered" 586 " (command-line operation)",
593 "A list of patches that receive a fixed value" 594 " (command-line operation)",
600 "Provide a zero phi field" 601 " (command-line operation)",
614 "correctResultBoundaryFields",
632 <<
"No times selected." <<
nl 647 const bool useCommandArgs =
args.
found(
"field");
651 bool fatalCombination =
false;
655 fatalCombination =
true;
657 <<
"Cannot specify both dictionary and command-line arguments" 663 fatalCombination =
true;
665 <<
"Cannot specify both 'create' and 'keepPatches'" <<
nl 671 fatalCombination =
true;
673 <<
"Missing mandatory 'expression' option'" <<
nl 676 if (fatalCombination)
688 "create",
"keepPatches",
"value-patches",
689 "field-mask",
"expression",
"dimensions" 693 if (!badOptions.empty())
697 <<
"Using a dictionary. Cannot specify these options:" <<
nl 722 if (
args.
found(
"dummy-phi") && !dummyPhi)
724 Info<<
"Adding a dummy phi" <<
endl;
752 Info<<
"Using command-line options for " 753 << fieldName <<
nl <<
endl;
755 setExprFieldsControl ctrl;
758 ctrl.debugParsing =
args.
found(
"debug-parser");
759 ctrl.cacheVariables = !
args.
found(
"no-variable-caching");
762 ctrl.keepPatches =
args.
found(
"keepPatches");
763 ctrl.correctPatches = !
args.
found(
"noCorrectPatches");
764 ctrl.correctBCs =
args.
found(
"correctResultBoundaryFields");
765 ctrl.hasDimensions =
args.
found(
"dimensions");
778 if (ctrl.hasDimensions)
797 else if (exprDictPtr)
811 for (
const entry& dEntry : actions)
813 if (!dEntry.isDict())
815 Info<<
"Ignore non-dictionary entry: " 816 << dEntry.keyword() <<
nl;
822 setExprFieldsControl ctrl;
825 ctrl.debugParsing =
args.
found(
"debug-parser");
826 ctrl.cacheVariables = !
args.
found(
"no-variable-caching");
831 ctrl.correctPatches = !
args.
found(
"noCorrectPatches");
832 ctrl.correctBCs =
args.
found(
"correctResultBoundaryFields");
839 if (ctrl.createNew && ctrl.keepPatches)
842 <<
"Cannot specify both 'create' and 'keepPatches'" 850 "correctResultBoundaryFields",
863 "fieldMask", {{
"condition", 2106}},
901 <<
"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.
Generic dimensioned Type class.
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.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
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)
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)
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)