ENH: harmomize schemes-lookup and solution internal accessor names

FIX: correct the schemes internal dictionary name

- change from '.' to '/' delimiter as per 886ba89ddb (#1073)
This commit is contained in:
Mark Olesen
2023-11-11 09:58:53 +01:00
parent ca25929372
commit 42feffc794
6 changed files with 205 additions and 98 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2019-2022 OpenCFD Ltd. Copyright (C) 2019-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -102,6 +102,19 @@ void Foam::schemesLookup::read(const dictionary& dict)
} }
const Foam::dictionary& Foam::schemesLookup::selectedDict() const
{
word select;
if (readIfPresent("select", select, keyType::LITERAL))
{
return subDict(select);
}
return *this;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::schemesLookup::schemesLookup Foam::schemesLookup::schemesLookup
@ -136,7 +149,7 @@ Foam::schemesLookup::schemesLookup
snGradSchemes_("snGradSchemes", objectPath()), snGradSchemes_("snGradSchemes", objectPath()),
laplacianSchemes_("laplacianSchemes", objectPath()), laplacianSchemes_("laplacianSchemes", objectPath()),
fluxRequired_(objectPath() + ".fluxRequired"), fluxRequired_(objectPath() / "fluxRequired"),
fluxRequiredDefault_(false), fluxRequiredDefault_(false),
steady_(false) steady_(false)
{ {
@ -153,7 +166,7 @@ Foam::schemesLookup::schemesLookup
if (readOpt() == IOobject::MUST_READ_IF_MODIFIED) if (readOpt() == IOobject::MUST_READ_IF_MODIFIED)
{ {
read(schemesDict()); read(selectedDict());
} }
} }
@ -177,7 +190,7 @@ bool Foam::schemesLookup::read()
{ {
clear(); // Clear current settings except fluxRequired clear(); // Clear current settings except fluxRequired
read(schemesDict()); read(selectedDict());
return true; return true;
} }
@ -186,68 +199,58 @@ bool Foam::schemesLookup::read()
} }
const Foam::dictionary& Foam::schemesLookup::schemesDict() const
{
if (found("select"))
{
return subDict(word(lookup("select")));
}
return *this;
}
Foam::ITstream& Foam::schemesLookup::ddtScheme(const word& name) const Foam::ITstream& Foam::schemesLookup::ddtScheme(const word& name) const
{ {
DebugInfo<< "Lookup ddtScheme for " << name << endl; DebugInfo<< "Lookup ddt scheme for " << name << endl;
return ddtSchemes_.lookup(name); return ddtSchemes_.lookup(name);
} }
Foam::ITstream& Foam::schemesLookup::d2dt2Scheme(const word& name) const Foam::ITstream& Foam::schemesLookup::d2dt2Scheme(const word& name) const
{ {
DebugInfo<< "Lookup d2dt2Scheme for " << name << endl; DebugInfo<< "Lookup d2dt2 scheme for " << name << endl;
return d2dt2Schemes_.lookup(name); return d2dt2Schemes_.lookup(name);
} }
Foam::ITstream& Foam::schemesLookup::interpolationScheme(const word& name) const Foam::ITstream& Foam::schemesLookup::interpolationScheme(const word& name) const
{ {
DebugInfo<< "Lookup interpolationScheme for " << name << endl; DebugInfo<< "Lookup interpolation scheme for " << name << endl;
return interpSchemes_.lookup(name); return interpSchemes_.lookup(name);
} }
Foam::ITstream& Foam::schemesLookup::divScheme(const word& name) const Foam::ITstream& Foam::schemesLookup::divScheme(const word& name) const
{ {
DebugInfo<< "Lookup divScheme for " << name << endl; DebugInfo<< "Lookup div scheme for " << name << endl;
return divSchemes_.lookup(name); return divSchemes_.lookup(name);
} }
Foam::ITstream& Foam::schemesLookup::gradScheme(const word& name) const Foam::ITstream& Foam::schemesLookup::gradScheme(const word& name) const
{ {
DebugInfo<< "Lookup gradScheme for " << name << endl; DebugInfo<< "Lookup grad scheme for " << name << endl;
return gradSchemes_.lookup(name); return gradSchemes_.lookup(name);
} }
Foam::ITstream& Foam::schemesLookup::lnGradScheme(const word& name) const Foam::ITstream& Foam::schemesLookup::lnGradScheme(const word& name) const
{ {
DebugInfo<< "Lookup lnGradScheme for " << name << endl; DebugInfo<< "Lookup lnGrad scheme for " << name << endl;
return lnGradSchemes_.lookup(name); return lnGradSchemes_.lookup(name);
} }
Foam::ITstream& Foam::schemesLookup::snGradScheme(const word& name) const Foam::ITstream& Foam::schemesLookup::snGradScheme(const word& name) const
{ {
DebugInfo<< "Lookup snGradScheme for " << name << endl; DebugInfo<< "Lookup snGrad scheme for " << name << endl;
return snGradSchemes_.lookup(name); return snGradSchemes_.lookup(name);
} }
Foam::ITstream& Foam::schemesLookup::laplacianScheme(const word& name) const Foam::ITstream& Foam::schemesLookup::laplacianScheme(const word& name) const
{ {
DebugInfo<< "Lookup laplacianScheme for " << name << endl; DebugInfo<< "Lookup laplacian scheme for " << name << endl;
return laplacianSchemes_.lookup(name); return laplacianSchemes_.lookup(name);
} }
@ -266,6 +269,12 @@ bool Foam::schemesLookup::fluxRequired(const word& name) const
} }
const Foam::dictionary& Foam::schemesLookup::schemesDict() const
{
return selectedDict();
}
void Foam::schemesLookup::writeDicts(Ostream& os) const void Foam::schemesLookup::writeDicts(Ostream& os) const
{ {
ddtSchemes_.writeEntryOptional(os); ddtSchemes_.writeEntryOptional(os);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2020-2022 OpenCFD Ltd. Copyright (C) 2020-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -30,10 +30,29 @@ Class
Description Description
Selector class for finite area/finite volume differencing schemes. Selector class for finite area/finite volume differencing schemes.
The schemes data are treated as MUST_READ_IF_MODIFIED even if The file will contain these types of entries:
the requested readOption is nominally MUST_READ or READ_IF_PRESENT. \table
This allows run-time modifications to behave as expected. Name | Description | Type | Reqd | Default
ddtSchemes | ddt | dict | no | none
d2dt2Schemes | d2dt2 (currently only finite-area) | dict | no | none
interpolationSchemes | interpolation | dict | no | linear
divSchemes | div | dict | yes | -
gradSchemes | grad | dict | yes | -
lnGradSchemes | line-normal grad (finite-area) | dict | no | corrected
snGradSchemes | surface-normal grad | dict | no | corrected
laplacianSchemes | laplacian | dict | yes | -
fluxRequired | | dict | no | -
\endtable
\par select
This is a rarely used feature to select between different groups of
settings within the file. If unspecified, the file contents are used
directly.
Note
The schemes data are treated as \c READ_MODIFIED even if the
requested \p readOption is nominally MUST_READ or READ_IF_PRESENT.
This allows run-time modifications to behave as expected. <br>
The optional fallback dictionary content for constructors is used The optional fallback dictionary content for constructors is used
when a file is missing or for a NO_READ, with a null pointer being when a file is missing or for a NO_READ, with a null pointer being
treated like an empty dictionary. treated like an empty dictionary.
@ -154,6 +173,12 @@ class schemesLookup
//- Read settings from the dictionary //- Read settings from the dictionary
void read(const dictionary& dict); void read(const dictionary& dict);
//- The entire dictionary or the optional "select" sub-dictionary.
const dictionary& selectedDict() const;
// Generated Methods
//- No copy construct //- No copy construct
schemesLookup(const schemesLookup&) = delete; schemesLookup(const schemesLookup&) = delete;
@ -190,21 +215,15 @@ public:
// Member Functions // Member Functions
//- The current schemes dictionary, respects the "select" keyword //- True if default ddt scheme is steady-state
bool steady() const noexcept { return steady_; }
//- True if default ddt scheme is not steady-state
bool transient() const noexcept { return !steady_; }
//- The entire dictionary or the optional "select" sub-dictionary.
const dictionary& schemesDict() const; const dictionary& schemesDict() const;
//- True if default ddtScheme is steady-state
bool steady() const noexcept
{
return steady_;
}
//- True if default ddtScheme is not steady-state
bool transient() const noexcept
{
return !steady_;
}
// Lookup Access // Lookup Access
@ -232,10 +251,10 @@ public:
//- Get laplacian scheme for given name, or default //- Get laplacian scheme for given name, or default
ITstream& laplacianScheme(const word& name) const; ITstream& laplacianScheme(const word& name) const;
//- Get flux-required for given name, or default //- Set flux-required for given name (mutable)
void setFluxRequired(const word& name) const; void setFluxRequired(const word& name) const;
//- Set flux-required for given name (mutable) //- Get flux-required for given name, or default
bool fluxRequired(const word& name) const; bool fluxRequired(const word& name) const;
@ -289,7 +308,7 @@ public:
return laplacianSchemes_.dict_; return laplacianSchemes_.dict_;
} }
//- Access to flux required dictionary //- Access flux-required dictionary
const dictionary& fluxRequired() const noexcept const dictionary& fluxRequired() const noexcept
{ {
return fluxRequired_; return fluxRequired_;
@ -346,7 +365,7 @@ public:
return laplacianSchemes_.dict_; return laplacianSchemes_.dict_;
} }
//- Access to flux required dictionary //- Access flux-required dictionary
dictionary& fluxRequired() noexcept dictionary& fluxRequired() noexcept
{ {
return fluxRequired_; return fluxRequired_;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -50,9 +50,9 @@ Foam::schemesLookup::lookupDetail::lookupDetail
} }
else else
{ {
dict_.name() = parentDictPath + "." + name_; dict_.name() = fileName::concat(parentDictPath, name_, '/');
} }
default_.name() = dict_.name() + ".default"; default_.name() = fileName::concat(dict_.name(), "default", '/');
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2022 OpenCFD Ltd. Copyright (C) 2019-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -41,7 +41,8 @@ namespace Foam
// List of sub-dictionaries to rewrite // List of sub-dictionaries to rewrite
static const Foam::List<Foam::word> subDictNames static const Foam::List<Foam::word> subDictNames
({ ({
"preconditioner", "smoother" "preconditioner",
"smoother"
}); });
@ -142,6 +143,19 @@ void Foam::solution::read(const dictionary& dict)
} }
const Foam::dictionary& Foam::solution::selectedDict() const
{
word select;
if (readIfPresent("select", select, keyType::LITERAL))
{
return subDict(select);
}
return *this;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::solution::solution Foam::solution::solution
@ -183,7 +197,7 @@ Foam::solution::solution
if (readOpt() == IOobject::MUST_READ_IF_MODIFIED) if (readOpt() == IOobject::MUST_READ_IF_MODIFIED)
{ {
read(solutionDict()); read(selectedDict());
} }
} }
@ -201,7 +215,7 @@ Foam::solution::solution
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// A non-default destructor since we had incomplete types in the header // No default destructor in header (incomplete types)
Foam::solution::~solution() Foam::solution::~solution()
{} {}
@ -283,6 +297,17 @@ bool Foam::solution::cache(const word& name) const
} }
// void Foam::solution::enableCache(const word& name) const
// {
// if (!cache_.found(name))
// {
// DebugInfo<< "Cache: enable cache for " << name << endl;
// cache_.add(name, true);
// caching_ = true;
// }
// }
bool Foam::solution::relaxField(const word& name) const bool Foam::solution::relaxField(const word& name) const
{ {
DebugInfo DebugInfo
@ -358,12 +383,20 @@ Foam::scalar Foam::solution::equationRelaxationFactor(const word& name) const
const Foam::dictionary& Foam::solution::solutionDict() const const Foam::dictionary& Foam::solution::solutionDict() const
{ {
if (found("select")) return selectedDict();
{ }
return subDict(get<word>("select"));
}
return *this;
const Foam::dictionary& Foam::solution::solutionDict(const word& name) const
{
DebugInfo<< "Lookup subDict : " << name << endl;
return selectedDict().subDict(name);
}
const Foam::dictionary& Foam::solution::solversDict() const
{
return solvers_;
} }
@ -385,7 +418,7 @@ bool Foam::solution::read()
{ {
if (regIOobject::read()) if (regIOobject::read())
{ {
read(solutionDict()); read(selectedDict());
return true; return true;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020-2022 OpenCFD Ltd. Copyright (C) 2020-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -30,10 +30,43 @@ Class
Description Description
Selector class for relaxation factors, solver type and solution. Selector class for relaxation factors, solver type and solution.
The solution data are treated as MUST_READ_IF_MODIFIED even if The file will contain these types of entries:
the requested readOption is nominally MUST_READ or READ_IF_PRESENT.
This allows run-time modifications to behave as expected.
\par solvers { }
A sub-dictionary listing of linear solver settings. For example,
\verbatim
solvers
{
p
{
solver PCG;
preconditioner DIC;
tolerance 1e-06;
relTol 0.05;
}
}
\endverbatim
\par select
This is a rarely used feature to select between different groups of
settings within the file. If unspecified, the file contents are used
directly.
There are currently no other specified entries, but the file will
often also contain other solution specifications. For example,
\verbatim
PIMPLE
{
nOuterCorrectors 2;
nCorrectors 1;
nNonOrthogonalCorrectors 0;
}
\endverbatim
Note
The solution data are treated as \c READ_MODIFIED even if the
requested \p readOption is nominally MUST_READ or READ_IF_PRESENT.
This allows run-time modifications to behave as expected. <br>
The optional fallback dictionary content for constructors is used The optional fallback dictionary content for constructors is used
when a file is missing or for a NO_READ, with a null pointer being when a file is missing or for a NO_READ, with a null pointer being
treated like an empty dictionary. treated like an empty dictionary.
@ -100,6 +133,12 @@ class solution
//- Read settings from the dictionary //- Read settings from the dictionary
void read(const dictionary&); void read(const dictionary&);
//- The entire dictionary or the optional "select" sub-dictionary.
const dictionary& selectedDict() const;
// Generated Methods
//- No copy construct //- No copy construct
solution(const solution&) = delete; solution(const solution&) = delete;
@ -114,7 +153,7 @@ public:
// Returns the number of settings changed // Returns the number of settings changed
static label upgradeSolverDict(dictionary& dict, const bool verbose=true); static label upgradeSolverDict(dictionary& dict, const bool verbose=true);
//- Debug switch //- Debug switch (registered name: "solution")
static int debug; static int debug;
@ -139,56 +178,64 @@ public:
); );
//- Destructor //- Destructor. Non-default in header (incomplete types)
virtual ~solution(); virtual ~solution();
// Member Functions // Member Functions
// Access // Access
//- Return true if the given field should be cached //- True if the given field should be cached
bool cache(const word& name) const; bool cache(const word& name) const;
//- Return true if the relaxation factor is given for the field //- True if the relaxation factor is given for the field
bool relaxField(const word& name) const; bool relaxField(const word& name) const;
//- Return true if the relaxation factor is given for the equation //- True if the relaxation factor is given for the equation
bool relaxEquation(const word& name) const; bool relaxEquation(const word& name) const;
//- Return the relaxation factor for the given field //- The relaxation factor for the given field
scalar fieldRelaxationFactor(const word& name) const; scalar fieldRelaxationFactor(const word& name) const;
//- Return the relaxation factor for the given equation //- The relaxation factor for the given equation
scalar equationRelaxationFactor(const word& name) const; scalar equationRelaxationFactor(const word& name) const;
//- Return the selected sub-dictionary of solvers if the "select" //- The entire dictionary or the optional "select" sub-dictionary.
//- keyword is given, otherwise return the complete dictionary const dictionary& solutionDict() const;
const dictionary& solutionDict() const;
//- Return the solver controls dictionary for the given field //- Return \p name sub-dictionary within the solutionDict().
const dictionary& solverDict(const word& name) const; // Same as \c solutionDict().subDict(...)
const dictionary& solutionDict(const word& name) const;
//- Return the solver controls dictionary for the given field //- The solver controls dictionary (all fields)
const dictionary& solver(const word& name) const; const dictionary& solversDict() const;
//- The solver controls dictionary for the given field.
//- Same as \c solversDict().subDict(...)
const dictionary& solverDict(const word& name) const;
//- The solver controls dictionary for the given field.
//- Same as solverDict(...)
const dictionary& solver(const word& name) const;
// Read // Read
//- Read the solution dictionary //- Read the solution dictionary
bool read(); bool read();
// Other // Other
//- Helper for printing cache message //- Helper for printing cache message
template<class FieldType> template<class FieldType>
static void cachePrintMessage static void cachePrintMessage
( (
const char* message, const char* message,
const word& name, const word& name,
const FieldType& vf const FieldType& fld
); );
}; };

View File

@ -34,15 +34,14 @@ void Foam::solution::cachePrintMessage
( (
const char* message, const char* message,
const word& name, const word& name,
const FieldType& vf const FieldType& fld // == regIOobject
) )
{ {
if (solution::debug) if (Foam::solution::debug)
{ {
Info<< "Cache: " << message << token::SPACE << name Info<< "Cache: " << message << ' ' << name
<< ", originating from " << vf.name() << ", originating from " << fld.name()
<< " event No. " << vf.eventNo() << " event:" << fld.eventNo() << endl;
<< endl;
} }
} }