[cig-commits] r14081 - cs/cigma/trunk/src

luis at geodynamics.org luis at geodynamics.org
Wed Feb 18 08:14:33 PST 2009


Author: luis
Date: 2009-02-18 08:14:32 -0800 (Wed, 18 Feb 2009)
New Revision: 14081

Modified:
   cs/cigma/trunk/src/MeshPart.cpp
   cs/cigma/trunk/src/MeshPart.h
   cs/cigma/trunk/src/core_readers.cpp
   cs/cigma/trunk/src/io_hdf5_reader.cpp
   cs/cigma/trunk/src/io_vtk_reader.cpp
Log:
Let the mesh instantiate its own locator class

Modified: cs/cigma/trunk/src/MeshPart.cpp
===================================================================
--- cs/cigma/trunk/src/MeshPart.cpp	2009-02-18 16:14:31 UTC (rev 14080)
+++ cs/cigma/trunk/src/MeshPart.cpp	2009-02-18 16:14:32 UTC (rev 14081)
@@ -3,6 +3,8 @@
 #include "io_hdf5_reader.h"
 #include "io_vtk_reader.h"
 #include "core_readers.h"
+#include "loc_bbox.h"
+#include "loc_kdtree.h"
 #include <cassert>
 #include <string>
 #include <sstream>
@@ -16,7 +18,14 @@
 shared_ptr<MeshPart> MeshPart::New(const MeshInfo& mesh_info)
 {
     TRI_LOG_STR("MeshPart::New()");
-    shared_ptr<MeshPart> mesh = ReadMeshPart(mesh_info);
+
+    shared_ptr<MeshPart> mesh;
+   
+    if (mesh_info)
+    {
+        mesh = ReadMeshPart(mesh_info);
+    }
+
     return mesh;
 }
 
@@ -48,6 +57,30 @@
     this->locator = loc;
 }
 
+void MeshPart::setLocator()
+{
+    const int ndim = this->n_dim();
+    const int ncells = this->n_cells();
+    if (ndim == 3)
+    {
+        if (ncells > BoundingBoxLocator::nnk)
+        {
+            shared_ptr<BoundingBoxLocator> loc(new BoundingBoxLocator);
+            loc->init(*this);
+            this->locator = loc;
+        }
+    }
+    else
+    {
+        if (ncells > KdtreeLocator::nnk)
+        {
+            shared_ptr<KdtreeLocator> loc(new KdtreeLocator);
+            loc->init(*this);
+            this->locator = loc;
+        }
+    }
+}
+
 void MeshPart::setCellType(Cell::type cell_type)
 {
     this->cell_type = cell_type;
@@ -97,6 +130,10 @@
 
 bool MeshPart::findCell2(double globalPoint[3], double uvw[3], int *cellIndex)
 {
+    const bool using_logger = false;
+
+    if (using_logger) { TRI_LOG_STR("MeshPart::findCell2()"); }
+
     assert(coords);
     assert(connect);
 
@@ -106,13 +143,15 @@
     *cellIndex = -1;
 
     // XXX: use cell iterator
-    shared_ptr<Cell> cell = Cell::New(this->cell_type);
+    shared_ptr<Cell> cell = Cell::New(cell_type);
     
     /* Attempt to use the locator if one is present */
     if (locator)
     {
-        locator->searchBoundingBox(globalPoint);
+        if (using_logger) { TRI_LOG_STR(">> Using locator"); }
 
+        locator->search(globalPoint);
+
         for (i = 0; i < locator->n_idx(); i++)
         {
             e = locator->idx(i);
@@ -128,6 +167,8 @@
         }
     }
 
+    if (using_logger) { TRI_LOG_STR(">> Point not found in index list. Checking every cell."); }
+
     /* Check every cell for the given point.
      * Since quadrature points are clustered together
      * on a given cell, remember the last cell that was
@@ -254,3 +295,26 @@
     }
 }
 
+void MeshPart::computeCellCentroids()
+{
+    TRI_LOG_STR("MeshPart::computeCellCentroids()");
+    shared_ptr<Cell> cell = this->getCell();
+    if (cell)
+    {
+        const int nel = this->n_cells();
+        const int ndim = this->n_dim();
+        centroid.resize(nel * ndim);
+        for (int e = 0; e < nel; e++)
+        {
+            this->getCell(e, *cell);
+
+            double c[3];
+            cell->centroid(c);
+
+            for (int j = 0; j < ndim; j++)
+            {
+                centroid[ndim*e + j] = c[j];
+            }
+        }
+    }
+}

Modified: cs/cigma/trunk/src/MeshPart.h
===================================================================
--- cs/cigma/trunk/src/MeshPart.h	2009-02-18 16:14:31 UTC (rev 14080)
+++ cs/cigma/trunk/src/MeshPart.h	2009-02-18 16:14:32 UTC (rev 14081)
@@ -3,6 +3,7 @@
 
 #include <boost/noncopyable.hpp>
 #include <boost/shared_ptr.hpp>
+#include <valarray>
 
 #include "NodeCoordinates.h"
 #include "ElementBlock.h"
@@ -23,8 +24,9 @@
     MeshPart();
     ~MeshPart();
 
+    int n_dim() const;
     int n_cells() const;
-    int n_dim() const;
+    int n_nodes() const;
 
     Cell::type getCellType() const;
     boost::shared_ptr<Cell> getCell() const;
@@ -40,12 +42,15 @@
     double getMaxCellDiameter() const;
 
     void computeCellVolumes();
+    void computeCellCentroids();
+
     double getVolume() const;
 
     /* direct setters */
     void setNodeCoordinates(const boost::shared_ptr<NodeCoordinates>& nc);
     void setElementBlock(const boost::shared_ptr<ElementBlock>& eb);
     void setLocator(const boost::shared_ptr<Locator>& loc);
+    void setLocator();
     void setCellType(Cell::type cell_type);
 
     /* incremental setters */
@@ -62,10 +67,12 @@
     boost::shared_ptr<NodeCoordinates> coords;
     boost::shared_ptr<Locator> locator;
     std::valarray<double> volume;
+    std::valarray<double> centroid;
 };
 
+inline int cigma::MeshPart::n_dim() const { return coords->n_dim(); }
 inline int cigma::MeshPart::n_cells() const { return connect->n_cells(); }
-inline int cigma::MeshPart::n_dim() const { return coords->n_dim(); }
+inline int cigma::MeshPart::n_nodes() const { return coords->n_points(); }
 inline cigma::Cell::type cigma::MeshPart::getCellType() const { return cell_type; }
 
 #endif

Modified: cs/cigma/trunk/src/core_readers.cpp
===================================================================
--- cs/cigma/trunk/src/core_readers.cpp	2009-02-18 16:14:31 UTC (rev 14080)
+++ cs/cigma/trunk/src/core_readers.cpp	2009-02-18 16:14:32 UTC (rev 14081)
@@ -5,8 +5,8 @@
 #include "Cell.h"
 #include "nc_array.h"
 #include "eb_array.h"
-#include "loc_bbox.h"
-#include "loc_kdtree.h"
+//#include "loc_bbox.h"
+//#include "loc_kdtree.h"
 
 #include "io_file_reader.h"
 #include "io_text_reader.h"
@@ -174,14 +174,16 @@
 
     if (mesh && mesh_info.use_locator)
     {
-        if (mesh->n_cells() > KdtreeLocator::nnk)
-        {
-            // XXX: is there a better way to initialize? inheritance on MeshPart perhaps?
-            //shared_ptr<BoundingBoxLocator> locator(new BoundingBoxLocator);
-            shared_ptr<KdtreeLocator> locator(new KdtreeLocator);
-            locator->init(*mesh);
-            mesh->setLocator(locator);
-        }
+        mesh->setLocator();
+
+        //if (mesh->n_cells() > KdtreeLocator::nnk)
+        //{
+        //    // XXX: is there a better way to initialize? inheritance on MeshPart perhaps?
+        //    //shared_ptr<BoundingBoxLocator> locator(new BoundingBoxLocator);
+        //    shared_ptr<KdtreeLocator> locator(new KdtreeLocator);
+        //    locator->init(*mesh);
+        //    mesh->setLocator(locator);
+        //}
     }
 
     return mesh;

Modified: cs/cigma/trunk/src/io_hdf5_reader.cpp
===================================================================
--- cs/cigma/trunk/src/io_hdf5_reader.cpp	2009-02-18 16:14:31 UTC (rev 14080)
+++ cs/cigma/trunk/src/io_hdf5_reader.cpp	2009-02-18 16:14:32 UTC (rev 14081)
@@ -7,8 +7,8 @@
 #include "io_hdf5.h"
 #include "nc_array.h"
 #include "eb_array.h"
-#include "loc_bbox.h"
-#include "loc_kdtree.h"
+//#include "loc_bbox.h"
+//#include "loc_kdtree.h"
 
 using namespace std;
 using namespace boost;
@@ -238,17 +238,19 @@
             }
         }
 
-        if (true)
-        {
-            if (mesh->n_cells() > KdtreeLocator::nnk)
-            {
-                // XXX: move this to a method in MeshPart
-                //shared_ptr<BoundingBoxLocator> locator(new BoundingBoxLocator);
-                shared_ptr<KdtreeLocator> locator(new KdtreeLocator);
-                locator->init(*mesh);
-                mesh->setLocator(locator);
-            }
-        }
+        mesh->setLocator();
+
+        //if (true)
+        //{
+        //    if (mesh->n_cells() > KdtreeLocator::nnk)
+        //    {
+        //        // XXX: move this to a method in MeshPart
+        //        //shared_ptr<BoundingBoxLocator> locator(new BoundingBoxLocator);
+        //        shared_ptr<KdtreeLocator> locator(new KdtreeLocator);
+        //        locator->init(*mesh);
+        //        mesh->setLocator(locator);
+        //    }
+        //}
     }
     else
     {

Modified: cs/cigma/trunk/src/io_vtk_reader.cpp
===================================================================
--- cs/cigma/trunk/src/io_vtk_reader.cpp	2009-02-18 16:14:31 UTC (rev 14080)
+++ cs/cigma/trunk/src/io_vtk_reader.cpp	2009-02-18 16:14:32 UTC (rev 14081)
@@ -12,8 +12,8 @@
 #include "nc_array.h"
 #include "eb_array.h"
 #include "core_array.h"
-#include "loc_bbox.h"
-#include "loc_kdtree.h"
+//#include "loc_bbox.h"
+//#include "loc_kdtree.h"
 
 #include "vtkUnstructuredGridReader.h"
 #include "vtkStructuredGridReader.h"
@@ -287,17 +287,19 @@
     mesh->connect   = this->getElementBlock(0);
     mesh->cell_type = this->getCellType(0);
 
+    mesh->setLocator();
+
     // XXX: move following block to a method in MeshPart
-    if (true)
-    {
-        if (mesh->n_cells() > KdtreeLocator::nnk)
-        {
-            //shared_ptr<BoundingBoxLocator> locator(new BoundingBoxLocator);
-            shared_ptr<KdtreeLocator> locator(new KdtreeLocator);
-            locator->init(*mesh);
-            mesh->setLocator(locator);
-        }
-    }
+    //if (true)
+    //{
+    //    if (mesh->n_cells() > KdtreeLocator::nnk)
+    //    {
+    //        //shared_ptr<BoundingBoxLocator> locator(new BoundingBoxLocator);
+    //        shared_ptr<KdtreeLocator> locator(new KdtreeLocator);
+    //        locator->init(*mesh);
+    //        mesh->setLocator(locator);
+    //    }
+    //}
 
     return mesh;
 }



More information about the CIG-COMMITS mailing list