Intrepid
/usr/src/RPM/BUILD/trilinos-11.12.1/packages/intrepid/src/Shared/MiniTensor/Intrepid_MiniTensor_TensorBase.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_TensorBase_h)
00043 #define Intrepid_MiniTensor_TensorBase_h
00044 
00045 #include <algorithm>
00046 #include <cassert>
00047 #include <iostream>
00048 #include <vector>
00049 
00050 #include "Intrepid_MiniTensor_Storage.h"
00051 #include "Intrepid_MiniTensor_Utilities.h"
00052 
00053 namespace Intrepid {
00054 
00058 enum ComponentValue {
00059   ZEROS,
00060   ONES,
00061   SEQUENCE,
00062   RANDOM_UNIFORM,
00063   RANDOM_NORMAL,
00064   NANS};
00065 
00071 template<typename T, typename ST>
00072 class TensorBase
00073 {
00074 public:
00075 
00079   typedef T value_type;
00080 
00084   typedef ST storage_type;
00085 
00089   TensorBase();
00090 
00095   explicit
00096   TensorBase(Index const dimension, Index const order);
00097 
00103   TensorBase(Index const dimension, Index const order,
00104       ComponentValue const value);
00105 
00111   TensorBase(Index const dimension, Index const order, T const & s);
00112 
00118   TensorBase(Index const dimension, Index const order, T const * data_ptr);
00119 
00124   TensorBase(TensorBase<T, ST> const & X);
00125 
00130   TensorBase<T, ST> &
00131   operator=(TensorBase<T, ST> const & X);
00132 
00136   virtual
00137   ~TensorBase() = 0;
00138 
00143   T const &
00144   operator[](Index const i) const;
00145 
00150   T &
00151   operator[](Index const i);
00152 
00156   Index
00157   get_number_components() const;
00158 
00163   void
00164   fill(ComponentValue const value);
00165 
00170   void
00171   fill(T const & s);
00172 
00177   void
00178   fill(T const * data_ptr);
00179 
00184   template<typename S, typename SS>
00185   TensorBase<T, ST> &
00186   operator+=(TensorBase<S, SS> const & X);
00187 
00192   template<typename S, typename SS>
00193   TensorBase<T, ST> &
00194   operator-=(TensorBase<S, SS> const & X);
00195 
00200   template<typename S>
00201   TensorBase<T, ST> &
00202   operator*=(S const & X);
00203 
00208   template<typename S>
00209   TensorBase<T, ST> &
00210   operator/=(S const & X);
00211 
00215   void
00216   clear();
00217 
00218 protected:
00219 
00223   void
00224   set_number_components(Index const number_components);
00225 
00229   Index
00230   get_dimension() const;
00231 
00236   void
00237   set_dimension(Index const dimension, Index const order);
00238 
00242   ST
00243   components_;
00244 
00248   Index
00249   dimension_;
00250 
00251 };
00252 
00256 template<typename T, typename ST>
00257 T
00258 norm_f(TensorBase<T, ST> const & X);
00259 
00263 template<typename T, typename ST>
00264 T
00265 norm_f_square(TensorBase<T, ST> const & X);
00266 
00270 template<typename R, typename S, typename T, typename SR, typename SS,
00271 typename ST>
00272 void
00273 add(
00274     TensorBase<R, SR> const & A,
00275     TensorBase<S, SS> const & B,
00276     TensorBase<T, ST> & C);
00277 
00281 template<typename R, typename S, typename T, typename SR, typename SS,
00282 typename ST>
00283 void
00284 subtract(
00285     TensorBase<R, SR> const & A,
00286     TensorBase<S, SS> const & B,
00287     TensorBase<T, ST> & C);
00288 
00292 template<typename T, typename ST>
00293 void
00294 minus(TensorBase<T, ST> const & A, TensorBase<T, ST> & B);
00295 
00299 template<typename T, typename ST>
00300 bool
00301 equal(TensorBase<T, ST> const & A, TensorBase<T, ST> const & B);
00302 
00306 template<typename T, typename ST>
00307 bool
00308 not_equal(TensorBase<T, ST> const & A, TensorBase<T, ST> const & B);
00309 
00313 template<typename R, typename S, typename T, typename SR, typename ST>
00314 void
00315 scale(TensorBase<R, SR> const & A, S const & s, TensorBase<T, ST> & B);
00316 
00320 template<typename R, typename S, typename T, typename SR, typename ST>
00321 void
00322 divide(TensorBase<R, SR> const & A, S const & s, TensorBase<T, ST> & B);
00323 
00327 template<typename R, typename S, typename T, typename SR, typename ST>
00328 void
00329 split(TensorBase<R, SR> const & A, S const & s, TensorBase<T, ST> & B);
00330 
00331 } // namespace Intrepid
00332 
00333 #include "Intrepid_MiniTensor_TensorBase.i.h"
00334 #include "Intrepid_MiniTensor_TensorBase.t.h"
00335 
00336 #endif //Intrepid_MiniTensor_TensorBase_h