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 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -439,6 +439,102 @@ volPointInterpolation::interpolate
} }
template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh> >
volPointInterpolation::interpolate
(
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
(
new GeometricField<Type, pointPatchField, pointMesh>
(
IOobject
(
name,
vf.instance(),
pm.thisDb()
),
pm,
vf.dimensions()
)
);
interpolateInternalField(vf, tpf());
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> template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh> > tmp<GeometricField<Type, pointPatchField, pointMesh> >
volPointInterpolation::interpolate volPointInterpolation::interpolate
@ -446,27 +542,7 @@ volPointInterpolation::interpolate
const GeometricField<Type, fvPatchField, volMesh>& vf const GeometricField<Type, fvPatchField, volMesh>& vf
) const ) const
{ {
const pointMesh& pm = pointMesh::New(vf.mesh()); return interpolate(vf, "volPointInterpolate(" + vf.name() + ')', false);
tmp<GeometricField<Type, pointPatchField, pointMesh> > tpf
(
new GeometricField<Type, pointPatchField, pointMesh>
(
IOobject
(
"volPointInterpolate(" + vf.name() + ')',
vf.instance(),
pm.thisDb()
),
pm,
vf.dimensions()
)
);
interpolateInternalField(vf, tpf());
interpolateBoundaryField(vf, tpf(), false);
return tpf;
} }

View File

@ -218,6 +218,16 @@ public:
const wordList& patchFieldTypes const wordList& patchFieldTypes
) const; ) 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 //- Interpolate volField using inverse distance weighting
// returning pointField // returning pointField
template<class Type> template<class Type>
@ -233,6 +243,7 @@ public:
( (
const tmp<GeometricField<Type, fvPatchField, volMesh> >& const tmp<GeometricField<Type, fvPatchField, volMesh> >&
) const; ) const;
}; };