|
Intrepid
|
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_Definitions_h) 00043 #define Intrepid_MiniTensor_Definitions_h 00044 00045 #include <complex> 00046 00047 #include "Sacado.hpp" 00048 #include "Sacado_mpl_disable_if.hpp" 00049 00050 namespace Intrepid { 00051 00053 #define STATIC_ASSERT(condition, name)\ 00054 typedef char static_assertion_failed_ ## name [(condition) ? 1 : -1] 00055 00057 typedef unsigned int Index; 00058 00060 typedef long unsigned int LongCount; 00061 00063 typedef double Real; 00064 00066 typedef std::complex<Real> Complex; 00067 00069 template <typename T, Index N> class Vector; 00070 template <typename T, Index N> class Tensor; 00071 template <typename T, Index N> class Tensor3; 00072 template <typename T, Index N> class Tensor4; 00073 00075 Index const 00076 DYNAMIC = 0; 00077 00079 using Sacado::Promote; 00080 using Sacado::mpl::lazy_disable_if; 00081 using Sacado::mpl::disable_if_c; 00082 00084 template <typename T> 00085 struct is_vector { 00086 static const bool value = false; 00087 }; 00088 00089 template <typename T, Index N> 00090 struct is_vector< Vector<T, N> > { 00091 static const bool value = true; 00092 }; 00093 00094 template <typename T, Index N> 00095 struct apply_vector { 00096 typedef Vector<typename T::type, N> type; 00097 }; 00098 00100 template <typename T> 00101 struct is_tensor { 00102 static const bool value = false; 00103 }; 00104 00105 template <typename T, Index N> 00106 struct is_tensor< Tensor<T, N> > { 00107 static const bool value = true; 00108 }; 00109 00110 template <typename T, Index N> 00111 struct apply_tensor { 00112 typedef Tensor<typename T::type, N> type; 00113 }; 00114 00116 template <typename T> 00117 struct is_tensor3 { 00118 static const bool value = false; 00119 }; 00120 00121 template <typename T, Index N> 00122 struct is_tensor3< Tensor3<T, N> > { 00123 static const bool value = true; 00124 }; 00125 00126 template <typename T, Index N> 00127 struct apply_tensor3 { 00128 typedef Tensor3<typename T::type, N> type; 00129 }; 00130 00132 template <typename T> 00133 struct is_tensor4 { 00134 static const bool value = false; 00135 }; 00136 00137 template <typename T, Index N> 00138 struct is_tensor4< Tensor4<T, N> > { 00139 static const bool value = true; 00140 }; 00141 00142 template <typename T, Index N> 00143 struct apply_tensor4 { 00144 typedef Tensor4<typename T::type, N> type; 00145 }; 00146 00148 template <typename T> 00149 struct order_1234 { 00150 static const bool value = false; 00151 }; 00152 00153 template <typename T, Index N> 00154 struct order_1234< Vector<T, N> > { 00155 static const bool value = true; 00156 }; 00157 00158 template <typename T, Index N> 00159 struct order_1234< Tensor<T, N> > { 00160 static const bool value = true; 00161 }; 00162 00163 template <typename T, Index N> 00164 struct order_1234< Tensor3<T, N> > { 00165 static const bool value = true; 00166 }; 00167 00168 template <typename T, Index N> 00169 struct order_1234< Tensor4<T, N> > { 00170 static const bool value = true; 00171 }; 00172 00174 00175 using std::string; 00176 00177 template <Index N> 00178 struct dimension_string { 00179 static string eval() {return string("INVALID");} 00180 }; 00181 00182 template <> 00183 struct dimension_string<DYNAMIC> { 00184 static string eval() {return string("DYNAMIC");} 00185 }; 00186 00187 template <> 00188 struct dimension_string<1> { 00189 static string eval() {return string("1");} 00190 }; 00191 00192 template <> 00193 struct dimension_string<2> { 00194 static string eval() {return string("2");} 00195 }; 00196 00197 template <> 00198 struct dimension_string<3> { 00199 static string eval() {return string("3");} 00200 }; 00201 00202 template <> 00203 struct dimension_string<4> { 00204 static string eval() {return string("4");} 00205 }; 00206 00207 } // namespace Intrepid 00208 00209 namespace Sacado { 00210 00211 using Intrepid::DYNAMIC; 00212 using Intrepid::Index; 00213 using Intrepid::Vector; 00214 using Intrepid::Tensor; 00215 using Intrepid::Tensor3; 00216 using Intrepid::Tensor4; 00217 using Intrepid::dimension_string; 00218 using std::complex; 00219 using std::string; 00220 00222 template <> 00223 struct Promote<double, Index> { 00224 typedef double type; 00225 }; 00226 00227 template <> 00228 struct Promote<Index, double> { 00229 typedef double type; 00230 }; 00231 00232 template <> 00233 struct Promote<float, Index> { 00234 typedef float type; 00235 }; 00236 00237 template <> 00238 struct Promote<Index, float> { 00239 typedef float type; 00240 }; 00241 00242 template <> 00243 struct Promote<complex<double>, Index> { 00244 typedef complex<double> type; 00245 }; 00246 00247 template <> 00248 struct Promote<Index, complex<double> > { 00249 typedef complex<double> type; 00250 }; 00251 00252 template <> 00253 struct Promote<complex<float>, Index> { 00254 typedef complex<float> type; 00255 }; 00256 00257 template <> 00258 struct Promote<Index, complex<float> > { 00259 typedef complex<float> type; 00260 }; 00261 00263 template <typename T, Index N> 00264 struct ScalarType< Vector<T, N> > { 00265 typedef typename ScalarType<T>::type type; 00266 }; 00267 00268 template <typename T, Index N> 00269 struct ValueType< Vector<T, N> > { 00270 typedef typename ValueType<T>::type type; 00271 }; 00272 00273 template <typename T, Index N> 00274 struct IsADType< Vector<T, N> > { 00275 static bool const value = IsADType<T>::value; 00276 }; 00277 00278 template <typename T, Index N> 00279 struct IsScalarType< Vector<T, N> > { 00280 static bool const value = IsScalarType<T>::value; 00281 }; 00282 00283 template <typename T, Index N> 00284 struct Value< Vector<T, N> > { 00285 typedef typename ValueType< Vector<T, N> >::type value_type; 00286 static const Vector<value_type, N> 00287 eval(Vector<T, N> const & x) 00288 { 00289 Vector<value_type, N> v(x.get_dimension()); 00290 00291 for (Index i = 0; i < x.get_number_components(); ++i) { 00292 v[i] = Value<T>::eval(x[i]); 00293 } 00294 00295 return v; 00296 } 00297 }; 00298 00299 template <typename T, Index N> 00300 struct ScalarValue< Vector<T, N> > { 00301 typedef typename ScalarType< Vector<T, N> >::type scalar_type; 00302 static const Vector<scalar_type, N> 00303 eval(Vector<T, N> const & x) 00304 { 00305 Vector<scalar_type, N> v(x.get_dimension()); 00306 00307 for (Index i = 0; i < x.get_number_components(); ++i) { 00308 v[i] = ScalarValue<T>::eval(x[i]); 00309 } 00310 return v; 00311 } 00312 }; 00313 00314 template <typename T, Index N> 00315 struct StringName< Vector<T, N> > { 00316 static string 00317 eval() 00318 { 00319 return string("Vector<") + StringName<T>::eval() + string(", ") + 00320 dimension_string<N>::eval() + string(">"); 00321 } 00322 }; 00323 00324 template <typename T, Index N> 00325 struct IsEqual< Vector<T, N> > { 00326 static bool eval(T const & x, T const & y) { return x == y; } 00327 }; 00328 00329 template <typename T, Index N> 00330 struct IsStaticallySized< Vector<T, N> > { 00331 static const bool value = true; 00332 }; 00333 00334 template <typename T> 00335 struct IsStaticallySized< Vector<T, DYNAMIC> > 00336 { 00337 static const bool value = false; 00338 }; 00339 00341 template <typename T, Index N> 00342 struct ScalarType< Tensor<T, N> > { 00343 typedef typename ScalarType<T>::type type; 00344 }; 00345 00346 template <typename T, Index N> 00347 struct ValueType< Tensor<T, N> > { 00348 typedef typename ValueType<T>::type type; 00349 }; 00350 00351 template <typename T, Index N> 00352 struct IsADType< Tensor<T, N> > { 00353 static bool const value = IsADType<T>::value; 00354 }; 00355 00356 template <typename T, Index N> 00357 struct IsScalarType< Tensor<T, N> > { 00358 static bool const value = IsScalarType<T>::value; 00359 }; 00360 00361 template <typename T, Index N> 00362 struct Value< Tensor<T, N> > { 00363 typedef typename ValueType< Tensor<T, N> >::type value_type; 00364 static const Tensor<value_type, N> 00365 eval(Tensor<T, N> const & x) 00366 { 00367 Tensor<value_type, N> v(x.get_dimension()); 00368 00369 for (Index i = 0; i < x.get_number_components(); ++i) { 00370 v[i] = Value<T>::eval(x[i]); 00371 } 00372 00373 return v; 00374 } 00375 }; 00376 00377 template <typename T, Index N> 00378 struct ScalarValue< Tensor<T, N> > { 00379 typedef typename ScalarType< Tensor<T, N> >::type scalar_type; 00380 static const Tensor<scalar_type, N> 00381 eval(Tensor<T, N> const & x) 00382 { 00383 Tensor<scalar_type, N> v(x.get_dimension()); 00384 00385 for (Index i = 0; i < x.get_number_components(); ++i) { 00386 v[i] = ScalarValue<T>::eval(x[i]); 00387 } 00388 00389 return v; 00390 } 00391 }; 00392 00393 template <typename T, Index N> 00394 struct StringName< Tensor<T, N> > { 00395 static string 00396 eval() 00397 { 00398 return string("Tensor<") + StringName<T>::eval() + string(", ") + 00399 dimension_string<N>::eval() + string(">"); 00400 } 00401 }; 00402 00403 template <typename T, Index N> 00404 struct IsEqual< Tensor<T, N> > { 00405 static bool eval(T const & x, T const & y) { return x == y; } 00406 }; 00407 00408 template <typename T, Index N> 00409 struct IsStaticallySized< Tensor<T, N> > { 00410 static const bool value = true; 00411 }; 00412 00413 template <typename T> 00414 struct IsStaticallySized< Tensor<T, DYNAMIC> > 00415 { 00416 static const bool value = false; 00417 }; 00418 00420 template <typename T, Index N> 00421 struct ScalarType< Tensor3<T, N> > { 00422 typedef typename ScalarType<T>::type type; 00423 }; 00424 00425 template <typename T, Index N> 00426 struct ValueType< Tensor3<T, N> > { 00427 typedef typename ValueType<T>::type type; 00428 }; 00429 00430 template <typename T, Index N> 00431 struct IsADType< Tensor3<T, N> > { 00432 static bool const value = IsADType<T>::value; 00433 }; 00434 00435 template <typename T, Index N> 00436 struct IsScalarType< Tensor3<T, N> > { 00437 static bool const value = IsScalarType<T>::value; 00438 }; 00439 00440 template <typename T, Index N> 00441 struct Value< Tensor3<T, N> > { 00442 typedef typename ValueType< Tensor3<T, N> >::type value_type; 00443 static const Tensor3<value_type, N> 00444 eval(Tensor3<T, N> const & x) 00445 { 00446 Tensor3<value_type, N> v(x.get_dimension()); 00447 00448 for (Index i = 0; i < x.get_number_components(); ++i) { 00449 v[i] = Value<T>::eval(x[i]); 00450 } 00451 00452 return v; 00453 } 00454 }; 00455 00456 template <typename T, Index N> 00457 struct ScalarValue< Tensor3<T, N> > { 00458 typedef typename ScalarType< Tensor3<T, N> >::type scalar_type; 00459 static const Tensor3<scalar_type, N> 00460 eval(Tensor3<T, N> const & x) 00461 { 00462 Tensor3<scalar_type, N> v(x.get_dimension()); 00463 00464 for (Index i = 0; i < x.get_number_components(); ++i) { 00465 v[i] = ScalarValue<T>::eval(x[i]); 00466 } 00467 00468 return v; 00469 } 00470 }; 00471 00472 template <typename T, Index N> 00473 struct StringName< Tensor3<T, N> > { 00474 static string 00475 eval() 00476 { 00477 return string("Tensor3<") + StringName<T>::eval() + string(", ") + 00478 dimension_string<N>::eval() + string(">"); 00479 } 00480 }; 00481 00482 template <typename T, Index N> 00483 struct IsEqual< Tensor3<T, N> > { 00484 static bool eval(T const & x, T const & y) { return x == y; } 00485 }; 00486 00487 template <typename T, Index N> 00488 struct IsStaticallySized< Tensor3<T, N> > 00489 { 00490 static const bool value = true; 00491 }; 00492 00493 template <typename T> 00494 struct IsStaticallySized< Tensor3<T, DYNAMIC> > 00495 { 00496 static const bool value = false; 00497 }; 00498 00500 template <typename T, Index N> 00501 struct ScalarType< Tensor4<T, N> > { 00502 typedef typename ScalarType<T>::type type; 00503 }; 00504 00505 template <typename T, Index N> 00506 struct ValueType< Tensor4<T, N> > { 00507 typedef typename ValueType<T>::type type; 00508 }; 00509 00510 template <typename T, Index N> 00511 struct IsADType< Tensor4<T, N> > { 00512 static bool const value = IsADType<T>::value; 00513 }; 00514 00515 template <typename T, Index N> 00516 struct IsScalarType< Tensor4<T, N> > { 00517 static bool const value = IsScalarType<T>::value; 00518 }; 00519 00520 template <typename T, Index N> 00521 struct Value< Tensor4<T, N> > { 00522 typedef typename ValueType< Tensor4<T, N> >::type value_type; 00523 static const Tensor4<value_type, N> 00524 eval(Tensor4<T, N> const & x) 00525 { 00526 Tensor4<value_type, N> v(x.get_dimension()); 00527 00528 for (Index i = 0; i < x.get_number_components(); ++i) { 00529 v[i] = Value<T>::eval(x[i]); 00530 } 00531 00532 return v; 00533 } 00534 }; 00535 00536 template <typename T, Index N> 00537 struct ScalarValue< Tensor4<T, N> > { 00538 typedef typename ScalarType< Tensor4<T, N> >::type scalar_type; 00539 static const Tensor4<scalar_type, N> 00540 eval(Tensor4<T, N> const & x) 00541 { 00542 Tensor4<scalar_type, N> v(x.get_dimension()); 00543 00544 for (Index i = 0; i < x.get_number_components(); ++i) { 00545 v[i] = ScalarValue<T>::eval(x[i]); 00546 } 00547 00548 return v; 00549 } 00550 }; 00551 00552 template <typename T, Index N> 00553 struct StringName< Tensor4<T, N> > { 00554 static string 00555 eval() 00556 { 00557 return string("Tensor4<") + StringName<T>::eval() + string(", ") + 00558 dimension_string<N>::eval() + string(">"); 00559 } 00560 }; 00561 00562 template <typename T, Index N> 00563 struct IsEqual< Tensor4<T, N> > { 00564 static bool eval(T const & x, T const & y) { return x == y; } 00565 }; 00566 00567 template <typename T, Index N> 00568 struct IsStaticallySized< Tensor4<T, N> > 00569 { 00570 static const bool value = true; 00571 }; 00572 00573 template <typename T> 00574 struct IsStaticallySized< Tensor4<T, DYNAMIC> > 00575 { 00576 static const bool value = false; 00577 }; 00578 00579 } // namespace Sacado 00580 00581 #endif // Intrepid_MiniTensor_Definitions_h
1.7.6.1