Intrepid
Intrepid_MiniTensor_Tensor3.i.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_Tensor3_i_h)
43 #define Intrepid_MiniTensor_Tensor3_i_h
44 
45 namespace Intrepid {
46 
47 //
48 // 3rd-order tensor default constructor
49 //
50 template<typename T>
51 inline
54 {
55  return;
56 }
57 
58 //
59 // 3rd-order tensor constructor with NaNs
60 //
61 template<typename T>
62 inline
63 Tensor3<T>::Tensor3(Index const dimension) :
64 TensorBase<T>::TensorBase(dimension, order)
65 {
66  return;
67 }
68 
69 //
70 // 3rd-order tensor constructor with a specified value
71 //
72 template<typename T>
73 inline
74 Tensor3<T>::Tensor3(Index const dimension, ComponentValue value) :
75 TensorBase<T>::TensorBase(dimension, order, value)
76 {
77  return;
78 }
79 
80 //
81 // 3rd-order tensor constructor with a scalar
82 //
83 template<typename T>
84 inline
85 Tensor3<T>::Tensor3(Index const dimension, T const & s) :
86 TensorBase<T>::TensorBase(dimension, order, s)
87 {
88  return;
89 }
90 
91 //
92 // Create 3rd-order tensor from array
93 //
94 template<typename T>
95 inline
96 Tensor3<T>::Tensor3(Index const dimension, T const * data_ptr) :
97 TensorBase<T>::TensorBase(dimension, order, data_ptr)
98 {
99  return;
100 }
101 
102 //
103 // Copy constructor
104 //
105 template<typename T>
106 inline
108 TensorBase<T>::TensorBase(A)
109 {
110  return;
111 }
112 
113 //
114 // 3rd-order tensor simple destructor
115 //
116 template<typename T>
117 inline
119 {
120  return;
121 }
122 
123 //
124 // 3rd-order tensor addition
125 //
126 template<typename S, typename T>
127 inline
129 operator+(Tensor3<S> const & A, Tensor3<T> const & B)
130 {
132  C;
133 
134  add(A, B, C);
135 
136  return C;
137 }
138 
139 //
140 // 3rd-order tensor subtraction
141 //
142 template<typename S, typename T>
143 inline
145 operator-(Tensor3<S> const & A, Tensor3<T> const & B)
146 {
148  C;
149 
150  subtract(A, B, C);
151 
152  return C;
153 }
154 
155 //
156 // 3rd-order tensor minus
157 //
158 template<typename T>
159 inline
161 operator-(Tensor3<T> const & A)
162 {
163  Tensor3<T>
164  B;
165 
166  minus(A, B);
167 
168  return B;
169 }
170 
171 //
172 // 3rd-order tensor equality
173 //
174 template<typename T>
175 inline
176 bool
177 operator==(Tensor3<T> const & A, Tensor3<T> const & B)
178 {
179  return equal(A, B);
180 }
181 
182 //
183 // 3rd-order tensor inequality
184 //
185 template<typename T>
186 inline
187 bool
188 operator!=(Tensor3<T> const & A, Tensor3<T> const & B)
189 {
190  return not_equal(A, B);
191 }
192 
193 //
194 // Scalar 3rd-order tensor product
195 //
196 template<typename S, typename T>
197 inline
198 typename lazy_disable_if< order_1234<S>, apply_tensor3< Promote<S,T> > >::type
199 operator*(S const & s, Tensor3<T> const & A)
200 {
202  B;
203 
204  scale(A, s, B);
205 
206  return B;
207 }
208 
209 //
210 // 3rd-order tensor scalar product
211 //
212 template<typename S, typename T>
213 inline
214 typename lazy_disable_if< order_1234<S>, apply_tensor3< Promote<S,T> > >::type
215 operator*(Tensor3<T> const & A, S const & s)
216 {
218  B;
219 
220  scale(A, s, B);
221 
222  return B;
223 }
224 
225 //
226 // 3rd-order tensor scalar division
227 //
228 template<typename S, typename T>
229 inline
231 operator/(Tensor3<T> const & A, S const & s)
232 {
234  B;
235 
236  divide(A, s, B);
237 
238  return B;
239 }
240 
241 //
242 // Indexing for constant 3rd order tensor
243 //
244 template<typename T>
245 inline
246 T const &
247 Tensor3<T>::operator()(Index const i, Index const j, Index const k) const
248 {
249  Tensor3<T> const &
250  self = (*this);
251 
252  Index const
253  N = self.get_dimension();
254 
255  assert(i < N);
256  assert(j < N);
257  assert(k < N);
258 
259  return self[(i * N + j) * N + k];
260 }
261 
262 //
263 // 3rd-order tensor indexing
264 //
265 template<typename T>
266 inline
267 T &
268 Tensor3<T>::operator()(Index const i, Index const j, Index const k)
269 {
270  Tensor3<T> &
271  self = (*this);
272 
273  Index const
274  N = self.get_dimension();
275 
276  assert(i < N);
277  assert(j < N);
278  assert(k < N);
279 
280  return self[(i * N + j) * N + k];
281 }
282 
283 } // namespace Intrepid
284 
285 #endif // Intrepid_MiniTensor_Tensor3_i_h
T const & operator()(Index const i, Index const j, Index const k) const