]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Tests for full tensors.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 6 Apr 2005 15:22:50 +0000 (15:22 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 6 Apr 2005 15:22:50 +0000 (15:22 +0000)
git-svn-id: https://svn.dealii.org/trunk@10387 0785d39b-7218-0410-832d-ea1e28bc413d

tests/base/Makefile
tests/base/full_tensor_01.cc [new file with mode: 0644]
tests/base/full_tensor_02.cc [new file with mode: 0644]
tests/base/full_tensor_03.cc [new file with mode: 0644]
tests/base/full_tensor_04.cc [new file with mode: 0644]
tests/base/full_tensor_05.cc [new file with mode: 0644]
tests/base/full_tensor_06.cc [new file with mode: 0644]

index 6dfa667f9d09ef86f92e3c95caae2bc1cc89a2ee..71c44f4055d590fe38beebd9c33b0a3c63081795 100644 (file)
@@ -30,6 +30,7 @@ tests_x =  logtest \
           table \
           tensor \
           symmetric_tensor_* \
+          full_tensor_* \
            timer \
           threads \
           polynomial* \
diff --git a/tests/base/full_tensor_01.cc b/tests/base/full_tensor_01.cc
new file mode 100644 (file)
index 0000000..4e5d10d
--- /dev/null
@@ -0,0 +1,43 @@
+//----------------------------  full_tensor_01.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.
+//
+//----------------------------  full_tensor_01.cc  ---------------------------
+
+// test full 2x2 tensors
+
+#include "../tests.h"
+#include <base/tensor.h>
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+
+int main ()
+{
+  std::ofstream logfile("full_tensor_01.output");
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  
+  Tensor<2,2> t;
+  t[0][0] = 1;
+  t[1][1] = 2;
+  t[0][1] = 4;
+  t[1][0] = 4;
+                                   // make sure transposition doesn't change
+                                   // anything
+  Assert (t == transpose(t), ExcInternalError());
+
+                                   // check norm of tensor
+  Assert (std::fabs(t.norm() - std::sqrt(1.*1+2*2+2*4*4)) < 1e-14,
+          ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/base/full_tensor_02.cc b/tests/base/full_tensor_02.cc
new file mode 100644 (file)
index 0000000..7d9569a
--- /dev/null
@@ -0,0 +1,52 @@
+//----------------------------  full_tensor_02.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.
+//
+//----------------------------  full_tensor_02.cc  ---------------------------
+
+// test full 3x3 tensors
+
+#include "../tests.h"
+#include <base/tensor.h>
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+
+int main ()
+{
+  std::ofstream logfile("full_tensor_02.output");
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  
+  Tensor<2,3> t;
+  t[0][0] = 1;
+  t[1][1] = 2;
+  t[2][2] = 3;
+  t[0][1] = 4;
+  t[1][0] = 4;
+  t[0][2] = 5;
+  t[2][0] = 5;
+  t[1][2] = 6;
+  t[2][1] = 6;
+
+  Assert (t[0][1] == t[1][0], ExcInternalError());
+
+                                   // make sure transposition doesn't change
+                                   // anything
+  Assert (t == transpose(t), ExcInternalError());
+
+                                   // check norm of tensor
+  Assert (std::fabs(t.norm() - std::sqrt(1.*1+2*2+3*3+2*4*4+2*5*5+2*6*6))
+          < 1e-14,
+          ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/base/full_tensor_03.cc b/tests/base/full_tensor_03.cc
new file mode 100644 (file)
index 0000000..f2b58db
--- /dev/null
@@ -0,0 +1,53 @@
+//----------------------------  full_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.
+//
+//----------------------------  full_tensor_03.cc  ---------------------------
+
+// test full 2x2x2x2 tensors
+
+#include "../tests.h"
+#include <base/tensor.h>
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+
+int main ()
+{
+  std::ofstream logfile("full_tensor_03.output");
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  
+  Tensor<4,2> t;
+  t[0][0][0][0] = 1;
+  t[1][1][1][1] = 2;
+  t[0][1][0][1] = 3;
+  t[1][0][1][0] = 3;
+
+  Assert (t[0][1][0][1] == t[1][0][1][0], ExcInternalError());
+
+                                   // check norm of tensor
+  deallog << t.norm() << std::endl;
+
+                                   // make sure norm is induced by scalar
+                                   // product
+  double norm_sqr = 0;
+  for (unsigned int i=0; i<2; ++i)
+    for (unsigned int j=0; j<2; ++j)
+      for (unsigned int k=0; k<2; ++k)
+       for (unsigned int l=0; l<2; ++l)
+         norm_sqr += t[i][j][k][l] * t[i][j][k][l];
+  
+  Assert (std::fabs (t.norm()*t.norm() - norm_sqr) < 1e-14,
+          ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/base/full_tensor_04.cc b/tests/base/full_tensor_04.cc
new file mode 100644 (file)
index 0000000..fad59d5
--- /dev/null
@@ -0,0 +1,52 @@
+//----------------------------  full_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.
+//
+//----------------------------  full_tensor_04.cc  ---------------------------
+
+// test full 3x3x3x3 tensors
+
+#include "../tests.h"
+#include <base/tensor.h>
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+
+int main ()
+{
+  std::ofstream logfile("full_tensor_04.output");
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  
+  Tensor<4,3> t;
+  t[0][0][0][0] = 1;
+  t[1][1][1][1] = 2;
+  t[0][1][0][1] = 3;
+  t[1][0][1][0] = 3;
+
+  Assert (t[0][1][0][1] == t[1][0][1][0], ExcInternalError());
+
+                                   // check norm of tensor
+  deallog << t.norm() << std::endl;
+
+                                   // make sure norm is induced by scalar
+                                   // product
+  double norm_sqr = 0;
+  for (unsigned int i=0; i<2; ++i)
+    for (unsigned int j=0; j<2; ++j)
+      for (unsigned int k=0; k<2; ++k)
+       for (unsigned int l=0; l<2; ++l)
+         norm_sqr += t[i][j][k][l] * t[i][j][k][l];
+  Assert (std::fabs (t.norm()*t.norm() - norm_sqr) < 1e-14,
+          ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/base/full_tensor_05.cc b/tests/base/full_tensor_05.cc
new file mode 100644 (file)
index 0000000..368692f
--- /dev/null
@@ -0,0 +1,87 @@
+//----------------------------  full_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.
+//
+//----------------------------  full_tensor_05.cc  ---------------------------
+
+// make sure the tensor t_ijkl=delta_ik delta_jl
+// actually maps a rank-2 tensor onto twice itself
+
+#include "../tests.h"
+#include <base/tensor.h>
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+
+
+template <int dim>
+void test ()
+{
+  Tensor<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);
+         
+  Tensor<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, 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/2, ExcInternalError());
+}
+
+  
+
+
+int main ()
+{
+  std::ofstream logfile("full_tensor_05.output");
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  test<2> ();
+  test<3> ();
+  
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/base/full_tensor_06.cc b/tests/base/full_tensor_06.cc
new file mode 100644 (file)
index 0000000..dfd3b0f
--- /dev/null
@@ -0,0 +1,92 @@
+//----------------------------  full_tensor_06.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.
+//
+//----------------------------  full_tensor_06.cc  ---------------------------
+
+// make sure a tensor similar to the elasticity tensor for the
+// isotropic case works as expected by comparing with a full tensor
+
+#include "../tests.h"
+#include <base/tensor.h>
+#include <base/tensor.h>
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+
+
+template <int dim>
+void test ()
+{
+  const double lambda = 5,
+              mu     = 7;
+  Tensor<4,dim> ts;
+  Tensor<4,dim>          ta;
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      {
+       ta[i][j][i][j] += mu;
+       ta[i][j][j][i] += mu;
+       ta[i][i][j][j] += lambda;
+      }
+  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)
+         ts[i][j][k][l] = ta[i][j][k][l];
+  
+  Tensor<2,dim> as, bs;
+  Tensor<2,dim>          aa, ba;
+
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      as[i][j] = aa[i][j] = (1. + (i+1)*(j+1));
+      
+  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 << ": "
+                     << ta[i][j][k][l] << ' ' << ts[i][j][k][l] << ' '
+                     << aa[k][l] << ' ' << as[k][l]
+                     << std::endl;
+             tmp_ij += ts[i][j][k][l] * as[k][l];
+           }
+       bs[i][j] = tmp_ij;
+      }
+  double_contract (ba, ta, aa);
+  
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j) 
+      {
+       Assert (as[i][j] == aa[i][j], ExcInternalError());
+       Assert (bs[i][j] == ba[i][j], ExcInternalError());
+      }
+  
+}
+
+  
+
+
+int main ()
+{
+  std::ofstream logfile("full_tensor_06.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.