Intrepid
/usr/src/RPM/BUILD/trilinos-11.12.1/packages/intrepid/src/Shared/MiniTensor/Intrepid_MiniTensor_Tensor3.i.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_Tensor3_i_h)
00043 #define Intrepid_MiniTensor_Tensor3_i_h
00044 
00045 namespace Intrepid {
00046 
00047 //
00048 // 3rd-order tensor constructor with NaNs
00049 //
00050 template<typename T, Index N>
00051 inline
00052 Tensor3<T, N>::Tensor3() :
00053 TensorBase<T, Store>::TensorBase()
00054 {
00055   return;
00056 }
00057 
00058 template<typename T, Index N>
00059 inline
00060 Tensor3<T, N>::Tensor3(Index const dimension) :
00061 TensorBase<T, Store>::TensorBase(dimension, ORDER)
00062 {
00063   return;
00064 }
00065 
00066 //
00067 // 3rd-order tensor constructor with a specified value
00068 //
00069 template<typename T, Index N>
00070 inline
00071 Tensor3<T, N>::Tensor3(ComponentValue const value) :
00072 TensorBase<T, Store>::TensorBase(N, ORDER, value)
00073 {
00074   return;
00075 }
00076 
00077 template<typename T, Index N>
00078 inline
00079 Tensor3<T, N>::Tensor3(Index const dimension, ComponentValue const value) :
00080 TensorBase<T, Store>::TensorBase(dimension, ORDER, value)
00081 {
00082   return;
00083 }
00084 
00085 //
00086 //  Create 3rd-order tensor from array
00087 //
00088 template<typename T, Index N>
00089 inline
00090 Tensor3<T, N>::Tensor3(T const * data_ptr) :
00091 TensorBase<T, Store>::TensorBase(N, ORDER, data_ptr)
00092 {
00093   return;
00094 }
00095 
00096 template<typename T, Index N>
00097 inline
00098 Tensor3<T, N>::Tensor3(Index const dimension, T const * data_ptr) :
00099 TensorBase<T, Store>::TensorBase(dimension, ORDER, data_ptr)
00100 {
00101   return;
00102 }
00103 
00104 //
00105 // Copy constructor
00106 //
00107 template<typename T, Index N>
00108 inline
00109 Tensor3<T, N>::Tensor3(Tensor3<T, N> const & A) :
00110 TensorBase<T, Store>::TensorBase(A)
00111 {
00112   return;
00113 }
00114 
00115 //
00116 // 3rd-order tensor simple destructor
00117 //
00118 template<typename T, Index N>
00119 inline
00120 Tensor3<T, N>::~Tensor3()
00121 {
00122   return;
00123 }
00124 
00125 //
00126 // Get dimension
00127 //
00128 template<typename T, Index N>
00129 inline
00130 Index
00131 Tensor3<T, N>::get_dimension() const
00132 {
00133   return IS_DYNAMIC == true ? TensorBase<T, Store>::get_dimension() : N;
00134 }
00135 
00136 //
00137 // Set dimension
00138 //
00139 template<typename T, Index N>
00140 inline
00141 void
00142 Tensor3<T, N>::set_dimension(Index const dimension)
00143 {
00144   if (IS_DYNAMIC == true) {
00145     TensorBase<T, Store>::set_dimension(dimension, ORDER);
00146   }
00147   else {
00148     assert(dimension == N);
00149   }
00150 
00151   return;
00152 }
00153 
00154 //
00155 // 3rd-order tensor addition
00156 //
00157 template<typename S, typename T, Index N>
00158 inline
00159 Tensor3<typename Promote<S, T>::type, N>
00160 operator+(Tensor3<S, N> const & A, Tensor3<T, N> const & B)
00161 {
00162   Tensor3<typename Promote<S, T>::type, N>
00163   C(A.get_dimension());
00164 
00165   add(A, B, C);
00166 
00167   return C;
00168 }
00169 
00170 //
00171 // 3rd-order tensor subtraction
00172 //
00173 template<typename S, typename T, Index N>
00174 inline
00175 Tensor3<typename Promote<S, T>::type, N>
00176 operator-(Tensor3<S, N> const & A, Tensor3<T, N> const & B)
00177 {
00178   Tensor3<typename Promote<S, T>::type, N>
00179   C(A.get_dimension());
00180 
00181   subtract(A, B, C);
00182 
00183   return C;
00184 }
00185 
00186 //
00187 // 3rd-order tensor minus
00188 //
00189 template<typename T, Index N>
00190 inline
00191 Tensor3<T, N>
00192 operator-(Tensor3<T, N> const & A)
00193 {
00194   Tensor3<T, N>
00195   B(A.get_dimension());
00196 
00197   minus(A, B);
00198 
00199   return B;
00200 }
00201 
00202 //
00203 // 3rd-order tensor equality
00204 //
00205 template<typename T, Index N>
00206 inline
00207 bool
00208 operator==(Tensor3<T, N> const & A, Tensor3<T, N> const & B)
00209 {
00210   return equal(A, B);
00211 }
00212 
00213 //
00214 // 3rd-order tensor inequality
00215 //
00216 template<typename T, Index N>
00217 inline
00218 bool
00219 operator!=(Tensor3<T, N> const & A, Tensor3<T, N> const & B)
00220 {
00221   return not_equal(A, B);
00222 }
00223 
00224 //
00225 // Scalar 3rd-order tensor product
00226 //
00227 template<typename S, typename T, Index N>
00228 inline
00229 typename lazy_disable_if< order_1234<S>, apply_tensor3< Promote<S,T>, N> >::type
00230 operator*(S const & s, Tensor3<T, N> const & A)
00231 {
00232   Tensor3<typename Promote<S, T>::type, N>
00233   B(A.get_dimension());
00234 
00235   scale(A, s, B);
00236 
00237   return B;
00238 }
00239 
00240 //
00241 // 3rd-order tensor scalar product
00242 //
00243 template<typename S, typename T, Index N>
00244 inline
00245 typename lazy_disable_if< order_1234<S>, apply_tensor3< Promote<S,T>, N> >::type
00246 operator*(Tensor3<T, N> const & A, S const & s)
00247 {
00248   Tensor3<typename Promote<S, T>::type, N>
00249   B(A.get_dimension());
00250 
00251   scale(A, s, B);
00252 
00253   return B;
00254 }
00255 
00256 //
00257 // 3rd-order tensor scalar division
00258 //
00259 template<typename S, typename T, Index N>
00260 inline
00261 Tensor3<typename Promote<S, T>::type, N>
00262 operator/(Tensor3<T, N> const & A, S const & s)
00263 {
00264   Tensor3<typename Promote<S, T>::type, N>
00265   B(A.get_dimension());
00266 
00267   divide(A, s, B);
00268 
00269   return B;
00270 }
00271 
00272 //
00273 // 3rd-order scalar tensor division
00274 //
00275 template<typename S, typename T, Index N>
00276 inline
00277 Tensor3<typename Promote<S, T>::type, N>
00278 operator/(S const & s, Tensor3<T, N> const & A)
00279 {
00280   Tensor3<typename Promote<S, T>::type, N>
00281   B(A.get_dimension());
00282 
00283   split(A, s, B);
00284 
00285   return B;
00286 }
00287 
00288 //
00289 // Indexing for constant 3rd order tensor
00290 //
00291 template<typename T, Index N>
00292 inline
00293 T const &
00294 Tensor3<T, N>::operator()(Index const i, Index const j, Index const k) const
00295 {
00296   Tensor3<T, N> const &
00297   self = (*this);
00298 
00299   Index const
00300   dimension = self.get_dimension();
00301 
00302   return self[(i * dimension + j) * dimension + k];
00303 }
00304 
00305 //
00306 // 3rd-order tensor indexing
00307 //
00308 template<typename T, Index N>
00309 inline
00310 T &
00311 Tensor3<T, N>::operator()(Index const i, Index const j, Index const k)
00312 {
00313   Tensor3<T, N> &
00314   self = (*this);
00315 
00316   Index const
00317   dimension = self.get_dimension();
00318 
00319   return self[(i * dimension + j) * dimension + k];
00320 }
00321 
00322 } // namespace Intrepid
00323 
00324 #endif // Intrepid_MiniTensor_Tensor3_i_h