]> https://gitweb.dealii.org/ - dealii.git/commitdiff
New testcase.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 29 Mar 2005 21:24:59 +0000 (21:24 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 29 Mar 2005 21:24:59 +0000 (21:24 +0000)
git-svn-id: https://svn.dealii.org/trunk@10300 0785d39b-7218-0410-832d-ea1e28bc413d

tests/base/symmetric_tensor_03.cc [new file with mode: 0644]
tests/base/symmetric_tensor_04.cc [new file with mode: 0644]
tests/base/symmetric_tensor_05.cc [new file with mode: 0644]

diff --git a/tests/base/symmetric_tensor_03.cc b/tests/base/symmetric_tensor_03.cc
new file mode 100644 (file)
index 0000000..72d35a9
--- /dev/null
@@ -0,0 +1,55 @@
+//----------------------------  symmetric_tensor_03.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2005 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  symmetric_tensor_03.cc  ---------------------------
+
+// test symmetric 2x2x2x2 tensors
+
+#include "../tests.h"
+#include <base/symmetric_tensor.h>
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+
+int main ()
+{
+  std::ofstream logfile("symmetric_tensor_03.output");
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  
+  SymmetricTensor<4,2> t;
+  t[0][0][0][0] = 1;
+  t[1][1][1][1] = 2;
+  t[0][1][0][1] = 3;
+
+  Assert (t[0][1][0][1] == t[1][0][1][0], ExcInternalError());
+
+                                   // check that if a single element is
+                                   // accessed, its transpose element gets the
+                                   // same value
+  t[1][0][0][1] = 4;
+  Assert (t[0][1][1][0] == 4, ExcInternalError());
+
+                                   // make sure transposition doesn't change
+                                   // anything
+  Assert (t == transpose(t), ExcInternalError());
+
+                                   // check norm of tensor
+  deallog << t.norm() << std::endl;
+
+                                   // make sure norm is induced by scalar
+                                   // product
+  Assert (std::fabs (t.norm()*t.norm() - t*t) < 1e-14,
+          ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/base/symmetric_tensor_04.cc b/tests/base/symmetric_tensor_04.cc
new file mode 100644 (file)
index 0000000..9a6af12
--- /dev/null
@@ -0,0 +1,55 @@
+//----------------------------  symmetric_tensor_04.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2005 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  symmetric_tensor_04.cc  ---------------------------
+
+// test symmetric 3x3x3x3 tensors
+
+#include "../tests.h"
+#include <base/symmetric_tensor.h>
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+
+int main ()
+{
+  std::ofstream logfile("symmetric_tensor_04.output");
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  
+  SymmetricTensor<4,3> t;
+  t[0][0][0][0] = 1;
+  t[1][1][1][1] = 2;
+  t[0][1][0][1] = 3;
+
+  Assert (t[0][1][0][1] == t[1][0][1][0], ExcInternalError());
+
+                                   // check that if a single element is
+                                   // accessed, its transpose element gets the
+                                   // same value
+  t[1][0][0][1] = 4;
+  Assert (t[0][1][1][0] == 4, ExcInternalError());
+
+                                   // make sure transposition doesn't change
+                                   // anything
+  Assert (t == transpose(t), ExcInternalError());
+
+                                   // check norm of tensor
+  deallog << t.norm() << std::endl;
+
+                                   // make sure norm is induced by scalar
+                                   // product
+  Assert (std::fabs (t.norm()*t.norm() - t*t) < 1e-14,
+          ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/base/symmetric_tensor_05.cc b/tests/base/symmetric_tensor_05.cc
new file mode 100644 (file)
index 0000000..833a077
--- /dev/null
@@ -0,0 +1,88 @@
+//----------------------------  symmetric_tensor_05.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2005 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  symmetric_tensor_05.cc  ---------------------------
+
+// make sure the tensor t_ijkl=delta_ik delta_jl + delta_il delta_jk
+// actually maps a rank-2 tensor onto twice itself
+
+#include "../tests.h"
+#include <base/symmetric_tensor.h>
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+
+
+template <int dim>
+void test ()
+{
+  SymmetricTensor<4,dim> t;
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      for (unsigned int k=0; k<dim; ++k)
+       for (unsigned int l=0; l<dim; ++l)
+         t[i][j][k][l] = (((i==k) && (j==l) ? 1 : 0) +
+                          ((i==l) && (j==k) ? 1 : 0));
+         
+  SymmetricTensor<2,dim> a, b;
+  a[0][0] = 1;
+  a[1][1] = 2;
+  a[0][1] = 3;
+
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      {
+       double tmp_ij = 0;
+       for (unsigned int k=0; k<dim; ++k)
+         for (unsigned int l=0; l<dim; ++l)
+           {
+             deallog << i << ' ' << j << ' ' << k << ' ' << l << ": "
+                     << t[i][j][k][l] << ' ' << a[k][l]
+                     << std::endl;
+             tmp_ij += t[i][j][k][l] * a[k][l];
+           }
+       b[i][j] = tmp_ij;
+      }  
+
+  Assert (a == b/2, ExcInternalError());
+
+                                  // try the same thing with scaled
+                                  // tensors etc
+  t *= 2;
+  b.clear ();
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      {
+       double tmp_ij = 0;
+       for (unsigned int k=0; k<dim; ++k)
+         for (unsigned int l=0; l<dim; ++l)
+           tmp_ij += t[i][j][k][l] * a[k][l];
+       b[i][j] = tmp_ij;
+      }
+
+  Assert (a == b/4, ExcInternalError());
+}
+
+  
+
+
+int main ()
+{
+  std::ofstream logfile("symmetric_tensor_05.output");
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  test<2> ();
+  test<3> ();
+  
+  deallog << "OK" << std::endl;
+}

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.