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

luis at geodynamics.org luis at geodynamics.org
Wed Oct 29 15:11:23 PDT 2008


Author: luis
Date: 2008-10-29 15:11:22 -0700 (Wed, 29 Oct 2008)
New Revision: 13161

Added:
   cs/cigma/trunk/src/py_MeshPart.h
Modified:
   cs/cigma/trunk/src/MeshPart.cpp
   cs/cigma/trunk/src/MeshPart.h
   cs/cigma/trunk/src/py_MeshPart.cpp
Log:
Updated cigma::MeshPart. Created header for the pyMeshPart binding

Modified: cs/cigma/trunk/src/MeshPart.cpp
===================================================================
--- cs/cigma/trunk/src/MeshPart.cpp	2008-10-29 22:11:20 UTC (rev 13160)
+++ cs/cigma/trunk/src/MeshPart.cpp	2008-10-29 22:11:22 UTC (rev 13161)
@@ -1,7 +1,132 @@
 #include "MeshPart.h"
-
 using namespace cigma;
+using boost::shared_ptr;
 
-MeshPart::MeshPart() {}
-MeshPart::~MeshPart() {}
+MeshPart::MeshPart()
+{
+}
 
+MeshPart::~MeshPart()
+{
+}
+
+void MeshPart::setCell(const shared_ptr<Cell>& cell)
+{
+    this->cell = cell;
+}
+
+void MeshPart::setNodeCoordinates(const shared_ptr<NodeCoordinates>& nc)
+{
+    this->coords = nc;
+}
+
+void MeshPart::setElementBlock(const shared_ptr<ElementBlock>& eb)
+{
+    this->connect = eb;
+}
+
+void MeshPart::setLocator(const shared_ptr<Locator>& loc)
+{
+    this->locator = loc;
+}
+
+void MeshPart::selectCell(int e)
+{
+    assert(cell);
+    this->getCellCoords(e, cell->globverts);
+}
+
+void MeshPart::getBoundingBox(double *minpt, double *maxpt)
+{
+    assert(coords);
+    coords->getBoundingBox(minpt, maxpt);
+}
+
+
+void MeshPart::getCellCoords(int cellIndex, double *globalCoords)
+{
+    assert(coords);
+    assert(connect);
+
+    int i,j;
+    const int nsd = coords->n_dim();
+    for (i = 0; i < connect->n_dofs(); i++)
+    {
+        const int n = connect->getId(cellIndex, i);
+
+        for (j = 0; j < nsd; j++)
+        {
+            globalCoords[3*i + j] = coords->getPoint(i,j);
+        }
+        
+        for (j = nsd; j < 3; j++)
+        {
+            globalCoords[3*i + j] = 0.0;
+        }
+    }
+}
+
+
+bool MeshPart::findCell(double globalPoint[3], double uvw[3], int *cellIndex)
+{
+    assert(coords);
+    assert(connect);
+
+    int i,e;
+    const int nel = connect->n_cells();
+
+    *cellIndex = -1;
+
+    /* Attempt to use the locator if one is present */
+    if (locator)
+    {
+        locator->searchBoundingBox(globalPoint);
+
+        for (i = 0; i < locator->n_idx(); i++)
+        {
+            e = locator->idx(i);
+
+            selectCell(e);
+            if (cell->global_interior(globalPoint))
+            {
+                *cellIndex = e;
+                return true;
+            }
+        }
+    }
+
+    /* Check every cell for the given point.
+     * Since quadrature points are clustered together
+     * on a given cell, remember the last cell that was
+     * checked and look there first.
+     */
+    static int last_cell = -1;
+    if ((0 <= last_cell) && (last_cell < nel))
+    {
+        selectCell(last_cell);
+        if (cell->global_interior(globalPoint))
+        {
+            *cellIndex = last_cell;
+            return true;
+        }
+    }
+
+    /* Search everything as a last resort. Don't forget
+     * to update the last_cell index to speed up the next
+     * few searches.
+     */
+    for (e = 0; e < nel; e++)
+    {
+        selectCell(e);
+        if (cell->global_interior(globalPoint))
+        {
+            *cellIndex = e;
+            last_cell = e;
+            return true;
+        }
+    }
+
+    /* give up */
+    return false;
+}
+

Modified: cs/cigma/trunk/src/MeshPart.h
===================================================================
--- cs/cigma/trunk/src/MeshPart.h	2008-10-29 22:11:20 UTC (rev 13160)
+++ cs/cigma/trunk/src/MeshPart.h	2008-10-29 22:11:22 UTC (rev 13161)
@@ -5,6 +5,8 @@
 #include "Locator.h"
 #include "NodeCoordinates.h"
 #include "ElementBlock.h"
+#include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
 
 namespace cigma
 {
@@ -12,11 +14,28 @@
 }
 
 
-class cigma::MeshPart
+class cigma::MeshPart : boost::noncopyable
 {
 public:
     MeshPart();
     ~MeshPart();
+
+    void setCell(const boost::shared_ptr<Cell>& cell); /* XXX */
+    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 selectCell(int e); /* XXX */
+
+    void getBoundingBox(double *minpt, double *maxpt);
+    void getCellCoords(int cellIndex, double *globalCoords);
+    bool findCell(double globalPoint[3], double uvw[3], int *cellIndex);
+
+public:
+    boost::shared_ptr<ElementBlock> connect;
+    boost::shared_ptr<NodeCoordinates> coords;
+    boost::shared_ptr<Locator> locator;
+    boost::shared_ptr<Cell> cell; /* XXX: replace by iterator */
 };
 
 #endif

Modified: cs/cigma/trunk/src/py_MeshPart.cpp
===================================================================
--- cs/cigma/trunk/src/py_MeshPart.cpp	2008-10-29 22:11:20 UTC (rev 13160)
+++ cs/cigma/trunk/src/py_MeshPart.cpp	2008-10-29 22:11:22 UTC (rev 13161)
@@ -1,11 +1,25 @@
-#include "MeshPart.h"
-#include <boost/python.hpp>
+#include "py_MeshPart.h"
 
+using namespace cigma;
+using namespace boost::python;
+
+// ----------------------------------------------------------------------------
+pyMeshPart::pyMeshPart()
+{
+}
+
+pyMeshPart::~pyMeshPart()
+{
+}
+
+
+// ----------------------------------------------------------------------------
+
 void export_MeshPart()
 {
     using namespace cigma;
     using namespace boost::python;
 
-    class_<MeshPart>("MeshPart")
+    class_<pyMeshPart, boost::noncopyable>("MeshPart")
         ;
 }

Added: cs/cigma/trunk/src/py_MeshPart.h
===================================================================
--- cs/cigma/trunk/src/py_MeshPart.h	                        (rev 0)
+++ cs/cigma/trunk/src/py_MeshPart.h	2008-10-29 22:11:22 UTC (rev 13161)
@@ -0,0 +1,13 @@
+#ifndef __PY_MESH_PART_H__
+#define __PY_MESH_PART_H__
+
+#include "numpy_util.h"
+#include "MeshPart.h"
+
+struct pyMeshPart : cigma::MeshPart
+{
+    pyMeshPart();
+    ~pyMeshPart();
+};
+
+#endif



More information about the CIG-COMMITS mailing list