]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add a way to get the tensor identity operator.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 31 May 2005 02:24:44 +0000 (02:24 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 31 May 2005 02:24:44 +0000 (02:24 +0000)
git-svn-id: https://svn.dealii.org/trunk@10784 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/symmetric_tensor.h
tests/base/symmetric_tensor_14.cc [new file with mode: 0644]
tests/results/i686-pc-linux-gnu+gcc3.2/base/symmetric_tensor_14.output [new file with mode: 0644]

index 68f93150e21ed71c534dd2aaf2845afd2ca1af1c..4a1f3eb20a0b6874649d8dc3c9e75500017e4565 100644 (file)
@@ -22,6 +22,7 @@ template <int rank, int dim> class SymmetricTensor;
 
 template <int dim> SymmetricTensor<2,dim> unit_symmetric_tensor ();
 template <int dim> SymmetricTensor<4,dim> deviator_tensor ();
+template <int dim> SymmetricTensor<4,dim> identity_tensor ();
 
 namespace internal
 {
@@ -882,6 +883,9 @@ class SymmetricTensor
 
     template <int dim2>
     friend SymmetricTensor<4,dim2> deviator_tensor ();
+
+    template <int dim2>
+    friend SymmetricTensor<4,dim2> identity_tensor ();
 };
 
 
@@ -2039,7 +2043,15 @@ unit_symmetric_tensor<3> ()
 
 
 /**
- * Return a unit symmetric tensor of rank 2 and dimension 2.
+ * Return the tensor of rank 4 that, when multiplied by a symmetric rank 2
+ * tensor <tt>t</tt> returns the deviator <tt>dev t</tt>. It is the operator
+ * representation of the linear deviator operator.
+ *
+ * For every tensor <tt>t</tt>, there holds the identity
+ * <tt>deviator(t)==deviator_tensor<dim>()*t</tt>, up to numerical
+ * round-off. The reason this operator representation is provided since one
+ * sometimes needs to invert operators like <tt>identity_tensor<dim>() +
+ * delta_t*deviator_tensor<dim>()</tt> or similar.
  * 
  * @relates SymmetricTensor
  * @author Wolfgang Bangerth, 2005
@@ -2072,6 +2084,47 @@ deviator_tensor ()
 
 
 
+/**
+ * Return the tensor of rank 4 that, when multiplied by a symmetric rank 2
+ * tensor <tt>t</tt> returns the deviator <tt>dev t</tt>. It is the operator
+ * representation of the linear deviator operator.
+ *
+ * For every tensor <tt>t</tt>, there holds the identity
+ * <tt>deviator(t)==deviator_tensor<dim>()*t</tt>, up to numerical
+ * round-off. The reason this operator representation is provided since one
+ * sometimes needs to invert operators like <tt>identity_tensor<dim>() +
+ * delta_t*deviator_tensor<dim>()</tt> or similar.
+ * 
+ * @relates SymmetricTensor
+ * @author Wolfgang Bangerth, 2005
+ */
+template <int dim>
+inline
+SymmetricTensor<4,dim>
+identity_tensor () 
+{
+  SymmetricTensor<4,dim> tmp;
+  
+                                   // fill the elements treating the diagonal
+  for (unsigned int i=0; i<dim; ++i)
+    tmp.data[i][i] = 1;
+
+                                   // then fill the ones that copy over the
+                                   // non-diagonal elements. note that during
+                                   // the double-contraction, we handle the
+                                   // off-diagonal elements twice, so simply
+                                   // copying requires a weight of 1/2
+  for (unsigned int i=dim;
+       i<internal::SymmetricTensorAccessors::StorageType<4,dim>
+                      ::n_rank2_components;
+       ++i)
+    tmp.data[i][i] = 0.5;
+  
+  return tmp;
+}
+
+
+
 /**
  * Return the symmetrized version of the full rank-2 tensor,
  * i.e. (t+transpose(t))/2, as a symmetric rank-2 tensor.
diff --git a/tests/base/symmetric_tensor_14.cc b/tests/base/symmetric_tensor_14.cc
new file mode 100644 (file)
index 0000000..ab75556
--- /dev/null
@@ -0,0 +1,58 @@
+//----------------------------  symmetric_tensor_14.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_14.cc  ---------------------------
+
+// test identity_tensor
+
+#include "../tests.h"
+#include <base/symmetric_tensor.h>
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+
+
+template <int dim>
+void test ()
+{
+  deallog << "dim=" << dim << std::endl;
+  
+  SymmetricTensor<2,dim> t;
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=i; j<dim; ++j)
+      t[i][j] = (1.+(i+1)*(j*2));
+
+  SymmetricTensor<2,dim> x = identity_tensor<dim>() * t;
+  Assert ((x-t).norm() < 1e-15*t.norm(), ExcInternalError());
+
+  deallog << "x=" << std::endl;
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      deallog << i << ' ' << j << ' ' << x[i][j] << std::endl;
+}
+
+  
+
+
+int main ()
+{
+  std::ofstream logfile("symmetric_tensor_14.output");
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  test<1> ();
+  test<2> ();
+  test<3> ();
+  
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/results/i686-pc-linux-gnu+gcc3.2/base/symmetric_tensor_14.output b/tests/results/i686-pc-linux-gnu+gcc3.2/base/symmetric_tensor_14.output
new file mode 100644 (file)
index 0000000..e890136
--- /dev/null
@@ -0,0 +1,22 @@
+
+DEAL::dim=1
+DEAL::x=
+DEAL::0 0 1.00
+DEAL::dim=2
+DEAL::x=
+DEAL::0 0 1.00
+DEAL::0 1 3.00
+DEAL::1 0 3.00
+DEAL::1 1 5.00
+DEAL::dim=3
+DEAL::x=
+DEAL::0 0 1.00
+DEAL::0 1 3.00
+DEAL::0 2 5.00
+DEAL::1 0 3.00
+DEAL::1 1 5.00
+DEAL::1 2 9.00
+DEAL::2 0 5.00
+DEAL::2 1 9.00
+DEAL::2 2 13.0
+DEAL::OK

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.