[cig-commits] r13166 - cs/cigma/trunk/tests/libcigma

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


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

Modified:
   cs/cigma/trunk/tests/libcigma/CellTest.cpp
Log:
A few sanity checks for the methods on cells

Modified: cs/cigma/trunk/tests/libcigma/CellTest.cpp
===================================================================
--- cs/cigma/trunk/tests/libcigma/CellTest.cpp	2008-10-29 22:11:29 UTC (rev 13165)
+++ cs/cigma/trunk/tests/libcigma/CellTest.cpp	2008-10-29 22:11:31 UTC (rev 13166)
@@ -1,3 +1,6 @@
+#include <iostream>
+using namespace std;
+
 #include "CellTest.h"
 using namespace libcigma;
 
@@ -5,25 +8,349 @@
 #include "fe_tet4.h"
 #include "fe_quad4.h"
 #include "fe_tri3.h"
+#include "Point.h"
 using namespace cigma;
 
+const double delta = 1e-8;
+
+static void test_interiors(Cell& cell, int npts, double *points, bool *expected_interiors)
+{
+    int i,j;
+    const int celldim = cell.n_celldim();
+    for (i = 0; i < npts; i++)
+    {
+        double *point = &points[celldim*i];
+        bool point_test = cell.interior(point);
+        CPPUNIT_ASSERT_EQUAL(point_test, expected_interiors[i]);
+    }
+}
+
+static void test_shapes(Cell& cell, int npts, double *points, double *expected_shapes)
+{
+    int i,j;
+    const int nno = cell.n_nodes();
+    const int celldim = cell.n_celldim();
+    for (i = 0; i < npts; i++)
+    {
+        double *point = &points[celldim*i];
+        double shapes[nno];
+        cell.shape(1, point, shapes);
+        for (j = 0; j < nno; j++)
+        {
+            CPPUNIT_ASSERT_DOUBLES_EQUAL(shapes[j], expected_shapes[nno*i + j], delta);
+        }
+    }
+}
+
+static void test_interpolation(Cell& cell, int npts, double *points, double *dofs, double *expected_values, int valdim)
+{
+    int i,j;
+    const int celldim = cell.n_celldim();
+    for (i = 0; i < npts; i++)
+    {
+        double *point = &points[celldim*i];
+        double value[valdim];
+        cell.interpolate(dofs, point, value, valdim);
+        for (j = 0; j < valdim; j++)
+        {
+            CPPUNIT_ASSERT_DOUBLES_EQUAL(value[j], expected_values[valdim*i + j], delta);
+        }
+    }
+}
+
+static void test_inverse(Cell& cell, int npts, double *globpts, double *expected_refpts)
+{
+    int i,j;
+    const int celldim = cell.n_celldim();
+    for (i = 0; i < npts; i++)
+    {
+        Point<3> xyz(&globpts[3*i], celldim);
+        Point<3> uvw;
+
+        cell.xyz2uvw(xyz.coord, uvw.coord);
+
+        for (j = 0; j < celldim; j++)
+        {
+            CPPUNIT_ASSERT_DOUBLES_EQUAL(uvw[j], expected_refpts[celldim*i + j], delta);
+        }
+    }
+}
+
+
+// ----------------------------------------------------------------------------
+
 void CellTest::test_hex8()
 {
     hex8 cell;
+    CPPUNIT_ASSERT_EQUAL(cell.n_nodes(), 8);
+    CPPUNIT_ASSERT_EQUAL(cell.n_celldim(), 3);
+
+    const int nno = 8;
+    const int celldim = 3;
+
+    // 
+    // points to use in this test routine
+    //
+    const int npts = 10;
+    double points[npts*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,
+         0.0,  0.0,  0.0,
+         2.0,  2.0,  2.0
+    };
+
+    //
+    // expected interior results
+    //
+    bool interiors[npts] = {
+        true, true, true, true,
+        true, true, true, true,
+        true, false
+    };
+
+    test_interiors(cell, npts, points, interiors);
+
+    //
+    // expected shape function values
+    //
+    double shape_values[npts*nno] = {
+        1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+        0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+        0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
+        0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 
+        0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 
+        0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 
+        0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 
+        0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 
+        0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
+        -0.125, 0.375, -1.125, 0.375, 0.375, -1.125, 3.375, -1.125
+    };
+
+    test_shapes(cell, npts, points, shape_values);
+
+    // 
+    // expected interpolation results
+    //
+    double scalar_dofs[2][nno*1] = {
+        {1, 2, 3, 4, 5, 6, 7, 8},
+        {1, 1, 1, 1, 1, 1, 1, 1}
+    };
+
+    double scalar_vals[2][npts*1] = {
+        {1, 2, 3, 4,  5, 6, 7, 8,  4.5, 8.5},
+        {1, 1, 1, 1,  1, 1, 1, 1,  1, 1},
+    };
+
+    double vector_dofs[2][nno*3] = {
+        { 11, 12, 13,
+          21, 22, 23,
+          31, 32, 33,
+          41, 42, 43,
+          51, 52, 53,
+          61, 62, 63,
+          71, 72, 73,
+          81, 82, 83 },
+        { 1, 1, 1,
+          1, 1, 0,
+          1, 0, 1,
+          1, 0, 0,
+          0, 1, 1,
+          0, 1, 0,
+          0, 0, 1,
+          0, 0, 0 },
+    };
+
+    double vector_vals[2][npts*3] = {
+        { 11, 12, 13,
+          21, 22, 23,
+          31, 32, 33,
+          41, 42, 43,
+          51, 52, 53,
+          61, 62, 63,
+          71, 72, 73,
+          81, 82, 83,
+          46, 47, 48,
+          86, 87, 88 },
+        { 1, 1, 1,
+          1, 1, 0,
+          1, 0, 1,
+          1, 0, 0,
+          0, 1, 1,
+          0, 1, 0,
+          0, 0, 1,
+          0, 0, 0,
+          0.5, 0.5, 0.5,
+          -0.5, -0.5, 2.5 },
+    };
+
+    for (int i = 0; i < 2; i++)
+    {
+        test_interpolation(cell, npts, points, scalar_dofs[i], scalar_vals[i], 1);
+        test_interpolation(cell, npts, points, vector_dofs[i], vector_vals[i], 3);
+    }
+
+    //
+    // expected results of inverse map
+    //
+    double coords[nno*3] = {
+        35.,  35.,  35.,
+        45.,  35.,  35.,
+        45.,  45.,  35.,
+        35.,  45.,  35.,
+        35.,  35.,  45.,
+        45.,  35.,  45.,
+        45.,  45.,  45.,
+        35.,  45.,  45.
+    };
+
+    double globpts[(8+5)*10] = {
+        35.,  35.,  35.,
+        45.,  35.,  35.,
+        45.,  45.,  35.,
+        35.,  45.,  35.,
+        35.,  35.,  45.,
+        45.,  35.,  45.,
+        45.,  45.,  45.,
+        35.,  45.,  45.,
+        41.65169581,  44.44171763,  41.20461625,
+        41.79305839,  41.01478074,  38.5994287 ,
+        40.20787609,  40.76457041,  41.36265142,
+        45.16112951,  43.69961499,  40.68446222,
+        43.36193796,  35.63568584,  43.0401509
+    };
+
+    double refpts[(8+5)*10] = {
+        -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,
+         0.33033916,  0.88834353,  0.24092325,
+         0.35861168,  0.20295615, -0.28011426,
+         0.04157522,  0.15291408,  0.27253028,
+         1.0322259 ,  0.739923  ,  0.13689244,
+         0.67238759, -0.87286283,  0.60803018
+    };
+
+    cell.set_global_vertices(coords, 3);
+    test_inverse(cell, 8+5, globpts, refpts);
 }
 
 void CellTest::test_tet4()
 {
     tet4 cell;
+    CPPUNIT_ASSERT_EQUAL(cell.n_nodes(), 4);
+    CPPUNIT_ASSERT_EQUAL(cell.n_celldim(), 3);
+
+    const int nno = 4;
+    const int celldim = 3;
+    const int npts = 6;
+
+    double points[npts*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,
+        0.1, 0.1, 0.1,
+        0.5, 0.5, 0.5
+    };
+
+    bool interiors[npts] = {
+        true, true, true, true,
+        true, false
+    };
+
+    double shape_values[npts*nno] = {
+        1.0, 0.0, 0.0, 0.0,
+        0.0, 1.0, 0.0, 0.0,
+        0.0, 0.0, 1.0, 0.0,
+        0.0, 0.0, 0.0, 1.0,
+        0.7, 0.1, 0.1, 0.1,
+        -0.5, 0.5, 0.5, 0.5
+    };
+
+    test_interiors(cell, npts, points, interiors);
+    test_shapes(cell, npts, points, shape_values);
 }
 
 void CellTest::test_quad4()
 {
     quad4 cell;
+    CPPUNIT_ASSERT_EQUAL(cell.n_nodes(), 4);
+    CPPUNIT_ASSERT_EQUAL(cell.n_celldim(), 2);
+
+    const int nno = 4;
+    const int celldim = 2;
+    const int npts = 6;
+
+    double points[npts*celldim] = {
+        -1.0, -1.0,
+        +1.0, -1.0,
+        +1.0, +1.0,
+        -1.0, +1.0,
+         0.0,  0.0,
+         2.0,  2.0
+    };
+
+    bool interiors[npts] = {
+        true, true, true, true,
+        true, false
+    };
+
+    double shape_values[npts*nno] = {
+        1.0, 0.0, 0.0, 0.0,
+        0.0, 1.0, 0.0, 0.0,
+        0.0, 0.0, 1.0, 0.0,
+        0.0, 0.0, 0.0, 1.0,
+        0.25, 0.25, 0.25, 0.25,
+        0.25, -0.75, 2.25, -0.75
+    };
+
+    test_interiors(cell, npts, points, interiors);
+    test_shapes(cell, npts, points, shape_values);
 }
 
 void CellTest::test_tri3()
 {
     tri3 cell;
+    CPPUNIT_ASSERT_EQUAL(cell.n_nodes(), 3);
+    CPPUNIT_ASSERT_EQUAL(cell.n_celldim(), 2);
+
+    const int nno = 3;
+    const int celldim = 2;
+    const int npts = 5;
+
+    double points[npts*celldim] = {
+        0.0, 0.0,
+        1.0, 0.0,
+        0.0, 1.0,
+        0.5, 0.5,
+        1.0, 1.0
+    };
+
+    bool interiors[npts] = {
+        true, true, true,
+        true, false
+    };
+
+    double shape_values[npts*nno] = {
+        1.0, 0.0, 0.0,
+        0.0, 1.0, 0.0,
+        0.0, 0.0, 1.0,
+        0.0, 0.5, 0.5,
+       -1.0, 1.0, 1.0
+    };
+
+    test_interiors(cell, npts, points, interiors);
+    test_shapes(cell, npts, points, shape_values);
 }
 



More information about the CIG-COMMITS mailing list