Intrepid
/usr/src/RPM/BUILD/trilinos-11.12.1/packages/intrepid/src/Shared/MiniTensor/Intrepid_MiniTensor_Tensor.h
00001 // @HEADER
00002 // ************************************************************************
00003 //
00004 //                           Intrepid Package
00005 //                 Copyright (2007) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions: Alejandro Mota (amota@sandia.gov)
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 
00042 #if !defined(Intrepid_MiniTensor_Tensor_h)
00043 #define Intrepid_MiniTensor_Tensor_h
00044 
00045 #include <algorithm>
00046 #include <cassert>
00047 #include <iostream>
00048 #include <vector>
00049 
00050 #include <boost/tuple/tuple.hpp>
00051 
00052 #include "Intrepid_MiniTensor_Vector.h"
00053 
00054 namespace Intrepid {
00055 
00059 enum ComponentOrder {CANONICAL, SIERRA_FULL, SIERRA_SYMMETRIC};
00060 
00061 template<typename T, Index N>
00062 struct tensor_store
00063 {
00064   typedef Storage<T, dimension_power<N, 2>::value> type;
00065 };
00066 
00070 template<typename T, Index N = DYNAMIC>
00071 class Tensor : public TensorBase<T, typename tensor_store<T, N>::type>
00072 {
00073 public:
00074 
00078   static
00079   Index const
00080   ORDER = 2;
00081 
00085   static
00086   bool const
00087   IS_DYNAMIC = N == DYNAMIC;
00088 
00092   typedef typename tensor_store<T, N>::type
00093   Store;
00094 
00098   static
00099   Index
00100   get_order() {return ORDER;}
00101 
00106   explicit
00107   Tensor();
00108 
00109   explicit
00110   Tensor(Index const dimension);
00111 
00117   explicit
00118   Tensor(ComponentValue const value);
00119 
00120   explicit
00121   Tensor(Index const dimension, ComponentValue const value);
00122 
00128   explicit
00129   Tensor(T const * data_ptr);
00130 
00131   explicit
00132   Tensor(Index const dimension, T const * data_ptr);
00133 
00137   Tensor(Tensor<T, N> const & A);
00138 
00142   Tensor(Tensor4<T, dimension_sqrt<N>::value> const & A);
00143 
00148   Tensor(T const & s00, T const & s01, T const & s10, T const & s11);
00149 
00154   Tensor(
00155       T const & s00, T const & s01, T const & s02,
00156       T const & s10, T const & s11, T const & s12,
00157       T const & s20, T const & s21, T const & s22);
00158 
00164   explicit
00165   Tensor(T const * data_ptr, ComponentOrder const component_order);
00166 
00167   explicit
00168   Tensor(Index const dimension, T const * data_ptr,
00169       ComponentOrder const component_order);
00170 
00174   ~Tensor();
00175 
00181   T const &
00182   operator()(Index const i, Index const j) const;
00183 
00189   T &
00190   operator()(Index const i, Index const j);
00191 
00195   Index
00196   get_dimension() const;
00197 
00201   void
00202   set_dimension(Index const dimension);
00203 
00208   void
00209   fill(ComponentValue const value);
00210 
00215   void
00216   fill(T const & s);
00217 
00222   void
00223   fill(T const * data_ptr);
00224 
00230   void
00231   fill(T const * data_ptr, ComponentOrder const component_order);
00232 
00233 };
00234 
00239 template<typename S, typename T, Index N>
00240 Tensor<typename Promote<S, T>::type, N>
00241 operator+(Tensor<S, N> const & A, Tensor<T, N> const & B);
00242 
00247 template<typename S, typename T, Index N>
00248 Tensor<typename Promote<S, T>::type, N>
00249 operator-(Tensor<S, N> const & A, Tensor<T, N> const & B);
00250 
00255 template<typename T, Index N>
00256 Tensor<T, N>
00257 operator-(Tensor<T, N> const & A);
00258 
00264 template<typename T, Index N>
00265 bool
00266 operator==(Tensor<T, N> const & A, Tensor<T, N> const & B);
00267 
00273 template<typename T, Index N>
00274 bool
00275 operator!=(Tensor<T, N> const & A, Tensor<T, N> const & B);
00276 
00283 template<typename S, typename T, Index N>
00284 Vector<typename Promote<S, T>::type, N>
00285 operator*(Tensor<T, N> const & A, Vector<S, N> const & u);
00286 
00293 template<typename S, typename T, Index N>
00294 Vector<typename Promote<S, T>::type, N>
00295 operator*(Vector<S, N> const & u, Tensor<T, N> const & A);
00296 
00301 template<typename S, typename T, Index N>
00302 Tensor<typename Promote<S, T>::type, N>
00303 operator*(Tensor<S, N> const & A, Tensor<T, N> const & B);
00304 
00311 template<typename S, typename T, Index N>
00312 typename lazy_disable_if< order_1234<S>, apply_tensor< Promote<S,T>, N> >::type
00313 operator*(S const & s, Tensor<T, N> const & A);
00314 
00321 template<typename S, typename T, Index N>
00322 typename lazy_disable_if< order_1234<S>, apply_tensor< Promote<S,T>, N> >::type
00323 operator*(Tensor<T, N> const & A, S const & s);
00324 
00331 template<typename S, typename T, Index N>
00332 Tensor<typename Promote<S, T>::type, N>
00333 operator/(Tensor<T, N> const & A, S const & s);
00334 
00341 template<typename S, typename T, Index N>
00342 Tensor<typename Promote<S, T>::type, N>
00343 operator/(S const & s, Tensor<T, N> const & A);
00344 
00351 template<typename T, Index N>
00352 std::istream &
00353 operator>>(std::istream & is, Tensor<T, N> & A);
00354 
00361 template<typename T, Index N>
00362 std::ostream &
00363 operator<<(std::ostream & os, Tensor<T, N> const & A);
00364 
00371 template<typename T, Index N>
00372 Vector<T, N>
00373 row(Tensor<T, N> const & A, Index const i);
00374 
00381 template<typename T, Index N>
00382 Vector<T, N>
00383 col(Tensor<T, N> const & A, Index const j);
00384 
00391 template<typename S, typename T, Index N>
00392 Vector<typename Promote<S, T>::type, N>
00393 dot(Tensor<T, N> const & A, Vector<S, N> const & u);
00394 
00401 template<typename S, typename T, Index N>
00402 Vector<typename Promote<S, T>::type, N>
00403 dot(Vector<S, N> const & u, Tensor<T, N> const & A);
00404 
00411 template<typename S, typename T, Index N>
00412 Tensor<typename Promote<S, T>::type, N>
00413 dot(Tensor<S, N> const & A, Tensor<T, N> const & B);
00414 
00421 template<typename S, typename T, Index N>
00422 Tensor<typename Promote<S, T>::type, N>
00423 t_dot(Tensor<S, N> const & A, Tensor<T, N> const & B);
00424 
00431 template<typename S, typename T, Index N>
00432 Tensor<typename Promote<S, T>::type, N>
00433 dot_t(Tensor<S, N> const & A, Tensor<T, N> const & B);
00434 
00441 template<typename S, typename T, Index N>
00442 Tensor<typename Promote<S, T>::type, N>
00443 t_dot_t(Tensor<S, N> const & A, Tensor<T, N> const & B);
00444 
00451 template<typename S, typename T, Index N>
00452 typename Promote<S, T>::type
00453 dotdot(Tensor<S, N> const & A, Tensor<T, N> const & B);
00454 
00461 template<typename S, typename T, Index N>
00462 Tensor<typename Promote<S, T>::type, N>
00463 dyad(Vector<S, N> const & u, Vector<T, N> const & v);
00464 
00471 template<typename S, typename T, Index N>
00472 Tensor<typename Promote<S, T>::type, N>
00473 bun(Vector<S, N> const & u, Vector<T, N> const & v);
00474 
00481 template<typename S, typename T, Index N>
00482 Tensor<typename Promote<S, T>::type, N>
00483 tensor(Vector<S, N> const & u, Vector<T, N> const & v);
00484 
00490 template<typename T, Index N>
00491 Tensor<T, N>
00492 diag(Vector<T, N> const & v);
00493 
00499 template<typename T, Index N>
00500 Vector<T, N>
00501 diag(Tensor<T, N> const & A);
00502 
00507 template<typename T, Index N>
00508 const Tensor<T, N>
00509 zero();
00510 
00511 template<typename T>
00512 const Tensor<T, DYNAMIC>
00513 zero(Index const dimension);
00514 
00515 template<typename T, Index N>
00516 const Tensor<T, N>
00517 zero(Index const dimension);
00518 
00522 template<typename T, Index N>
00523 const Tensor<T, N>
00524 identity();
00525 
00526 template<typename T>
00527 const Tensor<T, DYNAMIC>
00528 identity(Index const dimension);
00529 
00530 template<typename T, Index N>
00531 const Tensor<T, N>
00532 identity(Index const dimension);
00533 
00537 template<typename T, Index N>
00538 const Tensor<T, N>
00539 eye();
00540 
00541 template<typename T>
00542 const Tensor<T, DYNAMIC>
00543 eye(Index const dimension);
00544 
00545 template<typename T, Index N>
00546 const Tensor<T, N>
00547 eye(Index const dimension);
00548 
00552 template<typename T, Index N>
00553 Tensor<T, N>
00554 transpose(Tensor<T, N> const & A);
00555 
00559 template<typename T, Index N>
00560 Tensor<T, N>
00561 adjoint(Tensor<T, N> const & A);
00562 
00567 template<typename T, Index N>
00568 Tensor<T, N>
00569 sym(Tensor<T, N> const & A);
00570 
00575 template<typename T, Index N>
00576 Tensor<T, N>
00577 skew(Tensor<T, N> const & A);
00578 
00585 template<typename T, Index N>
00586 Tensor<T, N>
00587 skew(Vector<T, N> const & u);
00588 
00589 } // namespace Intrepid
00590 
00591 #include "Intrepid_MiniTensor_Tensor.i.h"
00592 #include "Intrepid_MiniTensor_Tensor.t.h"
00593 
00594 #endif //Intrepid_MiniTensor_Tensor_h