Intrepid
Intrepid_MiniTensor_Definitions.h
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions: Alejandro Mota (amota@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #if !defined(Intrepid_MiniTensor_Definitions_h)
43 #define Intrepid_MiniTensor_Definitions_h
44 
45 #include <complex>
46 
47 #include "Sacado.hpp"
48 #include "Sacado_mpl_disable_if.hpp"
49 
50 namespace Intrepid {
51 
55 typedef unsigned int Index;
56 
60 typedef long unsigned int LongCount;
61 
65 typedef double Real;
66 
70 typedef std::complex<Real> Complex;
71 
75 template <typename T> class Vector;
76 template <typename T> class Tensor;
77 template <typename T> class Tensor3;
78 template <typename T> class Tensor4;
79 
83 using Sacado::Promote;
84 using Sacado::mpl::lazy_disable_if;
85 
87 template <typename T>
88 struct is_vector {
89  static const bool value = false;
90 };
91 
92 template <typename T>
93 struct is_vector< Vector<T> > {
94  static const bool value = true;
95 };
96 
97 template <typename T>
98 struct apply_vector {
100 };
101 
103 template <typename T>
104 struct is_tensor {
105  static const bool value = false;
106 };
107 
108 template <typename T>
109 struct is_tensor< Tensor<T> > {
110  static const bool value = true;
111 };
112 
113 template <typename T>
114 struct apply_tensor {
116 };
117 
119 template <typename T>
120 struct is_tensor3 {
121  static const bool value = false;
122 };
123 
124 template <typename T>
125 struct is_tensor3< Tensor3<T> > {
126  static const bool value = true;
127 };
128 
129 template <typename T>
132 };
133 
135 template <typename T>
136 struct is_tensor4 {
137  static const bool value = false;
138 };
139 
140 template <typename T>
141 struct is_tensor4< Tensor4<T> > {
142  static const bool value = true;
143 };
144 
145 template <typename T>
148 };
149 
151 template <typename T>
152 struct order_1234 {
153  static const bool value = false;
154 };
155 
156 template <typename T>
157 struct order_1234< Vector<T> > {
158  static const bool value = true;
159 };
160 
161 template <typename T>
162 struct order_1234< Tensor<T> > {
163  static const bool value = true;
164 };
165 
166 template <typename T>
167 struct order_1234< Tensor3<T> > {
168  static const bool value = true;
169 };
170 
171 template <typename T>
172 struct order_1234< Tensor4<T> > {
173  static const bool value = true;
174 };
175 
176 } // namespace Intrepid
177 
178 namespace Sacado {
179 
183 template <>
184 struct Promote<double, Intrepid::Index> {
185  typedef double type;
186 };
187 
188 template <>
189 struct Promote<Intrepid::Index, double> {
190  typedef double type;
191 };
192 
193 template <>
194 struct Promote<float, Intrepid::Index> {
195  typedef float type;
196 };
197 
198 template <>
199 struct Promote<Intrepid::Index, float> {
200  typedef float type;
201 };
202 
203 template <>
204 struct Promote<std::complex<double>, Intrepid::Index> {
205  typedef std::complex<double> type;
206 };
207 
208 template <>
209 struct Promote<Intrepid::Index, std::complex<double> > {
210  typedef std::complex<double> type;
211 };
212 
213 template <>
214 struct Promote<std::complex<float>, Intrepid::Index> {
215  typedef std::complex<float> type;
216 };
217 
218 template <>
219 struct Promote<Intrepid::Index, std::complex<float> > {
220  typedef std::complex<float> type;
221 };
222 
226 template <typename T>
227 struct ScalarType< Intrepid::Vector<T> > {
228  typedef T type;
229 };
230 
231 template <typename T>
232 struct ValueType< Intrepid::Vector<T> > {
233  typedef T type;
234 };
235 
236 template <typename T>
237 struct IsADType< Intrepid::Vector<T> > {
238  static bool const value = IsADType<T>::value;
239 };
240 
241 template <typename T>
242 struct IsScalarType< Intrepid::Vector<T> > {
243  static bool const value = false;
244 };
245 
246 template <typename T>
247 struct Value< Intrepid::Vector<T> > {
248  typedef typename ValueType<T>::type value_type;
249  static const Intrepid::Vector<value_type> &
250  eval(Intrepid::Vector<T> const & x)
251  {
252  Intrepid::Index const
253  N = x.get_dimension();
254 
256  v(N);
257 
258  for (Intrepid::Index i = 0; i < N; ++i) {
259  v(i) = x(i).val();
260  }
261 
262  return v;
263  }
264 };
265 
266 template <typename T>
267 struct ScalarValue< Intrepid::Vector<T> > {
268  typedef typename ValueType<T>::type value_type;
269  typedef typename ScalarType<T>::type scalar_type;
270  static const Intrepid::Vector<scalar_type> &
271  eval(Intrepid::Vector<T> const & x)
272  {
273  Intrepid::Index const
274  N = x.get_dimension();
275 
277  v(N);
278 
279  for (Intrepid::Index i = 0; i < N; ++i) {
280  v(i) = ScalarValue<value_type>::eval(x(i).val());
281  }
282 
283  return v;
284  }
285 };
286 
287 template <typename T>
288 struct StringName< Intrepid::Vector<T> > {
289  static std::string
290  eval()
291  {
292  return std::string("Intrepid::Vector< ") +
293  StringName<T>::eval() + std::string(" >");
294  }
295 };
296 
297 template <typename T>
298 struct IsEqual< Intrepid::Vector<T> > {
299  static bool eval(T const & x, T const & y) { return x == y; }
300 };
301 
302 template <typename T>
303 struct IsStaticallySized< Intrepid::Vector<T> > {
304  static const bool value = false;
305 };
306 
310 template <typename T>
311 struct ScalarType< Intrepid::Tensor<T> > {
312  typedef T type;
313 };
314 
315 template <typename T>
316 struct ValueType< Intrepid::Tensor<T> > {
317  typedef T type;
318 };
319 
320 template <typename T>
321 struct IsADType< Intrepid::Tensor<T> > {
322  static bool const value = IsADType<T>::value;
323 };
324 
325 template <typename T>
326 struct IsScalarType< Intrepid::Tensor<T> > {
327  static bool const value = false;
328 };
329 
330 template <typename T>
331 struct Value< Intrepid::Tensor<T> > {
332  typedef typename ValueType<T>::type value_type;
333  static const Intrepid::Tensor<value_type> &
334  eval(Intrepid::Tensor<T> const & x)
335  {
336  Intrepid::Index const
337  N = x.get_dimension();
338 
340  v(N);
341 
342  for (Intrepid::Index i = 0; i < N; ++i) {
343  for (Intrepid::Index j = 0; j < N; ++j) {
344  v(i,j) = x(i,j).val();
345  }
346  }
347 
348  return v;
349  }
350 };
351 
352 template <typename T>
353 struct ScalarValue< Intrepid::Tensor<T> > {
354  typedef typename ValueType<T>::type value_type;
355  typedef typename ScalarType<T>::type scalar_type;
356  static const Intrepid::Tensor<scalar_type> &
357  eval(Intrepid::Tensor<T> const & x)
358  {
359  Intrepid::Index const
360  N = x.get_dimension();
361 
363  v(N);
364 
365  for (Intrepid::Index i = 0; i < N; ++i) {
366  for (Intrepid::Index j = 0; j < N; ++j) {
367  v(i,j) = ScalarValue<value_type>::eval(x(i,j).val());
368  }
369  }
370 
371  return v;
372  }
373 };
374 
375 template <typename T>
376 struct StringName< Intrepid::Tensor<T> > {
377  static std::string
378  eval()
379  {
380  return std::string("Intrepid::Tensor< ") +
381  StringName<T>::eval() + std::string(" >");
382  }
383 };
384 
385 template <typename T>
386 struct IsEqual< Intrepid::Tensor<T> > {
387  static bool eval(T const & x, T const & y) { return x == y; }
388 };
389 
390 template <typename T>
391 struct IsStaticallySized< Intrepid::Tensor<T> > {
392  static const bool value = false;
393 };
394 
398 template <typename T>
399 struct ScalarType< Intrepid::Tensor3<T> > {
400  typedef T type;
401 };
402 
403 template <typename T>
404 struct ValueType< Intrepid::Tensor3<T> > {
405  typedef T type;
406 };
407 
408 template <typename T>
409 struct IsADType< Intrepid::Tensor3<T> > {
410  static bool const value = IsADType<T>::value;
411 };
412 
413 template <typename T>
414 struct IsScalarType< Intrepid::Tensor3<T> > {
415  static bool const value = false;
416 };
417 
418 template <typename T>
419 struct Value< Intrepid::Tensor3<T> > {
420  typedef typename ValueType<T>::type value_type;
421  static const Intrepid::Tensor3<value_type> &
422  eval(Intrepid::Tensor3<T> const & x)
423  {
424  Intrepid::Index const
425  N = x.get_dimension();
426 
428  v(N);
429 
430  for (Intrepid::Index i = 0; i < N; ++i) {
431  for (Intrepid::Index j = 0; j < N; ++j) {
432  for (Intrepid::Index k = 0; k < N; ++k) {
433  v(i,j,k) = x(i,j,k).val();
434  }
435  }
436  }
437 
438  return v;
439  }
440 };
441 
442 template <typename T>
443 struct ScalarValue< Intrepid::Tensor3<T> > {
444  typedef typename ValueType<T>::type value_type;
445  typedef typename ScalarType<T>::type scalar_type;
446  static const Intrepid::Tensor3<scalar_type> &
447  eval(Intrepid::Tensor3<T> const & x)
448  {
449  Intrepid::Index const
450  N = x.get_dimension();
451 
453  v(N);
454 
455  for (Intrepid::Index i = 0; i < N; ++i) {
456  for (Intrepid::Index j = 0; j < N; ++j) {
457  for (Intrepid::Index k = 0; k < N; ++k) {
458  v(i,j,k) = ScalarValue<value_type>::eval(x(i,j,k).val());
459  }
460  }
461  }
462 
463  return v;
464  }
465 };
466 
467 template <typename T>
468 struct StringName< Intrepid::Tensor3<T> > {
469  static std::string
470  eval()
471  {
472  return std::string("Intrepid::Tensor3< ") +
473  StringName<T>::eval() + std::string(" >");
474  }
475 };
476 
477 template <typename T>
478 struct IsEqual< Intrepid::Tensor3<T> > {
479  static bool eval(T const & x, T const & y) { return x == y; }
480 };
481 
482 template <typename T>
483 struct IsStaticallySized< Intrepid::Tensor3<T> > {
484  static const bool value = false;
485 };
486 
490 template <typename T>
491 struct ScalarType< Intrepid::Tensor4<T> > {
492  typedef T type;
493 };
494 
495 template <typename T>
496 struct ValueType< Intrepid::Tensor4<T> > {
497  typedef T type;
498 };
499 
500 template <typename T>
501 struct IsADType< Intrepid::Tensor4<T> > {
502  static bool const value = IsADType<T>::value;
503 };
504 
505 template <typename T>
506 struct IsScalarType< Intrepid::Tensor4<T> > {
507  static bool const value = false;
508 };
509 
510 template <typename T>
511 struct Value< Intrepid::Tensor4<T> > {
512  typedef typename ValueType<T>::type value_type;
513  static const Intrepid::Tensor4<value_type> &
514  eval(Intrepid::Tensor4<T> const & x)
515  {
516  Intrepid::Index const
517  N = x.get_dimension();
518 
520  v(N);
521 
522  for (Intrepid::Index i = 0; i < N; ++i) {
523  for (Intrepid::Index j = 0; j < N; ++j) {
524  for (Intrepid::Index k = 0; k < N; ++k) {
525  for (Intrepid::Index l = 0; l < N; ++l) {
526  v(i,j,k,l) = x(i,j,k,l).val();
527  }
528  }
529  }
530  }
531 
532  return v;
533  }
534 };
535 
536 template <typename T>
537 struct ScalarValue< Intrepid::Tensor4<T> > {
538  typedef typename ValueType<T>::type value_type;
539  typedef typename ScalarType<T>::type scalar_type;
540  static const Intrepid::Tensor4<scalar_type> &
541  eval(Intrepid::Tensor4<T> const & x)
542  {
543  Intrepid::Index const
544  N = x.get_dimension();
545 
547  v(N);
548 
549  for (Intrepid::Index i = 0; i < N; ++i) {
550  for (Intrepid::Index j = 0; j < N; ++j) {
551  for (Intrepid::Index k = 0; k < N; ++k) {
552  for (Intrepid::Index l = 0; l < N; ++l) {
553  v(i,j,k,l) = ScalarValue<value_type>::eval(x(i,j,k,l).val());
554  }
555  }
556  }
557  }
558 
559  return v;
560  }
561 };
562 
563 template <typename T>
564 struct StringName< Intrepid::Tensor4<T> > {
565  static std::string
566  eval()
567  {
568  return std::string("Intrepid::Tensor4< ") +
569  StringName<T>::eval() + std::string(" >");
570  }
571 };
572 
573 template <typename T>
574 struct IsEqual< Intrepid::Tensor4<T> > {
575  static bool eval(T const & x, T const & y) { return x == y; }
576 };
577 
578 template <typename T>
579 struct IsStaticallySized< Intrepid::Tensor4<T> > {
580  static const bool value = false;
581 };
582 
583 } // namespace Sacado
584 
585 #endif // Intrepid_MiniTensor_Definitions_h
Tensors from 1st to 4th order.