ENH: fvSchemes,fvSolution : read file only once.

This commit is contained in:
mattijs
2010-12-03 11:12:44 +00:00
parent 1c3c1e017b
commit 11979f6a29
4 changed files with 250 additions and 217 deletions

View File

@ -43,9 +43,40 @@ static const Foam::List<Foam::word> subDictNames
);
//! @endcond
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
void Foam::solution::read(const dictionary& dict)
{
if (dict.found("cache"))
{
cache_ = dict.subDict("cache");
caching_ = cache_.lookupOrDefault("active", true);
}
if (dict.found("relaxationFactors"))
{
relaxationFactors_ = dict.subDict("relaxationFactors");
}
relaxationFactors_.readIfPresent("default", defaultRelaxationFactor_);
if (dict.found("solvers"))
{
solvers_ = dict.subDict("solvers");
upgradeSolverDict(solvers_);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::solution::solution(const objectRegistry& obr, const fileName& dictName)
Foam::solution::solution
(
const objectRegistry& obr,
const fileName& dictName,
const bool syncPar
)
:
IOdictionary
(
@ -56,7 +87,8 @@ Foam::solution::solution(const objectRegistry& obr, const fileName& dictName)
obr,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
),
syncPar
),
cache_(ITstream("cache", tokenList())()),
caching_(false),
@ -64,7 +96,7 @@ Foam::solution::solution(const objectRegistry& obr, const fileName& dictName)
defaultRelaxationFactor_(0),
solvers_(ITstream("solvers", tokenList())())
{
read();
read(solutionDict());
}
@ -250,26 +282,7 @@ bool Foam::solution::read()
{
if (regIOobject::read())
{
const dictionary& dict = solutionDict();
if (dict.found("cache"))
{
cache_ = dict.subDict("cache");
caching_ = cache_.lookupOrDefault("active", true);
}
if (dict.found("relaxationFactors"))
{
relaxationFactors_ = dict.subDict("relaxationFactors");
}
relaxationFactors_.readIfPresent("default", defaultRelaxationFactor_);
if (dict.found("solvers"))
{
solvers_ = dict.subDict("solvers");
upgradeSolverDict(solvers_);
}
read(solutionDict());
return true;
}

View File

@ -70,6 +70,9 @@ class solution
// Private Member Functions
//- Read settings from the dictionary
void read(const dictionary&);
//- Disallow default bitwise copy construct and assignment
solution(const solution&);
void operator=(const solution&);
@ -89,7 +92,12 @@ public:
// Constructors
//- Construct for given objectRegistry and dictionary
solution(const objectRegistry& obr, const fileName& dictName);
solution
(
const objectRegistry& obr,
const fileName& dictName,
const bool syncPar=true
);
// Member Functions

View File

@ -28,9 +28,9 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::fvSchemes::debug(Foam::debug::debugSwitch("fvSchemes", false));
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
void Foam::fvSchemes::clear()
@ -53,137 +53,9 @@ void Foam::fvSchemes::clear()
defaultFluxRequired_ = false;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fvSchemes::fvSchemes(const objectRegistry& obr)
:
IOdictionary
(
IOobject
(
"fvSchemes",
obr.time().system(),
obr,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
),
ddtSchemes_
(
ITstream
(
objectPath() + "::ddtSchemes",
tokenList()
)()
),
defaultDdtScheme_
(
ddtSchemes_.name() + "::default",
tokenList()
),
d2dt2Schemes_
(
ITstream
(
objectPath() + "::d2dt2Schemes",
tokenList()
)()
),
defaultD2dt2Scheme_
(
d2dt2Schemes_.name() + "::default",
tokenList()
),
interpolationSchemes_
(
ITstream
(
objectPath() + "::interpolationSchemes",
tokenList()
)()
),
defaultInterpolationScheme_
(
interpolationSchemes_.name() + "::default",
tokenList()
),
divSchemes_
(
ITstream
(
objectPath() + "::divSchemes",
tokenList()
)()
),
defaultDivScheme_
(
divSchemes_.name() + "::default",
tokenList()
),
gradSchemes_
(
ITstream
(
objectPath() + "::gradSchemes",
tokenList()
)()
),
defaultGradScheme_
(
gradSchemes_.name() + "::default",
tokenList()
),
snGradSchemes_
(
ITstream
(
objectPath() + "::snGradSchemes",
tokenList()
)()
),
defaultSnGradScheme_
(
snGradSchemes_.name() + "::default",
tokenList()
),
laplacianSchemes_
(
ITstream
(
objectPath() + "::laplacianSchemes",
tokenList()
)()
),
defaultLaplacianScheme_
(
laplacianSchemes_.name() + "::default",
tokenList()
),
fluxRequired_
(
ITstream
(
objectPath() + "::fluxRequired",
tokenList()
)()
),
defaultFluxRequired_(false)
void Foam::fvSchemes::read(const dictionary& dict)
{
read();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fvSchemes::read()
{
if (regIOobject::read())
{
const dictionary& dict = schemesDict();
// persistent settings across reads is incorrect
clear();
if (dict.found("ddtSchemes"))
{
ddtSchemes_ = dict.subDict("ddtSchemes");
@ -370,6 +242,143 @@ bool Foam::fvSchemes::read()
defaultFluxRequired_ = Switch(fluxRequired_.lookup("default"));
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fvSchemes::fvSchemes(const objectRegistry& obr, const bool syncPar)
:
IOdictionary
(
IOobject
(
"fvSchemes",
obr.time().system(),
obr,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
),
syncPar
),
ddtSchemes_
(
ITstream
(
objectPath() + "::ddtSchemes",
tokenList()
)()
),
defaultDdtScheme_
(
ddtSchemes_.name() + "::default",
tokenList()
),
d2dt2Schemes_
(
ITstream
(
objectPath() + "::d2dt2Schemes",
tokenList()
)()
),
defaultD2dt2Scheme_
(
d2dt2Schemes_.name() + "::default",
tokenList()
),
interpolationSchemes_
(
ITstream
(
objectPath() + "::interpolationSchemes",
tokenList()
)()
),
defaultInterpolationScheme_
(
interpolationSchemes_.name() + "::default",
tokenList()
),
divSchemes_
(
ITstream
(
objectPath() + "::divSchemes",
tokenList()
)()
),
defaultDivScheme_
(
divSchemes_.name() + "::default",
tokenList()
),
gradSchemes_
(
ITstream
(
objectPath() + "::gradSchemes",
tokenList()
)()
),
defaultGradScheme_
(
gradSchemes_.name() + "::default",
tokenList()
),
snGradSchemes_
(
ITstream
(
objectPath() + "::snGradSchemes",
tokenList()
)()
),
defaultSnGradScheme_
(
snGradSchemes_.name() + "::default",
tokenList()
),
laplacianSchemes_
(
ITstream
(
objectPath() + "::laplacianSchemes",
tokenList()
)()
),
defaultLaplacianScheme_
(
laplacianSchemes_.name() + "::default",
tokenList()
),
fluxRequired_
(
ITstream
(
objectPath() + "::fluxRequired",
tokenList()
)()
),
defaultFluxRequired_(false)
{
// persistent settings across reads is incorrect
clear();
read(schemesDict());
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fvSchemes::read()
{
if (regIOobject::read())
{
// persistent settings across reads is incorrect
clear();
read(schemesDict());
return true;
}

View File

@ -84,6 +84,9 @@ class fvSchemes
//- Clear the dictionaries and streams before reading
void clear();
//- Read settings from the dictionary
void read(const dictionary&);
//- Disallow default bitwise copy construct
fvSchemes(const fvSchemes&);
@ -100,7 +103,7 @@ public:
// Constructors
//- Construct for objectRegistry
fvSchemes(const objectRegistry& obr);
fvSchemes(const objectRegistry& obr, const bool syncPar = true);
// Member Functions