103 for (
const entry& dEntry : boundaryDict)
105 if (!dEntry.isDict())
110 const word& patchName = dEntry.keyword();
116 for (
const word& groupName : groupNames)
118 auto groupIter = groupToPatch.
find(groupName);
119 if (groupIter.good())
121 (*groupIter).append(patchName);
136 const bool addNonExisting,
149 const entry& mergeEntry,
150 const bool literalRE,
154 bool changed =
false;
165 const_cast<dictionary&>(thisEntry.
dict()),
178 thisDict.
add(mergeEntry.
clone(thisDict).ptr(),
true);
202 else if (shortcuts.
size())
207 for (
const label idx : indices)
209 const word&
name = shortcutNames[idx];
213 const label index = thisKeys.
find(keys[j]);
232 const bool addNonExisting,
235 const bool literalRE,
241 bool changed =
false;
246 for (
const word&
k : thisDict.
keys(
false))
254 for (
const entry& mergeEntry : mergeDict)
260 const word eraseKey =
key.substr(1);
261 if (thisDict.
remove(eraseKey))
265 thisKeysSet.
erase(eraseKey);
269 else if (literalRE || !(
key.isPattern() || shortcuts.
found(
key)))
299 thisDict.
add(mergeEntry.
clone(thisDict).ptr());
305 <<
"Ignoring non-existing entry " <<
key 315 if (!literalRE && thisKeysSet.
size())
320 for (
const entry& mergeEntry : mergeDict)
326 const word eraseKey =
key.substr(1);
341 for (
const label matchi : matches)
343 const word&
k = thisKeys[matchi];
363 for (
const label matchi : matches)
365 const word&
k = thisKeys[matchi];
394 int main(
int argc,
char *argv[])
398 "Utility to change dictionary entries" 399 " (such as the patch type for fields and polyMesh/boundary files)." 408 "Specify the subDict name of the replacements dictionary" 414 "Override instance setting (default is the time name)" 423 "Treat regular expressions literally (i.e., as a keyword)" 427 "enableFunctionEntries",
428 "Enable expansion of dictionary directives - #include, #codeStream etc" 432 "disablePatchGroups",
433 "Disable matching keys to patch groups" 443 if (times.
size() < 1)
453 if (times.
size() > 1)
456 <<
"Multiple times selected with 'instance' option" 468 const bool literalRE =
args.
found(
"literalRE");
471 Info<<
"Not interpreting any regular expressions (RE)" 472 <<
" in the changeDictionaryDict." <<
endl 473 <<
"Instead they are handled as any other entry, i.e. added if" 474 <<
" not present." <<
endl;
477 const bool enableEntries =
args.
found(
"enableFunctionEntries");
480 Info<<
"Allowing dictionary preprocessing (#include, #codeStream)." 492 const bool disablePatchGroups =
args.
found(
"disablePatchGroups");
493 if (disablePatchGroups)
495 Info<<
"Not interpreting any keys in the changeDictionary" 519 const dictionary& replaceDicts = *replaceDictsPtr;
522 <<
" with replacements for dictionaries " 530 Info<<
"Reading polyMesh/boundary file to extract patch names" 557 const_cast<word&
>(dictList.type()) = dictList.headerClassName();
561 for (
const entry&
e : dictList)
565 fieldDict.
add(
e.keyword(),
e.dict());
571 Info<<
"Loaded dictionary " << dictList.name()
572 <<
" with entries " << fieldDict.
toc() <<
endl;
578 if (!disablePatchGroups)
580 patchGroups = extractPatchGroups(fieldDict);
581 if (patchGroups.
size())
583 Info<<
"Extracted patch groups:" <<
endl;
587 Info<<
" group " << groups[i] <<
" with patches " 588 << patchGroups[groups[i]] <<
endl;
596 for (
const entry& replaceEntry : replaceDicts)
598 if (!replaceEntry.isDict())
604 const word& fieldName = replaceEntry.keyword();
605 const dictionary& replaceDict = replaceEntry.dict();
607 Info<<
"Replacing entries in dictionary " << fieldName <<
endl;
612 if (fieldName ==
"boundary")
614 Info<<
"Special handling of " << fieldName
615 <<
" as polyMesh/boundary file." <<
endl;
618 Info<<
"Merging entries from " << replaceDict.
toc() <<
endl;
619 merge(
false, fieldDict, replaceDict, literalRE, patchGroups);
621 Info<<
"fieldDict:" << fieldDict <<
endl;
626 label nEntries = fieldDict.size();
631 doneKeys[i] = dictList[i].keyword();
641 dictList.set(nEntries++, ePtr->
clone());
642 fieldDict.
remove(doneKeys[i]);
647 for (
const entry&
e : fieldDict)
649 dictList.set(nEntries++,
e.clone());
651 dictList.setSize(nEntries);
653 Info<<
"Writing modified " << fieldName <<
endl;
664 Info<<
"Loading dictionary " << fieldName <<
endl;
665 const word oldTypeName = localIOdictionary::typeName;
685 const_cast<word&
>(localIOdictionary::typeName) =
689 const_cast<word&
>(fieldDict.type()) =
690 fieldDict.headerClassName();
692 Info<<
"Loaded dictionary " << fieldName
693 <<
" with entries " << fieldDict.toc() <<
endl;
696 Info<<
"Merging entries from " << replaceDict.
toc() <<
endl;
697 merge(
true, fieldDict, replaceDict, literalRE, patchGroups);
699 Info<<
"Writing modified fieldDict " << fieldName <<
endl;
700 fieldDict.regIOobject::write();
705 <<
"Requested field to change " << fieldName
706 <<
" 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)
word findInstance(const fileName &dir, const word &name=word::null, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, const word &stopInstance=word::null) const
Return time instance (location) of dir that contains the file name (eg, used in reading mesh data)...
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.
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.
Operations on lists of strings.
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.
A class for handling words, derived from Foam::string.
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
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 select0) otherwise return just the current ti...
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
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
Return 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...
labelList findStrings(const regExp &matcher, const UList< StringType > &input, const bool invert=false)
Return list indices for strings matching the regular expression.
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...