Commit 4d215d8e authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: simplify access and caching logic for gradScheme (#1276)

parent ef0d1554
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -91,67 +91,49 @@ Foam::fv::gradScheme<Type>::grad
typedef typename outerProduct<vector, Type>::type GradType;
typedef GeometricField<GradType, fvPatchField, volMesh> GradFieldType;
if (!this->mesh().changing() && this->mesh().cache(name))
GradFieldType* pgGrad =
mesh().objectRegistry::template getObjectPtr<GradFieldType>(name);
if (!this->mesh().cache(name) || this->mesh().changing())
{
if (!mesh().objectRegistry::template foundObject<GradFieldType>(name))
// Delete any old occurrences to avoid double registration
if (pgGrad && pgGrad->ownedByRegistry())
{
solution::cachePrintMessage("Calculating and caching", name, vsf);
tmp<GradFieldType> tgGrad = calcGrad(vsf, name);
regIOobject::store(tgGrad.ptr());
solution::cachePrintMessage("Deleting", name, vsf);
pgGrad->release();
delete pgGrad;
}
solution::cachePrintMessage("Retrieving", name, vsf);
GradFieldType& gGrad =
mesh().objectRegistry::template lookupObjectRef<GradFieldType>
(
name
);
if (gGrad.upToDate(vsf))
{
return gGrad;
}
else
{
solution::cachePrintMessage("Deleting", name, vsf);
gGrad.release();
delete &gGrad;
solution::cachePrintMessage("Calculating", name, vsf);
return calcGrad(vsf, name);
}
solution::cachePrintMessage("Recalculating", name, vsf);
tmp<GradFieldType> tgGrad = calcGrad(vsf, name);
solution::cachePrintMessage("Storing", name, vsf);
regIOobject::store(tgGrad.ptr());
GradFieldType& gGrad =
mesh().objectRegistry::template lookupObjectRef<GradFieldType>
(
name
);
if (!pgGrad)
{
solution::cachePrintMessage("Calculating and caching", name, vsf);
return gGrad;
}
pgGrad = calcGrad(vsf, name).ptr();
regIOobject::store(pgGrad);
}
else
{
if (mesh().objectRegistry::template foundObject<GradFieldType>(name))
if (pgGrad->upToDate(vsf))
{
GradFieldType& gGrad =
mesh().objectRegistry::template lookupObjectRef<GradFieldType>
(
name
);
if (gGrad.ownedByRegistry())
{
solution::cachePrintMessage("Deleting", name, vsf);
gGrad.release();
delete &gGrad;
}
solution::cachePrintMessage("Reusing", name, vsf);
}
else
{
solution::cachePrintMessage("Updating", name, vsf);
pgGrad->release();
delete pgGrad;
solution::cachePrintMessage("Calculating", name, vsf);
return calcGrad(vsf, name);
pgGrad = calcGrad(vsf, name).ptr();
regIOobject::store(pgGrad);
}
}
return *pgGrad;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment