tensor_tools.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_TENSOR_TOOLS_H
21 #define LIBMESH_TENSOR_TOOLS_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/compare_types.h"
26 
27 namespace libMesh
28 {
29  // Forward declarations
30  template <typename T> class TypeVector;
31  template <typename T> class VectorValue;
32  template <typename T> class TypeTensor;
33  template <typename T> class TensorValue;
34  template <unsigned int N, typename T> class TypeNTensor;
35 
36  namespace TensorTools
37  {
38  // Any tensor-rank-independent code will need to include
39  // tensor_tools.h, so we define a product/dot-product here, starting
40  // with the generic case to apply to scalars.
41  // Vector specializations will follow.
42 
43  template <typename T, typename T2>
44  inline
45  typename boostcopy::enable_if_c<
47  typename CompareTypes<T, T2>::supertype>::type
48  inner_product(const T& a, const T2& b)
49  { return a * b; }
50 
51  template <typename T, typename T2>
52  inline
55  { return a * b; }
56 
57  template <typename T, typename T2>
58  inline
61  { return a.contract(b); }
62 
63  template <unsigned int N, typename T, typename T2>
64  inline
67  { return a.contract(b); }
68 
69  template<typename T>
70  inline
71  T norm_sq(T a) { return a*a; }
72 
73  template<typename T>
74  inline
75  T norm_sq(std::complex<T> a) { return std::norm(a); }
76 
77  template <typename T>
78  inline
80  {return a.size_sq();}
81 
82  template <typename T>
83  inline
85  {return a.size_sq();}
86 
87  // Any tensor-rank-independent code will need to include
88  // tensor_tools.h, so we define rank-increasing and real-to-number type
89  // conversion functions here, starting with the generic case to apply
90  // to scalars.
91  // Tensor(and higher?) specializations will go in the tensor
92  // header(s).
93  template <typename T>
95  {
97  };
98 
99  template <typename T>
101  {
103  };
104 
105 
106  template <typename T>
108  {
110  };
111 
112  template <typename T>
114  {
116  };
117 
118 
119  template <typename T>
121  {
123  };
124 
125  template <unsigned int N, typename T>
127  {
129  };
130 
131 
132  // Also need rank-decreasing case
133  template <typename T>
135  {
136  // The default case is typically an error, but for simpler
137  // templated code we need it to be compatible with Number
138  // operations...
139  typedef T type;
140  };
141 
142  template <typename T>
144  {
145  typedef T type;
146  };
147 
148  template <typename T>
150  {
151  typedef T type;
152  };
153 
154  template <typename T>
156  {
158  };
159 
160  template <typename T>
162  {
164  };
165 
166  template <unsigned int N, typename T>
168  {
169  typedef TypeNTensor<N-1,T> type;
170  };
171 
172  // Handle the complex-valued case
173  template <typename T>
174  struct MakeNumber
175  {
176 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
177  typedef std::complex<T> type;
178 #else
179  typedef T type;
180 #endif
181  };
182 
183  template <typename T>
184  struct MakeNumber<std::complex<T> >
185  {
186  // Compile-time error: we shouldn't need to make numbers out of
187  // numbers
188  //typedef std::complex<T> type;
189  };
190 
191 
192  template <typename T>
193  struct MakeNumber<TypeVector<T> >
194  {
196  };
197 
198  template <typename T>
200  {
202  };
203 
204  template <typename T>
205  struct MakeNumber<TypeTensor<T> >
206  {
208  };
209 
210  template <typename T>
212  {
214  };
215 
216  template <unsigned int N, typename T>
217  struct MakeNumber<TypeNTensor<N,T> >
218  {
219 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
221 #else
223 #endif
224  };
225 
226  // A utility for determining real-valued (e.g. shape function)
227  // types from corresponding complex-valued types
228  template <typename T>
229  struct MakeReal
230  {
231  typedef T type;
232  };
233 
234  template <typename T>
235  struct MakeReal<std::complex<T> >
236  {
237  typedef T type;
238  };
239 
240  template <typename T>
241  struct MakeReal<TypeVector<T> >
242  {
244  };
245 
246  template <typename T>
247  struct MakeReal<VectorValue<T> >
248  {
250  };
251 
252  template <typename T>
253  struct MakeReal<TypeTensor<T> >
254  {
256  };
257 
258  template <typename T>
259  struct MakeReal<TensorValue<T> >
260  {
262  };
263 
264  template <unsigned int N, typename T>
265  struct MakeReal<TypeNTensor<N,T> >
266  {
268  };
269 
270  // Needed for ExactSolution to compile
272 
275 
279 
282 
285 
289 
290  }//namespace TensorTools
291 
292 }//namespace libMesh
293 
294 #endif // LIBMESH_TENSOR_TOOLS_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:07 UTC

Hosted By:
SourceForge.net Logo