[cig-commits] r13176 - in cs/cigma/trunk: src tests/libcigma

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


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

Modified:
   cs/cigma/trunk/src/Cell.cpp
   cs/cigma/trunk/src/Cell.h
   cs/cigma/trunk/src/fe_hex8.cpp
   cs/cigma/trunk/src/fe_hex8.h
   cs/cigma/trunk/src/fe_quad4.cpp
   cs/cigma/trunk/src/fe_quad4.h
   cs/cigma/trunk/src/fe_tet4.cpp
   cs/cigma/trunk/src/fe_tet4.h
   cs/cigma/trunk/src/fe_tri3.cpp
   cs/cigma/trunk/src/fe_tri3.h
   cs/cigma/trunk/tests/libcigma/CellTest.cpp
   cs/cigma/trunk/tests/libcigma/CellTest.h
Log:
Added copy methods to Cell class (for use in iterator)

Modified: cs/cigma/trunk/src/Cell.cpp
===================================================================
--- cs/cigma/trunk/src/Cell.cpp	2008-10-29 22:11:50 UTC (rev 13175)
+++ cs/cigma/trunk/src/Cell.cpp	2008-10-29 22:11:53 UTC (rev 13176)
@@ -2,6 +2,7 @@
 #include <cassert>
 #include "Cell.h"
 #include "Numeric.h"
+#include "Exception.h"
 
 using namespace cigma;
 
@@ -9,19 +10,12 @@
 Cell::Cell()
 {
     //cout << "Calling Cell()" << endl;
-    //refverts = 0;
     globverts = 0;
 }
 
-
 Cell::~Cell()
 {
     //cout << "Calling ~Cell()" << endl;
-    /*
-    if (refverts != 0)
-    {
-        delete [] refverts;
-    } */
     if (globverts != 0)
     {
         delete [] globverts;
@@ -29,62 +23,62 @@
     }
 }
 
+void Cell::init()
+{
+    const int nno = n_nodes();
+    const int dim = n_celldim();
+    if (globverts == 0)
+    {
+        globverts = new double[nno * dim];
+    }
+}
 
-/*
-void Cell::set_reference_vertices(double *vertices)
+void Cell::reinit(const Cell& other)
 {
-    //
-    // This function should be only be called from the subclass constructor,
-    // when assigning the reference vertices to the cell.
-    //
-    int i,j;
     const int nno = n_nodes();
-    const int celldim = n_celldim();
-    const int dim = n_dim();
+    const int dim = n_celldim();
 
-    if (refverts != 0) delete [] refverts;
-    if (globverts != 0) delete [] globverts;
+    if (this->cell_type() != other.cell_type())
+    {
+        throw cigma::Exception("Cell::reinit", "Initializing from incompatible cell");
+    }
 
-    refverts = new double[nno*celldim];
-    globverts = new double[nno*dim];
+    if (other.globverts != 0)
+    {
+        Cell::init();
 
-    // copy data from vertices
+        for (int i = 0; i < nno * dim; i++)
+        {
+            globverts[i] = other.globverts[i];
+        }
+    }
+}
+
+void Cell::set_vertices(double *vertices, int vertexdim)
+{
+    int i,j;
+    const int nno = n_nodes();
+    const int dim = n_celldim();
     for (i = 0; i < nno; i++)
     {
-        for (j = 0; j < celldim; j++)
+        for (j = 0; j < dim; j++)
         {
-            int n = celldim*i + j;
-            refverts[n] = vertices[n];
-            globverts[dim*i+j] = vertices[n];
+            globverts[dim*i + j] = vertices[vertexdim*i + j];
         }
-        for (j = celldim; j < dim; j++)
-        {
-            globverts[dim*i + j] = 0.0;
-        }
     }
+}
 
-    return;
-} */
-
-
-void Cell::set_global_vertices(double *vertices, int vdim)
+void Cell::set_vertices(float *vertices, int vertexdim)
 {
-    // Copy data instead
     int i,j;
     const int nno = n_nodes();
-    const int celldim = n_celldim();
-    //const int dim = n_dim();
-    assert(vdim == celldim);
+    const int dim = n_celldim();
     for (i = 0; i < nno; i++)
     {
-        for (j = 0; j < vdim; j++)
+        for (j = 0; j < dim; j++)
         {
-            globverts[celldim*i + j] = vertices[vdim*i + j];
+            globverts[dim*i + j] = vertices[vertexdim*i + j];
         }
-        for (j = vdim; j < celldim; j++)
-        {
-            globverts[celldim*i + j] = 0.0;
-        }
     }
 }
 
@@ -98,7 +92,7 @@
     case 2: return jacobian(point[0], point[1], 0.0, jac);
     case 1: return jacobian(point[0], 0.0, 0.0, jac);
     }
-    assert(false);
+    throw cigma::Exception("Cell::jacobian", "Invalid cell dimension");
     return 0.0;
 }
 
@@ -396,7 +390,6 @@
 void Cell::bbox(double *min, double *max)
 {
     const int nno = n_nodes();
-    //const int nsd = n_dim();
     const int nsd = n_celldim();
     minmax(globverts, nno, nsd, min, max);
 }
@@ -405,7 +398,6 @@
 void Cell::centroid(double c[3])
 {
     const int nno = n_nodes();
-    //const int nsd = n_dim();
     const int nsd = n_celldim();
     cigma::centroid(globverts, nno, nsd, c);
 }

Modified: cs/cigma/trunk/src/Cell.h
===================================================================
--- cs/cigma/trunk/src/Cell.h	2008-10-29 22:11:50 UTC (rev 13175)
+++ cs/cigma/trunk/src/Cell.h	2008-10-29 22:11:53 UTC (rev 13176)
@@ -17,8 +17,12 @@
     
     virtual int n_nodes() const = 0;
     virtual int n_celldim() const = 0;
-    //virtual int n_dim() const = 0;
 
+    void init();
+    void reinit(const Cell &other);
+    void set_vertices(double *vertices, int vertexdim);
+    void set_vertices(float *vertices, int vertexdim);
+
     virtual void shape(int num, double *points, double *values) = 0;
     virtual void grad_shape(int num, double *points, double *values) = 0;
 
@@ -31,20 +35,17 @@
     virtual void xyz2uvw(double xyz[3], double uvw[3]);
     void uvw2xyz(double uvw[3], double xyz[3]);
     
-    /*
     typedef enum {
-        POINT = 0,
-        TRIANGLE,
-        QUADRANGLE,
-        TETRAHEDRON,
-        HEXAHEDRON
-    } Geometry;*/
-    //virtual Geometry geometry() = 0;
-    virtual boost::shared_ptr<Quadrature> default_quadrature() = 0;
+        TRI3,
+        QUAD4,
+        TET4,
+        HEX8
+    } type;
 
-    //void set_reference_vertices(double *vertices);
-    void set_global_vertices(double *vertices, int vdim);
+    virtual type cell_type() const = 0;
 
+    virtual boost::shared_ptr<Quadrature> default_quadrature() = 0; // XXX: move this out of Cell.h
+
     virtual double volume() = 0;
 
     virtual bool interior(double u, double v, double w) = 0;
@@ -55,8 +56,7 @@
     void centroid(double c[3]);
 
 public:
-    //double *refverts;   // [nno x celldim]
-    double *globverts;  // [nno x nsd]
+    double *globverts;  // [nno x celldim]
 
 };
 

Modified: cs/cigma/trunk/src/fe_hex8.cpp
===================================================================
--- cs/cigma/trunk/src/fe_hex8.cpp	2008-10-29 22:11:50 UTC (rev 13175)
+++ cs/cigma/trunk/src/fe_hex8.cpp	2008-10-29 22:11:53 UTC (rev 13176)
@@ -73,24 +73,14 @@
 
 hex8::hex8()
 {
-    /*
-    const int nno = 8;
-    const int celldim = 3;
-    double verts[nno*celldim] = {
-        -1.0, -1.0, -1.0,
-        +1.0, -1.0, -1.0,
-        +1.0, +1.0, -1.0,
-        -1.0, +1.0, -1.0,
-        -1.0, -1.0, +1.0,
-        +1.0, -1.0, +1.0,
-        +1.0, +1.0, +1.0,
-        -1.0, +1.0, +1.0
-    };
-    set_reference_vertices(verts);
-    */
-    globverts = new double[n_nodes() * n_celldim()];
+    Cell::init();
 }
 
+hex8::hex8(const hex8& h)
+{
+    Cell::reinit(h);
+}
+
 hex8::~hex8()
 {
 }

Modified: cs/cigma/trunk/src/fe_hex8.h
===================================================================
--- cs/cigma/trunk/src/fe_hex8.h	2008-10-29 22:11:50 UTC (rev 13175)
+++ cs/cigma/trunk/src/fe_hex8.h	2008-10-29 22:11:53 UTC (rev 13176)
@@ -12,13 +12,13 @@
 {
 public:
     hex8();
+    hex8(const hex8& h);
     ~hex8();
 
     int n_nodes() const { return 8; }
     int n_celldim() const { return 3; }
-    //int n_dim() const { return 3; }
 
-    //Geometry geometry() { return HEXAHEDRON; }
+    Cell::type cell_type() const { return HEX8; }
     boost::shared_ptr<Quadrature> default_quadrature();
 
     void shape(int num, double *points, double *values);

Modified: cs/cigma/trunk/src/fe_quad4.cpp
===================================================================
--- cs/cigma/trunk/src/fe_quad4.cpp	2008-10-29 22:11:50 UTC (rev 13175)
+++ cs/cigma/trunk/src/fe_quad4.cpp	2008-10-29 22:11:53 UTC (rev 13176)
@@ -42,20 +42,14 @@
 
 quad4::quad4()
 {
-    /*
-    const int nno = 4;
-    const int celldim = 2;
-    double verts[nno*celldim] = {
-        -1.0, -1.0,
-        +1.0, -1.0,
-        +1.0, +1.0,
-        -1.0, +1.0
-    };
-    set_reference_vertices(verts);
-    */
-    globverts = new double[n_nodes() * n_celldim()];
+    Cell::init();
 }
 
+quad4::quad4(const quad4& q)
+{
+    Cell::reinit(q);
+}
+
 quad4::~quad4()
 {
 }

Modified: cs/cigma/trunk/src/fe_quad4.h
===================================================================
--- cs/cigma/trunk/src/fe_quad4.h	2008-10-29 22:11:50 UTC (rev 13175)
+++ cs/cigma/trunk/src/fe_quad4.h	2008-10-29 22:11:53 UTC (rev 13176)
@@ -12,13 +12,13 @@
 {
 public:
     quad4();
+    quad4(const quad4& q);
     ~quad4();
 
     int n_nodes() const { return 4; }
     int n_celldim() const { return 2; }
-    //int n_dim() const { return 3; }
 
-    //Geometry geometry() { return QUADRANGLE; }
+    Cell::type cell_type() const { return QUAD4; }
     boost::shared_ptr<Quadrature> default_quadrature();
 
     void shape(int num, double *points, double *values);

Modified: cs/cigma/trunk/src/fe_tet4.cpp
===================================================================
--- cs/cigma/trunk/src/fe_tet4.cpp	2008-10-29 22:11:50 UTC (rev 13175)
+++ cs/cigma/trunk/src/fe_tet4.cpp	2008-10-29 22:11:53 UTC (rev 13176)
@@ -49,20 +49,14 @@
 
 tet4::tet4()
 {
-    /*
-    const int nno = 4;
-    const int celldim = 3;
-    double verts[nno*celldim] = {
-        0.0, 0.0, 0.0,
-        1.0, 0.0, 0.0,
-        0.0, 1.0, 0.0,
-        0.0, 0.0, 1.0
-    };
-    set_reference_vertices(verts);
-    */
-    globverts = new double[n_nodes() * n_celldim()];
+    Cell::init();
 }
 
+tet4::tet4(const tet4& t)
+{
+    Cell::reinit(t);
+}
+
 tet4::~tet4()
 {
 }

Modified: cs/cigma/trunk/src/fe_tet4.h
===================================================================
--- cs/cigma/trunk/src/fe_tet4.h	2008-10-29 22:11:50 UTC (rev 13175)
+++ cs/cigma/trunk/src/fe_tet4.h	2008-10-29 22:11:53 UTC (rev 13176)
@@ -12,13 +12,13 @@
 {
 public:
     tet4();
+    tet4(const tet4& t);
     ~tet4();
 
     int n_nodes() const { return 4; }
     int n_celldim() const { return 3; }
-    //int n_dim() const { return 3; }
 
-    //Geometry geometry() { return TETRAHEDRON; }
+    Cell::type cell_type() const { return TET4; }
     boost::shared_ptr<Quadrature> default_quadrature();
 
     void shape(int num, double *points, double *values);

Modified: cs/cigma/trunk/src/fe_tri3.cpp
===================================================================
--- cs/cigma/trunk/src/fe_tri3.cpp	2008-10-29 22:11:50 UTC (rev 13175)
+++ cs/cigma/trunk/src/fe_tri3.cpp	2008-10-29 22:11:53 UTC (rev 13176)
@@ -37,19 +37,14 @@
 
 tri3::tri3()
 {
-    /*
-    const int nno = 3;
-    const int celldim = 2;
-    double verts[nno*celldim] = {
-        0.0, 0.0,
-        1.0, 0.0,
-        0.0, 1.0
-    };
-    set_reference_vertices(verts);
-    */
-    globverts = new double[n_nodes() * n_celldim()];
+    Cell::init();
 }
 
+tri3::tri3(const tri3& t)
+{
+    Cell::reinit(t);
+}
+
 tri3::~tri3()
 {
 }

Modified: cs/cigma/trunk/src/fe_tri3.h
===================================================================
--- cs/cigma/trunk/src/fe_tri3.h	2008-10-29 22:11:50 UTC (rev 13175)
+++ cs/cigma/trunk/src/fe_tri3.h	2008-10-29 22:11:53 UTC (rev 13176)
@@ -12,13 +12,13 @@
 {
 public:
     tri3();
+    tri3(const tri3& t);
     ~tri3();
 
     int n_nodes() const { return 3; }
     int n_celldim() const { return 2; }
-    //int n_dim() const { return 3; }
 
-    //Geometry geometry() { return TRIANGLE; }
+    Cell::type cell_type() const { return TRI3; }
     boost::shared_ptr<Quadrature> default_quadrature();
 
     void shape(int num, double *points, double *values);

Modified: cs/cigma/trunk/tests/libcigma/CellTest.cpp
===================================================================
--- cs/cigma/trunk/tests/libcigma/CellTest.cpp	2008-10-29 22:11:50 UTC (rev 13175)
+++ cs/cigma/trunk/tests/libcigma/CellTest.cpp	2008-10-29 22:11:53 UTC (rev 13176)
@@ -79,6 +79,32 @@
 
 // ----------------------------------------------------------------------------
 
+void CellTest::test_copy()
+{
+    int i,j;
+    double data[4*3] = {
+        1, 2, 3,
+        4, 5, 6,
+        7, 8, 9,
+        10, 11, 12
+    };
+
+    tet4 t1,t2;
+    t1.set_vertices(data, 3);
+    t2.reinit(t1);
+    const int nno = t1.n_nodes();
+    const int dim = t1.n_celldim();
+    for (i = 0; i < nno; i++)
+    {
+        for (j = 0; j < dim; j++)
+        {
+            int n = dim*i + j;
+            CPPUNIT_ASSERT_DOUBLES_EQUAL(t1.globverts[n], t2.globverts[n], delta);
+            CPPUNIT_ASSERT_DOUBLES_EQUAL(t2.globverts[n], data[n], delta);
+        }
+    }
+}
+
 void CellTest::test_hex8()
 {
     hex8 cell;
@@ -241,7 +267,7 @@
          0.67238759, -0.87286283,  0.60803018
     };
 
-    cell.set_global_vertices(coords, 3);
+    cell.set_vertices(coords, 3);
     test_inverse(cell, 8+5, globpts, refpts);
 }
 

Modified: cs/cigma/trunk/tests/libcigma/CellTest.h
===================================================================
--- cs/cigma/trunk/tests/libcigma/CellTest.h	2008-10-29 22:11:50 UTC (rev 13175)
+++ cs/cigma/trunk/tests/libcigma/CellTest.h	2008-10-29 22:11:53 UTC (rev 13176)
@@ -10,6 +10,7 @@
     class CellTest : public CPPUNIT_NS::TestFixture
     {
         CPPUNIT_TEST_SUITE(CellTest);
+        CPPUNIT_TEST(test_copy);
         CPPUNIT_TEST(test_hex8);
         CPPUNIT_TEST(test_tet4);
         CPPUNIT_TEST(test_quad4);
@@ -19,7 +20,7 @@
     public:
         CellTest() {}
         ~CellTest() {}
-
+        void test_copy();
         void test_hex8();
         void test_tet4();
         void test_quad4();



More information about the CIG-COMMITS mailing list