mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support "one-shot" changes to the dictionary inputMode (issue #429)
- Instead of relying on #inputMode to effect a global change it is now
possible (and recommended) to a temporary change in the inputMode
for the following entry.
#default : provide default value if entry is not already defined
#overwrite : silently remove a previously existing entry
#warn : warn about duplicate entries
#error : error if any duplicate entries occur
#merge : merge sub-dictionaries when possible (the default mode)
This is generally less cumbersome than the switching the global
inputMode. For example to provide a set of fallback values.
#includeIfPresent "user-files"
...
#default value uniform 10;
vs.
#includeIfPresent "user-files"
#inputMode protect
...
value uniform 10;
#inputMode merge // _Assuming_ we actually had this before
These directives can also be used to suppress the normal dictionary
merge semantics:
#overwrite dict { entry val; ... }
This commit is contained in:
@ -13,18 +13,19 @@ FoamFile
|
|||||||
object testDict;
|
object testDict;
|
||||||
}
|
}
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
#inputMode merge
|
|
||||||
#includeIfPresent "someUnknownFile"
|
#includeIfPresent "someUnknownFile"
|
||||||
#includeIfPresent "$FOAM_CASE/someUnknownFile"
|
#includeIfPresent "$FOAM_CASE/someUnknownFile"
|
||||||
#includeIfPresent "$FOAM_CASE/someUnknownFile-$FOAM_CASENAME"
|
#includeIfPresent "$FOAM_CASE/someUnknownFile-$FOAM_CASENAME"
|
||||||
|
|
||||||
internalField uniform 1;
|
internalField uniform 1;
|
||||||
|
|
||||||
// use 'protect' to supply defaults
|
// supply defaults
|
||||||
#inputMode protect
|
#default internalField uniform 10;
|
||||||
internalField uniform 10;
|
#default dimensions [ 1 2 -2 0 0 0 0 ];
|
||||||
dimensions [ 0 2 -2 0 0 0 0 ];
|
#overwrite dimensions [ 0 2 -2 0 0 0 0 ];
|
||||||
#inputMode merge
|
// #warn dimensions [ 0 2 -2 0 0 0 0 ];
|
||||||
|
// #error dimensions [ 0 2 -2 0 0 0 0 ];
|
||||||
|
|
||||||
active
|
active
|
||||||
{
|
{
|
||||||
@ -86,12 +87,12 @@ boundaryField
|
|||||||
#remove inactive
|
#remove inactive
|
||||||
|
|
||||||
inlet_7 { ${${varType}}} // Test indirection/recursive expansion
|
inlet_7 { ${${varType}}} // Test indirection/recursive expansion
|
||||||
#inputMode overwrite
|
|
||||||
inlet_8 { $active }
|
inlet_8 { $active }
|
||||||
|
|
||||||
|
#overwrite inlet_8 { type none; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// NB: the inputMode has a global scope
|
|
||||||
#inputMode merge
|
|
||||||
#include "testDict2"
|
#include "testDict2"
|
||||||
|
|
||||||
foo
|
foo
|
||||||
|
|||||||
@ -14,8 +14,6 @@ FoamFile
|
|||||||
}
|
}
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#inputMode merge;
|
|
||||||
|
|
||||||
surfaceConformation
|
surfaceConformation
|
||||||
{
|
{
|
||||||
pointPairDistanceCoeff 0.1;
|
pointPairDistanceCoeff 0.1;
|
||||||
|
|||||||
@ -41,6 +41,51 @@ namespace functionEntries
|
|||||||
dictionaryIstream,
|
dictionaryIstream,
|
||||||
inputMode
|
inputMode
|
||||||
);
|
);
|
||||||
|
|
||||||
|
addNamedToMemberFunctionSelectionTable
|
||||||
|
(
|
||||||
|
functionEntry,
|
||||||
|
inputModeDefault,
|
||||||
|
execute,
|
||||||
|
dictionaryIstream,
|
||||||
|
default
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToMemberFunctionSelectionTable
|
||||||
|
(
|
||||||
|
functionEntry,
|
||||||
|
inputModeMerge,
|
||||||
|
execute,
|
||||||
|
dictionaryIstream,
|
||||||
|
merge
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToMemberFunctionSelectionTable
|
||||||
|
(
|
||||||
|
functionEntry,
|
||||||
|
inputModeOverwrite,
|
||||||
|
execute,
|
||||||
|
dictionaryIstream,
|
||||||
|
overwrite
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToMemberFunctionSelectionTable
|
||||||
|
(
|
||||||
|
functionEntry,
|
||||||
|
inputModeWarn,
|
||||||
|
execute,
|
||||||
|
dictionaryIstream,
|
||||||
|
warn
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToMemberFunctionSelectionTable
|
||||||
|
(
|
||||||
|
functionEntry,
|
||||||
|
inputModeError,
|
||||||
|
execute,
|
||||||
|
dictionaryIstream,
|
||||||
|
error
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,4 +135,54 @@ bool Foam::functionEntries::inputMode::execute
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionEntries::inputModeDefault::execute
|
||||||
|
(
|
||||||
|
dictionary& parentDict,
|
||||||
|
Istream& is
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return entry::New(parentDict, is, entry::inputMode::PROTECT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionEntries::inputModeMerge::execute
|
||||||
|
(
|
||||||
|
dictionary& parentDict,
|
||||||
|
Istream& is
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return entry::New(parentDict, is, entry::inputMode::MERGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionEntries::inputModeOverwrite::execute
|
||||||
|
(
|
||||||
|
dictionary& parentDict,
|
||||||
|
Istream& is
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return entry::New(parentDict, is, entry::inputMode::OVERWRITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionEntries::inputModeWarn::execute
|
||||||
|
(
|
||||||
|
dictionary& parentDict,
|
||||||
|
Istream& is
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return entry::New(parentDict, is, entry::inputMode::WARN);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionEntries::inputModeError::execute
|
||||||
|
(
|
||||||
|
dictionary& parentDict,
|
||||||
|
Istream& is
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return entry::New(parentDict, is, entry::inputMode::ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -84,6 +84,86 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class inputModeDefault Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- Temporarily change inputMode to %protect for the following entry
|
||||||
|
class inputModeDefault
|
||||||
|
:
|
||||||
|
public functionEntry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Execute in a sub-dict context
|
||||||
|
static bool execute(dictionary& parentDict, Istream& is);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class inputModeMerge Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- Temporarily change inputMode to %merge for the following entry
|
||||||
|
class inputModeMerge
|
||||||
|
:
|
||||||
|
public functionEntry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Execute in a sub-dict context
|
||||||
|
static bool execute(dictionary& parentDict, Istream& is);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class inputModeOverwrite Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- Temporarily change inputMode to %overwrite for the following entry
|
||||||
|
class inputModeOverwrite
|
||||||
|
:
|
||||||
|
public functionEntry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Execute in a sub-dict context
|
||||||
|
static bool execute(dictionary& parentDict, Istream& is);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class inputModeWarn Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- Temporarily change inputMode to %warn for the following entry
|
||||||
|
class inputModeWarn
|
||||||
|
:
|
||||||
|
public functionEntry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Execute in a sub-dict context
|
||||||
|
static bool execute(dictionary& parentDict, Istream& is);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class inputModeError Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- Temporarily change inputMode to %error for the following entry
|
||||||
|
class inputModeError
|
||||||
|
:
|
||||||
|
public functionEntry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Execute in a sub-dict context
|
||||||
|
static bool execute(dictionary& parentDict, Istream& is);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace functionEntries
|
} // End namespace functionEntries
|
||||||
|
|||||||
@ -12,6 +12,4 @@ maxCo 12;
|
|||||||
|
|
||||||
maxDeltaT 1;
|
maxDeltaT 1;
|
||||||
|
|
||||||
#inputMode merge
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -12,6 +12,4 @@ maxCo 2.5;
|
|||||||
|
|
||||||
maxDeltaT 0.3;
|
maxDeltaT 0.3;
|
||||||
|
|
||||||
#inputMode merge
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -12,6 +12,4 @@ maxCo 8;
|
|||||||
|
|
||||||
maxDeltaT 1;
|
maxDeltaT 1;
|
||||||
|
|
||||||
#inputMode merge
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -12,6 +12,4 @@ maxCo 5;
|
|||||||
|
|
||||||
maxDeltaT 1;
|
maxDeltaT 1;
|
||||||
|
|
||||||
#inputMode merge
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -12,6 +12,4 @@ maxCo 12;
|
|||||||
|
|
||||||
maxDeltaT 1;
|
maxDeltaT 1;
|
||||||
|
|
||||||
#inputMode merge
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -12,6 +12,4 @@ turbulentKE 37;
|
|||||||
turbulentOmega 32;
|
turbulentOmega 32;
|
||||||
turbulentEpsilon 30;
|
turbulentEpsilon 30;
|
||||||
|
|
||||||
#inputMode merge
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -10,6 +10,5 @@ flowVelocity (10 0 0);
|
|||||||
pressure 0;
|
pressure 0;
|
||||||
turbulentKE 1.5;
|
turbulentKE 1.5;
|
||||||
turbulentEpsilon 0.88;
|
turbulentEpsilon 0.88;
|
||||||
#inputMode merge
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -11,6 +11,5 @@ pressure 0;
|
|||||||
turbulentKE 0.375;
|
turbulentKE 0.375;
|
||||||
turbulentOmega 3.6;
|
turbulentOmega 3.6;
|
||||||
turbulentEpsilon 0.12;
|
turbulentEpsilon 0.12;
|
||||||
#inputMode merge
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
Reference in New Issue
Block a user