ENH: volPointInterpolation: have cached version

This commit is contained in:
mattijs
2013-10-03 10:50:53 +01:00
parent 029f881827
commit df246e54cc
2 changed files with 109 additions and 22 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -443,10 +443,34 @@ template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh> >
volPointInterpolation::interpolate
(
const GeometricField<Type, fvPatchField, volMesh>& vf
const GeometricField<Type, fvPatchField, volMesh>& vf,
const word& name,
const bool cache
) const
{
typedef GeometricField<Type, pointPatchField, pointMesh> PointFieldType;
const pointMesh& pm = pointMesh::New(vf.mesh());
const objectRegistry& db = pm.thisDb();
if (!cache || vf.mesh().changing())
{
// Delete any old occurences to avoid double registration
if (db.objectRegistry::template foundObject<PointFieldType>(name))
{
PointFieldType& pf = const_cast<PointFieldType&>
(
db.objectRegistry::template lookupObject<PointFieldType>(name)
);
if (pf.ownedByRegistry())
{
solution::cachePrintMessage("Deleting", name, vf);
pf.release();
delete &pf;
}
}
tmp<GeometricField<Type, pointPatchField, pointMesh> > tpf
(
@ -454,7 +478,7 @@ volPointInterpolation::interpolate
(
IOobject
(
"volPointInterpolate(" + vf.name() + ')',
name,
vf.instance(),
pm.thisDb()
),
@ -467,6 +491,58 @@ volPointInterpolation::interpolate
interpolateBoundaryField(vf, tpf(), false);
return tpf;
}
else
{
if (!db.objectRegistry::template foundObject<PointFieldType>(name))
{
solution::cachePrintMessage("Calculating and caching", name, vf);
tmp<PointFieldType> tpf = interpolate(vf, name, false);
PointFieldType* pfPtr = tpf.ptr();
regIOobject::store(pfPtr);
return *pfPtr;
}
else
{
PointFieldType& pf = const_cast<PointFieldType&>
(
db.objectRegistry::template lookupObject<PointFieldType>(name)
);
if (pf.upToDate(vf)) //TBD: , vf.mesh().points()))
{
solution::cachePrintMessage("Reusing", name, vf);
return pf;
}
else
{
solution::cachePrintMessage("Deleting", name, vf);
pf.release();
delete &pf;
solution::cachePrintMessage("Recalculating", name, vf);
tmp<PointFieldType> tpf = interpolate(vf, name, false);
solution::cachePrintMessage("Storing", name, vf);
PointFieldType* pfPtr = tpf.ptr();
regIOobject::store(pfPtr);
// Note: return reference, not pointer
return *pfPtr;
}
}
}
}
template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh> >
volPointInterpolation::interpolate
(
const GeometricField<Type, fvPatchField, volMesh>& vf
) const
{
return interpolate(vf, "volPointInterpolate(" + vf.name() + ')', false);
}

View File

@ -218,6 +218,16 @@ public:
const wordList& patchFieldTypes
) const;
//- Interpolate volField using inverse distance weighting
// returning pointField with name. Optionally caches
template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh> > interpolate
(
const GeometricField<Type, fvPatchField, volMesh>&,
const word& name,
const bool cache
) const;
//- Interpolate volField using inverse distance weighting
// returning pointField
template<class Type>
@ -233,6 +243,7 @@ public:
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >&
) const;
};