Reference documentation for deal.II version 8.5.1
sacado_product_type.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2015 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__sacado_product_type_h
17 #define dealii__sacado_product_type_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/base/tensor.h>
21 #include <deal.II/base/symmetric_tensor.h>
22 #include <deal.II/base/template_constraints.h>
23 
24 #ifdef DEAL_II_WITH_TRILINOS
25 #include "Sacado.hpp"
26 
27 DEAL_II_NAMESPACE_OPEN
28 
29 template <typename T>
30 struct ProductType<Sacado::Fad::DFad<T>, float>
31 {
32  typedef Sacado::Fad::DFad<T> type;
33 };
34 
35 template <typename T>
36 struct ProductType<float, Sacado::Fad::DFad<T> >
37 {
38  typedef Sacado::Fad::DFad<T> type;
39 };
40 
41 template <typename T>
42 struct ProductType<Sacado::Fad::DFad<T>, double>
43 {
44  typedef Sacado::Fad::DFad<T> type;
45 };
46 
47 template <typename T>
48 struct ProductType<double, Sacado::Fad::DFad<T> >
49 {
50  typedef Sacado::Fad::DFad<T> type;
51 };
52 
53 template <typename T>
54 struct ProductType<Sacado::Fad::DFad<T>, int>
55 {
56  typedef Sacado::Fad::DFad<T> type;
57 };
58 
59 template <typename T>
60 struct ProductType<int, Sacado::Fad::DFad<T> >
61 {
62  typedef Sacado::Fad::DFad<T> type;
63 };
64 
65 template <typename T, typename U>
66 struct ProductType<Sacado::Fad::DFad<T>, Sacado::Fad::DFad<U> >
67 {
68  typedef Sacado::Fad::DFad<typename ProductType<T,U>::type > type;
69 };
70 
71 template <typename T>
72 struct EnableIfScalar<Sacado::Fad::DFad<T> >
73 {
74  typedef Sacado::Fad::DFad<T> type;
75 };
76 
77 
78 
88 template <int dim, typename Number, typename T>
89 inline
90 Sacado::Fad::DFad<T>
91 scalar_product (const SymmetricTensor<2,dim,Sacado::Fad::DFad<T> > &t1,
92  const Tensor<2,dim,Number> &t2)
93 {
94  Sacado::Fad::DFad<T> s = 0;
95  for (unsigned int i=0; i<dim; ++i)
96  for (unsigned int j=0; j<dim; ++j)
97  s += t1[i][j] * t2[i][j];
98  return s;
99 }
100 
101 
111 template <int dim, typename Number, typename T >
112 inline
113 Sacado::Fad::DFad<T>
115  const SymmetricTensor<2,dim,Sacado::Fad::DFad<T> > &t2)
116 {
117  return scalar_product(t2, t1);
118 }
119 
120 
130 template <int dim, typename Number, typename T>
131 inline
132 Sacado::Fad::DFad<T>
134  const Tensor<2,dim,Sacado::Fad::DFad<T> > &t2)
135 {
136  Sacado::Fad::DFad<T> s = 0;
137  for (unsigned int i=0; i<dim; ++i)
138  for (unsigned int j=0; j<dim; ++j)
139  s += t1[i][j] * t2[i][j];
140  return s;
141 }
142 
143 
153 template <int dim, typename Number, typename T >
154 inline
155 Sacado::Fad::DFad<T>
156 scalar_product (const Tensor<2,dim,Sacado::Fad::DFad<T> > &t1,
158 {
159  return scalar_product(t2, t1);
160 }
161 
162 DEAL_II_NAMESPACE_CLOSE
163 
164 #endif // DEAL_II_WITH_TRILINOS
165 
166 #endif
Sacado::Fad::DFad< T > scalar_product(const Tensor< 2, dim, Sacado::Fad::DFad< T > > &t1, const SymmetricTensor< 2, dim, Number > &t2)
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 > scalar_product(const Tensor< 2, dim, Number > &t1, const SymmetricTensor< 2, dim, Sacado::Fad::DFad< T > > &t2)
Definition: mpi.h:41
Sacado::Fad::DFad< T > scalar_product(const SymmetricTensor< 2, dim, Number > &t1, const Tensor< 2, dim, Sacado::Fad::DFad< T > > &t2)