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

tests/base/symmetric_tensor_07.cc [new file with mode: 0644]

diff --git a/tests/base/symmetric_tensor_07.cc b/tests/base/symmetric_tensor_07.cc
new file mode 100644 (file)
index 0000000..80d555a
--- /dev/null
@@ -0,0 +1,182 @@
+//----------------------------  symmetric_tensor_07.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_07.cc  ---------------------------
+
+// in symmetric_tensor_06 we have established that contracting with a
+// symmetric tensor by hand works as with a full tensor that is stored
+// in non-symmetric form. here make sure that we can abbreviate the contraction 
+
+#include "../tests.h"
+#include <base/symmetric_tensor.h>
+#include <base/tensor.h>
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+
+
+SymmetricTensor<2,1>
+operator * (const SymmetricTensor<4,1> &t,
+           const SymmetricTensor<2,1> &s)
+{
+  const unsigned int dim = 1;
+  SymmetricTensor<2,dim> tmp;
+  tmp[0][0] = t[0][0][0][0] * s[0][0];
+  return tmp;
+}
+
+
+
+SymmetricTensor<2,1>
+operator * (const SymmetricTensor<2,1> &s,
+           const SymmetricTensor<4,1> &t)
+{
+  const unsigned int dim = 1;
+  SymmetricTensor<2,dim> tmp;
+  tmp[0][0] = t[0][0][0][0] * s[0][0];
+  return tmp;
+}
+
+
+
+SymmetricTensor<2,2>
+operator * (const SymmetricTensor<4,2> &t,
+           const SymmetricTensor<2,2> &s)
+{
+  const unsigned int dim = 2;
+  SymmetricTensor<2,dim> tmp;
+
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=i; j<dim; ++j)
+      tmp[i][j] = t[i][j][0][0] * s[0][0] +
+                 t[i][j][1][1] * s[1][1] +
+                 2 * t[i][j][0][1] * s[0][1];
+
+  return tmp;
+}
+
+
+
+SymmetricTensor<2,2>
+operator * (const SymmetricTensor<2,2> &s,
+           const SymmetricTensor<4,2> &t)
+{
+  const unsigned int dim = 2;
+  SymmetricTensor<2,dim> tmp;
+
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=i; j<dim; ++j)
+      tmp[i][j] = s[0][0] * t[0][0][i][j] * +
+                 s[1][1] * t[1][1][i][j] +
+                 2 * s[0][1] * t[0][1][i][j];
+
+  return tmp;
+}
+
+
+
+SymmetricTensor<2,3>
+operator * (const SymmetricTensor<4,3> &t,
+           const SymmetricTensor<2,3> &s)
+{
+  const unsigned int dim = 3;
+  SymmetricTensor<2,dim> tmp;
+
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=i; j<dim; ++j)
+      tmp[i][j] = t[i][j][0][0] * s[0][0] +
+                 t[i][j][1][1] * s[1][1] +
+                 t[i][j][2][2] * s[2][2] +
+                 2 * t[i][j][0][1] * s[0][1] +
+                 2 * t[i][j][0][2] * s[0][2] +
+                 2 * t[i][j][1][2] * s[1][2];
+
+  return tmp;
+}
+
+
+
+SymmetricTensor<2,3>
+operator * (const SymmetricTensor<2,3> &s,
+           const SymmetricTensor<4,3> &t)
+{
+  const unsigned int dim = 3;
+  SymmetricTensor<2,dim> tmp;
+
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=i; j<dim; ++j)
+      tmp[i][j] = s[0][0] * t[0][0][i][j] +
+                 s[1][1] * t[1][1][i][j] +
+                 s[2][2] * t[2][2][i][j] +
+                 2 * s[0][1] * t[0][1][i][j] +
+                 2 * s[0][2] * t[0][2][i][j] +
+                 2 * s[1][2] * t[1][2][i][j];
+
+  return tmp;
+}
+
+  
+
+template <int dim>
+void test ()
+{
+  const double lambda = 5,
+              mu     = 7;
+  SymmetricTensor<4,dim> ts;
+  Tensor<4,dim>          ta;
+  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] = (((i==k) && (j==l) ? mu : 0) +
+                                            ((i==l) && (j==k) ? mu : 0) +
+                                            ((i==j) && (k==l) ? lambda : 0));
+         
+  SymmetricTensor<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));
+
+  bs = ts * as;
+  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());
+
+       deallog << as[i][j] << ' ' << bs[i][i] << std::endl;
+      }
+
+                                  // also test that the elasticity
+                                  // tensor is positive definite
+  deallog << as * ts * as << std::endl;
+  Assert (as * ts * as > 0, ExcInternalError());
+}
+
+  
+
+
+int main ()
+{
+  std::ofstream logfile("symmetric_tensor_07.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.