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);
269 else if (literalRE || !(
key.isPattern() || shortcuts.
found(
key)))
277 thisKeysSet.erase(eptr->
keyword());
299 thisDict.
add(mergeEntry.
clone(thisDict).ptr());
305 <<
"Ignoring non-existing entry " <<
key
315 if (!literalRE && thisKeysSet.size())
318 wordList thisKeys(thisKeysSet.toc());
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];
344 thisKeysSet.erase(
k);
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
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const fileName & name() const noexcept
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.
static word defaultRegion
IOstream::streamFormat writeFormat() const
const word dictName("faMeshDefinition")
virtual bool isDict() const noexcept
static word timeName(const scalar t, const int precision=precision_)
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
static fileCheckTypes fileModificationChecking
static void addNote(const string ¬e)
bool insert(const Key &key, const T &obj)
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
const keyType & keyword() const noexcept
void append(const T &val)
defineTemplateTypeNameAndDebug(faScalarMatrix, 0)
Ostream & endl(Ostream &os)
A HashTable with keys but without contents that is similar to std::unordered_set.
bool readIfPresent(const word &optName, T &val) const
List< word > wordList
A List of words.
List< keyType > keys(bool patterns=false) const
A class for handling keywords in dictionaries.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
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)
static int disableFunctionEntries
virtual const dictionary & dict() const =0
List< Key > sortedToc() const
iterator find(const Key &key)
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)
#define FatalErrorInFunction
static void addOptions(const bool constant=true, const bool withZero=false)
bool remove(const word &keyword)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
virtual void setTime(const Time &t)
entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
const dimensionedScalar e
@ REGEX
Regular expression.
bool insert(const Key &key)
word name(const expressions::valueTypeCode typeCode)
Operations on lists of strings.
entry * add(entry *entryPtr, bool mergeEntry=false)
virtual autoPtr< entry > clone(const dictionary &parentDict) const =0
#define IOWarningInFunction(ios)
bool found(const Key &key) const
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Foam::argList args(argc, argv)
#define WarningInFunction
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
bool found(const word &optName) const