Commit 6e10b0de authored by Mark Olesen's avatar Mark Olesen
Browse files

adjusted dictionary #inputMode directive

- #inputMode error
  now issues a FatalError on duplicate entries

- #inputMode warn
  issues a warning on duplicate entries, corresponds to the
  old behaviour of 'error'

- #inputMode protect
  prevents overwriting existing entries

The 'protect' mode provides a simple mechanism for supplying default values.
eg,
    in file1:
        #inputMode  protect
        intensity       0.1;
        mixingLength    0.005;
        #inputMode  merge

        inlet
        {
            type        turbulentIntensityKineticEnergyInlet;
            intensity   $intensity;
        }

    which is included from file2:

        intensity   0.05;
        #include    "file1"
parent 0be0e96f
/*-------------------------------*- C++ -*---------------------------------*\
| ========= |
| \\ / OpenFOAM |
| \\ / |
| \\ / The Open Source CFD Toolbox |
| \\/ http://www.OpenFOAM.org |
\*-------------------------------------------------------------------------*/
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: Any |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object testDict;
version 2.0;
format ascii;
class dictionary;
object testDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#inputMode merge
dimensions [ 0 2 -2 0 0 0 0 ];
internalField uniform 1;
// use 'protect' to supply defaults
#inputMode protect
internalField uniform 10;
dimensions [ 0 2 -2 0 0 0 0 ];
#inputMode merge
active
{
type turbulentIntensityKineticEnergyInlet;
......@@ -31,6 +36,7 @@ inactive
type zeroGradient;
}
boundaryField
{
Default_Boundary_Region
......@@ -101,4 +107,4 @@ baz
// this should work too
#remove ( bar baz )
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
/*-------------------------------*- C++ -*---------------------------------*\
| ========= |
| \\ / OpenFOAM |
| \\ / |
| \\ / The Open Source CFD Toolbox |
| \\/ http://www.OpenFOAM.org |
\*-------------------------------------------------------------------------*/
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: Any |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object testDict;
version 2.0;
format ascii;
class dictionary;
object testDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
boundaryField
{
......@@ -27,4 +26,4 @@ boundaryField
}
#inputMode overwrite
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -53,7 +53,8 @@ bool Foam::dictionary::findInPatterns
{
if
(
patternMatch ? reLink()->match(Keyword)
patternMatch
? reLink()->match(Keyword)
: wcLink()->keyword() == Keyword
)
{
......@@ -83,7 +84,8 @@ bool Foam::dictionary::findInPatterns
{
if
(
patternMatch ? reLink()->match(Keyword)
patternMatch
? reLink()->match(Keyword)
: wcLink()->keyword() == Keyword
)
{
......
......@@ -73,7 +73,7 @@ bool Foam::entry::getKeyword(keyType& keyword, Istream& is)
{
cerr<< "--> FOAM Warning : " << std::endl
<< " From function "
<< "entry::getKeyword(keyType& keyword, Istream& is)" << std::endl
<< "entry::getKeyword(keyType&, Istream&)" << std::endl
<< " in file " << __FILE__
<< " at line " << __LINE__ << std::endl
<< " Reading " << is.name().c_str() << std::endl
......@@ -88,7 +88,7 @@ bool Foam::entry::getKeyword(keyType& keyword, Istream& is)
bool Foam::entry::New(dictionary& parentDict, Istream& is)
{
is.fatalCheck("entry::New(const dictionary& parentDict, Istream& is)");
is.fatalCheck("entry::New(const dictionary& parentDict, Istream&)");
keyType keyword;
......@@ -97,9 +97,9 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
{
return false;
}
else // Keyword starts entry ...
else // Keyword starts entry ...
{
if (keyword[0] == '#') // ... Function entry
if (keyword[0] == '#') // ... Function entry
{
word functionName = keyword(1, keyword.size()-1);
return functionEntry::execute(functionName, parentDict, is);
......@@ -128,9 +128,14 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
false,
false
);
if (existingPtr)
{
if (functionEntries::inputModeEntry::overwrite())
if (functionEntries::inputModeEntry::merge())
{
mergeEntry = true;
}
else if (functionEntries::inputModeEntry::overwrite())
{
// clear dictionary so merge acts like overwrite
if (existingPtr->isDict())
......@@ -139,9 +144,30 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
}
mergeEntry = true;
}
else if (functionEntries::inputModeEntry::merge())
else if (functionEntries::inputModeEntry::protect())
{
mergeEntry = true;
// read and discard the entry
if (nextToken == token::BEGIN_BLOCK)
{
dictionaryEntry dummy(keyword, parentDict, is);
}
else
{
primitiveEntry dummy(keyword, parentDict, is);
}
return true;
}
else if (functionEntries::inputModeEntry::error())
{
FatalIOErrorIn
(
"entry::New(const dictionary& parentDict, Istream&)",
is
)
<< "ERROR! duplicate entry: " << keyword
<< exit(FatalIOError);
return false;
}
}
......@@ -168,7 +194,7 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
Foam::autoPtr<Foam::entry> Foam::entry::New(Istream& is)
{
is.fatalCheck("entry::New(Istream& is)");
is.fatalCheck("entry::New(Istream&)");
keyType keyword;
......
......@@ -58,7 +58,7 @@ bool Foam::functionEntry::execute
is.fatalCheck
(
"functionEntry::execute"
"(const word& functionName, dictionary& parentDict, Istream& is)"
"(const word& functionName, dictionary& parentDict, Istream&)"
);
if (!executedictionaryIstreamMemberFunctionTablePtr_)
......
......@@ -131,7 +131,7 @@ bool Foam::functionEntries::includeEntry::execute
FatalIOErrorIn
(
"functionEntries::includeEntry::includeEntry"
"(dictionary& parentDict, primitiveEntry& entry, Istream&)",
"(dictionary& parentDict, primitiveEntry&, Istream&)",
is
) << "Cannot open include file " << ifs.name()
<< " while reading dictionary " << parentDict.name()
......
......@@ -34,8 +34,8 @@ Description
#include "includeFile"
@endverbatim
The usual expansion of environment variables and other constructs (eg,
the @c ~OpenFOAM/ expansion) is retained.
The usual expansion of environment variables and other constructs
(eg, the @c ~OpenFOAM/ expansion) is retained.
See Also
fileName, string::expand()
......
......@@ -72,6 +72,14 @@ void Foam::functionEntries::inputModeEntry::setMode(Istream& is)
{
mode_ = OVERWRITE;
}
else if (mode == "protect")
{
mode_ = PROTECT;
}
else if (mode == "warn")
{
mode_ = WARN;
}
else if (mode == "error")
{
mode_ = ERROR;
......@@ -79,7 +87,8 @@ void Foam::functionEntries::inputModeEntry::setMode(Istream& is)
else
{
WarningIn("Foam::functionEntries::inputModeEntry::setMode(Istream&)")
<< "unsupported input mode " << mode
<< "unsupported input mode '" << mode
<< "' ... defaulting to 'merge'"
<< endl;
}
}
......@@ -116,4 +125,15 @@ bool Foam::functionEntries::inputModeEntry::overwrite()
}
bool Foam::functionEntries::inputModeEntry::protect()
{
return mode_ == PROTECT;
}
bool Foam::functionEntries::inputModeEntry::error()
{
return mode_ == ERROR;
}
// ************************************************************************* //
......@@ -37,8 +37,10 @@ Description
The possible input modes:
@param merge merge sub-dictionaries when possible
@param overwrite keep last entry and silently remove previous ones
@param error flag duplicate entry as an error
@param default currently the same as merge
@param protect keep initial entry and silently ignore subsequent ones
@param warn keep initial entry and warn about subsequent ones
@param error issue a FatalError for duplicate entries
@param default currently identical to merge
SourceFiles
inputModeEntry.C
......@@ -65,15 +67,17 @@ class inputModeEntry
:
public functionEntry
{
//- input mode options
//- The input mode options
enum inputMode
{
ERROR,
MERGE,
OVERWRITE
OVERWRITE,
PROTECT,
WARN,
ERROR
};
//- current input mode
//- The current input mode
static inputMode mode_;
......@@ -100,7 +104,7 @@ public:
//- Execute the functionEntry in a sub-dict context
static bool execute(dictionary& parentDict, Istream&);
//- Reset the inputMode to %default
//- Reset the inputMode to %default (ie, %merge)
static void clear();
//- Return true if the inputMode is %merge
......@@ -109,6 +113,12 @@ public:
//- Return true if the inputMode is %overwrite
static bool overwrite();
//- Return true if the inputMode is %protect
static bool protect();
//- Return true if the inputMode is %error
static bool error();
};
......
......@@ -83,7 +83,7 @@ bool Foam::primitiveEntry::expandVariable
// lookup the variable name in the given dictionary....
const entry* ePtr = dict.lookupEntryPtr(varName, true, true);
// ...if defined insert its tokens into this
// ...if defined insert its tokens into this
if (ePtr != NULL)
{
append(ePtr->stream());
......@@ -91,7 +91,7 @@ bool Foam::primitiveEntry::expandVariable
}
else
{
// if not in the dictionary see if it is an environment
// if not in the dictionary see if it is an environment
// variable
string enVarString = getEnv(varName);
......@@ -123,7 +123,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is)
{
is.fatalCheck
(
"primitiveEntry::readData(const dictionary& dict, Istream& is)"
"primitiveEntry::readData(const dictionary&, Istream&)"
);
label blockCount = 0;
......@@ -177,7 +177,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is)
is.fatalCheck
(
"primitiveEntry::readData(const dictionary& dict, Istream& is)"
"primitiveEntry::readData(const dictionary&, Istream&)"
);
if (currToken.good())
......@@ -205,7 +205,7 @@ void Foam::primitiveEntry::readEntry(const dictionary& dict, Istream& is)
{
FatalIOErrorIn
(
"primitiveEntry::readEntry(const dictionary& dict,Istream& is)",
"primitiveEntry::readEntry(const dictionary&, Istream&)",
is
) << "ill defined primitiveEntry starting at keyword '"
<< keyword() << '\''
......@@ -266,7 +266,7 @@ void Foam::primitiveEntry::write(Ostream& os) const
os << token::SPACE;
}
}
os << token::END_STATEMENT << endl;
}
......@@ -297,7 +297,7 @@ Foam::Ostream& Foam::operator<<
{
os << " ...";
}
os << endl;
return os;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment