Intrepid
Intrepid_MiniTensor_TensorBase.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_TensorBase_h)
43 #define Intrepid_MiniTensor_TensorBase_h
44 
45 #include <algorithm>
46 #include <cassert>
47 #include <iostream>
48 #include <vector>
49 
50 #include "Intrepid_MiniTensor_Definitions.h"
51 #include "Intrepid_MiniTensor_Storage.h"
52 #include "Intrepid_MiniTensor_Utilities.h"
53 
54 namespace Intrepid {
55 
59 enum ComponentValue {ZEROS, ONES, RANDOM};
60 
64 template<typename T>
66 {
67 public:
68 
72  typedef T type;
73 
77  TensorBase();
78 
84  TensorBase(Index const dimension, Index const order);
85 
92  TensorBase(Index const dimension, Index const order, ComponentValue value);
93 
100  TensorBase(Index const dimension, Index const order, T const & s);
101 
108  TensorBase(Index const dimension, Index const order, T const * data_ptr);
109 
114  TensorBase(TensorBase<T> const & X);
115 
119  virtual
120  ~TensorBase();
121 
126  T const &
127  operator[](Index const i) const;
128 
133  T &
134  operator[](Index const i);
135 
139  Index
140  get_dimension() const;
141 
145  void
146  set_dimension(Index const dimension);
147 
151  Index
152  get_number_components() const;
153 
158  void
159  fill(ComponentValue value);
160 
165  void
166  fill(T const * data_ptr);
167 
172  TensorBase<T> &
173  operator=(TensorBase<T> const & X);
174 
179  TensorBase<T> &
180  operator+=(TensorBase<T> const & X);
181 
186  TensorBase<T> &
187  operator-=(TensorBase<T> const & X);
188 
192  void
193  clear();
194 
198  virtual
199  Index
200  get_order() const = 0;
201 
202 protected:
203 
207  void
208  set_number_components(Index const number_components);
209 
213  Index
215 
221 
222 };
223 
227 template<typename T>
228 T
229 norm_f(TensorBase<T> const & X);
230 
234 template<typename T>
235 T
236 norm_f_square(TensorBase<T> const & X);
237 
241 template<typename R, typename S, typename T>
242 void
243 add(TensorBase<R> const & A, TensorBase<S> const & B, TensorBase<T> & C);
244 
248 template<typename R, typename S, typename T>
249 void
250 subtract(TensorBase<R> const & A, TensorBase<S> const & B, TensorBase<T> & C);
251 
255 template<typename T>
256 void
257 minus(TensorBase<T> const & A, TensorBase<T> & B);
258 
262 template<typename T>
263 bool
264 equal(TensorBase<T> const & A, TensorBase<T> const & B);
265 
269 template<typename T>
270 bool
271 not_equal(TensorBase<T> const & A, TensorBase<T> const & B);
272 
276 template<typename R, typename S, typename T>
277 void
278 scale(TensorBase<R> const & A, S const & s, TensorBase<T> & B);
279 
283 template<typename R, typename S, typename T>
284 void
285 divide(TensorBase<R> const & A, S const & s, TensorBase<T> & B);
286 
287 } // namespace Intrepid
288 
289 #include "Intrepid_MiniTensor_TensorBase.i.h"
290 #include "Intrepid_MiniTensor_TensorBase.t.h"
291 
292 #endif //Intrepid_MiniTensor_TensorBase_h
void set_dimension(Index const dimension)
TensorBase< T > & operator=(TensorBase< T > const &X)
T const & operator[](Index const i) const
void fill(ComponentValue value)
virtual Index get_order() const =0
void set_number_components(Index const number_components)
TensorBase< T > & operator-=(TensorBase< T > const &X)
TensorBase< T > & operator+=(TensorBase< T > const &X)
MiniTensor::StorageRCPArray< T > components_