[cig-commits] r6672 - cs/cigma/trunk/sandbox/c/tests

luis at geodynamics.org luis at geodynamics.org
Tue Apr 24 15:09:47 PDT 2007


Author: luis
Date: 2007-04-24 15:09:46 -0700 (Tue, 24 Apr 2007)
New Revision: 6672

Added:
   cs/cigma/trunk/sandbox/c/tests/qr.h5
   cs/cigma/trunk/sandbox/c/tests/test_common.c
   cs/cigma/trunk/sandbox/c/tests/test_qr.c
   cs/cigma/trunk/sandbox/c/tests/test_tet4.c
Modified:
   cs/cigma/trunk/sandbox/c/tests/Makefile
Log:
Sanity checks for functions in cigma library


Modified: cs/cigma/trunk/sandbox/c/tests/Makefile
===================================================================
--- cs/cigma/trunk/sandbox/c/tests/Makefile	2007-04-24 22:08:22 UTC (rev 6671)
+++ cs/cigma/trunk/sandbox/c/tests/Makefile	2007-04-24 22:09:46 UTC (rev 6672)
@@ -1,16 +1,31 @@
 CC = gcc
-CFLAGS = -Wall -g 
+LD = gcc
+OPTIMIZE = -g
 INCLUDES = -I..
-LIBRARIES = -L..
+LIBRARIES = -L.. -Wl,--rpath -Wl,..
 LIBS = -lcigma -lhdf5
 
-TARGETS = test_mesh
+CFLAGS = -Wall -fPIC $(OPTIMIZE) $(INCLUDES) $(LIBRARIES)
 
+TARGETS = test_mesh \
+		  test_qr \
+		  test_tet4 \
+		  test_common
+
 all: $(TARGETS)
 
 test_mesh: test_mesh.c
-	$(CC) $(CFLAGS) $(INCLUDES) $(LIBRARIES) $< -o $@ $(LIBS)
+	$(CC) $(CFLAGS) $< -o $@ $(LIBS)
 
+test_qr: test_qr.c
+	$(CC) $(CFLAGS) $< -o $@ $(LIBS)
+
+test_tet4: test_tet4.c
+	$(CC) $(CFLAGS) $< -o $@ $(LIBS)
+
+test_common: test_common.c
+	$(CC) $(CFLAGS) $< -o $@ $(LIBS)
+
 clean:
 	rm -f $(TARGETS)
 

Added: cs/cigma/trunk/sandbox/c/tests/qr.h5
===================================================================
(Binary files differ)


Property changes on: cs/cigma/trunk/sandbox/c/tests/qr.h5
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: cs/cigma/trunk/sandbox/c/tests/test_common.c
===================================================================
--- cs/cigma/trunk/sandbox/c/tests/test_common.c	2007-04-24 22:08:22 UTC (rev 6671)
+++ cs/cigma/trunk/sandbox/c/tests/test_common.c	2007-04-24 22:09:46 UTC (rev 6672)
@@ -0,0 +1,57 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "common.h"
+
+double relative(double a, double b)
+{
+    return 100 * (b - a)/a;
+}
+
+void display(char *lhs, double a, double b)
+{
+    printf("%s = %g  (%g%%)\n", lhs, b-a, relative(a,b));
+}
+
+int main(int argc, char *argv[])
+{
+    // x = numpy.random.rand(3,3)
+    double x[3*3] = {
+        0.946938064293, 0.938422952181, 0.547150183861,
+        0.357024276576, 0.0915660318218, 0.744489960953,
+        0.254916722044, 0.401961600912, 0.899098289403
+    };
+
+    // y = numpy.random.rand(4,4)
+    double y[4*4] = {
+        0.749255681616, 0.601726829068, 0.322624932027, 0.552755245286,
+        0.512189205379, 0.565678439509, 0.36170329247, 0.648798303295,
+        0.751073452252, 0.234564764206, 0.336464581301, 0.81318932981,
+        0.887471111472, 0.346416322698, 0.169225404909, 0.436142450865
+    };
+
+    // z = 1000 * numpy.random.rand(4,4)
+    double z[4*4] = {
+        929.692592005, 373.574551898, 886.825332236, 762.855520112,
+        207.72419653, 912.45502321, 140.297093513, 411.368439554,
+        813.530640335, 127.759885901, 788.306182949, 531.528945614,
+        694.198635678, 321.436908736, 680.495936175, 132.123707609
+    };
+
+    // numpy.linalg.det
+    double x_det = -0.262805708233;
+    double y_det = 0.0043930480585;
+    double z_det = 1839051314.33;
+    
+
+    double x_det3x3, y_det4x4, z_det4x4;
+
+    x_det3x3 = det3x3(x);
+    y_det4x4 = det4x4(y);
+    z_det4x4 = det4x4(z);
+
+    display("det3x3(x) - det(x)", x_det, x_det3x3);
+    display("det4x4(y) - det(y)", y_det, y_det4x4);
+    display("det4x4(z) - det(z)", z_det, z_det4x4);
+
+    return EXIT_SUCCESS;
+}

Added: cs/cigma/trunk/sandbox/c/tests/test_qr.c
===================================================================
--- cs/cigma/trunk/sandbox/c/tests/test_qr.c	2007-04-24 22:08:22 UTC (rev 6671)
+++ cs/cigma/trunk/sandbox/c/tests/test_qr.c	2007-04-24 22:09:46 UTC (rev 6672)
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "qr.h"
+
+int main(int argc, char *argv[])
+{
+    int n, q;
+    int ierr;
+    rule_t qr;
+
+    char *path[] = {
+        "/FIAT/cools/tet_1",
+        "/FIAT/cools/tet_2",
+        "/FIAT/cools/tet_3",
+        "/FIAT/cools/tet_4",
+    };
+
+
+    for (n = 0; n < 4; n++)
+    {
+        ierr = qr_init1(&qr, "qr.h5", path[n]);
+
+        if (ierr < 0)
+        {
+            fprintf(stderr, "Could not find qr.h5");
+            return EXIT_FAILURE;
+        }
+
+        printf("Reading rule %s with %d points on %d dimensions\n",
+               path[n], qr.nq, qr.n);
+
+        for (q = 0; q < qr.nq; q++)
+        {
+            printf("w[%2d] = %lf; x[%2d] = (%+lf, %+lf, %+lf)\n",
+                   q, qr.weights[q],
+                   q, qr.points[3*q+0], qr.points[3*q+1], qr.points[3*q+2]);
+        }
+        printf("\n");
+
+        qr_fini(&qr);
+    }
+    return EXIT_SUCCESS;
+}

Added: cs/cigma/trunk/sandbox/c/tests/test_tet4.c
===================================================================
--- cs/cigma/trunk/sandbox/c/tests/test_tet4.c	2007-04-24 22:08:22 UTC (rev 6671)
+++ cs/cigma/trunk/sandbox/c/tests/test_tet4.c	2007-04-24 22:09:46 UTC (rev 6672)
@@ -0,0 +1,104 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "tet4.h"
+
+#define NTET 21
+double tets[NTET][12] = {
+    {-1, -1, -1,  +1, -1, -1,  -1, +1, -1,  -1, -1, +1},
+    {11750,250,-22250,11750,0,-22500,11500,0,-22500,11500,250,-22500},
+    {1750,16000,-7250,1500,15750,-7500,1500,16000,-7250,1500,16000,-7500},
+    {1000,1250,-24000,750,1250,-23750,750,1000,-23750,1000,1000,-23750},
+    {6250,250,-23500,6250,0,-23250,6000,250,-23250,6000,0,-23250},
+    {5750,500,-22750,5750,250,-22500,5500,500,-22500,5500,250,-22500},
+    {4500,500,-24000,4500,250,-23750,4750,250,-24000,4750,500,-24000},
+    {2000,8250,-8000,2000,8250,-8250,2000,8000,-8000,1750,8250,-8000},
+    {10750,14500,-13000,11000,14750,-13250,11000,14500,-13000,11000,14500,-13250},
+    {22250,16500,-13750,22250,16500,-13500,22000,16500,-13500,22250,16250,-13500},
+    {7500,10500,-14750,7750,10500,-14750,7750,10250,-14750,7750,10500,-15000},
+    {7500,3750,-15750,7500,4000,-15750,7500,4000,-15500,7750,4000,-15500},
+    {500,750,-23000,500,500,-22750,250,750,-22750,250,500,-22750},
+    {500,1750,-23750,750,1500,-23750,750,1750,-23500,500,1500,-23750},
+    {16000,750,-24000,16250,750,-23750,16000,500,-24000,16250,500,-24000},
+    {1500,3000,-24000,1500,3250,-24000,1750,3250,-23750,1750,3000,-24000},
+    {14750,500,-23250,15000,250,-23250,14750,250,-23250,15000,500,-23500},
+    {11000,18000,-4500,10750,17750,-4750,10750,18000,-4500,10750,18000,-4750},
+    {250,0,-24000,250,250,-24000,250,0,-23750,500,0,-24000},
+    {20000,24000,0,20250,24000,0,20250,23750,0,20250,24000,-250},
+    {20250,24000,0,20500,24000,0,20250,23750,0,20250,24000,-250}
+};
+
+#define NQ 14
+double cools_weights[NQ] = {
+    0.025396825396825397,
+    0.025396825396825397,
+    0.025396825396825397,
+    0.025396825396825397,
+    0.025396825396825397,
+    0.025396825396825397,
+    0.11811976632397428,
+    0.11811976632397428,
+    0.11811976632397428,
+    0.11811976632397428,
+    0.17711832891412096,
+    0.17711832891412096,
+    0.17711832891412096,
+    0.17711832891412096,
+};
+double cools_points[NQ*3] = {
+    -1.0,  0.0,  0.0,
+     0.0,  0.0, -1.0,
+    -1.0,  0.0, -1.0,
+    -1.0, -1.0,  0.0,
+     0.0, -1.0, -1.0,
+     0.0, -1.0,  0.0,
+    -0.79894646954959103, -0.79894646954959103, -0.79894646954959103,
+     0.39683940864877321, -0.79894646954959103, -0.79894646954959103,
+    -0.79894646954959103,  0.39683940864877321, -0.79894646954959103,
+    -0.79894646954959103, -0.79894646954959103,  0.39683940864877321,
+    -0.37125425301361559, -0.37125425301361559, -0.88623724095915324,
+    -0.37125425301361559, -0.37125425301361559, -0.37125425301361559,
+    -0.88623724095915324, -0.37125425301361559, -0.37125425301361559,
+    -0.37125425301361559, -0.88623724095915324, -0.37125425301361559
+};
+
+void display_points(double *qpts, double nq);
+
+int main(int argc, char *argv[])
+{
+    int n;
+    tet4_t T;
+    double J[9];
+    double tab[NQ*4];
+    double qpts[NQ*3];
+    double *verts;
+
+    for (n = 0; n < NTET; n++)
+    {
+        verts = (double *) &tets[n];
+        tet4_set1(&T, verts);
+
+        // calculate jacobian matrix
+        tet4_jacobian_2(&T, J);
+
+        // extract quadrature points
+        tet4_tabulate(cools_points, NQ, tab);
+        tet4_batch_eval3(verts, tab, NQ, qpts);
+
+        printf("tet[%d]\n", n);
+        display_points(qpts, NQ);
+        printf("\n");
+    }
+
+    return 0;
+}
+
+
+void display_points(double *qpts, double nq)
+{
+    int i;
+    for (i = 0; i < nq; i++)
+    {
+        printf("\tx[%2d] = (%lf, %lf, %lf)\n",
+               i, qpts[3*i], qpts[3*i+1], qpts[3*i+2]);
+    }
+}



More information about the cig-commits mailing list