BACKPORT: Gradient caching. Backport: Dominik Christ. Merge: Dominik Christ

This commit is contained in:
Dominik Christ 2015-08-07 12:48:50 +01:00
commit 02fc7e5574
23 changed files with 303 additions and 66 deletions

View file

@ -53,7 +53,7 @@ grad
const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf
)
{
return fv::gaussGrad<Type>::grad(ssf);
return fv::gaussGrad<Type>::gradf(ssf, "grad(" + ssf.name() + ')');
}
@ -98,7 +98,7 @@ grad
(
vf.mesh(),
vf.mesh().schemesDict().gradScheme(name)
)().grad(vf);
)().grad(vf, name);
}

View file

@ -46,9 +46,10 @@ tmp
typename outerProduct<vector, Type>::type, fvPatchField, volMesh
>
>
beGaussGrad<Type>::grad
beGaussGrad<Type>::calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>& vsf
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const
{
typedef typename outerProduct<vector, Type>::type GradType;
@ -68,7 +69,7 @@ beGaussGrad<Type>::grad
(
IOobject
(
"grad("+ssf.name()+')',
name,
ssf.instance(),
mesh,
IOobject::NO_READ,

View file

@ -122,9 +122,10 @@ public:
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
> calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>&
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const;
};

View file

@ -52,9 +52,10 @@ tmp
typename outerProduct<vector, Type>::type, fvPatchField, volMesh
>
>
extendedLeastSquaresGrad<Type>::grad
extendedLeastSquaresGrad<Type>::calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>& vsf
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const
{
typedef typename outerProduct<vector, Type>::type GradType;
@ -67,7 +68,7 @@ extendedLeastSquaresGrad<Type>::grad
(
IOobject
(
"grad("+vsf.name()+')',
name,
vsf.instance(),
mesh,
IOobject::NO_READ,

View file

@ -105,9 +105,10 @@ public:
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
> calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>&
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const;
};

View file

@ -52,9 +52,10 @@ tmp
typename outerProduct<vector, Type>::type, fvPatchField, volMesh
>
>
fourthGrad<Type>::grad
fourthGrad<Type>::calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>& vsf
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const
{
// The fourth-order gradient is calculated in two passes. First,
@ -79,7 +80,7 @@ fourthGrad<Type>::grad
(
IOobject
(
"grad("+vsf.name()+')',
name,
vsf.instance(),
mesh,
IOobject::NO_READ,

View file

@ -86,9 +86,10 @@ public:
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
> calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>&
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const;
};

View file

@ -46,9 +46,10 @@ tmp
typename outerProduct<vector, Type>::type, fvPatchField, volMesh
>
>
gaussGrad<Type>::grad
gaussGrad<Type>::gradf
(
const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf
const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf,
const word& name
)
{
typedef typename outerProduct<vector, Type>::type GradType;
@ -61,7 +62,7 @@ gaussGrad<Type>::grad
(
IOobject
(
"grad("+ssf.name()+')',
name,
ssf.instance(),
mesh,
IOobject::NO_READ,
@ -125,16 +126,17 @@ tmp
typename outerProduct<vector, Type>::type, fvPatchField, volMesh
>
>
gaussGrad<Type>::grad
gaussGrad<Type>::calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>& vsf
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const
{
typedef typename outerProduct<vector, Type>::type GradType;
tmp<GeometricField<GradType, fvPatchField, volMesh> > tgGrad
(
grad(tinterpScheme_().interpolate(vsf))
gradf(tinterpScheme_().interpolate(vsf), name)
);
GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad();

View file

@ -88,7 +88,7 @@ public:
tinterpScheme_(new linear<Type>(mesh))
{}
//- Construct from Istream
//- Construct from mesh and Istream
gaussGrad(const fvMesh& mesh, Istream& is)
:
gradScheme<Type>(mesh),
@ -122,20 +122,22 @@ public:
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
> gradf
(
const GeometricField<Type, fvsPatchField, surfaceMesh>&
const GeometricField<Type, fvsPatchField, surfaceMesh>&,
const word& name
);
//- Return the gradient of the given field calculated
// using Gauss' theorem on the interpolated field
tmp
virtual tmp
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
> calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>&
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const;
//- Return the BlockLduSystem corresponding to the implicit grad

View file

@ -29,6 +29,7 @@ Description
#include "fv.H"
#include "HashTable.H"
#include "primitiveFields.H"
#include "objectRegistry.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -98,6 +99,176 @@ gradScheme<Type>::~gradScheme()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Foam::tmp
<
Foam::GeometricField
<
typename Foam::outerProduct<Foam::vector, Type>::type,
Foam::fvPatchField,
Foam::volMesh
>
>
Foam::fv::gradScheme<Type>::grad
(
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const
{
typedef typename outerProduct<vector, Type>::type GradType;
typedef GeometricField<GradType, fvPatchField, volMesh> GradFieldType;
if (!this->mesh().changing() && this->mesh().schemesDict().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;
}
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()
<< endl;
}
GradFieldType& gGrad = const_cast<GradFieldType&>
(
mesh().objectRegistry::template lookupObject<GradFieldType>(name)
);
if (gGrad.upToDate(vsf.name()))
{
return gGrad;
}
else
{
if (fvSchemes::debug)
{
Info << "Cache: Deleting " << name
<< " originating from " << vsf.name()
<< " event No. " << vsf.eventNo()
<< endl;
}
gGrad.release();
delete &gGrad;
if (fvSchemes::debug)
{
Info << "Cache: Recalculating " << name
<< " originating from " << vsf.name()
<< " event No. " << vsf.eventNo()
<< endl;
}
tmp<GradFieldType> tgGrad = calcGrad(vsf, name);
if (fvSchemes::debug)
{
Info << "Cache: Storing " << name
<< " originating from " << vsf.name()
<< " event No. " << vsf.eventNo()
<< endl;
}
regIOobject::store(tgGrad.ptr());
GradFieldType& gGrad = const_cast<GradFieldType&>
(
mesh().objectRegistry::template lookupObject<GradFieldType>
(
name
)
);
return gGrad;
}
}
else
{
if (mesh().objectRegistry::template foundObject<GradFieldType>(name))
{
GradFieldType& gGrad = const_cast<GradFieldType&>
(
mesh().objectRegistry::template lookupObject<GradFieldType>
(
name
)
);
if (gGrad.ownedByRegistry())
{
if (fvSchemes::debug)
{
Info << "Cache: Deleting " << name
<< " originating from " << vsf.name()
<< " event No. " << vsf.eventNo()
<< endl;
}
gGrad.release();
delete &gGrad;
}
}
if (fvSchemes::debug)
{
Info << "Cache: Calculating " << name
<< " originating from " << vsf.name()
<< " event No. " << vsf.eventNo()
<< endl;
}
return calcGrad(vsf, name);
}
}
template<class Type>
Foam::tmp
<
Foam::GeometricField
<
typename Foam::outerProduct<Foam::vector, Type>::type,
Foam::fvPatchField,
Foam::volMesh
>
>
Foam::fv::gradScheme<Type>::grad
(
const GeometricField<Type, fvPatchField, volMesh>& vsf
) const
{
return grad(vsf, "grad(" + vsf.name() + ')');
}
template<class Type>
Foam::tmp
<
Foam::GeometricField
<
typename Foam::outerProduct<Foam::vector, Type>::type,
Foam::fvPatchField,
Foam::volMesh
>
>
Foam::fv::gradScheme<Type>::grad
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >& tvsf
) const
{
typedef typename outerProduct<vector, Type>::type GradType;
typedef GeometricField<GradType, fvPatchField, volMesh> GradFieldType;
tmp<GradFieldType> tgrad = grad(tvsf());
tvsf.clear();
return tgrad;
}
template<class Type>
tmp
<

View file

@ -127,16 +127,54 @@ public:
return mesh_;
}
//- Calculate and return the grad of the given field
//- Calculate and return the grad of the given field.
// Used by grad either to recalculate the cached gradient when it is
// out of date with respect to the field or when it is not cached.
virtual tmp
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>&,
const word& name
) const = 0;
//- Calculate and return the grad of the given field
// which may have been cached
tmp
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
(
const GeometricField<Type, fvPatchField, volMesh>&,
const word& name
) const;
//- Calculate and return the grad of the given field
// with the default name
// which may have been cached
tmp
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
(
const GeometricField<Type, fvPatchField, volMesh>&
) const = 0;
) const;
//- Calculate and return the grad of the given field
// with the default name
// which may have been cached
tmp
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >&
) const;
//- Return the BlockLduSystem corresponding to the implicit grad
// discretization. For block coupled systems.

View file

@ -52,9 +52,10 @@ tmp
typename outerProduct<vector, Type>::type, fvPatchField, volMesh
>
>
leastSquaresGrad<Type>::grad
leastSquaresGrad<Type>::calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>& vsf
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const
{
typedef typename outerProduct<vector, Type>::type GradType;
@ -67,7 +68,7 @@ leastSquaresGrad<Type>::grad
(
IOobject
(
"grad("+vsf.name()+')',
name,
vsf.instance(),
mesh,
IOobject::NO_READ,

View file

@ -88,13 +88,16 @@ public:
// Member Functions
tmp
//- Return the gradient of the given field to the gradScheme::grad
// for optional caching
virtual tmp
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
> calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>&
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const;
//- Return the BlockLduSystem corresponding to the implicit least

View file

@ -121,9 +121,10 @@ public:
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
> calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>&
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const;

View file

@ -91,9 +91,10 @@ inline void cellLimitedGrad<Type>::limitFace
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<>
tmp<volVectorField> cellLimitedGrad<scalar>::grad
tmp<volVectorField> cellLimitedGrad<scalar>::calcGrad
(
const volScalarField& vsf
const volScalarField& vsf,
const word& name
) const
{
const fvMesh& mesh = vsf.mesh();
@ -243,9 +244,10 @@ tmp<volVectorField> cellLimitedGrad<scalar>::grad
template<>
tmp<volTensorField> cellLimitedGrad<vector>::grad
tmp<volTensorField> cellLimitedGrad<vector>::calcGrad
(
const volVectorField& vsf
const volVectorField& vsf,
const word& name
) const
{
const fvMesh& mesh = vsf.mesh();

View file

@ -120,9 +120,10 @@ public:
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
> calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>&
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const;
};

View file

@ -48,9 +48,10 @@ makeFvGradScheme(cellMDLimitedGrad)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<>
tmp<volVectorField> cellMDLimitedGrad<scalar>::grad
tmp<volVectorField> cellMDLimitedGrad<scalar>::calcGrad
(
const volScalarField& vsf
const volScalarField& vsf,
const word& name
) const
{
const fvMesh& mesh = vsf.mesh();
@ -189,9 +190,10 @@ tmp<volVectorField> cellMDLimitedGrad<scalar>::grad
template<>
tmp<volTensorField> cellMDLimitedGrad<vector>::grad
tmp<volTensorField> cellMDLimitedGrad<vector>::calcGrad
(
const volVectorField& vsf
const volVectorField& vsf,
const word& name
) const
{
const fvMesh& mesh = vsf.mesh();

View file

@ -121,9 +121,10 @@ public:
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
> calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>&
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const;
//- Return the BlockLduSystem corresponding to the implicit face

View file

@ -70,9 +70,10 @@ inline void faceLimitedGrad<Type>::limitFace
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<>
tmp<volVectorField> faceLimitedGrad<scalar>::grad
tmp<volVectorField> faceLimitedGrad<scalar>::calcGrad
(
const volScalarField& vsf
const volScalarField& vsf,
const word& name
) const
{
const fvMesh& mesh = vsf.mesh();
@ -206,9 +207,10 @@ tmp<volVectorField> faceLimitedGrad<scalar>::grad
template<>
tmp<volTensorField> faceLimitedGrad<vector>::grad
tmp<volTensorField> faceLimitedGrad<vector>::calcGrad
(
const volVectorField& vvf
const volVectorField& vvf,
const word& name
) const
{
const fvMesh& mesh = vvf.mesh();

View file

@ -121,9 +121,10 @@ public:
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
> calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>&
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const;
};

View file

@ -50,9 +50,10 @@ makeFvGradScheme(faceMDLimitedGrad)
// FaceLimited scalar gradient
template<>
tmp<volVectorField> faceMDLimitedGrad<scalar>::grad
tmp<volVectorField> faceMDLimitedGrad<scalar>::calcGrad
(
const volScalarField& vsf
const volScalarField& vsf,
const word& name
) const
{
const fvMesh& mesh = vsf.mesh();
@ -188,9 +189,10 @@ tmp<volVectorField> faceMDLimitedGrad<scalar>::grad
template<>
tmp<volTensorField> faceMDLimitedGrad<vector>::grad
tmp<volTensorField> faceMDLimitedGrad<vector>::calcGrad
(
const volVectorField& vvf
const volVectorField& vvf,
const word& name
) const
{
const fvMesh& mesh = vvf.mesh();

View file

@ -54,9 +54,10 @@ tmp
typename outerProduct<vector, Type>::type, fvPatchField, volMesh
>
>
leastSquaresSolidInterfaceGrad<Type>::grad
leastSquaresSolidInterfaceGrad<Type>::calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>& vsf
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const
{
typedef typename outerProduct<vector, Type>::type GradType;
@ -69,7 +70,7 @@ leastSquaresSolidInterfaceGrad<Type>::grad
(
IOobject
(
"grad("+vsf.name()+')',
name,
vsf.instance(),
mesh,
IOobject::NO_READ,

View file

@ -94,9 +94,10 @@ public:
<
GeometricField
<typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
> calcGrad
(
const GeometricField<Type, fvPatchField, volMesh>&
const GeometricField<Type, fvPatchField, volMesh>& vsf,
const word& name
) const;
};