Intrepid
Intrepid_MiniTensor_Tensor.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_Tensor_h)
43 #define Intrepid_MiniTensor_Tensor_h
44 
45 #include <algorithm>
46 #include <cassert>
47 #include <iostream>
48 #include <vector>
49 
50 #include <boost/tuple/tuple.hpp>
51 
52 #include "Intrepid_MiniTensor_Vector.h"
53 
54 namespace Intrepid {
55 
59 enum ComponentOrder {CANONICAL, SIERRA_FULL, SIERRA_SYMMETRIC};
60 
64 template<typename T>
65 class Tensor : public TensorBase<T>
66 {
67 public:
68 
72  static Index const
73  order = 2U;
74 
78  Tensor();
79 
84  explicit
85  Tensor(Index const dimension);
86 
92  explicit
93  Tensor(Index const dimension, ComponentValue value);
94 
100  Tensor(Index const dimension, T const & s);
101 
106  Tensor(T const & s00, T const & s01, T const & s10, T const & s11);
107 
112  Tensor(
113  T const & s00, T const & s01, T const & s02,
114  T const & s10, T const & s11, T const & s12,
115  T const & s20, T const & s21, T const & s22);
116 
122  Tensor(Index const dimension, T const * data_ptr);
123 
129  Tensor(
130  Index const dimension,
131  T const * data_ptr,
132  ComponentOrder const component_order);
133 
137  Tensor(Tensor<T> const & A);
138 
142  Tensor(Tensor4<T> const & A);
143 
147  ~Tensor();
148 
154  T const &
155  operator()(Index const i, Index const j) const;
156 
162  T &
163  operator()(Index const i, Index const j);
164 
169  void
170  fill(ComponentValue value);
171 
177  void
178  fill(
179  T const * data_ptr,
180  ComponentOrder const component_order = CANONICAL);
181 
185  Index
186  get_order() const {return order;}
187 
188 };
189 
194 template<typename S, typename T>
195 Tensor<typename Promote<S, T>::type>
196 operator+(Tensor<S> const & A, Tensor<T> const & B);
197 
202 template<typename S, typename T>
203 Tensor<typename Promote<S, T>::type>
204 operator-(Tensor<S> const & A, Tensor<T> const & B);
205 
210 template<typename T>
211 Tensor<T>
212 operator-(Tensor<T> const & A);
213 
219 template<typename T>
220 bool
221 operator==(Tensor<T> const & A, Tensor<T> const & B);
222 
228 template<typename T>
229 bool
230 operator!=(Tensor<T> const & A, Tensor<T> const & B);
231 
238 template<typename S, typename T>
239 Vector<typename Promote<S, T>::type>
240 operator*(Tensor<T> const & A, Vector<S> const & u);
241 
248 template<typename S, typename T>
249 Vector<typename Promote<S, T>::type>
250 operator*(Vector<S> const & u, Tensor<T> const & A);
251 
256 template<typename S, typename T>
257 Tensor<typename Promote<S, T>::type>
258 operator*(Tensor<S> const & A, Tensor<T> const & B);
259 
266 template<typename S, typename T>
267 typename lazy_disable_if< order_1234<S>, apply_tensor< Promote<S,T> > >::type
268 operator*(S const & s, Tensor<T> const & A);
269 
276 template<typename S, typename T>
277 typename lazy_disable_if< order_1234<S>, apply_tensor< Promote<S,T> > >::type
278 operator*(Tensor<T> const & A, S const & s);
279 
286 template<typename S, typename T>
287 Tensor<typename Promote<S, T>::type>
288 operator/(Tensor<T> const & A, S const & s);
289 
296 template<typename T>
297 std::istream &
298 operator>>(std::istream & is, Tensor<T> & A);
299 
306 template<typename T>
307 std::ostream &
308 operator<<(std::ostream & os, Tensor<T> const & A);
309 
316 template<typename T>
317 Vector<T>
318 row(Tensor<T> const & A, Index const i);
319 
326 template<typename T>
327 Vector<T>
328 col(Tensor<T> const & A, Index const j);
329 
336 template<typename S, typename T>
337 Vector<typename Promote<S, T>::type>
338 dot(Tensor<T> const & A, Vector<S> const & u);
339 
346 template<typename S, typename T>
347 Vector<typename Promote<S, T>::type>
348 dot(Vector<S> const & u, Tensor<T> const & A);
349 
356 template<typename S, typename T>
357 Tensor<typename Promote<S, T>::type>
358 dot(Tensor<S> const & A, Tensor<T> const & B);
359 
366 template<typename S, typename T>
367 Tensor<typename Promote<S, T>::type>
368 t_dot(Tensor<S> const & A, Tensor<T> const & B);
369 
376 template<typename S, typename T>
377 Tensor<typename Promote<S, T>::type>
378 dot_t(Tensor<S> const & A, Tensor<T> const & B);
379 
386 template<typename S, typename T>
387 Tensor<typename Promote<S, T>::type>
388 t_dot_t(Tensor<S> const & A, Tensor<T> const & B);
389 
396 template<typename S, typename T>
397 typename Promote<S, T>::type
398 dotdot(Tensor<S> const & A, Tensor<T> const & B);
399 
406 template<typename S, typename T>
407 Tensor<typename Promote<S, T>::type>
408 dyad(Vector<S> const & u, Vector<T> const & v);
409 
416 template<typename S, typename T>
417 Tensor<typename Promote<S, T>::type>
418 bun(Vector<S> const & u, Vector<T> const & v);
419 
426 template<typename S, typename T>
427 Tensor<typename Promote<S, T>::type>
428 tensor(Vector<S> const & u, Vector<T> const & v);
429 
435 template<typename T>
436 Tensor<T>
437 diag(Vector<T> const & v);
438 
444 template<typename T>
445 Vector<T>
446 diag(Tensor<T> const & A);
447 
452 template<typename T>
453 const Tensor<T>
454 zero(Index const N);
455 
459 template<typename T>
460 const Tensor<T>
461 identity(Index const N);
462 
466 template<typename T>
467 const Tensor<T>
468 eye(Index const N);
469 
473 template<typename T>
474 Tensor<T>
475 transpose(Tensor<T> const & A);
476 
480 template<typename T>
481 Tensor<T>
482 adjoint(Tensor<T> const & A);
483 
488 template<typename T>
489 Tensor<T>
490 sym(Tensor<T> const & A);
491 
496 template<typename T>
497 Tensor<T>
498 skew(Tensor<T> const & A);
499 
506 template<typename T>
507 Tensor<T>
508 skew(Vector<T> const & u);
509 
510 } // namespace Intrepid
511 
512 #include "Intrepid_MiniTensor_Tensor.i.h"
513 #include "Intrepid_MiniTensor_Tensor.t.h"
514 
515 #endif //Intrepid_MiniTensor_Tensor_h
static Index const order
void fill(ComponentValue value)
T const & operator()(Index const i, Index const j) const