mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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"
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
/*-------------------------------*- 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;
|
||||
@ -12,12 +12,17 @@ FoamFile
|
||||
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 )
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
/*-------------------------------*- 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;
|
||||
@ -12,8 +12,7 @@ FoamFile
|
||||
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;
|
||||
|
||||
@ -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();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -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() << '\''
|
||||
|
||||
Reference in New Issue
Block a user