diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index 5ca407c90c..cc25676c75 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -109,26 +109,24 @@ sets // plane : values on plane defined by point, normal. // patch : values on patch. // -// 1] planes are triangulated by default -// 2] patches are not triangulated by default +// 1] patches are not triangulated by default +// 2] planes are always triangulated +// 3] iso-surfaces are always triangulated surfaces ( constantPlane { - type plane; + type plane; // always triangulated basePoint (0.0501 0.0501 0.005); normalVector (0.1 0.1 1); //- Optional: restrict to a particular zone // zoneName zone1; - - // Optional: whether to leave as faces or triangulate (=default) - triangulate false; } interpolatedPlane { - type plane; + type plane; // always triangulated // make plane relative to the coordinateSystem (Cartesian) coordinateSystem { @@ -136,7 +134,6 @@ surfaces } basePoint (0 0 0); normalVector (0.1 0.1 1); - triangulate false; interpolate true; } @@ -145,6 +142,7 @@ surfaces type patch; patchName movingWall; // Optional: whether to leave as faces (=default) or triangulate + // triangulate false; } movingWall_interpolated @@ -153,26 +151,27 @@ surfaces patchName movingWall; interpolate true; // Optional: whether to leave as faces (=default) or triangulate + // triangulate false; } interpolatedIso { // Iso surface for interpolated values only - type isoSurface; + type isoSurface; // always triangulated isoField rho; isoValue 0.5; interpolate true; - //regularise false; //optional: do not simplify + // regularise false; // Optional: do not simplify } constantIso { - // Iso surface for constant values. Guarantees triangles to not - // cross cells. - type isoSurfaceCell; + // Iso surface for constant values. + // Triangles guaranteed not to cross cells. + type isoSurfaceCell; // always triangulated isoField rho; isoValue 0.5; interpolate false; - //regularise false; //optional: do not simplify + // regularise false; // Optional: do not simplify } ); diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurface.C b/src/sampling/sampledSurface/distanceSurface/distanceSurface.C index f337d14253..32d7deb4b3 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurface.C +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurface.C @@ -31,7 +31,7 @@ License #include "addToRunTimeSelectionTable.H" #include "fvMesh.H" #include "isoSurface.H" -//#include "isoSurfaceCell.H" +// #include "isoSurfaceCell.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -45,10 +45,9 @@ namespace Foam void Foam::distanceSurface::createGeometry() { - // Clear any stored topo + // Clear any stored topologies facesPtr_.clear(); - const fvMesh& fvm = static_cast(mesh()); // Distance to cell centres @@ -232,21 +231,20 @@ Foam::distanceSurface::distanceSurface signed_(readBool(dict.lookup("signed"))), regularise_(dict.lookupOrDefault("regularise", true)), zoneName_(word::null), + needsUpdate_(true), isoSurfPtr_(NULL), facesPtr_(NULL) { -// label zoneId = -1; -// if (dict.readIfPresent("zone", zoneName_)) +// dict.readIfPresent("zone", zoneName_); +// +// if (debug && zoneName_.size()) // { -// zoneId = mesh.cellZones().findZoneID(zoneName_); -// if (debug && zoneId < 0) +// if (mesh.cellZones().findZoneID(zoneName_) < 0) // { // Info<< "cellZone \"" << zoneName_ -// << "\" not found - using entire mesh" -// << endl; +// << "\" not found - using entire mesh" << endl; // } // } - correct(true); } @@ -258,13 +256,39 @@ Foam::distanceSurface::~distanceSurface() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::distanceSurface::correct(const bool meshChanged) +bool Foam::distanceSurface::needsUpdate() const { - // Only change of mesh changes plane - zone restriction gets lost - if (meshChanged) + return needsUpdate_; +} + + +bool Foam::distanceSurface::expire() +{ + // Clear any stored topologies + facesPtr_.clear(); + + // already marked as expired + if (needsUpdate_) { - createGeometry(); + return false; } + + needsUpdate_ = true; + return true; +} + + +bool Foam::distanceSurface::update() +{ + if (!needsUpdate_) + { + return false; + } + + createGeometry(); + + needsUpdate_ = false; + return true; } diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H b/src/sampling/sampledSurface/distanceSurface/distanceSurface.H index 64aebb1a9a..7331fb3e3e 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurface.H @@ -71,6 +71,9 @@ class distanceSurface //- zone name (if restricted to zones) word zoneName_; + //- Track if the surface needs an update + mutable bool needsUpdate_; + //- Distance to cell centres autoPtr cellDistancePtr_; @@ -127,6 +130,18 @@ public: // Member Functions + //- Does the surface need an update? + virtual bool needsUpdate() const; + + //- Mark the surface as needing an update. + // May also free up unneeded data. + // Return false if surface was already marked as expired. + virtual bool expire(); + + //- Update the surface as required. + // Do nothing (and return false) if no update was needed + virtual bool update(); + //- Points of surface virtual const pointField& points() const { @@ -151,9 +166,6 @@ public: } - //- Correct for mesh movement and/or field changes - virtual void correct(const bool meshChanged); - const isoSurface& surface() const { return isoSurfPtr_(); diff --git a/src/sampling/sampledSurface/isoSurface/isoSurface.C b/src/sampling/sampledSurface/isoSurface/isoSurface.C index 5d77290b0f..4725b25eb3 100644 --- a/src/sampling/sampledSurface/isoSurface/isoSurface.C +++ b/src/sampling/sampledSurface/isoSurface/isoSurface.C @@ -512,7 +512,7 @@ void Foam::isoSurface::calcSnappedCc ( false, // do not check for duplicate tris localTriPoints, - triPointReverseMap, + triPointReverseMap, triMap ) ); @@ -696,7 +696,7 @@ void Foam::isoSurface::calcSnappedPoint ( false, // do not check for duplicate tris localTriPoints, - triPointReverseMap, + triPointReverseMap, triMap ) ); @@ -1084,7 +1084,7 @@ void Foam::isoSurface::walkOrientation forAll(fEdges, fp) { label edgeI = fEdges[fp]; - + // my points: label p0 = tri[fp]; label p1 = tri[tri.fcIndex(fp)]; @@ -1121,7 +1121,7 @@ void Foam::isoSurface::walkOrientation changedFaces.transfer(newChangedFaces); } -} +} void Foam::isoSurface::orientSurface @@ -1146,7 +1146,7 @@ void Foam::isoSurface::orientSurface for ( ; - seedTriI < surf.size() && flipState[seedTriI] != -1; + seedTriI < surf.size() && flipState[seedTriI] != -1; seedTriI++ ) {} @@ -1355,7 +1355,7 @@ Foam::isoSurface::isoSurface : mesh_(cVals.mesh()), iso_(iso), - mergeDistance_(mergeTol*mag(mesh_.bounds().max()-mesh_.bounds().min())) + mergeDistance_(mergeTol*mesh_.bounds().mag()) { // Determine if any cut through face/cell calcCutTypes(cVals, pVals); diff --git a/src/sampling/sampledSurface/isoSurface/isoSurfaceCell.C b/src/sampling/sampledSurface/isoSurface/isoSurfaceCell.C index 6557112012..a80e92669a 100644 --- a/src/sampling/sampledSurface/isoSurface/isoSurfaceCell.C +++ b/src/sampling/sampledSurface/isoSurface/isoSurfaceCell.C @@ -1409,7 +1409,7 @@ Foam::isoSurfaceCell::isoSurfaceCell : mesh_(mesh), iso_(iso), - mergeDistance_(mergeTol*mag(mesh.bounds().max()-mesh.bounds().min())) + mergeDistance_(mergeTol*mesh.bounds().mag()) { // Determine if cell is tet PackedList<1> isTet(mesh_.nCells()); diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C index 0c7832f176..a0d6b07aca 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C @@ -176,100 +176,105 @@ void Foam::sampledIsoSurface::getIsoFields() const } -void Foam::sampledIsoSurface::createGeometry() const +bool Foam::sampledIsoSurface::updateGeometry() const { const fvMesh& fvm = static_cast(mesh()); - if (fvm.time().timeIndex() != storedTimeIndex_) + // no update needed + if (fvm.time().timeIndex() == prevTimeIndex_) { - storedTimeIndex_ = fvm.time().timeIndex(); + return false; + } - getIsoFields(); - // Clear any stored topo - surfPtr_.clear(); - facesPtr_.clear(); + prevTimeIndex_ = fvm.time().timeIndex(); + getIsoFields(); - if (average_) - { - //- From point field and interpolated cell. - volScalarField cellAvg + // Clear any stored topo + surfPtr_.clear(); + facesPtr_.clear(); + + if (average_) + { + //- From point field and interpolated cell. + volScalarField cellAvg + ( + IOobject ( - IOobject - ( - "cellAvg", - fvm.time().timeName(), - fvm.time(), - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), - fvm, - dimensionedScalar("zero", dimless, scalar(0.0)) - ); - labelField nPointCells(fvm.nCells(), 0); + "cellAvg", + fvm.time().timeName(), + fvm.time(), + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + fvm, + dimensionedScalar("zero", dimless, scalar(0.0)) + ); + labelField nPointCells(fvm.nCells(), 0); + { + for (label pointI = 0; pointI < fvm.nPoints(); pointI++) { - for (label pointI = 0; pointI < fvm.nPoints(); pointI++) + const labelList& pCells = fvm.pointCells(pointI); + + forAll(pCells, i) { - const labelList& pCells = fvm.pointCells(pointI); + label cellI = pCells[i]; - forAll(pCells, i) - { - label cellI = pCells[i]; - - cellAvg[cellI] += (*pointFieldPtr_)[pointI]; - nPointCells[cellI]++; - } + cellAvg[cellI] += (*pointFieldPtr_)[pointI]; + nPointCells[cellI]++; } } - forAll(cellAvg, cellI) - { - cellAvg[cellI] /= nPointCells[cellI]; - } - // Give value to calculatedFvPatchFields - cellAvg.correctBoundaryConditions(); - - surfPtr_.reset - ( - new isoSurface - ( - cellAvg, - *pointFieldPtr_, - isoVal_, - regularise_ - ) - ); } - else + forAll(cellAvg, cellI) { - //- Direct from cell field and point field. - surfPtr_.reset + cellAvg[cellI] /= nPointCells[cellI]; + } + // Give value to calculatedFvPatchFields + cellAvg.correctBoundaryConditions(); + + surfPtr_.reset + ( + new isoSurface ( - new isoSurface - ( - *volFieldPtr_, - *pointFieldPtr_, - isoVal_, - regularise_ - ) - ); - } - - - if (debug) - { - Pout<< "sampledIsoSurface::createGeometry() : constructed iso:" - << nl - << " regularise : " << regularise_ << nl - << " average : " << average_ << nl - << " isoField : " << isoField_ << nl - << " isoValue : " << isoVal_ << nl - << " points : " << points().size() << nl - << " tris : " << surface().size() << nl - << " cut cells : " << surface().meshCells().size() - << endl; - } + cellAvg, + *pointFieldPtr_, + isoVal_, + regularise_ + ) + ); } + else + { + //- Direct from cell field and point field. + surfPtr_.reset + ( + new isoSurface + ( + *volFieldPtr_, + *pointFieldPtr_, + isoVal_, + regularise_ + ) + ); + } + + + if (debug) + { + Pout<< "sampledIsoSurface::updateGeometry() : constructed iso:" + << nl + << " regularise : " << regularise_ << nl + << " average : " << average_ << nl + << " isoField : " << isoField_ << nl + << " isoValue : " << isoVal_ << nl + << " points : " << points().size() << nl + << " tris : " << surface().size() << nl + << " cut cells : " << surface().meshCells().size() + << endl; + } + + return true; } @@ -290,7 +295,7 @@ Foam::sampledIsoSurface::sampledIsoSurface zoneName_(word::null), surfPtr_(NULL), facesPtr_(NULL), - storedTimeIndex_(-1), + prevTimeIndex_(-1), storedVolFieldPtr_(NULL), volFieldPtr_(NULL), storedPointFieldPtr_(NULL), @@ -306,15 +311,14 @@ Foam::sampledIsoSurface::sampledIsoSurface << " span across cells." << exit(FatalError); } -// label zoneId = -1; -// if (dict.readIfPresent("zone", zoneName_)) +// dict.readIfPresent("zone", zoneName_); +// +// if (debug && zoneName_.size()) // { -// zoneId = mesh.cellZones().findZoneID(zoneName_); -// if (debug && zoneId < 0) +// if (mesh.cellZones().findZoneID(zoneName_) < 0) // { // Info<< "cellZone \"" << zoneName_ -// << "\" not found - using entire mesh" -// << endl; +// << "\" not found - using entire mesh" << endl; // } // } } @@ -328,14 +332,34 @@ Foam::sampledIsoSurface::~sampledIsoSurface() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::sampledIsoSurface::correct(const bool meshChanged) +bool Foam::sampledIsoSurface::needsUpdate() const { - // Only change of mesh changes plane - zone restriction gets lost - if (meshChanged) + const fvMesh& fvm = static_cast(mesh()); + + return fvm.time().timeIndex() != prevTimeIndex_; +} + + +bool Foam::sampledIsoSurface::expire() +{ + surfPtr_.clear(); + facesPtr_.clear(); + + // already marked as expired + if (prevTimeIndex_ == -1) { - surfPtr_.clear(); - facesPtr_.clear(); + return false; } + + // force update + prevTimeIndex_ = -1; + return true; +} + + +bool Foam::sampledIsoSurface::update() +{ + return updateGeometry(); } diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H index 3ccd72f629..6485419247 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H @@ -79,8 +79,8 @@ class sampledIsoSurface // Recreated for every isoSurface - //- Time at last call - mutable label storedTimeIndex_; + //- Time at last call, also track it surface needs an update + mutable label prevTimeIndex_; //- Cached volfield mutable autoPtr storedVolFieldPtr_; @@ -98,7 +98,8 @@ class sampledIsoSurface void getIsoFields() const; //- Create iso surface (if time has changed) - void createGeometry() const; + // Do nothing (and return false) if no update was needed + bool updateGeometry() const; //- sample field on faces template @@ -137,6 +138,19 @@ public: // Member Functions + //- Does the surface need an update? + virtual bool needsUpdate() const; + + //- Mark the surface as needing an update. + // May also free up unneeded data. + // Return false if surface was already marked as expired. + virtual bool expire(); + + //- Update the surface as required. + // Do nothing (and return false) if no update was needed + virtual bool update(); + + //- Points of surface virtual const pointField& points() const { @@ -160,9 +174,6 @@ public: return facesPtr_; } - //- Correct for mesh movement and/or field changes - virtual void correct(const bool meshChanged); - const isoSurface& surface() const { diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C index c258761ab7..7ce9e3b0f6 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C @@ -42,142 +42,147 @@ namespace Foam // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::sampledIsoSurfaceCell::createGeometry() const +bool Foam::sampledIsoSurfaceCell::updateGeometry() const { const fvMesh& fvm = static_cast(mesh()); - if (fvm.time().timeIndex() != storedTimeIndex_) + // no update needed + if (fvm.time().timeIndex() == prevTimeIndex_) { - storedTimeIndex_ = fvm.time().timeIndex(); + return false; + } - // Clear any stored topo - facesPtr_.clear(); + prevTimeIndex_ = fvm.time().timeIndex(); - // Optionally read volScalarField - autoPtr readFieldPtr_; + // Clear any stored topo + facesPtr_.clear(); - // 1. see if field in database - // 2. see if field can be read - const volScalarField* cellFldPtr = NULL; - if (fvm.foundObject(isoField_)) + // Optionally read volScalarField + autoPtr readFieldPtr_; + + // 1. see if field in database + // 2. see if field can be read + const volScalarField* cellFldPtr = NULL; + if (fvm.foundObject(isoField_)) + { + if (debug) { - if (debug) - { - Info<< "sampledIsoSurfaceCell::createGeometry() : lookup " - << isoField_ << endl; - } - - cellFldPtr = &fvm.lookupObject(isoField_); - } - else - { - // Bit of a hack. Read field and store. - - if (debug) - { - Info<< "sampledIsoSurfaceCell::createGeometry() : reading " - << isoField_ << " from time " <(); - } - const volScalarField& cellFld = *cellFldPtr; - - tmp pointFld - ( - volPointInterpolation::New(fvm).interpolate(cellFld) - ); - - if (average_) - { - //- From point field and interpolated cell. - scalarField cellAvg(fvm.nCells(), scalar(0.0)); - labelField nPointCells(fvm.nCells(), 0); - { - for (label pointI = 0; pointI < fvm.nPoints(); pointI++) - { - const labelList& pCells = fvm.pointCells(pointI); - - forAll(pCells, i) - { - label cellI = pCells[i]; - - cellAvg[cellI] += pointFld().internalField()[pointI]; - nPointCells[cellI]++; - } - } - } - forAll(cellAvg, cellI) - { - cellAvg[cellI] /= nPointCells[cellI]; - } - - const isoSurfaceCell iso - ( - fvm, - cellAvg, - pointFld().internalField(), - isoVal_, - regularise_ - ); - - const_cast - ( - *this - ).triSurface::operator=(iso); - meshCells_ = iso.meshCells(); - } - else - { - //- Direct from cell field and point field. Gives bad continuity. - const isoSurfaceCell iso - ( - fvm, - cellFld.internalField(), - pointFld().internalField(), - isoVal_, - regularise_ - ); - - const_cast - ( - *this - ).triSurface::operator=(iso); - meshCells_ = iso.meshCells(); + Info<< "sampledIsoSurfaceCell::updateGeometry() : lookup " + << isoField_ << endl; } + cellFldPtr = &fvm.lookupObject(isoField_); + } + else + { + // Bit of a hack. Read field and store. if (debug) { - Pout<< "sampledIsoSurfaceCell::createGeometry() : constructed iso:" - << nl - << " regularise : " << regularise_ << nl - << " average : " << average_ << nl - << " isoField : " << isoField_ << nl - << " isoValue : " << isoVal_ << nl - << " points : " << points().size() << nl - << " tris : " << triSurface::size() << nl - << " cut cells : " << meshCells_.size() << endl; + Info<< "sampledIsoSurfaceCell::updateGeometry() : reading " + << isoField_ << " from time " <(); } + const volScalarField& cellFld = *cellFldPtr; + + tmp pointFld + ( + volPointInterpolation::New(fvm).interpolate(cellFld) + ); + + if (average_) + { + //- From point field and interpolated cell. + scalarField cellAvg(fvm.nCells(), scalar(0.0)); + labelField nPointCells(fvm.nCells(), 0); + { + for (label pointI = 0; pointI < fvm.nPoints(); pointI++) + { + const labelList& pCells = fvm.pointCells(pointI); + + forAll(pCells, i) + { + label cellI = pCells[i]; + + cellAvg[cellI] += pointFld().internalField()[pointI]; + nPointCells[cellI]++; + } + } + } + forAll(cellAvg, cellI) + { + cellAvg[cellI] /= nPointCells[cellI]; + } + + const isoSurfaceCell iso + ( + fvm, + cellAvg, + pointFld().internalField(), + isoVal_, + regularise_ + ); + + const_cast + ( + *this + ).triSurface::operator=(iso); + meshCells_ = iso.meshCells(); + } + else + { + //- Direct from cell field and point field. Gives bad continuity. + const isoSurfaceCell iso + ( + fvm, + cellFld.internalField(), + pointFld().internalField(), + isoVal_, + regularise_ + ); + + const_cast + ( + *this + ).triSurface::operator=(iso); + meshCells_ = iso.meshCells(); + } + + + if (debug) + { + Pout<< "sampledIsoSurfaceCell::updateGeometry() : constructed iso:" + << nl + << " regularise : " << regularise_ << nl + << " average : " << average_ << nl + << " isoField : " << isoField_ << nl + << " isoValue : " << isoVal_ << nl + << " points : " << points().size() << nl + << " tris : " << triSurface::size() << nl + << " cut cells : " << meshCells_.size() << endl; + } + + return true; } @@ -197,18 +202,17 @@ Foam::sampledIsoSurfaceCell::sampledIsoSurfaceCell average_(dict.lookupOrDefault("average", true)), zoneName_(word::null), facesPtr_(NULL), - storedTimeIndex_(-1), + prevTimeIndex_(-1), meshCells_(0) { -// label zoneId = -1; -// if (dict.readIfPresent("zone", zoneName_)) +// dict.readIfPresent("zone", zoneName_); +// +// if (debug && zoneName_.size()) // { -// zoneId = mesh.cellZones().findZoneID(zoneName_); -// if (debug && zoneId < 0) +// if (mesh.cellZones().findZoneID(zoneName_) < 0) // { // Info<< "cellZone \"" << zoneName_ -// << "\" not found - using entire mesh" -// << endl; +// << "\" not found - using entire mesh" << endl; // } // } } @@ -222,13 +226,33 @@ Foam::sampledIsoSurfaceCell::~sampledIsoSurfaceCell() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::sampledIsoSurfaceCell::correct(const bool meshChanged) +bool Foam::sampledIsoSurfaceCell::needsUpdate() const { - // Only change of mesh changes plane - zone restriction gets lost - if (meshChanged) + const fvMesh& fvm = static_cast(mesh()); + + return fvm.time().timeIndex() != prevTimeIndex_; +} + + +bool Foam::sampledIsoSurfaceCell::expire() +{ + facesPtr_.clear(); + + // already marked as expired + if (prevTimeIndex_ == -1) { - facesPtr_.clear(); + return false; } + + // force update + prevTimeIndex_ = -1; + return true; +} + + +bool Foam::sampledIsoSurfaceCell::update() +{ + return updateGeometry(); } diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H index 7d6868ae98..8f54b97134 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H @@ -47,7 +47,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class sampledIsoSurfaceCell Declaration + Class sampledIsoSurfaceCell Declaration \*---------------------------------------------------------------------------*/ class sampledIsoSurfaceCell @@ -78,8 +78,8 @@ class sampledIsoSurfaceCell // Recreated for every isoSurface - //- Time at last call - mutable label storedTimeIndex_; + //- Time at last call, also track it surface needs an update + mutable label prevTimeIndex_; //- For every triangle the original cell in mesh mutable labelList meshCells_; @@ -88,7 +88,8 @@ class sampledIsoSurfaceCell // Private Member Functions //- Create iso surface (if time has changed) - void createGeometry() const; + // Do nothing (and return false) if no update was needed + bool updateGeometry() const; //- sample field on faces template @@ -127,6 +128,19 @@ public: // Member Functions + //- Does the surface need an update? + virtual bool needsUpdate() const; + + //- Mark the surface as needing an update. + // May also free up unneeded data. + // Return false if surface was already marked as expired. + virtual bool expire(); + + //- Update the surface as required. + // Do nothing (and return false) if no update was needed + virtual bool update(); + + //- Points of surface virtual const pointField& points() const { @@ -151,10 +165,6 @@ public: } - //- Correct for mesh movement and/or field changes - virtual void correct(const bool meshChanged); - - //- sample field on surface virtual tmp sample ( diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCellTemplates.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCellTemplates.C index 144a0ddf41..f2a70481bf 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCellTemplates.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCellTemplates.C @@ -40,7 +40,7 @@ Foam::sampledIsoSurfaceCell::sampleField ) const { // Recreate geometry if time has changed - createGeometry(); + updateGeometry(); return tmp >(new Field(vField, meshCells_)); } @@ -54,7 +54,7 @@ Foam::sampledIsoSurfaceCell::interpolateField ) const { // Recreate geometry if time has changed - createGeometry(); + updateGeometry(); // One value per point tmp > tvalues(new Field(points().size())); diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTemplates.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTemplates.C index a36811b75e..6e5ed61925 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTemplates.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTemplates.C @@ -39,7 +39,8 @@ Foam::sampledIsoSurface::sampleField ) const { // Recreate geometry if time has changed - createGeometry(); + updateGeometry(); + return tmp >(new Field(vField, surface().meshCells())); } @@ -67,8 +68,9 @@ Foam::sampledIsoSurface::interpolateField // Get pointers to sampling field (both original and interpolated one) getIsoFields(); + // Recreate geometry if time has changed - createGeometry(); + updateGeometry(); // Sample. return surface().interpolate diff --git a/src/sampling/sampledSurface/patch/sampledPatch.C b/src/sampling/sampledSurface/patch/sampledPatch.C index 37f19ec1ea..06d22adf78 100644 --- a/src/sampling/sampledSurface/patch/sampledPatch.C +++ b/src/sampling/sampledSurface/patch/sampledPatch.C @@ -40,17 +40,83 @@ namespace Foam addNamedToRunTimeSelectionTable(sampledSurface, sampledPatch, word, patch); } -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::sampledPatch::createGeometry() +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::sampledPatch::sampledPatch +( + const word& name, + const polyMesh& mesh, + const word& patchName, + const bool triangulate +) +: + sampledSurface(name, mesh), + patchName_(patchName), + triangulate_(triangulate), + needsUpdate_(true), + patchFaceLabels_(0) +{} + + +Foam::sampledPatch::sampledPatch +( + const word& name, + const polyMesh& mesh, + const dictionary& dict +) +: + sampledSurface(name, mesh, dict), + patchName_(dict.lookup("patchName")), + triangulate_(dict.lookupOrDefault("triangulate", false)), + needsUpdate_(true), + patchFaceLabels_(0) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::sampledPatch::~sampledPatch() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::sampledPatch::needsUpdate() const { + return needsUpdate_; +} + + +bool Foam::sampledPatch::expire() +{ + // already marked as expired + if (needsUpdate_) + { + return false; + } + sampledSurface::clearGeom(); MeshStorage::clear(); patchFaceLabels_.clear(); - if (patchIndex_ != -1) + needsUpdate_ = true; + return true; +} + + +bool Foam::sampledPatch::update() +{ + if (!needsUpdate_) { - const polyPatch& p = mesh().boundaryMesh()[patchIndex_]; + return false; + } + + label patchI = mesh().boundaryMesh().findPatchID(patchName_); + + if (patchI != -1) + { + const polyPatch& p = mesh().boundaryMesh()[patchI]; this->storedPoints() = p.localPoints(); this->storedFaces() = p.localFaces(); @@ -76,60 +142,9 @@ void Foam::sampledPatch::createGeometry() print(Pout); Pout << endl; } -} - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::sampledPatch::sampledPatch -( - const word& name, - const polyMesh& mesh, - const word& patchName, - const bool triangulate -) -: - sampledSurface(name, mesh), - patchName_(patchName), - patchIndex_(mesh.boundaryMesh().findPatchID(patchName_)), - triangulate_(triangulate), - patchFaceLabels_(0) -{ - createGeometry(); -} - - -Foam::sampledPatch::sampledPatch -( - const word& name, - const polyMesh& mesh, - const dictionary& dict -) -: - sampledSurface(name, mesh, dict), - patchName_(dict.lookup("patchName")), - patchIndex_(mesh.boundaryMesh().findPatchID(patchName_)), - triangulate_(dict.lookupOrDefault("triangulate", false)), - patchFaceLabels_(0) -{ - createGeometry(); -} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::sampledPatch::~sampledPatch() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -void Foam::sampledPatch::correct(const bool meshChanged) -{ - if (meshChanged) - { - createGeometry(); - } + needsUpdate_ = false; + return true; } @@ -143,13 +158,6 @@ void Foam::sampledPatch::remapFaces if (&faceMap && faceMap.size()) { MeshStorage::remapFaces(faceMap); -// -// List