Merge branch 'master' of /home/dm4/OpenFOAM/OpenFOAM-dev

This commit is contained in:
sergio
2012-08-08 10:28:14 +01:00
3 changed files with 187 additions and 333 deletions

View File

@ -58,11 +58,15 @@ Usage
- changeDictionary [OPTION]
\param -literalRE \n
Do not interpret regular expressions; treat them as any other keyword.
Do not interpret regular expressions or patchGroups;
treat them as any other keyword.
\param -enableFunctionEntries \n
By default all dictionary preprocessing of fields is disabled
\param -disablePatchGroups \n
By default all keys are also checked for being patchGroups
\*---------------------------------------------------------------------------*/
#include "argList.H"
@ -84,7 +88,47 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
bool merge(dictionary&, const dictionary&, const bool);
// Extract groupPatch (= shortcut) info from boundary file info
HashTable<wordList, word> extractPatchGroups(const dictionary& boundaryDict)
{
HashTable<wordList, word> groupToPatch;
forAllConstIter(dictionary, boundaryDict, iter)
{
const word& patchName = iter().keyword();
const dictionary& patchDict = iter().dict();
wordList groups;
if (patchDict.readIfPresent("inGroups", groups))
{
forAll(groups, i)
{
HashTable<wordList, word>::iterator fndGroup = groupToPatch.find
(
groups[i]
);
if (fndGroup == groupToPatch.end())
{
groupToPatch.insert(groups[i], wordList(1, patchName));
}
else
{
fndGroup().append(patchName);
}
}
}
}
return groupToPatch;
}
bool merge
(
dictionary&,
const dictionary&,
const bool,
const HashTable<wordList, word>&
);
// Add thisEntry to dictionary thisDict.
@ -93,7 +137,8 @@ bool addEntry
dictionary& thisDict,
entry& thisEntry,
const entry& mergeEntry,
const bool literalRE
const bool literalRE,
const HashTable<wordList, word>& shortcuts
)
{
bool changed = false;
@ -108,7 +153,8 @@ bool addEntry
(
const_cast<dictionary&>(thisEntry.dict()),
mergeEntry.dict(),
literalRE
literalRE,
shortcuts
)
)
{
@ -135,7 +181,8 @@ bool merge
(
dictionary& thisDict,
const dictionary& mergeDict,
const bool literalRE
const bool literalRE,
const HashTable<wordList, word>& shortcuts
)
{
bool changed = false;
@ -156,7 +203,7 @@ bool merge
{
const keyType& key = mergeIter().keyword();
if (literalRE || !key.isPattern())
if (literalRE || !(key.isPattern() || shortcuts.found(key)))
{
entry* entryPtr = thisDict.lookupEntryPtr
(
@ -179,7 +226,8 @@ bool merge
thisDict,
*entryPtr,
mergeIter(),
literalRE
literalRE,
shortcuts
)
)
{
@ -196,29 +244,54 @@ bool merge
}
// Pass 2. Wildcard matches (if any) on any non-match keys.
// Pass 2. Wildcard or shortcut matches (if any) on any non-match keys.
if (!literalRE && thisKeysSet.size() > 0)
{
// Pick up remaining dictionary entries
wordList thisKeys(thisKeysSet.toc());
forAllConstIter(IDLList<entry>, mergeDict, mergeIter)
{
const keyType& key = mergeIter().keyword();
// List of indices into thisKeys
labelList matches;
if (key.isPattern())
{
// Find all matching entries in the original thisDict
// Wildcard match
matches = findStrings(key, thisKeys);
labelList matches = findStrings(key, thisKeys);
}
else if (shortcuts.size())
{
// See if patchGroups expand to valid thisKeys
const wordList shortcutNames = shortcuts.toc();
labelList indices = findStrings(key, shortcutNames);
forAll(indices, i)
{
const word& name = shortcutNames[indices[i]];
const wordList& keys = shortcuts[name];
forAll(keys, j)
{
label index = findIndex(thisKeys, keys[j]);
if (index != -1)
{
matches.append(index);
}
}
}
}
// Add all matches
forAll(matches, i)
{
label matchI = matches[i];
const word& thisKey = thisKeys[matches[i]];
entry& thisEntry = const_cast<entry&>
(
thisDict.lookupEntry(thisKeys[matchI], false, false)
thisDict.lookupEntry(thisKey, false, false)
);
if
@ -228,7 +301,9 @@ bool merge
thisDict,
thisEntry,
mergeIter(),
literalRE
literalRE,
HashTable<wordList, word>(0) // no shortcuts
// at deeper levels
)
)
{
@ -237,7 +312,6 @@ bool merge
}
}
}
}
return changed;
}
@ -273,6 +347,12 @@ int main(int argc, char *argv[])
"enableFunctionEntries",
"enable expansion of dictionary directives - #include, #codeStream etc"
);
argList::addBoolOption
(
"disablePatchGroups",
"disable matching keys to patch groups"
);
#include "addRegionOption.H"
#include "setRootCase.H"
@ -304,7 +384,6 @@ int main(int argc, char *argv[])
}
const bool literalRE = args.optionFound("literalRE");
if (literalRE)
{
Info<< "Not interpreting any regular expressions (RE)"
@ -328,6 +407,15 @@ int main(int argc, char *argv[])
}
const bool disablePatchGroups = args.optionFound("disablePatchGroups");
if (disablePatchGroups)
{
Info<< "Not interpreting any keys in the changeDictionary"
<< " as patchGroups"
<< endl;
}
fileName regionPrefix = "";
if (regionName != fvMesh::defaultRegion)
{
@ -369,20 +457,12 @@ int main(int argc, char *argv[])
<< replaceDicts.toc() << endl;
// Every replacement is a dictionary name and a keyword in this
forAllConstIter(dictionary, replaceDicts, fieldIter)
{
const word& fieldName = fieldIter().keyword();
Info<< "Replacing entries in dictionary " << fieldName << endl;
// Always read boundary to get patch groups
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Handle 'boundary' specially:
// - is PtrList of dictionaries
// - is in polyMesh/
if (fieldName == "boundary")
{
Info<< "Special handling of " << fieldName
<< " as polyMesh/boundary file." << endl;
Info<< "Reading polyMesh/boundary file to extract patch names"
<< endl;
// Read PtrList of dictionary as dictionary.
const word oldTypeName = IOPtrList<entry>::typeName;
@ -391,15 +471,16 @@ int main(int argc, char *argv[])
(
IOobject
(
fieldName,
"boundary",
runTime.findInstance
(
regionPrefix/polyMesh::meshSubDir,
fieldName
"boundary",
IOobject::READ_IF_PRESENT
),
polyMesh::meshSubDir,
mesh,
IOobject::MUST_READ,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
)
@ -415,15 +496,52 @@ int main(int argc, char *argv[])
fieldDict.add(dictList[i].keyword(), dictList[i].dict());
}
Info<< "Loaded dictionary " << fieldName
if (dictList.size())
{
Info<< "Loaded dictionary " << dictList.name()
<< " with entries " << fieldDict.toc() << endl;
}
// Extract any patchGroups information (= shortcut for set of
// patches)
HashTable<wordList, word> patchGroups;
if (!disablePatchGroups)
{
patchGroups = extractPatchGroups(fieldDict);
if (patchGroups.size())
{
Info<< "Extracted patch groups:" << endl;
wordList groups(patchGroups.sortedToc());
forAll(groups, i)
{
Info<< " group " << groups[i] << " with patches "
<< patchGroups[groups[i]] << endl;
}
}
}
// Every replacement is a dictionary name and a keyword in this
forAllConstIter(dictionary, replaceDicts, fieldIter)
{
const word& fieldName = fieldIter().keyword();
Info<< "Replacing entries in dictionary " << fieldName << endl;
// Handle 'boundary' specially:
// - is PtrList of dictionaries
// - is in polyMesh/
if (fieldName == "boundary")
{
Info<< "Special handling of " << fieldName
<< " as polyMesh/boundary file." << endl;
// Get the replacement dictionary for the field
const dictionary& replaceDict = fieldIter().dict();
Info<< "Merging entries from " << replaceDict.toc() << endl;
// Merge the replacements in
merge(fieldDict, replaceDict, literalRE);
merge(fieldDict, replaceDict, literalRE, patchGroups);
Info<< "fieldDict:" << fieldDict << endl;
@ -492,7 +610,7 @@ int main(int argc, char *argv[])
Info<< "Merging entries from " << replaceDict.toc() << endl;
// Merge the replacements in
merge(fieldDict, replaceDict, literalRE);
merge(fieldDict, replaceDict, literalRE, patchGroups);
Info<< "Writing modified fieldDict " << fieldName << endl;
fieldDict.regIOobject::write();

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -104,7 +104,7 @@ class codedFixedValueFvPatchField
// Private data
//- Dictionary contents for the boundary condition
mutable dictionary dict_;
const dictionary dict_;
const word redirectType_;

View File

@ -1,264 +0,0 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object Ma;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 0 0 0 0];
internalField uniform 3;
boundaryField
{
inlet
{
type calculated;
value uniform 3;
}
outlet
{
type calculated;
value uniform 3;
}
bottom
{
type symmetryPlane;
}
top
{
type symmetryPlane;
}
obstacle
{
type calculated;
value nonuniform List<scalar>
208
(
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
)
;
}
defaultFaces
{
type empty;
}
}
// ************************************************************************* //