diff --git a/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolate.C b/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolate.C index 0f2b751bbd..f86aa7ee08 100644 --- a/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolate.C +++ b/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolate.C @@ -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 @@ -439,6 +439,102 @@ volPointInterpolation::interpolate } +template +tmp > +volPointInterpolation::interpolate +( + const GeometricField& vf, + const word& name, + const bool cache +) const +{ + typedef GeometricField 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(name)) + { + PointFieldType& pf = const_cast + ( + db.objectRegistry::template lookupObject(name) + ); + + if (pf.ownedByRegistry()) + { + solution::cachePrintMessage("Deleting", name, vf); + pf.release(); + delete &pf; + } + } + + + tmp > tpf + ( + new GeometricField + ( + IOobject + ( + name, + vf.instance(), + pm.thisDb() + ), + pm, + vf.dimensions() + ) + ); + + interpolateInternalField(vf, tpf()); + interpolateBoundaryField(vf, tpf(), false); + + return tpf; + } + else + { + if (!db.objectRegistry::template foundObject(name)) + { + solution::cachePrintMessage("Calculating and caching", name, vf); + tmp tpf = interpolate(vf, name, false); + PointFieldType* pfPtr = tpf.ptr(); + regIOobject::store(pfPtr); + return *pfPtr; + } + else + { + PointFieldType& pf = const_cast + ( + db.objectRegistry::template lookupObject(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 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 tmp > volPointInterpolation::interpolate @@ -446,27 +542,7 @@ volPointInterpolation::interpolate const GeometricField& vf ) const { - const pointMesh& pm = pointMesh::New(vf.mesh()); - - tmp > tpf - ( - new GeometricField - ( - IOobject - ( - "volPointInterpolate(" + vf.name() + ')', - vf.instance(), - pm.thisDb() - ), - pm, - vf.dimensions() - ) - ); - - interpolateInternalField(vf, tpf()); - interpolateBoundaryField(vf, tpf(), false); - - return tpf; + return interpolate(vf, "volPointInterpolate(" + vf.name() + ')', false); } diff --git a/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolation.H b/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolation.H index 96765ea14d..eabfca7654 100644 --- a/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolation.H +++ b/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolation.H @@ -218,6 +218,16 @@ public: const wordList& patchFieldTypes ) const; + //- Interpolate volField using inverse distance weighting + // returning pointField with name. Optionally caches + template + tmp > interpolate + ( + const GeometricField&, + const word& name, + const bool cache + ) const; + //- Interpolate volField using inverse distance weighting // returning pointField template @@ -233,6 +243,7 @@ public: ( const tmp >& ) const; + };