Moved cacheing control to solution for consistency

This commit is contained in:
Hrvoje Jasak 2016-05-11 21:55:22 +01:00
parent 7c7e4e416f
commit 75272ad78f
7 changed files with 82 additions and 104 deletions

View file

@ -56,7 +56,6 @@ void Foam::fvSchemes::clear()
defaultLaplacianScheme_.clear(); defaultLaplacianScheme_.clear();
fluxRequired_.clear(); fluxRequired_.clear();
defaultFluxRequired_ = false; defaultFluxRequired_ = false;
cacheFields_.clear();
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -174,15 +173,7 @@ Foam::fvSchemes::fvSchemes(const objectRegistry& obr)
tokenList() tokenList()
)() )()
), ),
defaultFluxRequired_(false), defaultFluxRequired_(false)
cacheFields_
(
ITstream
(
objectPath() + "::cacheFields",
tokenList()
)()
)
{ {
if (!headerOk()) if (!headerOk())
{ {
@ -408,11 +399,6 @@ bool Foam::fvSchemes::read()
} }
} }
if (dict.found("cacheFields"))
{
cacheFields_ = dict.subDict("cacheFields");
}
return true; return true;
} }
else else
@ -590,22 +576,4 @@ bool Foam::fvSchemes::fluxRequired(const word& name) const
} }
bool Foam::fvSchemes::cache(const word& name) const
{
if (debug)
{
Info<< "Lookup cache for " << name << endl;
}
if (cacheFields_.found(name))
{
return true;
}
else
{
return false;
}
}
// ************************************************************************* // // ************************************************************************* //

View file

@ -79,8 +79,6 @@ class fvSchemes
dictionary fluxRequired_; dictionary fluxRequired_;
bool defaultFluxRequired_; bool defaultFluxRequired_;
dictionary cacheFields_;
// Private Member Functions // Private Member Functions
@ -128,8 +126,6 @@ public:
bool fluxRequired(const word& name) const; bool fluxRequired(const word& name) const;
bool cache(const word& name) const;
// Edit // Edit

View file

@ -118,28 +118,16 @@ Foam::fv::gradScheme<Type>::grad
typedef typename outerProduct<vector, Type>::type GradType; typedef typename outerProduct<vector, Type>::type GradType;
typedef GeometricField<GradType, fvPatchField, volMesh> GradFieldType; typedef GeometricField<GradType, fvPatchField, volMesh> GradFieldType;
if (!this->mesh().changing() && this->mesh().schemesDict().cache(name)) if (!this->mesh().changing() && this->mesh().solutionDict().cache(name))
{ {
if (!mesh().objectRegistry::template foundObject<GradFieldType>(name)) if (!mesh().objectRegistry::template foundObject<GradFieldType>(name))
{ {
if (fvSchemes::debug) solution::cachePrintMessage("Calculating and caching", name, vsf);
{
Info<< "Cache: Calculating and caching " << name
<< " originating from " << vsf.name()
<< " event No. " << vsf.eventNo()
<< endl;
}
tmp<GradFieldType> tgGrad = calcGrad(vsf, name); tmp<GradFieldType> tgGrad = calcGrad(vsf, name);
regIOobject::store(tgGrad.ptr()); regIOobject::store(tgGrad.ptr());
} }
if (fvSchemes::debug) solution::cachePrintMessage("Retrieving", name, vsf);
{
Info<< "Cache: Retrieving " << name
<< " originating from " << vsf.name()
<< " event No. " << vsf.eventNo();
}
GradFieldType& gGrad = const_cast<GradFieldType&> GradFieldType& gGrad = const_cast<GradFieldType&>
( (
mesh().objectRegistry::template lookupObject<GradFieldType>(name) mesh().objectRegistry::template lookupObject<GradFieldType>(name)
@ -147,7 +135,7 @@ Foam::fv::gradScheme<Type>::grad
if (gGrad.upToDate(vsf.name())) if (gGrad.upToDate(vsf.name()))
{ {
if (fvSchemes::debug) if (solution::debug)
{ {
Info<< ": up-to-date." << endl; Info<< ": up-to-date." << endl;
} }
@ -156,24 +144,15 @@ Foam::fv::gradScheme<Type>::grad
} }
else else
{ {
if (fvSchemes::debug) if (solution::debug)
{ {
Info<< ": not up-to-date." << nl Info<< ": not up-to-date." << endl;
<< "Cache: Deleting " << name solution::cachePrintMessage("Deleting", name, vsf);
<< " originating from " << vsf.name()
<< " event No. " << vsf.eventNo()
<< endl;
} }
gGrad.release(); gGrad.release();
delete &gGrad; delete &gGrad;
if (fvSchemes::debug) solution::cachePrintMessage("Recalculating", name, vsf);
{
Info<< "Cache: Recalculating " << name
<< " originating from " << vsf.name()
<< " event No. " << vsf.eventNo()
<< endl;
}
tmp<GradFieldType> tgGrad = calcGrad(vsf, name); tmp<GradFieldType> tgGrad = calcGrad(vsf, name);
// Note: in order for the patchNeighbourField to be // Note: in order for the patchNeighbourField to be
@ -182,13 +161,7 @@ Foam::fv::gradScheme<Type>::grad
// shall be moved into the library fvc operators // shall be moved into the library fvc operators
tgGrad().correctBoundaryConditions(); tgGrad().correctBoundaryConditions();
if (fvSchemes::debug) solution::cachePrintMessage("Storing", name, vsf);
{
Info<< "Cache: Storing " << name
<< " originating from " << vsf.name()
<< " event No. " << vsf.eventNo()
<< endl;
}
regIOobject::store(tgGrad.ptr()); regIOobject::store(tgGrad.ptr());
GradFieldType& gGrad = const_cast<GradFieldType&> GradFieldType& gGrad = const_cast<GradFieldType&>
( (
@ -215,25 +188,13 @@ Foam::fv::gradScheme<Type>::grad
if (gGrad.ownedByRegistry()) if (gGrad.ownedByRegistry())
{ {
if (fvSchemes::debug) solution::cachePrintMessage("Deleting", name, vsf);
{
Info<< "Cache: Deleting " << name
<< " originating from " << vsf.name()
<< " event No. " << vsf.eventNo()
<< endl;
}
gGrad.release(); gGrad.release();
delete &gGrad; delete &gGrad;
} }
} }
if (fvSchemes::debug) solution::cachePrintMessage("Calculating", name, vsf);
{
Info<< "Cache: Calculating " << name
<< " originating from " << vsf.name()
<< " event No. " << vsf.eventNo()
<< endl;
}
return calcGrad(vsf, name); return calcGrad(vsf, name);
} }
} }

View file

@ -64,6 +64,8 @@ Foam::solution::solution(const objectRegistry& obr, const fileName& dictName)
IOobject::NO_WRITE IOobject::NO_WRITE
) )
), ),
cache_(dictionary::null),
caching_(false),
relaxationFactors_ relaxationFactors_
( (
ITstream("relaxationFactors", tokenList())() ITstream("relaxationFactors", tokenList())()
@ -179,6 +181,12 @@ bool Foam::solution::read()
if (readOk) if (readOk)
{ {
if (found("cache"))
{
cache_ = subDict("cache");
caching_ = cache_.lookupOrDefault("active", true);
}
if (found("relaxationFactors")) if (found("relaxationFactors"))
{ {
relaxationFactors_ = subDict("relaxationFactors"); relaxationFactors_ = subDict("relaxationFactors");
@ -199,6 +207,24 @@ bool Foam::solution::read()
} }
bool Foam::solution::cache(const word& name) const
{
if (caching_)
{
if (debug)
{
Info<< "Cache: find entry for " << name << endl;
}
return cache_.found(name);
}
else
{
return false;
}
}
bool Foam::solution::relax(const word& name) const bool Foam::solution::relax(const word& name) const
{ {
if (debug) if (debug)

View file

@ -53,6 +53,12 @@ class solution
{ {
// Private data // Private data
//- Dictionary of temporary fields to cache
dictionary cache_;
//- Switch for the caching mechanism
bool caching_;
//- Dictionary of relaxation factors for all the fields //- Dictionary of relaxation factors for all the fields
dictionary relaxationFactors_; dictionary relaxationFactors_;
@ -65,6 +71,9 @@ class solution
// Private Member Functions // Private Member Functions
//- Read settings from the dictionary
void read(const dictionary&);
//- Disallow default bitwise copy construct and assignment //- Disallow default bitwise copy construct and assignment
solution(const solution&); solution(const solution&);
void operator=(const solution&); void operator=(const solution&);
@ -84,13 +93,29 @@ public:
// Constructors // Constructors
//- Construct for given objectRegistry and dictionary //- Construct for given objectRegistry and dictionary
solution(const objectRegistry& obr, const fileName& dictName); solution
(
const objectRegistry& obr,
const fileName& dictName
);
// Member Functions // Member Functions
// Access // Access
//- Return true if the given field should be cached
bool cache(const word& name) const;
//- Helper for printing cache message
template<class FieldType>
static void cachePrintMessage
(
const char* message,
const word& name,
const FieldType& vf
);
//- Return true if the relaxation factor is given for the field //- Return true if the relaxation factor is given for the field
bool relax(const word& name) const; bool relax(const word& name) const;
@ -138,6 +163,12 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "solutionTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View file

@ -40,8 +40,6 @@ divSchemes
laplacianSchemes laplacianSchemes
{ {
default Gauss linear corrected; default Gauss linear corrected;
// default Gauss linear limited 0.5;
// default Gauss linear limited 0.333;
} }
interpolationSchemes interpolationSchemes
@ -61,12 +59,5 @@ fluxRequired
p; p;
} }
cacheFields
{
grad(U);
grad(p);
grad(k);
grad(omega);
}
// ************************************************************************* // // ************************************************************************* //

View file

@ -28,8 +28,7 @@ solvers
agglomerator faceAreaPair; agglomerator faceAreaPair;
nCellsInCoarsestLevel 10; nCellsInCoarsestLevel 10;
mergeLevels 1; mergeLevels 1;
}; }
U U
{ {
solver smoothSolver; solver smoothSolver;
@ -37,8 +36,7 @@ solvers
tolerance 1e-8; tolerance 1e-8;
relTol 0.1; relTol 0.1;
nSweeps 1; nSweeps 1;
}; }
k k
{ {
solver smoothSolver; solver smoothSolver;
@ -46,8 +44,7 @@ solvers
tolerance 1e-8; tolerance 1e-8;
relTol 0.1; relTol 0.1;
nSweeps 1; nSweeps 1;
}; }
omega omega
{ {
solver smoothSolver; solver smoothSolver;
@ -55,7 +52,7 @@ solvers
tolerance 1e-8; tolerance 1e-8;
relTol 0.1; relTol 0.1;
nSweeps 1; nSweeps 1;
}; }
} }
SIMPLE SIMPLE
@ -71,4 +68,12 @@ relaxationFactors
omega 0.7; omega 0.7;
} }
cache
{
// grad(U);
// grad(p);
// grad(k);
// grad(omega);
}
// ************************************************************************* // // ************************************************************************* //