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