102 for (
const entry& dEntry : boundaryDict)
104 if (!dEntry.isDict())
109 const word& patchName = dEntry.keyword();
115 for (
const word& groupName : groupNames)
117 auto groupIter = groupToPatch.
find(groupName);
118 if (groupIter.good())
120 (*groupIter).append(patchName);
135 const bool addNonExisting,
148 const entry& mergeEntry,
149 const bool literalRE,
153 bool changed =
false;
164 const_cast<dictionary&>(thisEntry.
dict()),
177 thisDict.
add(mergeEntry.
clone(thisDict).ptr(),
true);
201 else if (shortcuts.
size())
206 for (
const label idx : indices)
208 const word&
name = shortcutNames[idx];
210 for (
const word&
k : keys)
212 const label index = thisKeys.
find(
k);
231 const bool addNonExisting,
234 const bool literalRE,
240 bool changed =
false;
245 for (
const word&
k : thisDict.
keys(
false))
253 for (
const entry& mergeEntry : mergeDict)
259 const word eraseKey =
key.substr(1);
260 if (thisDict.
remove(eraseKey))
264 thisKeysSet.
erase(eraseKey);
268 else if (literalRE || !(
key.isPattern() || shortcuts.
found(
key)))
298 thisDict.
add(mergeEntry.
clone(thisDict).ptr());
304 <<
"Ignoring non-existing entry " <<
key 314 if (!literalRE && thisKeysSet.
size())
319 for (
const entry& mergeEntry : mergeDict)
325 const word eraseKey =
key.substr(1);
340 for (
const label matchi : matches)
342 const word&
k = thisKeys[matchi];
362 for (
const label matchi : matches)
364 const word&
k = thisKeys[matchi];
393 int main(
int argc,
char *argv[])
397 "Utility to change dictionary entries" 398 " (such as the patch type for fields and polyMesh/boundary files)." 407 "Specify the subDict name of the replacements dictionary" 413 "Override instance setting (default is the time name)" 422 "Treat regular expressions literally (i.e., as a keyword)" 426 "enableFunctionEntries",
427 "Enable expansion of dictionary directives - #include, #codeStream etc" 431 "disablePatchGroups",
432 "Disable matching keys to patch groups" 442 if (times.
size() < 1)
452 if (times.
size() > 1)
455 <<
"Multiple times selected with 'instance' option" 467 const bool literalRE =
args.
found(
"literalRE");
470 Info<<
"Not interpreting any regular expressions (RE)" 471 <<
" in the changeDictionaryDict." <<
endl 472 <<
"Instead they are handled as any other entry, i.e. added if" 473 <<
" not present." <<
endl;
476 const bool enableEntries =
args.
found(
"enableFunctionEntries");
479 Info<<
"Allowing dictionary preprocessing (#include, #codeStream)." 491 const bool disablePatchGroups =
args.
found(
"disablePatchGroups");
492 if (disablePatchGroups)
494 Info<<
"Not interpreting any keys in the changeDictionary" 518 const dictionary& replaceDicts = *replaceDictsPtr;
521 <<
" with replacements for dictionaries " 529 Info<<
"Reading polyMesh/boundary file to extract patch names" 556 const_cast<word&
>(dictList.type()) = dictList.headerClassName();
560 for (
const entry&
e : dictList)
564 fieldDict.
add(
e.keyword(),
e.dict());
570 Info<<
"Loaded dictionary " << dictList.name()
571 <<
" with entries " << fieldDict.
toc() <<
endl;
577 if (!disablePatchGroups)
579 patchGroups = extractPatchGroups(fieldDict);
580 if (patchGroups.
size())
582 Info<<
"Extracted patch groups:" <<
endl;
586 Info<<
" group " << groups[i] <<
" with patches " 587 << patchGroups[groups[i]] <<
endl;
595 for (
const entry& replaceEntry : replaceDicts)
597 if (!replaceEntry.isDict())
603 const word& fieldName = replaceEntry.keyword();
604 const dictionary& replaceDict = replaceEntry.dict();
606 Info<<
"Replacing entries in dictionary " << fieldName <<
endl;
611 if (fieldName ==
"boundary")
613 Info<<
"Special handling of " << fieldName
614 <<
" as polyMesh/boundary file." <<
endl;
617 Info<<
"Merging entries from " << replaceDict.
toc() <<
endl;
618 merge(
false, fieldDict, replaceDict, literalRE, patchGroups);
620 Info<<
"fieldDict:" << fieldDict <<
endl;
625 label nEntries = fieldDict.size();
630 doneKeys[i] = dictList[i].keyword();
640 dictList.set(nEntries++, ePtr->
clone());
641 fieldDict.
remove(doneKeys[i]);
646 for (
const entry&
e : fieldDict)
648 dictList.set(nEntries++,
e.clone());
650 dictList.setSize(nEntries);
652 Info<<
"Writing modified " << fieldName <<
endl;
663 Info<<
"Loading dictionary " << fieldName <<
endl;
664 const word oldTypeName = localIOdictionary::typeName;
684 const_cast<word&
>(localIOdictionary::typeName) =
688 const_cast<word&
>(fieldDict.type()) =
689 fieldDict.headerClassName();
691 Info<<
"Loaded dictionary " << fieldName
692 <<
" with entries " << fieldDict.toc() <<
endl;
695 Info<<
"Merging entries from " << replaceDict.
toc() <<
endl;
696 merge(
true, fieldDict, replaceDict, literalRE, patchGroups);
698 Info<<
"Writing modified fieldDict " << fieldName <<
endl;
699 fieldDict.regIOobject::write();
704 <<
"Requested field to change " << fieldName
705 <<
" does not exist in " << fieldHeader.path() <<
endl;
A class for handling keywords in dictionaries.
virtual autoPtr< entry > clone(const dictionary &parentDict) const =0
Construct on freestore as copy with reference to the.
static void addNote(const string ¬e)
Add extra notes for the usage information.
void size(const label n)
Older name for setAddressableSize.
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.
void append(const T &val)
Append an element at the end of the list.
bool found(const Key &key) const
Same as contains()
const word dictName("faMeshDefinition")
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary, otherwise Fatal.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
A simple container for options an IOstream can normally have.
label k
Boltzmann constant.
Ignore writing from objectRegistry::writeObject()
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
const fileName & name() const noexcept
The dictionary name.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
wordList toc() const
Return the table of contents.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
#define forAll(list, i)
Loop across all elements in list.
bool remove(const word &keyword)
Remove an entry specified by keyword.
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
label size() const noexcept
The number of elements in table.
static int disableFunctionEntries
Enable or disable use of function entries and variable expansions.
const dimensionedScalar e
Elementary charge.
const keyType & keyword() const noexcept
Return keyword.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
word findInstance(const fileName &directory, const word &name=word::null, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, const word &stopInstance=word::null, const bool constant_fallback=true) const
Return time instance (location) of directory containing the file name (eg, used in reading mesh data)...
A class for handling words, derived from Foam::string.
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
static labelList matching(const wordRe &select, const UList< StringType > &input, const bool invert=false)
Determine the list indices for all matches.
Reading is optional [identical to LAZY_READ].
static const word null
An empty word.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
static instantList selectIfPresent(Time &runTime, const argList &args)
If any time option provided return the set of times - as per select0() - otherwise return just the cu...
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
label find(const T &val) const
Find index of the first occurrence of the value.
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.
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...
defineTemplateTypeNameAndDebug(faScalarMatrix, 0)
static fileCheckTypes fileModificationChecking
Type of file modification checking.
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
List< word > wordList
List of word.
A PtrList of objects of type <T> with automated input and output.
#define WarningInFunction
Report a warning using Foam::Warning.
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
const entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool isDict() const noexcept
True if this entry is a dictionary.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
List< Key > toc() const
The table of contents (the keys) in unsorted order.
IOstreamOption::streamFormat writeFormat() const noexcept
Get write stream format.
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Do not request registration (bool: false)
bool found(const word &optName) const
Return true if the named option is found.
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'.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...