]> https://gitweb.dealii.org/ - dealii.git/commitdiff
specialized scalar_product symmetric*tensor with sacado 1855/head
authoralberto sartori <alberto.sartori86@gmail.com>
Tue, 10 Nov 2015 12:06:35 +0000 (13:06 +0100)
committeralberto sartori <alberto.sartori86@gmail.com>
Tue, 10 Nov 2015 12:07:26 +0000 (13:07 +0100)
include/deal.II/base/sacado_product_type.h
tests/base/sacado_product_type_06.cc [new file with mode: 0644]
tests/base/sacado_product_type_06.with_trilinos=on.output [new file with mode: 0644]
tests/base/sacado_product_type_07.cc [new file with mode: 0644]
tests/base/sacado_product_type_07.with_trilinos=on.output [new file with mode: 0644]
tests/base/sacado_product_type_08.cc [new file with mode: 0644]
tests/base/sacado_product_type_08.with_trilinos=on.output [new file with mode: 0644]
tests/base/sacado_product_type_09.cc [new file with mode: 0644]
tests/base/sacado_product_type_09.with_trilinos=on.output [new file with mode: 0644]

index 5cf6042568667386345579eaa4a7ccea593ba63a..8767d2c257f5a69a0443a8e537ed2f8b1817c1da 100644 (file)
@@ -72,6 +72,91 @@ struct EnableIfScalar<Sacado::Fad::DFad<T> >
   typedef Sacado::Fad::DFad<T> type;
 };
 
+
+
+/**
+ * Compute the scalar product $a:b=\sum_{i,j} a_{ij}b_{ij}$ between two
+ * tensors $a,b$ of rank 2. We don't use <code>operator*</code> for this
+ * operation since the product between two tensors is usually assumed to be
+ * the contraction over the last index of the first tensor and the first index
+ * of the second tensor, for example $(a\cdot b)_{ij}=\sum_k a_{ik}b_{kj}$.
+ *
+ * @relates Tensor @relates SymmetricTensor
+ */
+template <int dim, typename Number, typename T>
+inline
+Sacado::Fad::DFad<T>
+scalar_product (const SymmetricTensor<2,dim,Sacado::Fad::DFad<T> > &t1,
+                const Tensor<2,dim,Number> &t2)
+{
+  Sacado::Fad::DFad<T> s = 0;
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      s += t1[i][j] * t2[i][j];
+  return s;
+}
+
+
+/**
+ * Compute the scalar product $a:b=\sum_{i,j} a_{ij}b_{ij}$ between two
+ * tensors $a,b$ of rank 2. We don't use <code>operator*</code> for this
+ * operation since the product between two tensors is usually assumed to be
+ * the contraction over the last index of the first tensor and the first index
+ * of the second tensor, for example $(a\cdot b)_{ij}=\sum_k a_{ik}b_{kj}$.
+ *
+ * @relates Tensor @relates SymmetricTensor
+ */
+template <int dim, typename Number, typename T >
+inline
+Sacado::Fad::DFad<T>
+scalar_product (const Tensor<2,dim,Number> &t1,
+                const SymmetricTensor<2,dim,Sacado::Fad::DFad<T> > &t2)
+{
+  return scalar_product(t2, t1);
+}
+
+
+/**
+ * Compute the scalar product $a:b=\sum_{i,j} a_{ij}b_{ij}$ between two
+ * tensors $a,b$ of rank 2. We don't use <code>operator*</code> for this
+ * operation since the product between two tensors is usually assumed to be
+ * the contraction over the last index of the first tensor and the first index
+ * of the second tensor, for example $(a\cdot b)_{ij}=\sum_k a_{ik}b_{kj}$.
+ *
+ * @relates Tensor @relates SymmetricTensor
+ */
+template <int dim, typename Number, typename T>
+inline
+Sacado::Fad::DFad<T>
+scalar_product (const SymmetricTensor<2,dim,Number> &t1,
+                const Tensor<2,dim,Sacado::Fad::DFad<T> > &t2)
+{
+  Sacado::Fad::DFad<T> s = 0;
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      s += t1[i][j] * t2[i][j];
+  return s;
+}
+
+
+/**
+ * Compute the scalar product $a:b=\sum_{i,j} a_{ij}b_{ij}$ between two
+ * tensors $a,b$ of rank 2. We don't use <code>operator*</code> for this
+ * operation since the product between two tensors is usually assumed to be
+ * the contraction over the last index of the first tensor and the first index
+ * of the second tensor, for example $(a\cdot b)_{ij}=\sum_k a_{ik}b_{kj}$.
+ *
+ * @relates Tensor @relates SymmetricTensor
+ */
+template <int dim, typename Number, typename T >
+inline
+Sacado::Fad::DFad<T>
+scalar_product (const Tensor<2,dim,Sacado::Fad::DFad<T> > &t1,
+                const SymmetricTensor<2,dim,Number> &t2)
+{
+  return scalar_product(t2, t1);
+}
+
 DEAL_II_NAMESPACE_CLOSE
 
 #endif // DEAL_II_WITH_TRILINOS
diff --git a/tests/base/sacado_product_type_06.cc b/tests/base/sacado_product_type_06.cc
new file mode 100644 (file)
index 0000000..9e83608
--- /dev/null
@@ -0,0 +1,53 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// test scalar_product between tensors and symmetric tensors with Sacado
+
+#include <iomanip>
+#include <fstream>
+
+#include <deal.II/base/symmetric_tensor.h>
+#include <deal.II/base/sacado_product_type.h>
+
+#include "../tests.h"
+
+
+int main()
+{
+  typedef Sacado::Fad::DFad<double> Sdouble;
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+
+  // check product with Tensor<2,dim>
+  Tensor<2,2,Sdouble> t;
+  SymmetricTensor<2,2,double> st;
+  Sdouble a(2,0,7.0);
+  Sdouble b(2,1,3.0);
+
+  for (unsigned int i=0; i<2; ++i)
+    for (unsigned int j=0; j<2; ++j)
+      {
+        t[i][j] = 2.*a+i*j*b;
+        st[i][j] = (1.+(i+1)*(j*2));
+      }
+
+  deallog << scalar_product(t,st) << std::endl;
+  deallog << scalar_product(st,t) << std::endl;
+
+}
diff --git a/tests/base/sacado_product_type_06.with_trilinos=on.output b/tests/base/sacado_product_type_06.with_trilinos=on.output
new file mode 100644 (file)
index 0000000..84cd33e
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::127.000 [ 16.0000 5.00000 ]
+DEAL::127.000 [ 16.0000 5.00000 ]
diff --git a/tests/base/sacado_product_type_07.cc b/tests/base/sacado_product_type_07.cc
new file mode 100644 (file)
index 0000000..4cb8f94
--- /dev/null
@@ -0,0 +1,56 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// test scalar_product between tensors and symmetric tensors with Sacado
+
+#include <iomanip>
+#include <fstream>
+
+#include <deal.II/base/symmetric_tensor.h>
+#include <deal.II/base/sacado_product_type.h>
+
+#include "../tests.h"
+
+
+int main()
+{
+  typedef Sacado::Fad::DFad<double> Sdouble;
+  typedef Sacado::Fad::DFad<Sdouble> SSdouble;
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+
+  // check product with Tensor<2,dim>
+  Tensor<2,2,SSdouble> t;
+  SymmetricTensor<2,2,double> st;
+  SSdouble a(2,0,7.0);
+  SSdouble b(2,1,3.0);
+  a.val() = Sdouble(2,0,7.0);
+  b.val() = Sdouble(2,1,3.0);
+
+  for (unsigned int i=0; i<2; ++i)
+    for (unsigned int j=0; j<2; ++j)
+      {
+        t[i][j] = 2.*a+i*j*b;
+        st[i][j] = (1.+(i+1)*(j*2));
+      }
+
+  deallog << scalar_product(t,st) << std::endl;
+  deallog << scalar_product(st,t) << std::endl;
+
+}
diff --git a/tests/base/sacado_product_type_07.with_trilinos=on.output b/tests/base/sacado_product_type_07.with_trilinos=on.output
new file mode 100644 (file)
index 0000000..4eef31d
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::127.000 [ 16.0000 5.00000 ] [ 16.0000 [ ] 5.00000 [ ] ]
+DEAL::127.000 [ 16.0000 5.00000 ] [ 16.0000 [ ] 5.00000 [ ] ]
diff --git a/tests/base/sacado_product_type_08.cc b/tests/base/sacado_product_type_08.cc
new file mode 100644 (file)
index 0000000..5709c11
--- /dev/null
@@ -0,0 +1,53 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// test scalar_product between tensors and symmetric tensors with Sacado
+
+#include <iomanip>
+#include <fstream>
+
+#include <deal.II/base/symmetric_tensor.h>
+#include <deal.II/base/sacado_product_type.h>
+
+#include "../tests.h"
+
+
+int main()
+{
+  typedef Sacado::Fad::DFad<double> Sdouble;
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+
+  // check product with Tensor<2,dim>
+  Tensor<2,2,double> t;
+  SymmetricTensor<2,2,Sdouble> st;
+  Sdouble a(2,0,7.0);
+  Sdouble b(2,1,3.0);
+
+  for (unsigned int i=0; i<2; ++i)
+    for (unsigned int j=0; j<2; ++j)
+      {
+        t[i][j] = (1.+(i+1)*(j*2));
+        st[i][j] = 2.*a+i*j*b;
+      }
+
+  deallog << scalar_product(t,st) << std::endl;
+  deallog << scalar_product(st,t) << std::endl;
+
+}
diff --git a/tests/base/sacado_product_type_08.with_trilinos=on.output b/tests/base/sacado_product_type_08.with_trilinos=on.output
new file mode 100644 (file)
index 0000000..7d96063
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::155.000 [ 20.0000 5.00000 ]
+DEAL::155.000 [ 20.0000 5.00000 ]
diff --git a/tests/base/sacado_product_type_09.cc b/tests/base/sacado_product_type_09.cc
new file mode 100644 (file)
index 0000000..9335820
--- /dev/null
@@ -0,0 +1,56 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// test scalar_product between tensors and symmetric tensors with Sacado
+
+#include <iomanip>
+#include <fstream>
+
+#include <deal.II/base/symmetric_tensor.h>
+#include <deal.II/base/sacado_product_type.h>
+
+#include "../tests.h"
+
+
+int main()
+{
+  typedef Sacado::Fad::DFad<double> Sdouble;
+  typedef Sacado::Fad::DFad<Sdouble> SSdouble;
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+
+  // check product with Tensor<2,dim>
+  Tensor<2,2,double> t;
+  SymmetricTensor<2,2,SSdouble> st;
+  SSdouble a(2,0,7.0);
+  SSdouble b(2,1,3.0);
+  a.val() = Sdouble(2,0,7.0);
+  b.val() = Sdouble(2,1,3.0);
+
+  for (unsigned int i=0; i<2; ++i)
+    for (unsigned int j=0; j<2; ++j)
+      {
+        t[i][j] = (1.+(i+1)*(j*2));
+        st[i][j] = 2.*a+i*j*b;
+      }
+
+  deallog << scalar_product(t,st) << std::endl;
+  deallog << scalar_product(st,t) << std::endl;
+
+}
diff --git a/tests/base/sacado_product_type_09.with_trilinos=on.output b/tests/base/sacado_product_type_09.with_trilinos=on.output
new file mode 100644 (file)
index 0000000..e3d7469
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::155.000 [ 20.0000 5.00000 ] [ 20.0000 [ ] 5.00000 [ ] ]
+DEAL::155.000 [ 20.0000 5.00000 ] [ 20.0000 [ ] 5.00000 [ ] ]

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.