Skip to content

Patch for axom@0.11 #341

@kennyweiss

Description

@kennyweiss

I am in the process of updating axom to v0.11 in a code that I support that also depends on spheral.

I needed the following patches to spheral to get the build working against the new axom and figured I'd pass it along.
(Caveat: Our spheral is about a year out old, and our Axom was newer than spheral's):

diff --git a/src/Geometry/GeomPolyhedron.cc b/src/Geometry/GeomPolyhedron.cc
index ec368a723..6d42eead5 100644
--- a/src/Geometry/GeomPolyhedron.cc
+++ b/src/Geometry/GeomPolyhedron.cc
@@ -58,7 +58,6 @@ GeomPolyhedron():
   mCentroid(),
   mRinterior2(-1.0),
   mConvex(true),
-  mSurfaceMeshPtr(nullptr),
   mSurfaceMeshQueryPtr(nullptr),
   mSignedDistancePtr(nullptr) {
   if (mDevnull == NULL) mDevnull = fopen("/dev/null", "w");
@@ -79,7 +78,6 @@ GeomPolyhedron(const vector<GeomPolyhedron::Vector>& points):
   mCentroid(),
   mRinterior2(-1.0),
   mConvex(true),
-  mSurfaceMeshPtr(nullptr),
   mSurfaceMeshQueryPtr(nullptr),
   mSignedDistancePtr(nullptr) {
   TIME_BEGIN("Polyhedron_construct1");
@@ -256,7 +254,6 @@ GeomPolyhedron(const vector<GeomPolyhedron::Vector>& points,
   mCentroid(),
   mRinterior2(-1.0),
   mConvex(false),
-  mSurfaceMeshPtr(nullptr),
   mSurfaceMeshQueryPtr(nullptr),
   mSignedDistancePtr(nullptr) {
   TIME_BEGIN("Polyhedron_construct2");
@@ -291,7 +288,6 @@ GeomPolyhedron(const GeomPolyhedron& rhs):
   mCentroid(rhs.mCentroid),
   mRinterior2(rhs.mRinterior2),
   mConvex(rhs.mConvex),
-  mSurfaceMeshPtr(nullptr),
   mSurfaceMeshQueryPtr(nullptr),
   mSignedDistancePtr(nullptr) {
   for (Facet& facet: mFacets) facet.mVerticesPtr = &mVertices;
@@ -330,7 +326,6 @@ operator=(const GeomPolyhedron& rhs) {
 //------------------------------------------------------------------------------
 GeomPolyhedron::
 ~GeomPolyhedron() {
-  if (mSurfaceMeshPtr != nullptr) delete mSurfaceMeshPtr;
   if (mSurfaceMeshQueryPtr != nullptr) delete mSurfaceMeshQueryPtr;
   if (mSignedDistancePtr != nullptr) delete mSignedDistancePtr;
 }
@@ -348,7 +343,7 @@ contains(const GeomPolyhedron::Vector& point,
 
     // Experimental version using Axom
     using AxPoint = axom::quest::InOutOctree<3>::SpacePt;
-    if (mSurfaceMeshPtr == nullptr) this->buildAxomData();
+    if (mSurfaceMeshPtr) {this->buildAxomData();}
     const auto inside = mSurfaceMeshQueryPtr->within(AxPoint(&const_cast<Vector&>(point)[0]));
     if (not inside and countBoundary) {
       return this->distance(point) < tol;
@@ -748,7 +743,7 @@ distance(const GeomPolyhedron::Vector& p,
 
     // Experimental version using Axom
     using AxPoint = axom::quest::InOutOctree<3>::SpacePt;
-    if (mSurfaceMeshPtr == nullptr) this->buildAxomData();
+    if (mSurfaceMeshPtr) {this->buildAxomData();}
     return std::abs(mSignedDistancePtr->computeDistance(AxPoint(&const_cast<Vector&>(p)[0])));
 
   } else {
@@ -933,10 +928,9 @@ setBoundingBox() {
   TIME_END("Polyhedron_BB_R2");
 
   // Clear any existing Axom information, so it's reconstructed if needed
-  if (mSurfaceMeshPtr != nullptr) delete mSurfaceMeshPtr;
   if (mSurfaceMeshQueryPtr != nullptr) delete mSurfaceMeshQueryPtr;
   if (mSignedDistancePtr != nullptr) delete mSignedDistancePtr;
-  mSurfaceMeshPtr = nullptr;
+  mSurfaceMeshPtr.reset();
   mSurfaceMeshQueryPtr = nullptr;
   mSignedDistancePtr = nullptr;
   TIME_END("Polyhedron_BB");
@@ -980,10 +974,10 @@ buildAxomData() const {
   bb.addPoint(AxPoint(&xmin[0]));
   bb.addPoint(AxPoint(&xmax[0]));
   axom::mint::write_vtk(meshPtr, "blago.vtk");
-  mSurfaceMeshPtr = meshPtr;
+  mSurfaceMeshPtr = std::shared_ptr<axom::quest::InOutOctree<3>::SurfaceMesh>(meshPtr);
   mSurfaceMeshQueryPtr = new AxOctree(bb, mSurfaceMeshPtr);
   mSurfaceMeshQueryPtr->generateIndex();
-  mSignedDistancePtr = new AxDistance(mSurfaceMeshPtr,
+  mSignedDistancePtr = new AxDistance(mSurfaceMeshPtr.get(),
                                       true,               // is_watertight
                                       25,                 // max_objects
                                       10);                // max_levels
diff --git a/src/Geometry/GeomPolyhedron.hh b/src/Geometry/GeomPolyhedron.hh
index 427760b90..0cb130d68 100644
--- a/src/Geometry/GeomPolyhedron.hh
+++ b/src/Geometry/GeomPolyhedron.hh
@@ -156,7 +156,7 @@ private:
   Vector mXmin, mXmax, mCentroid;
   double mRinterior2;
   bool mConvex;
-  mutable axom::quest::InOutOctree<3>::SurfaceMesh* mSurfaceMeshPtr;
+  mutable std::shared_ptr<axom::quest::InOutOctree<3>::SurfaceMesh> mSurfaceMeshPtr;
   mutable axom::quest::InOutOctree<3>* mSurfaceMeshQueryPtr;
   mutable axom::quest::SignedDistance<3>* mSignedDistancePtr;

The main difference is that the mesh pointer within Axom's InOutOctree is now using a shared_ptr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions