42 #if !defined(Intrepid_MiniTensor_Tensor_i_h)
43 #define Intrepid_MiniTensor_Tensor_i_h
51 greater_than(S
const & a, S
const & b)
53 return a.first > b.first;
63 std::pair<Vector<T>, Tensor<T> >
64 sort_permutation(Vector<T>
const & u)
68 N = u.get_dimension();
70 std::vector<std::pair<T, Index > >
73 for (Index i = 0; i < N; ++i) {
78 std::sort(s.begin(), s.end(), greater_than< std::pair<T, Index > > );
85 for (Index i = 0; i < N; ++i) {
87 P(s[i].second, i) = 1.0;
90 return std::make_pair(v, P);
114 assert(data_ptr != NULL);
130 switch (component_order) {
141 self[0] = data_ptr[0];
142 self[4] = data_ptr[1];
143 self[8] = data_ptr[2];
145 self[1] = data_ptr[3];
146 self[5] = data_ptr[4];
147 self[6] = data_ptr[5];
149 self[3] = data_ptr[6];
150 self[7] = data_ptr[7];
151 self[2] = data_ptr[8];
154 case SIERRA_SYMMETRIC:
155 self[0] = data_ptr[0];
156 self[4] = data_ptr[1];
157 self[8] = data_ptr[2];
159 self[1] = data_ptr[3];
160 self[5] = data_ptr[4];
161 self[6] = data_ptr[5];
163 self[3] = data_ptr[3];
164 self[7] = data_ptr[4];
165 self[2] = data_ptr[5];
169 std::cerr <<
"ERROR: " << __PRETTY_FUNCTION__;
170 std::cerr << std::endl;
171 std::cerr <<
"Unknown component order.";
172 std::cerr << std::endl;
235 T
const & s00, T
const & s01,
236 T
const & s10, T
const & s11)
259 T
const & s00, T
const & s01, T
const & s02,
260 T
const & s10, T
const & s11, T
const & s12,
261 T
const & s20, T
const & s21, T
const & s22)
300 Index
const dimension,
302 ComponentOrder
const component_order)
304 assert(data_ptr != NULL);
311 fill(data_ptr, component_order);
338 dimension_2nd = dimension_4th * dimension_4th;
346 number_components = dimension_2nd * dimension_2nd;
348 for (Index i = 0; i < number_components; ++i) {
382 return self[i * N + j];
402 return self[i * N + j];
408 template<
typename S,
typename T>
424 template<
typename S,
typename T>
426 Tensor<typename Promote<S, T>::type>
427 operator-(Tensor<S>
const & A, Tensor<T>
const & B)
429 Tensor<typename Promote<S, T>::type>
443 operator-(Tensor<T>
const & A)
459 operator==(Tensor<T>
const & A, Tensor<T>
const & B)
470 operator!=(Tensor<T>
const & A, Tensor<T>
const & B)
472 return not_equal(A, B);
478 template<
typename S,
typename T>
480 typename lazy_disable_if< order_1234<S>, apply_tensor< Promote<S,T> > >::type
481 operator*(S
const & s, Tensor<T>
const & A)
483 Tensor<typename Promote<S, T>::type>
494 template<
typename S,
typename T>
496 typename lazy_disable_if< order_1234<S>, apply_tensor< Promote<S,T> > >::type
497 operator*(Tensor<T>
const & A, S
const & s)
499 Tensor<typename Promote<S, T>::type>
510 template<
typename S,
typename T>
512 Tensor<typename Promote<S, T>::type>
513 operator/(Tensor<T>
const & A, S
const & s)
515 Tensor<typename Promote<S, T>::type>
526 template<
typename S,
typename T>
528 Vector<typename Promote<S, T>::type>
529 operator*(Tensor<T>
const & A, Vector<S>
const & u)
537 template<
typename S,
typename T>
539 Vector<typename Promote<S, T>::type>
540 operator*(Vector<S>
const & u, Tensor<T>
const & A)
548 template<
typename S,
typename T>
550 Tensor<typename Promote<S, T>::type>
551 operator*(Tensor<S>
const & A, Tensor<T>
const & B)
561 row(Tensor<T>
const & A, Index
const i)
564 N = A.get_dimension();
571 for (Index j = 0; j < N; ++j) {
596 col(Tensor<T>
const & A, Index
const j)
599 N = A.get_dimension();
606 for (Index i = 0; i < N; ++i) {
633 template<
typename S,
typename T>
635 Vector<typename Promote<S, T>::type>
636 dot(Tensor<T>
const & A, Vector<S>
const & u)
639 N = A.get_dimension();
641 assert(u.get_dimension() == N);
643 Vector<typename Promote<S, T>::type>
649 for (Index i = 0; i < N; ++i) {
651 typename Promote<S, T>::type
654 for (Index p = 0; p < N; ++p) {
662 v(0) = A(0,0)*u(0) + A(0,1)*u(1) + A(0,2)*u(2);
663 v(1) = A(1,0)*u(0) + A(1,1)*u(1) + A(1,2)*u(2);
664 v(2) = A(2,0)*u(0) + A(2,1)*u(1) + A(2,2)*u(2);
668 v(0) = A(0,0)*u(0) + A(0,1)*u(1);
669 v(1) = A(1,0)*u(0) + A(1,1)*u(1);
683 template<
typename S,
typename T>
685 Vector<typename Promote<S, T>::type>
686 dot(Vector<S>
const & u, Tensor<T>
const & A)
689 N = A.get_dimension();
691 assert(u.get_dimension() == N);
693 Vector<typename Promote<S, T>::type>
699 for (Index i = 0; i < N; ++i) {
701 typename Promote<S, T>::type
704 for (Index p = 0; p < N; ++p) {
712 v(0) = A(0,0)*u(0) + A(1,0)*u(1) + A(2,0)*u(2);
713 v(1) = A(0,1)*u(0) + A(1,1)*u(1) + A(2,1)*u(2);
714 v(2) = A(0,2)*u(0) + A(1,2)*u(1) + A(2,2)*u(2);
718 v(0) = A(0,0)*u(0) + A(1,0)*u(1);
719 v(1) = A(0,1)*u(0) + A(1,1)*u(1);
733 template<
typename S,
typename T>
735 Tensor<typename Promote<S, T>::type>
736 dot(Tensor<S>
const & A, Tensor<T>
const & B)
739 N = A.get_dimension();
741 assert(B.get_dimension() == N);
743 Tensor<typename Promote<S, T>::type>
749 for (Index i = 0; i < N; ++i) {
750 for (Index j = 0; j < N; ++j) {
752 typename Promote<S, T>::type
755 for (Index p = 0; p < N; ++p) {
756 s += A(i, p) * B(p, j);
764 C(0,0) = A(0,0)*B(0,0) + A(0,1)*B(1,0) + A(0,2)*B(2,0);
765 C(0,1) = A(0,0)*B(0,1) + A(0,1)*B(1,1) + A(0,2)*B(2,1);
766 C(0,2) = A(0,0)*B(0,2) + A(0,1)*B(1,2) + A(0,2)*B(2,2);
768 C(1,0) = A(1,0)*B(0,0) + A(1,1)*B(1,0) + A(1,2)*B(2,0);
769 C(1,1) = A(1,0)*B(0,1) + A(1,1)*B(1,1) + A(1,2)*B(2,1);
770 C(1,2) = A(1,0)*B(0,2) + A(1,1)*B(1,2) + A(1,2)*B(2,2);
772 C(2,0) = A(2,0)*B(0,0) + A(2,1)*B(1,0) + A(2,2)*B(2,0);
773 C(2,1) = A(2,0)*B(0,1) + A(2,1)*B(1,1) + A(2,2)*B(2,1);
774 C(2,2) = A(2,0)*B(0,2) + A(2,1)*B(1,2) + A(2,2)*B(2,2);
778 C(0,0) = A(0,0)*B(0,0) + A(0,1)*B(1,0);
779 C(0,1) = A(0,0)*B(0,1) + A(0,1)*B(1,1);
781 C(1,0) = A(1,0)*B(0,0) + A(1,1)*B(1,0);
782 C(1,1) = A(1,0)*B(0,1) + A(1,1)*B(1,1);
796 template<
typename S,
typename T>
798 Tensor<typename Promote<S, T>::type>
799 t_dot(Tensor<S>
const & A, Tensor<T>
const & B)
802 N = A.get_dimension();
804 assert(B.get_dimension() == N);
806 Tensor<typename Promote<S, T>::type>
812 for (Index i = 0; i < N; ++i) {
813 for (Index j = 0; j < N; ++j) {
815 typename Promote<S, T>::type
818 for (Index p = 0; p < N; ++p) {
819 s += A(p, i) * B(p, j);
827 C(0,0) = A(0,0)*B(0,0) + A(1,0)*B(1,0) + A(2,0)*B(2,0);
828 C(0,1) = A(0,0)*B(0,1) + A(1,0)*B(1,1) + A(2,0)*B(2,1);
829 C(0,2) = A(0,0)*B(0,2) + A(1,0)*B(1,2) + A(2,0)*B(2,2);
831 C(1,0) = A(0,1)*B(0,0) + A(1,1)*B(1,0) + A(2,1)*B(2,0);
832 C(1,1) = A(0,1)*B(0,1) + A(1,1)*B(1,1) + A(2,1)*B(2,1);
833 C(1,2) = A(0,1)*B(0,2) + A(1,1)*B(1,2) + A(2,1)*B(2,2);
835 C(2,0) = A(0,2)*B(0,0) + A(1,2)*B(1,0) + A(2,2)*B(2,0);
836 C(2,1) = A(0,2)*B(0,1) + A(1,2)*B(1,1) + A(2,2)*B(2,1);
837 C(2,2) = A(0,2)*B(0,2) + A(1,2)*B(1,2) + A(2,2)*B(2,2);
841 C(0,0) = A(0,0)*B(0,0) + A(1,0)*B(1,0);
842 C(0,1) = A(0,0)*B(0,1) + A(1,0)*B(1,1);
844 C(1,0) = A(0,1)*B(0,0) + A(1,1)*B(1,0);
845 C(1,1) = A(0,1)*B(0,1) + A(1,1)*B(1,1);
859 template<
typename S,
typename T>
861 Tensor<typename Promote<S, T>::type>
862 dot_t(Tensor<S>
const & A, Tensor<T>
const & B)
865 N = A.get_dimension();
867 assert(B.get_dimension() == N);
869 Tensor<typename Promote<S, T>::type>
875 for (Index i = 0; i < N; ++i) {
876 for (Index j = 0; j < N; ++j) {
878 typename Promote<S, T>::type
881 for (Index p = 0; p < N; ++p) {
882 s += A(i, p) * B(j, p);
890 C(0,0) = A(0,0)*B(0,0) + A(0,1)*B(0,1) + A(0,2)*B(0,2);
891 C(0,1) = A(0,0)*B(1,0) + A(0,1)*B(1,1) + A(0,2)*B(1,2);
892 C(0,2) = A(0,0)*B(2,0) + A(0,1)*B(2,1) + A(0,2)*B(2,2);
894 C(1,0) = A(1,0)*B(0,0) + A(1,1)*B(0,1) + A(1,2)*B(0,2);
895 C(1,1) = A(1,0)*B(1,0) + A(1,1)*B(1,1) + A(1,2)*B(1,2);
896 C(1,2) = A(1,0)*B(2,0) + A(1,1)*B(2,1) + A(1,2)*B(2,2);
898 C(2,0) = A(2,0)*B(0,0) + A(2,1)*B(0,1) + A(2,2)*B(0,2);
899 C(2,1) = A(2,0)*B(1,0) + A(2,1)*B(1,1) + A(2,2)*B(1,2);
900 C(2,2) = A(2,0)*B(2,0) + A(2,1)*B(2,1) + A(2,2)*B(2,2);
904 C(0,0) = A(0,0)*B(0,0) + A(0,1)*B(0,1);
905 C(0,1) = A(0,0)*B(1,0) + A(0,1)*B(1,1);
907 C(1,0) = A(1,0)*B(0,0) + A(1,1)*B(0,1);
908 C(1,1) = A(1,0)*B(1,0) + A(1,1)*B(1,1);
922 template<
typename S,
typename T>
924 Tensor<typename Promote<S, T>::type>
925 t_dot_t(Tensor<S>
const & A, Tensor<T>
const & B)
928 N = A.get_dimension();
930 assert(B.get_dimension() == N);
932 Tensor<typename Promote<S, T>::type>
938 for (Index i = 0; i < N; ++i) {
939 for (Index j = 0; j < N; ++j) {
941 typename Promote<S, T>::type
944 for (Index p = 0; p < N; ++p) {
945 s += A(p, i) * B(j, p);
953 C(0,0) = A(0,0)*B(0,0) + A(1,0)*B(0,1) + A(2,0)*B(0,2);
954 C(0,1) = A(0,0)*B(1,0) + A(1,0)*B(1,1) + A(2,0)*B(1,2);
955 C(0,2) = A(0,0)*B(2,0) + A(1,0)*B(2,1) + A(2,0)*B(2,2);
957 C(1,0) = A(0,1)*B(0,0) + A(1,1)*B(0,1) + A(2,1)*B(0,2);
958 C(1,1) = A(0,1)*B(1,0) + A(1,1)*B(1,1) + A(2,1)*B(1,2);
959 C(1,2) = A(0,1)*B(2,0) + A(1,1)*B(2,1) + A(2,1)*B(2,2);
961 C(2,0) = A(0,2)*B(0,0) + A(1,2)*B(0,1) + A(2,2)*B(0,2);
962 C(2,1) = A(0,2)*B(1,0) + A(1,2)*B(1,1) + A(2,2)*B(1,2);
963 C(2,2) = A(0,2)*B(2,0) + A(1,2)*B(2,1) + A(2,2)*B(2,2);
967 C(0,0) = A(0,0)*B(0,0) + A(1,0)*B(0,1);
968 C(0,1) = A(0,0)*B(1,0) + A(1,0)*B(1,1);
970 C(1,0) = A(0,1)*B(0,0) + A(1,1)*B(0,1);
971 C(1,1) = A(0,1)*B(1,0) + A(1,1)*B(1,1);
985 template<
typename S,
typename T>
987 typename Promote<S, T>::type
988 dotdot(Tensor<S>
const & A, Tensor<T>
const & B)
991 N = A.get_dimension();
993 assert(B.get_dimension() == N);
995 typename Promote<S, T>::type
1001 for (Index p = 0; p < N; ++p) {
1002 for (Index q = 0; q < N; ++q) {
1003 s += A(p, q) * B(p, q);
1009 s+= A(0,0)*B(0,0) + A(0,1)*B(0,1) + A(0,2)*B(0,2);
1010 s+= A(1,0)*B(1,0) + A(1,1)*B(1,1) + A(1,2)*B(1,2);
1011 s+= A(2,0)*B(2,0) + A(2,1)*B(2,1) + A(2,2)*B(2,2);
1015 s+= A(0,0)*B(0,0) + A(0,1)*B(0,1);
1016 s+= A(1,0)*B(1,0) + A(1,1)*B(1,1);
1030 template<
typename S,
typename T>
1032 Tensor<typename Promote<S, T>::type>
1033 dyad(Vector<S>
const & u, Vector<T>
const & v)
1036 N = u.get_dimension();
1038 assert(v.get_dimension() == N);
1040 Tensor<typename Promote<S, T>::type>
1046 for (Index i = 0; i < N; ++i) {
1048 typename Promote<S, T>::type
const
1051 for (Index j = 0; j < N; ++j) {
1058 A(0,0) = u(0) * v(0);
1059 A(0,1) = u(0) * v(1);
1060 A(0,2) = u(0) * v(2);
1062 A(1,0) = u(1) * v(0);
1063 A(1,1) = u(1) * v(1);
1064 A(1,2) = u(1) * v(2);
1066 A(2,0) = u(2) * v(0);
1067 A(2,1) = u(2) * v(1);
1068 A(2,2) = u(2) * v(2);
1072 A(0,0) = u(0) * v(0);
1073 A(0,1) = u(0) * v(1);
1075 A(1,0) = u(1) * v(0);
1076 A(1,1) = u(1) * v(1);
1090 template<
typename S,
typename T>
1092 Tensor<typename Promote<S, T>::type>
1093 bun(Vector<S>
const & u, Vector<T>
const & v)
1104 template<
typename S,
typename T>
1106 Tensor<typename Promote<S, T>::type>
1107 tensor(Vector<S>
const & u, Vector<T>
const & v)
1117 template<
typename T>
1119 diag(Vector<T>
const & v)
1122 N = v.get_dimension();
1130 for (Index i = 0; i < N; ++i) {
1156 template<
typename T>
1158 diag(Tensor<T>
const & A)
1161 N = A.get_dimension();
1169 for (Index i = 0; i < N; ++i) {
1194 template<
typename T>
1199 return Tensor<T>(N, ZEROS);
1205 template<
typename T>
1208 identity(Index
const N)
1216 for (Index i = 0; i < N; ++i) {
1240 template<
typename T>
1245 return identity<T>(N);
1251 template<
typename T>
1254 transpose(Tensor<T>
const & A)
1257 N = A.get_dimension();
1265 for (Index i = 0; i < N; ++i) {
1266 for (Index j = i + 1; j < N; ++j) {
1267 std::swap(B(i, j), B(j, i));
1273 std::swap(B(0,1), B(1,0));
1274 std::swap(B(0,2), B(2,0));
1276 std::swap(B(1,2), B(2,1));
1281 std::swap(B(0,1), B(1,0));
1294 template<
typename T>
1297 sym(Tensor<T>
const & A)
1300 N = A.get_dimension();
1308 B = 0.5 * (A + transpose(A));
1313 T
const & s00 = A(0,0);
1314 T
const & s11 = A(1,1);
1315 T
const & s22 = A(2,2);
1317 T
const & s01 = 0.5 * (A(0,1) + A(1,0));
1318 T
const & s02 = 0.5 * (A(0,2) + A(2,0));
1319 T
const & s12 = 0.5 * (A(1,2) + A(2,1));
1337 T
const & s00 = A(0,0);
1338 T
const & s11 = A(1,1);
1340 T
const & s01 = 0.5 * (A(0,1) + A(1,0));
1359 template<
typename T>
1362 skew(Tensor<T>
const & A)
1365 N = A.get_dimension();
1373 B = 0.5 * (A - transpose(A));
1378 T
const & s01 = 0.5*(A(0,1)-A(1,0));
1379 T
const & s02 = 0.5*(A(0,2)-A(2,0));
1380 T
const & s12 = 0.5*(A(1,2)-A(2,1));
1398 T
const & s01 = 0.5*(A(0,1)-A(1,0));
1418 template<
typename T>
1421 skew(Vector<T>
const & u)
1424 N = u.get_dimension();
1446 std::cerr <<
"ERROR: " << __PRETTY_FUNCTION__;
1447 std::cerr << std::endl;
1448 std::cerr <<
"Skew from vector undefined for R^" << N;
1449 std::cerr << std::endl;
1460 #endif // Intrepid_MiniTensor_Tensor_i_h
void set_dimension(Index const dimension)
Index get_dimension() const
void fill(ComponentValue value)
void fill(ComponentValue value)
T const & operator()(Index const i, Index const j) const