Moved cacheing control to solution for consistency
This commit is contained in:
parent
7c7e4e416f
commit
75272ad78f
7 changed files with 82 additions and 104 deletions
|
@ -56,7 +56,6 @@ void Foam::fvSchemes::clear()
|
|||
defaultLaplacianScheme_.clear();
|
||||
fluxRequired_.clear();
|
||||
defaultFluxRequired_ = false;
|
||||
cacheFields_.clear();
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
@ -174,15 +173,7 @@ Foam::fvSchemes::fvSchemes(const objectRegistry& obr)
|
|||
tokenList()
|
||||
)()
|
||||
),
|
||||
defaultFluxRequired_(false),
|
||||
cacheFields_
|
||||
(
|
||||
ITstream
|
||||
(
|
||||
objectPath() + "::cacheFields",
|
||||
tokenList()
|
||||
)()
|
||||
)
|
||||
defaultFluxRequired_(false)
|
||||
{
|
||||
if (!headerOk())
|
||||
{
|
||||
|
@ -408,11 +399,6 @@ bool Foam::fvSchemes::read()
|
|||
}
|
||||
}
|
||||
|
||||
if (dict.found("cacheFields"))
|
||||
{
|
||||
cacheFields_ = dict.subDict("cacheFields");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
|
|
@ -79,8 +79,6 @@ class fvSchemes
|
|||
dictionary fluxRequired_;
|
||||
bool defaultFluxRequired_;
|
||||
|
||||
dictionary cacheFields_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
|
@ -128,8 +126,6 @@ public:
|
|||
|
||||
bool fluxRequired(const word& name) const;
|
||||
|
||||
bool cache(const word& name) const;
|
||||
|
||||
|
||||
// Edit
|
||||
|
||||
|
|
|
@ -118,28 +118,16 @@ Foam::fv::gradScheme<Type>::grad
|
|||
typedef typename outerProduct<vector, Type>::type GradType;
|
||||
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 (fvSchemes::debug)
|
||||
{
|
||||
Info<< "Cache: Calculating and caching " << name
|
||||
<< " originating from " << vsf.name()
|
||||
<< " event No. " << vsf.eventNo()
|
||||
<< endl;
|
||||
}
|
||||
solution::cachePrintMessage("Calculating and caching", name, vsf);
|
||||
tmp<GradFieldType> tgGrad = calcGrad(vsf, name);
|
||||
regIOobject::store(tgGrad.ptr());
|
||||
}
|
||||
|
||||
if (fvSchemes::debug)
|
||||
{
|
||||
Info<< "Cache: Retrieving " << name
|
||||
<< " originating from " << vsf.name()
|
||||
<< " event No. " << vsf.eventNo();
|
||||
}
|
||||
|
||||
solution::cachePrintMessage("Retrieving", name, vsf);
|
||||
GradFieldType& gGrad = const_cast<GradFieldType&>
|
||||
(
|
||||
mesh().objectRegistry::template lookupObject<GradFieldType>(name)
|
||||
|
@ -147,7 +135,7 @@ Foam::fv::gradScheme<Type>::grad
|
|||
|
||||
if (gGrad.upToDate(vsf.name()))
|
||||
{
|
||||
if (fvSchemes::debug)
|
||||
if (solution::debug)
|
||||
{
|
||||
Info<< ": up-to-date." << endl;
|
||||
}
|
||||
|
@ -156,24 +144,15 @@ Foam::fv::gradScheme<Type>::grad
|
|||
}
|
||||
else
|
||||
{
|
||||
if (fvSchemes::debug)
|
||||
if (solution::debug)
|
||||
{
|
||||
Info<< ": not up-to-date." << nl
|
||||
<< "Cache: Deleting " << name
|
||||
<< " originating from " << vsf.name()
|
||||
<< " event No. " << vsf.eventNo()
|
||||
<< endl;
|
||||
Info<< ": not up-to-date." << endl;
|
||||
solution::cachePrintMessage("Deleting", name, vsf);
|
||||
}
|
||||
gGrad.release();
|
||||
delete &gGrad;
|
||||
|
||||
if (fvSchemes::debug)
|
||||
{
|
||||
Info<< "Cache: Recalculating " << name
|
||||
<< " originating from " << vsf.name()
|
||||
<< " event No. " << vsf.eventNo()
|
||||
<< endl;
|
||||
}
|
||||
solution::cachePrintMessage("Recalculating", name, vsf);
|
||||
tmp<GradFieldType> tgGrad = calcGrad(vsf, name);
|
||||
|
||||
// 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
|
||||
tgGrad().correctBoundaryConditions();
|
||||
|
||||
if (fvSchemes::debug)
|
||||
{
|
||||
Info<< "Cache: Storing " << name
|
||||
<< " originating from " << vsf.name()
|
||||
<< " event No. " << vsf.eventNo()
|
||||
<< endl;
|
||||
}
|
||||
solution::cachePrintMessage("Storing", name, vsf);
|
||||
regIOobject::store(tgGrad.ptr());
|
||||
GradFieldType& gGrad = const_cast<GradFieldType&>
|
||||
(
|
||||
|
@ -215,25 +188,13 @@ Foam::fv::gradScheme<Type>::grad
|
|||
|
||||
if (gGrad.ownedByRegistry())
|
||||
{
|
||||
if (fvSchemes::debug)
|
||||
{
|
||||
Info<< "Cache: Deleting " << name
|
||||
<< " originating from " << vsf.name()
|
||||
<< " event No. " << vsf.eventNo()
|
||||
<< endl;
|
||||
}
|
||||
solution::cachePrintMessage("Deleting", name, vsf);
|
||||
gGrad.release();
|
||||
delete &gGrad;
|
||||
}
|
||||
}
|
||||
|
||||
if (fvSchemes::debug)
|
||||
{
|
||||
Info<< "Cache: Calculating " << name
|
||||
<< " originating from " << vsf.name()
|
||||
<< " event No. " << vsf.eventNo()
|
||||
<< endl;
|
||||
}
|
||||
solution::cachePrintMessage("Calculating", name, vsf);
|
||||
return calcGrad(vsf, name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,8 @@ Foam::solution::solution(const objectRegistry& obr, const fileName& dictName)
|
|||
IOobject::NO_WRITE
|
||||
)
|
||||
),
|
||||
cache_(dictionary::null),
|
||||
caching_(false),
|
||||
relaxationFactors_
|
||||
(
|
||||
ITstream("relaxationFactors", tokenList())()
|
||||
|
@ -179,6 +181,12 @@ bool Foam::solution::read()
|
|||
|
||||
if (readOk)
|
||||
{
|
||||
if (found("cache"))
|
||||
{
|
||||
cache_ = subDict("cache");
|
||||
caching_ = cache_.lookupOrDefault("active", true);
|
||||
}
|
||||
|
||||
if (found("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
|
||||
{
|
||||
if (debug)
|
||||
|
|
|
@ -53,6 +53,12 @@ class solution
|
|||
{
|
||||
// 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 relaxationFactors_;
|
||||
|
||||
|
@ -65,6 +71,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&);
|
||||
|
@ -84,13 +93,29 @@ public:
|
|||
// Constructors
|
||||
|
||||
//- Construct for given objectRegistry and dictionary
|
||||
solution(const objectRegistry& obr, const fileName& dictName);
|
||||
solution
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const fileName& dictName
|
||||
);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// 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
|
||||
bool relax(const word& name) const;
|
||||
|
||||
|
@ -138,6 +163,12 @@ public:
|
|||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "solutionTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
|
|
|
@ -40,8 +40,6 @@ divSchemes
|
|||
laplacianSchemes
|
||||
{
|
||||
default Gauss linear corrected;
|
||||
// default Gauss linear limited 0.5;
|
||||
// default Gauss linear limited 0.333;
|
||||
}
|
||||
|
||||
interpolationSchemes
|
||||
|
@ -61,12 +59,5 @@ fluxRequired
|
|||
p;
|
||||
}
|
||||
|
||||
cacheFields
|
||||
{
|
||||
grad(U);
|
||||
grad(p);
|
||||
grad(k);
|
||||
grad(omega);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
|
|
|
@ -28,8 +28,7 @@ solvers
|
|||
agglomerator faceAreaPair;
|
||||
nCellsInCoarsestLevel 10;
|
||||
mergeLevels 1;
|
||||
};
|
||||
|
||||
}
|
||||
U
|
||||
{
|
||||
solver smoothSolver;
|
||||
|
@ -37,8 +36,7 @@ solvers
|
|||
tolerance 1e-8;
|
||||
relTol 0.1;
|
||||
nSweeps 1;
|
||||
};
|
||||
|
||||
}
|
||||
k
|
||||
{
|
||||
solver smoothSolver;
|
||||
|
@ -46,8 +44,7 @@ solvers
|
|||
tolerance 1e-8;
|
||||
relTol 0.1;
|
||||
nSweeps 1;
|
||||
};
|
||||
|
||||
}
|
||||
omega
|
||||
{
|
||||
solver smoothSolver;
|
||||
|
@ -55,7 +52,7 @@ solvers
|
|||
tolerance 1e-8;
|
||||
relTol 0.1;
|
||||
nSweeps 1;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
SIMPLE
|
||||
|
@ -71,4 +68,12 @@ relaxationFactors
|
|||
omega 0.7;
|
||||
}
|
||||
|
||||
cache
|
||||
{
|
||||
// grad(U);
|
||||
// grad(p);
|
||||
// grad(k);
|
||||
// grad(omega);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
|
|
Reference in a new issue