Go to the documentation of this file.
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.found())
121 (*groupIter).append(patchName);
136 const bool addNonExisting,
149 const entry& mergeEntry,
150 const bool literalRE,
154 bool changed =
false;
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);
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"
526 const dictionary& replaceDicts = *replaceDictsPtr;
529 <<
" with replacements for dictionaries "
537 Info<<
"Reading polyMesh/boundary file to extract patch names"
564 const_cast<word&
>(dictList.type()) = dictList.headerClassName();
568 for (
const entry&
e : dictList)
572 fieldDict.
add(
e.keyword(),
e.dict());
578 Info<<
"Loaded dictionary " << dictList.name()
579 <<
" with entries " << fieldDict.
toc() <<
endl;
585 if (!disablePatchGroups)
587 patchGroups = extractPatchGroups(fieldDict);
588 if (patchGroups.
size())
590 Info<<
"Extracted patch groups:" <<
endl;
594 Info<<
" group " << groups[i] <<
" with patches "
595 << patchGroups[groups[i]] <<
endl;
603 for (
const entry& replaceEntry : replaceDicts)
605 if (!replaceEntry.isDict())
611 const word& fieldName = replaceEntry.keyword();
612 const dictionary& replaceDict = replaceEntry.dict();
614 Info<<
"Replacing entries in dictionary " << fieldName <<
endl;
619 if (fieldName ==
"boundary")
621 Info<<
"Special handling of " << fieldName
622 <<
" as polyMesh/boundary file." <<
endl;
625 Info<<
"Merging entries from " << replaceDict.
toc() <<
endl;
626 merge(
false, fieldDict, replaceDict, literalRE, patchGroups);
628 Info<<
"fieldDict:" << fieldDict <<
endl;
633 label nEntries = fieldDict.size();
638 doneKeys[i] = dictList[i].keyword();
648 dictList.set(nEntries++, ePtr->
clone());
649 fieldDict.
remove(doneKeys[i]);
654 for (
const entry&
e : fieldDict)
656 dictList.set(nEntries++,
e.clone());
658 dictList.setSize(nEntries);
660 Info<<
"Writing modified " << fieldName <<
endl;
671 Info<<
"Loading dictionary " << fieldName <<
endl;
672 const word oldTypeName = IOdictionary::typeName;
689 const_cast<word&
>(IOdictionary::typeName) = oldTypeName;
692 const_cast<word&
>(fieldDict.type()) =
693 fieldDict.headerClassName();
695 Info<<
"Loaded dictionary " << fieldName
696 <<
" with entries " << fieldDict.toc() <<
endl;
699 Info<<
"Merging entries from " << replaceDict.
toc() <<
endl;
700 merge(
true, fieldDict, replaceDict, literalRE, patchGroups);
702 Info<<
"Writing modified fieldDict " << fieldName <<
endl;
703 fieldDict.regIOobject::write();
708 <<
"Requested field to change " << fieldName
709 <<
" does not exist in " << fieldHeader.path() <<
endl;
A keyword and a list of tokens is an 'entry'.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
label size() const noexcept
The number of elements in table.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
A class for handling words, derived from Foam::string.
A class for handling file names.
A PtrList of objects of type <T> with automated input and output.
const keyType & keyword() const
Return keyword.
List< Key > toc() const
The table of contents (the keys) in unsorted order.
static word defaultRegion
Return the default region name.
bool isPattern() const
The keyType is treated as a pattern, not as literal string.
IOstream::streamFormat writeFormat() const
The write stream format.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
static word timeName(const scalar t, const int precision=precision_)
static fileCheckTypes fileModificationChecking
Type of file modification checking.
static void addNote(const string ¬e)
Add extra notes for the usage information.
const word dictName("blockMeshDict")
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
void append(const T &val)
Append an element at the end of the list.
defineTemplateTypeNameAndDebug(faScalarMatrix, 0)
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
#define forAll(list, i)
Loop across all elements in list.
List< word > wordList
A List of words.
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
A class for handling keywords in dictionaries.
const fileName & name() const
The dictionary name.
virtual bool isDict() const
Return true if this entry is a dictionary.
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
messageStream Info
Information stream (uses stdout - output is on the master only)
word name(const complex &c)
Return string representation of complex.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
The IOstreamOption is a simple container for options an IOstream can normally have.
static instantList selectIfPresent(Time &runTime, const argList &args)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
labelList findStrings(const regExp &matcher, const UList< StringType > &input, const bool invert=false)
Return list indices for strings matching the regular expression.
static int disableFunctionEntries
Enable or disable use of function entries and variable expansions.
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
word findInstance(const fileName &dir, const word &name=word::null, const IOobject::readOption rOpt=IOobject::MUST_READ, const word &stopInstance=word::null) const
errorManipArg< error, int > exit(error &err, const int errNo=1)
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static void addOptions(const bool constant=true, const bool withZero=false)
Add timeSelector options to argList::validOptions.
bool remove(const word &keyword)
Remove an entry specified by keyword.
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find for an entry (non-const access) with the given keyword.
label k
Boltzmann constant.
const dimensionedScalar e
Elementary charge.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
static const word null
An empty word.
Operations on lists of strings.
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
virtual autoPtr< entry > clone(const dictionary &parentDict) const =0
Construct on freestore as copy with reference to the.
wordList toc() const
Return the table of contents.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
bool found(const Key &key) const
Return true if hashed entry is found in table.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Foam::argList args(argc, argv)
#define WarningInFunction
Report a warning using Foam::Warning.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
bool found(const word &optName) const
Return true if the named option is found.