]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Extend testcases.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 8 Nov 1998 20:37:40 +0000 (20:37 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 8 Nov 1998 20:37:40 +0000 (20:37 +0000)
git-svn-id: https://svn.dealii.org/trunk@658 0785d39b-7218-0410-832d-ea1e28bc413d

tests/base/tensor.cc
tests/deal.II/Makefile
tests/deal.II/gradients.cc
tests/deal.II/second_derivatives.cc [new file with mode: 0644]

index 3c030bb652a32f37c8b445baf12ab2968af50410..326e0ea5a3d7d6057543c0017ba8581a43874c6b 100644 (file)
@@ -1,27 +1,45 @@
 #include <base/tensor.h>
 #include <iostream>
 
+
+
 int main () {
-  const unsigned int dim=3;
+  double a[3][3] = {{1, 2, 3}, {3, 4, 5}, {6, 7, 8}};
+  double b[3][3] = {{25,31,37}, {45,57,69}, {75,96,117}};
   
-  Tensor<2,dim> t;
+  const unsigned int dim=3;
+  Tensor<2,dim> t(a);
   Tensor<2,dim> tt;
+  Tensor<2,dim> result(b);
 
+  cout << "t=" << endl;
   for (unsigned int i=0; i<dim; ++i)
-    for (unsigned int j=0; j<dim; ++j)
-      cout << i << ' ' << j << ':' << t[i][j] << endl;
-  cout << "----------------------------" << endl;
-       
-  t[0][0] = 1;
-  t[0][1] = 2;
-  for (unsigned int i=0; i<dim; ++i)
-    for (unsigned int j=0; j<dim; ++j)
-      cout << i << ' ' << j << ':' << t[i][j] << endl;
-  cout << "----------------------------" << endl;
-
+    {
+      for (unsigned int j=0; j<dim; ++j)
+       cout << t[i][j] << ' ';
+      cout << endl;
+    };
+  cout << endl;
+  
   contract (tt,t,t);
 
+  cout << "tt=" << endl;
   for (unsigned int i=0; i<dim; ++i)
-    for (unsigned int j=0; j<dim; ++j)
-      cout << i << ' ' << j << ':' << tt[i][j] << endl;
+    {
+      for (unsigned int j=0; j<dim; ++j)
+       cout << tt[i][j] << ' ';
+      cout << endl;
+    };
+  cout << endl;
+
+  if (tt==result)
+    {
+      cout << "Result OK." << endl;
+      return 0;
+    }
+  else
+    {
+      cout << "Result WRONG!" << endl;
+      return 1;
+    };
 };
index d80ad5bdb9521a71e5104e490a46e6897bcad2b4..37395421e40d89690975fff12b1618d4b092b4e2 100644 (file)
@@ -40,7 +40,7 @@ endif
 
 
 # rule to make executables
-%.testcase:
+%.testcase: %.cc $(libraries)
        @echo ============================ Compiling Testcase:   $<
        @$(CXX) $(flags) $< -o $@ $(libraries)
 
index 15a5f04a21346f0e6576f22d28f6492dc7f43538..ff0f2de02da9465e52090745805084a1a66e51d0 100644 (file)
@@ -36,6 +36,7 @@ int main () {
   
                                   // test for each of the four
                                   // shape functions
+  bool testcase_succeeded = true;
   for (unsigned int vertex=0; vertex<4; ++vertex)
     {
       val.clear ();
@@ -78,7 +79,15 @@ int main () {
           << ": "
           << (ok ? "OK" : "WRONG!")
           << endl;
+
+      if (!ok)
+       testcase_succeeded = false;
     };
 
   cout << "------------------------------------------------------" << endl;
+
+  if (testcase_succeeded)
+    return 0;
+  else
+    return 1;
 };
diff --git a/tests/deal.II/second_derivatives.cc b/tests/deal.II/second_derivatives.cc
new file mode 100644 (file)
index 0000000..b33d670
--- /dev/null
@@ -0,0 +1,163 @@
+// test for correctness of gradients on a given cell
+
+
+#include <grid/tria.h>
+#include <grid/tria_boundary.h>
+#include <grid/dof.h>
+#include <fe/fe_values.h>
+#include <fe/fe_lib.lagrange.h>
+#include <base/quadrature_lib.h>
+#include <grid/tria_iterator.h>
+#include <grid/dof_accessor.h>
+#include <lac/dvector.h>
+
+
+
+
+int main () {
+  Triangulation<2> tria;
+  tria.create_hypercube (0,1);
+
+  FELinear<2> fe;
+  DoFHandler<2> dof(&tria);
+  dof.distribute_dofs(fe);
+
+  StraightBoundary<2> b;
+  QTrapez<2> q;
+  FEValues<2> fevalues(fe,q,update_second_derivatives);
+  
+  
+  dVector val(4);
+
+  cout << "------------------------------------------------------------" << endl
+       << "Testing transformation of 2nd derivatives of shape function:" << endl;
+  
+                                  // test for each of the four
+                                  // shape functions. first loop:
+                                  // unit cell, second loop:
+                                  // one vertex moved
+  bool testcase_succeeded = true;
+  for (unsigned int loop=0; loop<2; ++loop)
+    {
+      cout << "Test loop: " << loop << endl
+          << "-----------" << endl;
+         
+                                  // move one vertex of the only cell
+      if (loop==1)
+       tria.begin_active()->vertex(2)(0) = 2;
+      fevalues.reinit (dof.begin_active(),b);
+      
+      for (unsigned int vertex=0; vertex<4; ++vertex)
+       {
+         val.clear ();
+         val(vertex) = 1;
+         
+         vector<Tensor<2,2> > derivs(4);
+         fevalues.get_function_2nd_derivatives (val, derivs);
+         
+         cout << "  Vertex " << vertex << ": ";
+         switch (loop)
+           {
+             case 0:
+                   for (unsigned int point=0; point<4; ++point)
+                     {
+                                                        // on the unit cell,
+                                                        // the second derivative
+                                                        // of a linear element
+                                                        // should be zero
+                       if (derivs[point] != Tensor<2,2>())
+                         {
+                           testcase_succeeded = false;
+                           cout << "WRONG! ";
+                         }
+                       else
+                         cout << "OK ";
+                     };
+                   break;
+
+             case 1:
+                                                    // are these numbers ok?
+                                                    // I have never checked
+                                                    // them, exept for the
+                                                    // symmetry of the tensors
+                                                    // and some of the signs of
+                                                    // the entries! Someone
+                                                    // should really try to
+                                                    // verify at least
+                                                    // some of the numbers
+                   static double _true_value[4][4][2][2]
+                     = { { {{0,1},
+                            {1,0}},
+                           {{0,0},
+                            {0,0}},
+                           {{0,1},
+                            {1,-2}},
+                           {{0,0},
+                            {0,0}}  },
+                         { {{0,-1},
+                            {-1,0}},
+                           {{0,0},
+                            {0,0}},
+                           {{0,-1},
+                            {-1,2}},
+                           {{0,0},
+                            {0,0}}  },
+                         { {{0,0},
+                            {0,0}},
+                           {{0,-.25},
+                            {-.25,0}},
+                           {{0,0},
+                            {0,0}},
+                           {{0,-.25},
+                            {-.25,0.5}}  },
+                         { {{0,0},
+                            {0,0}},
+                           {{0,.25},
+                            {.25,0}},
+                           {{0,0},
+                            {0,0}},
+                           {{0,.25},
+                            {.25,-.5}}  }  };
+                   static Tensor<2,2> true_value[4][4]
+                     = {{ Tensor<2,2>(_true_value[0][0]),
+                          Tensor<2,2>(_true_value[0][1]),
+                          Tensor<2,2>(_true_value[0][2]),
+                          Tensor<2,2>(_true_value[0][3])  },
+                        { Tensor<2,2>(_true_value[1][0]),
+                          Tensor<2,2>(_true_value[1][1]),
+                          Tensor<2,2>(_true_value[1][2]),
+                          Tensor<2,2>(_true_value[1][3])  },
+                        { Tensor<2,2>(_true_value[2][0]),
+                          Tensor<2,2>(_true_value[2][1]),
+                          Tensor<2,2>(_true_value[2][2]),
+                          Tensor<2,2>(_true_value[2][3])  },
+                        { Tensor<2,2>(_true_value[3][0]),
+                          Tensor<2,2>(_true_value[3][1]),
+                          Tensor<2,2>(_true_value[3][2]),
+                          Tensor<2,2>(_true_value[3][3])  }};
+                   
+                   for (unsigned int point=0; point<4; ++point)
+                     {
+                       if (derivs[point] != true_value[vertex][point])
+                         {
+                           testcase_succeeded = false;
+                           cout << "WRONG! ";
+                         }
+                       else
+                         cout << "OK ";
+                     };
+                   break;
+           };
+
+         cout << endl;
+       };
+    };
+  
+
+  cout << "------------------------------------------------------" << endl;
+
+  if (testcase_succeeded)
+    return 0;
+  else
+    return 1;
+};

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.