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;
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];
393int 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)
450 if (
args.readIfPresent(
"instance", instance))
452 if (times.
size() > 1)
455 <<
"Multiple times selected with 'instance' option"
461 runTime.setTime(times[timei], timei);
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"
513 if (
args.found(
"subDict"))
515 replaceDictsPtr = &
dict.subDict(
args[
"subDict"]);
518 const dictionary& replaceDicts = *replaceDictsPtr;
520 Info<<
"Read dictionary " <<
dict.name()
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;
label size() const noexcept
The number of elements in list.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
A HashTable similar to std::unordered_map.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
List< Key > toc() const
The table of contents (the keys) in unsorted order.
bool found(const Key &key) const
Same as contains().
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
label size() const noexcept
The number of elements in table.
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
A PtrList of objects of type <T> with automated input and output.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
@ NO_REGISTER
Do not request registration (bool: false).
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
static fileCheckTypes fileModificationChecking
Type of file modification checking.
A simple container for options an IOstream can normally have.
void append(const T &val)
Append an element at the end of the list.
void size(const label n)
Older name for setAddressableSize.
label find(const T &val) const
Find index of the first occurrence of the value.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
static void addNote(const string ¬e)
Add extra notes for the usage information.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
bool remove(const word &keyword)
Remove an entry specified by keyword.
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
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...
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
wordList toc() const
Return the table of contents.
A keyword and a list of tokens is an 'entry'.
virtual bool isDict() const noexcept
True if this entry is a dictionary.
virtual autoPtr< entry > clone(const dictionary &parentDict) const =0
Construct on freestore as copy with reference to the.
const keyType & keyword() const noexcept
Return keyword.
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary, otherwise Fatal.
static int disableFunctionEntries
Enable or disable use of function entries and variable expansions.
A class for handling keywords in dictionaries.
@ REGEX
Regular expression.
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir).
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh").
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
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...
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
static labelList matching(const wordRe &select, const UList< StringType > &input, const bool invert=false)
Determine the list indices for all matches.
A class for handling words, derived from Foam::string.
static const word null
An empty word.
#define defineTemplateTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information for templates, useful.
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const word dictName("faMeshDefinition")
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
#define WarningInFunction
Report a warning using Foam::Warning.
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
List< word > wordList
List of word.
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
List< label > labelList
A List of labels.
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< instant > instantList
List of instants.
Ostream & endl(Ostream &os)
Add newline and flush stream.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.