]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Memory squeeze
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 19 Aug 2022 15:44:55 +0000 (17:44 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 19 Aug 2022 15:44:55 +0000 (17:44 +0200)
src/INTERP_KERNEL/BBTree.txx
src/INTERP_KERNEL/BoundingBox.cxx
src/INTERP_KERNEL/BoundingBox.hxx
src/INTERP_KERNEL/Interpolation1D0D.txx
src/INTERP_KERNEL/Interpolation2D3D.txx
src/INTERP_KERNEL/Interpolation3D.txx
src/INTERP_KERNEL/Interpolation3D1D.txx
src/INTERP_KERNEL/MeshElement.hxx
src/INTERP_KERNEL/MeshElement.txx

index b9bb357fdd89f88940300ad85e7b7de5a4f09436..2a78e6dbc4868d59c987766a30644c697db473f2 100644 (file)
@@ -23,6 +23,7 @@
 #include <algorithm>
 
 #include <iostream>
+#include <memory>
 #include <limits>
 #include <cmath>
 
@@ -76,24 +77,26 @@ public:
         _terminal=true;
       
       }
-    double* nodes=new double [nbelems];
-    _elems.resize(nbelems);
-    for (ConnType i=0; i<nbelems; i++)
-      {
-        ConnType elem;
-        if (elems!=0)
-          elem= elems[i];
-        else
-          elem=i;
+    double median = std::numeric_limits<double>::max();
+    {
+      std::unique_ptr<double[]> nodes( new double [nbelems] );
+      _elems.resize(nbelems);
+      for (ConnType i=0; i<nbelems; i++)
+        {
+          ConnType elem;
+          if (elems)
+            elem= elems[i];
+          else
+            elem=i;
 
-        _elems[i]=elem;
-        nodes[i]=bbs[elem*dim*2+(level%dim)*2];
-      }
-    if (_terminal) { delete[] nodes; return;}
+          _elems[i]=elem;
+          nodes[i]=bbs[elem*dim*2+(level%dim)*2];
+        }
+      if (_terminal) { return; }
 
-    std::nth_element<double*>(nodes, nodes+nbelems/2, nodes+nbelems);
-    double median = *(nodes+nbelems/2);
-    delete[] nodes;
+      std::nth_element<double*>(nodes.get(), nodes.get()+nbelems/2, nodes.get()+nbelems);
+      median = *(nodes.get()+nbelems/2);
+    }
     // std:: cout << *median <<std::endl;
 
     std::vector<ConnType> new_elems_left;
index db5fd091850b2c5a5d0f48cdd434197939a7d1bf..fe9e99204e38e313919654def3764d346b638425 100644 (file)
@@ -36,6 +36,30 @@ namespace INTERP_KERNEL
    *
    */
   BoundingBox::BoundingBox(const double** pts, const unsigned numPts)
+  {
+    initializeWith(pts,numPts);
+  }
+
+  void BoundingBox::fillInXMinXmaxYminYmaxZminZmaxFormat(double data[6]) const
+  {
+    data[0] = this->getCoordinate(BoundingBox::XMIN);
+    data[1] = this->getCoordinate(BoundingBox::XMAX);
+    data[2] = this->getCoordinate(BoundingBox::YMIN);
+    data[3] = this->getCoordinate(BoundingBox::YMAX);
+    data[4] = this->getCoordinate(BoundingBox::ZMIN);
+    data[5] = this->getCoordinate(BoundingBox::ZMAX);
+  }
+
+  /**
+   * Constructor creating box from an array of the points corresponding
+   * to the vertices of the element.
+   * Each point is represented by an array of three doubles.
+   *
+   * @param pts     array of points 
+   * @param numPts  number of vertices
+   *
+   */
+  void BoundingBox::initializeWith(const double** pts, const unsigned numPts)
   {
     // initialize with first two points
     const double *pt0(pts[0]);
index 52641ccf347f65e58cfb7fc22c4619dfdeab6573..4c7919538342e4963d4e9cddcb364fc956165b7e 100644 (file)
@@ -33,15 +33,20 @@ namespace INTERP_KERNEL
   class INTERPKERNEL_EXPORT BoundingBox 
   {
   public:
-
     /// Enumeration representing the six coordinates that define the bounding box
     enum BoxCoord { XMIN = 0, YMIN = 1, ZMIN = 2, XMAX = 3, YMAX = 4, ZMAX = 5 };
-        
+    
+    BoundingBox() { }
+
     BoundingBox(const double** pts, const unsigned numPts);
 
     BoundingBox(const BoundingBox& box1, const BoundingBox& box2);
 
     ~BoundingBox() { }
+    
+    void fillInXMinXmaxYminYmaxZminZmaxFormat(double data[6]) const;
+
+    void initializeWith(const double** pts, const unsigned numPts);
 
     bool isDisjointWith(const BoundingBox& box) const;
     
index dcd25a93815d7def599de806e879fadfe63f4768..fc1a2e43939c72ffc4a19556b71bc4120d610fa3 100755 (executable)
@@ -73,19 +73,17 @@ namespace INTERP_KERNEL
     // create BBTree structure
     // - get bounding boxes
     std::vector<double> bboxes(2*SPACEDIM*numSrcElems);
-    ConnType* srcElemIdx = new ConnType[numSrcElems];
     for(ConnType i = 0; i < numSrcElems ; ++i)
       {
         // get source bboxes in right order
         srcElems[i]->getBoundingBox()->toCompactData(bboxes.data()+6*i);
-        srcElemIdx[i] = srcElems[i]->getIndex();
       }
 
     adjustBoundingBoxes(bboxes);
     const double *bboxPtr(nullptr);
     if(numSrcElems>0)
       bboxPtr=&bboxes[0];
-    BBTree<SPACEDIM,ConnType> tree(bboxPtr, srcElemIdx, 0, numSrcElems);
+    BBTree<SPACEDIM,ConnType> tree(bboxPtr, nullptr, 0, numSrcElems);
     const ConnType *trgConnPtr(targetMesh.getConnectivityPtr()),*trgConnIPtr(targetMesh.getConnectivityIndexPtr());
     const ConnType *srcConnPtr(srcMesh.getConnectivityPtr()),*srcConnIPtr(srcMesh.getConnectivityIndexPtr());
     const double *trgCooPtr(targetMesh.getCoordinatesPtr()),*srcCooPtr(srcMesh.getCoordinatesPtr());
@@ -109,7 +107,6 @@ namespace INTERP_KERNEL
               }
           }
       }
-    delete [] srcElemIdx;
     for(ConnType i = 0 ; i < numSrcElems ; ++i)
       delete srcElems[i];
     return srcMesh.getNumberOfNodes();
index 6069c689e3f5dca3e599240df0e33d89fc41cc11..e813a11db787d0e6bb10ebd46bcbbcb23fb4382f 100755 (executable)
@@ -111,54 +111,37 @@ namespace INTERP_KERNEL
     // create BBTree structure
     // - get bounding boxes
     std::vector<double> bboxes(6 * numSrcElems);
-    ConnType* srcElemIdx = new ConnType[numSrcElems];
     for(ConnType i = 0; i < numSrcElems ; ++i)
       {
         // get source bboxes in right order
         const BoundingBox* box = srcElems[i]->getBoundingBox();
-        bboxes[6*i+0] = box->getCoordinate(BoundingBox::XMIN);
-        bboxes[6*i+1] = box->getCoordinate(BoundingBox::XMAX);
-        bboxes[6*i+2] = box->getCoordinate(BoundingBox::YMIN);
-        bboxes[6*i+3] = box->getCoordinate(BoundingBox::YMAX);
-        bboxes[6*i+4] = box->getCoordinate(BoundingBox::ZMIN);
-        bboxes[6*i+5] = box->getCoordinate(BoundingBox::ZMAX);
-
-        // source indices have to begin with zero for BBox, I think
-        srcElemIdx[i] = srcElems[i]->getIndex();
+        box->fillInXMinXmaxYminYmaxZminZmaxFormat(bboxes.data()+6*i);
       }
 
     // [ABN] Adjust 2D bounding box (those might be flat in the cases where the 2D surf are perfectly aligned with the axis)
     performAdjustmentOfBB(intersector, bboxes);
 
-    BBTree<3,ConnType> tree(bboxes.data(), srcElemIdx, 0, numSrcElems, 0.);
+    BBTree<3,ConnType> tree(bboxes.data(), nullptr, 0, numSrcElems, 0.);
 
     // for each target element, get source elements with which to calculate intersection
     // - calculate intersection by calling intersectCells
     for(ConnType i = 0; i < numTargetElems; ++i)
       {
         const BoundingBox* box = targetElems[i]->getBoundingBox();
-        const ConnType targetIdx = targetElems[i]->getIndex();
 
         // get target bbox in right order
         double targetBox[6];
-        targetBox[0] = box->getCoordinate(BoundingBox::XMIN);
-        targetBox[1] = box->getCoordinate(BoundingBox::XMAX);
-        targetBox[2] = box->getCoordinate(BoundingBox::YMIN);
-        targetBox[3] = box->getCoordinate(BoundingBox::YMAX);
-        targetBox[4] = box->getCoordinate(BoundingBox::ZMIN);
-        targetBox[5] = box->getCoordinate(BoundingBox::ZMAX);
+        box->fillInXMinXmaxYminYmaxZminZmaxFormat(targetBox);
 
         std::vector<ConnType> intersectElems;
 
         tree.getIntersectingElems(targetBox, intersectElems);
 
         if ( !intersectElems.empty() )
-            intersector->intersectCells(targetIdx, intersectElems, matrix);
+            intersector->intersectCells(i, intersectElems, matrix);
 
       }
 
-    delete [] srcElemIdx;
-
     DuplicateFacesType::iterator iter;
     for (iter = intersectFaces.begin(); iter != intersectFaces.end(); ++iter)
       {
index 38ca91132d9f3e558e9a178b6f871d7d577822fd..76f3056decdb63c1b8174131aa85f326f043d0aa 100755 (executable)
@@ -309,46 +309,31 @@ namespace INTERP_KERNEL
       // create BBTree structure
       // - get bounding boxes
     std::unique_ptr<double[]> bboxes( new double[6 * numSrcElems] );
-    std::unique_ptr<ConnType[]> srcElemIdx( new ConnType[numSrcElems] );
     for(ConnType i = 0; i < numSrcElems ; ++i)
       {
         // get source bboxes in right order
-        const BoundingBox* box = srcElems[i]->getBoundingBox();
-        bboxes[6*i+0] = box->getCoordinate(BoundingBox::XMIN);
-        bboxes[6*i+1] = box->getCoordinate(BoundingBox::XMAX);
-        bboxes[6*i+2] = box->getCoordinate(BoundingBox::YMIN);
-        bboxes[6*i+3] = box->getCoordinate(BoundingBox::YMAX);
-        bboxes[6*i+4] = box->getCoordinate(BoundingBox::ZMIN);
-        bboxes[6*i+5] = box->getCoordinate(BoundingBox::ZMAX);
-
-        // source indices have to begin with zero for BBox, I think
-        srcElemIdx[i] = srcElems[i]->getIndex();
+        const BoundingBox *box = srcElems[i]->getBoundingBox();
+        box->fillInXMinXmaxYminYmaxZminZmaxFormat(bboxes.get()+6*i);
       }
 
-    BBTree<3,ConnType> tree(bboxes.get(), srcElemIdx.get(), 0, numSrcElems);
+    BBTree<3,ConnType> tree(bboxes.get(), nullptr, 0, numSrcElems);
 
     // for each target element, get source elements with which to calculate intersection
     // - calculate intersection by calling intersectCells
     for(ConnType i = 0; i < numTargetElems; ++i)
       {
         const BoundingBox* box = targetElems[i]->getBoundingBox();
-        const ConnType targetIdx = targetElems[i]->getIndex();
 
         // get target bbox in right order
         double targetBox[6];
-        targetBox[0] = box->getCoordinate(BoundingBox::XMIN);
-        targetBox[1] = box->getCoordinate(BoundingBox::XMAX);
-        targetBox[2] = box->getCoordinate(BoundingBox::YMIN);
-        targetBox[3] = box->getCoordinate(BoundingBox::YMAX);
-        targetBox[4] = box->getCoordinate(BoundingBox::ZMIN);
-        targetBox[5] = box->getCoordinate(BoundingBox::ZMAX);
+        box->fillInXMinXmaxYminYmaxZminZmaxFormat(targetBox);
 
         std::vector<ConnType> intersectElems;
 
         tree.getIntersectingElems(targetBox, intersectElems);
 
         if ( !intersectElems.empty() )
-          intersector->intersectCells(targetIdx,intersectElems,result);
+          intersector->intersectCells(i,intersectElems,result);
       }
 
 #endif
index fdec33c6c25710adbb6198dd51477650949881db..63b4cc14798b4150f9e13e133665ee82f89b6149 100755 (executable)
@@ -85,49 +85,34 @@ namespace INTERP_KERNEL
     // create BBTree structure
     // - get bounding boxes
     std::vector<double> bboxes(6*numSrcElems);
-    std::unique_ptr<ConnType[]> srcElemIdx{ new ConnType[numSrcElems] };
     for(ConnType i = 0; i < numSrcElems ; ++i)
       {
         // get source bboxes in right order
         const BoundingBox* box = srcElems[i]->getBoundingBox();
-        bboxes[6*i+0] = box->getCoordinate(BoundingBox::XMIN);
-        bboxes[6*i+1] = box->getCoordinate(BoundingBox::XMAX);
-        bboxes[6*i+2] = box->getCoordinate(BoundingBox::YMIN);
-        bboxes[6*i+3] = box->getCoordinate(BoundingBox::YMAX);
-        bboxes[6*i+4] = box->getCoordinate(BoundingBox::ZMIN);
-        bboxes[6*i+5] = box->getCoordinate(BoundingBox::ZMAX);
-
-        srcElemIdx[i] = srcElems[i]->getIndex();
+        box->fillInXMinXmaxYminYmaxZminZmaxFormat(bboxes.data()+6*i);
       }
 
     adjustBoundingBoxes(bboxes);
     const double *bboxPtr = nullptr;
     if(numSrcElems>0)
       bboxPtr=bboxes.data();
-    BBTree<3,ConnType> tree(bboxPtr, srcElemIdx.get(), 0, numSrcElems);
+    BBTree<3,ConnType> tree(bboxPtr, nullptr, 0, numSrcElems);
 
     // for each target element, get source elements with which to calculate intersection
     // - calculate intersection by calling intersectCells
     for(ConnType i = 0; i < numTargetElems; ++i)
       {
         const BoundingBox* box = targetElems[i]->getBoundingBox();
-        const ConnType targetIdx = targetElems[i]->getIndex();
-
         // get target bbox in right order
         double targetBox[6];
-        targetBox[0] = box->getCoordinate(BoundingBox::XMIN);
-        targetBox[1] = box->getCoordinate(BoundingBox::XMAX);
-        targetBox[2] = box->getCoordinate(BoundingBox::YMIN);
-        targetBox[3] = box->getCoordinate(BoundingBox::YMAX);
-        targetBox[4] = box->getCoordinate(BoundingBox::ZMIN);
-        targetBox[5] = box->getCoordinate(BoundingBox::ZMAX);
+        box->fillInXMinXmaxYminYmaxZminZmaxFormat(targetBox);
 
         std::vector<ConnType> intersectElems;
 
         tree.getIntersectingElems(targetBox, intersectElems);
 
         if ( !intersectElems.empty() )
-          intersector->intersectCells(targetIdx,intersectElems,result);
+          intersector->intersectCells(i,intersectElems,result);
       }
     return intersector->getNumberOfColsOfResMatrix();
   }
index b0e7b8272197b645390438b7d979f02debebb52f..1ff56a61d4b3136ee11b11f33bfce5c04634abdc 100644 (file)
@@ -41,13 +41,11 @@ namespace INTERP_KERNEL
     template<class MyMeshType>
     MeshElement(const ConnType index, const MyMeshType& mesh);
     
-    ~MeshElement();
-    
-    ConnType getIndex() const { return _index; }
+    ~MeshElement() { }
     
     nbnodesincelltype getNumberOfNodes() const { return _number; }
     
-    const BoundingBox* getBoundingBox() const { return _box; }
+    const BoundingBox *getBoundingBox() const { return &_box; }
 
   private:
     /// disallow copying
@@ -56,13 +54,10 @@ namespace INTERP_KERNEL
     /// disallow assignment
     MeshElement& operator=(const MeshElement& elem);
 
-    /// global number of the element
-    const ConnType _index;
-
     nbnodesincelltype _number;
     
     /// bounding box of the element - does not change after having been initialised
-    BoundingBox* _box;
+    BoundingBox _box;
   };
 
   /**
index 2a21431ec143b900c0413aed2b8fcf9a489faa53..7aee107981b491e1a5e5f895e5a82480c0b010f8 100755 (executable)
@@ -28,6 +28,7 @@
 #include <assert.h>
 #include <type_traits>
 #include <limits>
+#include <memory>
 
 namespace INTERP_KERNEL
 {
@@ -41,35 +42,24 @@ namespace INTERP_KERNEL
   template<class ConnType>
   template<class MyMeshType>
   MeshElement<ConnType>::MeshElement(const ConnType index, const MyMeshType& mesh)
-    : _index(index), _number( 0 ), _box(nullptr)
+    : _number( 0 )
   {
     auto numberCore = mesh.getNumberOfNodesOfElement(OTT<typename MyMeshType::MyConnType,MyMeshType::My_numPol>::indFC(index));
     if(numberCore < std::numeric_limits<nbnodesincelltype>::max())
     {
       _number = static_cast< nbnodesincelltype >(numberCore);
-      const double**vertices = new const double*[_number];
+      std::unique_ptr<const double*[]> vertices( new const double*[_number] );
       for( nbnodesincelltype i = 0 ; i < _number ; ++i)
         vertices[i] = getCoordsOfNode(i , OTT<typename MyMeshType::MyConnType,MyMeshType::My_numPol>::indFC(index), mesh);
 
       // create bounding box
-      _box = new BoundingBox(vertices,_number);
-      delete [] vertices;
+      _box.initializeWith(vertices.get(),_number);
     }
     else
     {
-      std::cerr << "ERROR at index " << index << " : exceeding capacity !" << std::endl;
+      THROW_IK_EXCEPTION("ERROR at index " << index << " : exceeding capacity !");
     }
   }
-    
-  /**
-   * Destructor
-   *
-   */
-  template<class ConnType>
-  MeshElement<ConnType>::~MeshElement()
-  {
-    delete _box;
-  }
 
   /////////////////////////////////////////////////////////////////////
   /// ElementBBoxOrder                                    /////////////