5 #ifndef __TEMPLATES_HPP__
6 #define __TEMPLATES_HPP__
10 template <
typename T>
using ShardVec = boost::shared_ptr<std::vector<T>>;
34 ublas::shallow_array_adaptor<T>(
n, ptr));
56 template <
typename T1>
60 n,
m, ublas::shallow_array_adaptor<T>(
n *
m, ptr));
71 template <
class KeyExtractor1,
class KeyExtractor2>
struct KeyFromKey {
76 const KeyExtractor2 &key2_ = KeyExtractor2())
88 template <
typename id_type>
struct LtBit {
89 inline bool operator()(
const id_type &valueA,
const id_type &valueB)
const {
90 return valueA.to_ulong() < valueB.to_ulong();
94 template <
typename id_type>
struct EqBit {
95 inline bool operator()(
const id_type &valueA,
const id_type &valueB)
const {
96 return valueA.to_ulong() == valueB.to_ulong();
102 return value.to_ulong();
106 template <
class X>
inline std::string
toString(X x) {
107 std::ostringstream buffer;
113 static inline auto get(ublas::vector<T, A> &data) {
134 template <
int S = 1,
class T,
class A>
139 template <
int Tensor_Dim,
int S,
class T,
class L,
class A>
142 template <
int S,
class T,
class A>
144 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
146 if (data.size1() != 3)
148 "getFTensor1FromMat<3>: wrong size of data matrix, number of "
149 "rows should be 3 but is " +
150 boost::lexical_cast<std::string>(data.size1()));
153 &data(0, 0), &data(1, 0), &data(2, 0));
157 template <
int S,
class T,
class A>
159 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
161 if (data.size1() != 4)
163 "getFTensor1FromMat<4>: wrong size of data matrix, number of "
164 "rows should be 4 but is " +
165 boost::lexical_cast<std::string>(data.size1()));
168 &data(0, 0), &data(1, 0), &data(2, 0), &data(3, 0));
172 template <
int S,
class T,
class A>
174 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
176 if (data.size1() != 6)
178 "getFTensor1FromMat<6>: wrong size of data matrix, number of "
179 "rows should be 6 but is " +
180 boost::lexical_cast<std::string>(data.size1()));
183 &data(0, 0), &data(1, 0), &data(2, 0), &data(3, 0), &data(4, 0),
188 template <
int S,
class T,
class A>
190 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
192 if (data.size1() != 9)
194 "getFTensor1FromMat<9>: wrong size of data matrix, number of "
195 "rows should be 9 but is " +
196 boost::lexical_cast<std::string>(data.size1()));
199 &data(0, 0), &data(1, 0), &data(2, 0), &data(3, 0), &data(4, 0),
200 &data(5, 0), &data(6, 0), &data(7, 0), &data(8, 0));
204 template <
int S,
class T,
class A>
206 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
208 if (data.size1() != 2)
210 "getFTensor1FromMat<2>: wrong size of data matrix, number of "
211 "rows should be 2 but is " +
212 boost::lexical_cast<std::string>(data.size1()));
219 template <
int S,
class T,
class A>
221 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
223 if (data.size1() != 1)
225 "getFTensor1FromMat<1>: wrong size of data matrix, number of "
226 "rows should be 1 but is " +
227 boost::lexical_cast<std::string>(data.size1()));
236 template <
int Tensor_Dim,
int S = 1,
class T,
class L,
class A>
239 static_assert(!std::is_same<T, T>::value,
"not implemented");
245 template <
int Tensor_Dim,
int S = 1>
251 template <
int Tensor_Dim1,
int Tensor_Dim2,
int S,
class T,
class L,
class A>
253 static inline auto get(ublas::matrix<T, L, A> &data) {
255 if (data.size1() != Tensor_Dim1 * Tensor_Dim2) {
257 "getFTensor2FromMat<" +
258 boost::lexical_cast<std::string>(Tensor_Dim1) +
"," +
259 boost::lexical_cast<std::string>(Tensor_Dim2) +
260 ">: wrong size of rows in data matrix, should be " +
261 boost::lexical_cast<std::string>(Tensor_Dim1 * Tensor_Dim2) +
262 " but is " + boost::lexical_cast<std::string>(data.size1()));
265 std::array<double *, Tensor_Dim1 * Tensor_Dim2> ptrs;
266 for (
auto i = 0;
i != Tensor_Dim1 * Tensor_Dim2; ++
i)
267 ptrs[
i] = &data(
i, 0);
276 template <
int Tensor_Dim1,
int Tensor_Dim2>
283 template <
int Tensor_Dim1,
int Tensor_Dim2>
296 template <
int Tensor_Dim,
int S,
class T,
class L,
class A>
299 template <
int S,
class T,
class L,
class A>
301 static inline auto get(ublas::matrix<T, L, A> &data) {
303 if (data.size1() != 6)
305 "getFTensor2SymmetricFromMat<3>: wrong size of data matrix, numer "
306 "of rows should be 6 but is " +
307 boost::lexical_cast<std::string>(data.size1()));
310 &data(0, 0), &data(1, 0), &data(2, 0), &data(3, 0), &data(4, 0),
315 template <
int S,
class T,
class L,
class A>
317 static inline auto get(ublas::matrix<T, L, A> &data) {
319 if (data.size1() != 3)
321 "getFTensor2SymmetricFromMat<2>: wrong size of data matrix, numer "
322 "of rows should be 3 but is " +
323 boost::lexical_cast<std::string>(data.size1()));
326 &data(0, 0), &data(1, 0), &data(2, 0));
333 template <
int Tensor_Dim,
int S,
class T,
class L,
class A>
338 template <
int Tensor_Dim,
int S = 1>
344 template <
int Tensor_Dim01,
int Tensor_Dim23,
int S,
class T,
class L,
class A>
347 template <
int S,
class T,
class A>
349 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
351 if (data.size1() != 1)
353 "getFTensor4DdgFromMat<1, 1>: wrong size of data matrix, number "
354 "of rows should be 1 but is " +
355 boost::lexical_cast<std::string>(data.size1()));
361 template <
int S,
class T,
class A>
363 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
365 if (data.size1() != 9) {
367 "getFTensor4DdgFromMat<2, 2>: wrong size of data matrix, number "
368 "of rows should be 9 but is " +
369 boost::lexical_cast<std::string>(data.size1()));
373 &data(0, 0), &data(1, 0), &data(2, 0), &data(3, 0), &data(4, 0),
374 &data(5, 0), &data(6, 0), &data(7, 0), &data(8, 0)};
378 template <
int S,
class T,
class A>
380 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
382 if (data.size1() != 36) {
383 cerr << data.size1() << endl;
385 "getFTensor4DdgFromMat<3, 3>: wrong size of data matrix, number "
386 "of rows should be 36 but is " +
387 boost::lexical_cast<std::string>(data.size1()));
391 &data(0, 0), &data(1, 0), &data(2, 0), &data(3, 0), &data(4, 0),
392 &data(5, 0), &data(6, 0), &data(7, 0), &data(8, 0), &data(9, 0),
393 &data(10, 0), &data(11, 0), &data(12, 0), &data(13, 0), &data(14, 0),
394 &data(15, 0), &data(16, 0), &data(17, 0), &data(18, 0), &data(19, 0),
395 &data(20, 0), &data(21, 0), &data(22, 0), &data(23, 0), &data(24, 0),
396 &data(25, 0), &data(26, 0), &data(27, 0), &data(28, 0), &data(29, 0),
397 &data(30, 0), &data(31, 0), &data(32, 0), &data(33, 0), &data(34, 0),
415 template <
int Tensor_Dim01,
int Tensor_Dim23,
int S = 1,
class T,
class L,
419 static_assert(!std::is_same<T, T>::value,
420 "Such getFTensor4DdgFromMat specialisation is not implemented");
423 template <
int Tensor_Dim01,
int Tensor_Dim23,
int S = 1>
430 template <
int Tensor_Dim01,
int Tensor_Dim23,
int S,
class T>
434 static inline auto get(T *ptr) {
437 ptr + 0, ptr + 1, ptr + 2, ptr + 3, ptr + 4, ptr + 5,
438 ptr + 6, ptr + 7, ptr + 8, ptr + 9, ptr + 10, ptr + 11,
439 ptr + 12, ptr + 13, ptr + 14, ptr + 15, ptr + 16, ptr + 17,
440 ptr + 18, ptr + 19, ptr + 20, ptr + 21, ptr + 22, ptr + 23,
441 ptr + 24, ptr + 25, ptr + 26, ptr + 27, ptr + 28, ptr + 29,
442 ptr + 30, ptr + 31, ptr + 32, ptr + 33, ptr + 34, ptr + 35};
446 template <
int Tensor_Dim01,
int Tensor_Dim23,
int S = 1,
class T =
double>
451 template <
int Tensor_Dim01,
int Tensor_Dim2,
int S,
class T,
class L,
class A>
454 template <
int S,
class T,
class A>
456 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
458 if (data.size1() != 1)
460 "getFTensor3DgFromMat<1, 1>: wrong size of data matrix, number "
461 "of rows should be 1 but is " +
462 boost::lexical_cast<std::string>(data.size1()));
468 template <
int S,
class T,
class A>
470 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
472 if (data.size1() != 6) {
474 "getFTensor4DdgFromMat<2, 2>: wrong size of data matrix, number "
475 "of rows should be 6 but is " +
476 boost::lexical_cast<std::string>(data.size1()));
480 &data(0, 0), &data(1, 0), &data(2, 0),
481 &data(3, 0), &data(4, 0), &data(5, 0)};
485 template <
int S,
class T,
class A>
487 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
489 if (data.size1() != 18) {
490 cerr << data.size1() << endl;
492 "getFTensor3DgFromMat<3, 3>: wrong size of data matrix, number "
493 "of rows should be 18 but is " +
494 boost::lexical_cast<std::string>(data.size1()));
498 &data(0, 0), &data(1, 0), &data(2, 0), &data(3, 0), &data(4, 0),
499 &data(5, 0), &data(6, 0), &data(7, 0), &data(8, 0), &data(9, 0),
500 &data(10, 0), &data(11, 0), &data(12, 0), &data(13, 0), &data(14, 0),
501 &data(15, 0), &data(16, 0), &data(17, 0)};
517 template <
int Tensor_Dim01,
int Tensor_Dim2,
int S = 1,
class T,
class L,
521 static_assert(!std::is_same<T, T>::value,
522 "Such getFTensor3DgFromMat specialisation is not implemented");
525 template <
int Tensor_Dim01,
int Tensor_Dim2,
int S = 1>
531 template <
int Tensor_Dim0,
int Tensor_Dim1,
int Tensor_Dim2,
int Tensor_Dim3,
532 int S,
class T,
class L,
class A>
535 template <
int S,
class T,
class A>
537 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
539 if (data.size1() != 1)
541 "getFTensor4FromMat<1, 1, 1, 1>: wrong size of data matrix, number "
542 "of rows should be 1 but is " +
543 boost::lexical_cast<std::string>(data.size1()));
550 template <
int S,
class T,
class A>
552 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
554 if (data.size1() != 16) {
556 "getFTensor4FromMat<2, 2, 2, 2>: wrong size of data matrix, number "
557 "of rows should be 16 but is " +
558 boost::lexical_cast<std::string>(data.size1()));
562 &data(0, 0), &data(1, 0), &data(2, 0), &data(3, 0),
563 &data(4, 0), &data(5, 0), &data(6, 0), &data(7, 0),
564 &data(8, 0), &data(9, 0), &data(10, 0), &data(11, 0),
565 &data(12, 0), &data(13, 0), &data(14, 0), &data(15, 0)};
569 template <
int S,
class T,
class A>
571 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
573 if (data.size1() != 81) {
574 cerr << data.size1() << endl;
576 "getFTensor4FromMat<3, 3, 3, 3>: wrong size of data matrix, number "
577 "of rows should be 81 but is " +
578 boost::lexical_cast<std::string>(data.size1()));
582 &data(0, 0), &data(1, 0), &data(2, 0), &data(3, 0), &data(4, 0),
583 &data(5, 0), &data(6, 0), &data(7, 0), &data(8, 0), &data(9, 0),
584 &data(10, 0), &data(11, 0), &data(12, 0), &data(13, 0), &data(14, 0),
585 &data(15, 0), &data(16, 0), &data(17, 0), &data(18, 0), &data(19, 0),
586 &data(20, 0), &data(21, 0), &data(22, 0), &data(23, 0), &data(24, 0),
587 &data(25, 0), &data(26, 0), &data(27, 0), &data(28, 0), &data(29, 0),
588 &data(30, 0), &data(31, 0), &data(32, 0), &data(33, 0), &data(34, 0),
589 &data(35, 0), &data(36, 0), &data(37, 0), &data(38, 0), &data(39, 0),
590 &data(40, 0), &data(41, 0), &data(42, 0), &data(43, 0), &data(44, 0),
591 &data(45, 0), &data(46, 0), &data(47, 0), &data(48, 0), &data(49, 0),
592 &data(50, 0), &data(51, 0), &data(52, 0), &data(53, 0), &data(54, 0),
593 &data(55, 0), &data(56, 0), &data(57, 0), &data(58, 0), &data(59, 0),
594 &data(60, 0), &data(61, 0), &data(62, 0), &data(63, 0), &data(64, 0),
595 &data(65, 0), &data(66, 0), &data(67, 0), &data(68, 0), &data(69, 0),
596 &data(70, 0), &data(71, 0), &data(72, 0), &data(73, 0), &data(74, 0),
597 &data(75, 0), &data(76, 0), &data(77, 0), &data(78, 0), &data(79, 0),
616 template <
int Tensor_Dim0,
int Tensor_Dim1,
int Tensor_Dim2,
int Tensor_Dim3,
617 int S = 1,
class T,
class L,
class A>
619 Tensor_Dim1, Tensor_Dim2, Tensor_Dim3>
621 static_assert(!std::is_same<T, T>::value,
622 "Such getFTensor4FromMat specialisation is not implemented");
625 template <
int Tensor_Dim0,
int Tensor_Dim1,
int Tensor_Dim2,
int Tensor_Dim3,
633 template <
int Tensor_Dim0,
int Tensor_Dim1,
int Tensor_Dim2,
int S,
class T,
637 template <
int S,
class T,
class A>
639 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
641 if (data.size1() != 1)
643 "getFTensor3FromMat<1, 1, 1>: wrong size of data matrix, number "
644 "of rows should be 1 but is " +
645 boost::lexical_cast<std::string>(data.size1()));
652 template <
int S,
class T,
class A>
654 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
656 if (data.size1() != 8)
658 "getFTensor3FromMat<2, 2, 2>: wrong size of data matrix, number "
659 "of rows should be 8 but is " +
660 boost::lexical_cast<std::string>(data.size1()));
663 &data(0, 0), &data(1, 0), &data(2, 0), &data(3, 0), &data(4, 0),
664 &data(5, 0), &data(6, 0), &data(7, 0)
670 template <
int S,
class T,
class A>
672 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
674 if (data.size1() != 12)
676 "getFTensor3FromMat<3, 2, 2>: wrong size of data matrix, number "
677 "of rows should be 12 but is " +
678 boost::lexical_cast<std::string>(data.size1()));
681 &data(0, 0), &data(1, 0), &data(2, 0), &data(3, 0),
682 &data(4, 0), &data(5, 0), &data(6, 0), &data(7, 0),
683 &data(8, 0), &data(9, 0), &data(10, 0), &data(11, 0)};
687 template <
int S,
class T,
class A>
689 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
691 if (data.size1() != 12)
693 "getFTensor3FromMat<2, 2, 3>: wrong size of data matrix, number "
694 "of rows should be 12 but is " +
695 boost::lexical_cast<std::string>(data.size1()));
698 &data(0, 0), &data(1, 0), &data(2, 0), &data(3, 0),
699 &data(4, 0), &data(5, 0), &data(6, 0), &data(7, 0),
700 &data(8, 0), &data(9, 0), &data(10, 0), &data(11, 0)};
704 template <
int S,
class T,
class A>
706 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
708 if (data.size1() != 27)
710 "getFTensor3FromMat<3, 3, 3>: wrong size of data matrix, number "
711 "of rows should be 27 but is " +
712 boost::lexical_cast<std::string>(data.size1()));
715 &data(0, 0), &data(1, 0), &data(2, 0), &data(3, 0), &data(4, 0),
716 &data(5, 0), &data(6, 0), &data(7, 0), &data(8, 0), &data(9, 0),
717 &data(10, 0), &data(11, 0), &data(12, 0), &data(13, 0), &data(14, 0),
718 &data(15, 0), &data(16, 0), &data(17, 0), &data(18, 0), &data(19, 0),
719 &data(20, 0), &data(21, 0), &data(22, 0), &data(23, 0), &data(24, 0),
720 &data(25, 0), &data(26, 0)};
724 template <
int S,
class T,
class A>
726 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
728 if (data.size1() != 54)
730 "getFTensor3FromMat<6, 3, 3>: wrong size of data matrix, number "
731 "of rows should be 54 but is " +
732 boost::lexical_cast<std::string>(data.size1()));
734 std::array<double *, 54> ptrs;
735 for (
auto i = 0;
i != 54; ++
i)
736 ptrs[
i] = &data(
i, 0);
741 template <
int S,
class T,
class A>
743 static inline auto get(ublas::matrix<T, ublas::row_major, A> &data) {
745 if (data.size1() != 54)
747 "getFTensor3FromMat<3, 3, 6>: wrong size of data matrix, number "
748 "of rows should be 54 but is " +
749 boost::lexical_cast<std::string>(data.size1()));
751 std::array<double *, 54> ptrs;
752 for (
auto i = 0;
i != 54; ++
i)
753 ptrs[
i] = &data(
i, 0);
772 template <
int Tensor_Dim0,
int Tensor_Dim1,
int Tensor_Dim2,
int S = 1,
class T,
775 Tensor_Dim1, Tensor_Dim2>
777 static_assert(!std::is_same<T, T>::value,
778 "Such getFTensor3FromMat specialisation is not implemented");
781 template <
int Tensor_Dim0,
int Tensor_Dim1,
int Tensor_Dim2,
int S = 1>
792 inline static auto get(T *ptr) {
799 inline static auto get(T *ptr) {
807 inline static auto get(T *ptr) {
815 inline static auto get(T *ptr) {
823 inline static auto get(T *ptr) {
825 ptr + 0, ptr + 1, ptr + 2, ptr + 3, ptr + 4, ptr + 5);
836 template <
int DIM,
int S = DIM>
843 template <
int DIM,
int S = DIM>
850 template <
int DIM,
int S = DIM>
860 inline static auto get(T *ptr) {
862 ptr + 0, ptr + 1, ptr + 2, ptr + 3, ptr + 4, ptr + 5);
868 inline static auto get(T *ptr) {
870 ptr + 0, ptr + 1, ptr + 2, ptr + 3, ptr + 4, ptr + 5, ptr + 6, ptr + 7,
871 ptr + 8, ptr + 9, ptr + 10, ptr + 11, ptr + 12, ptr + 13, ptr + 14,
872 ptr + 15, ptr + 16, ptr + 17, ptr + 18, ptr + 19, ptr + 20, ptr + 21,
873 ptr + 22, ptr + 23, ptr + 24, ptr + 25, ptr + 26, ptr + 27, ptr + 28,
874 ptr + 29, ptr + 30, ptr + 31, ptr + 32, ptr + 33, ptr + 34, ptr + 35);
880 inline static auto get(T *ptr) {
882 ptr + 0, ptr + 1, ptr + 2, ptr + 3, ptr + 4, ptr + 5, ptr + 6, ptr + 7,
889 inline static auto get(T *ptr) {
897 inline static auto get(T *ptr) {
905 inline static auto get(T *ptr) {
912 inline static auto get(T *ptr) {
924 template <
int DIM1,
int DIM2,
int S = DIM1 * DIM2>
936 template <
int DIM1,
int DIM2,
int S = DIM1 * DIM2>
948 template <
int DIM1,
int DIM2>
952 "Such getFTensor2HVecFromPtr is not implemented");
985 template <
int DIM1,
int DIM2,
int DIM3>
990 "Such getFTensor3FromPtr is not implemented");
997 ptr + 0, ptr + 1, ptr + 2, ptr + 3, ptr + 4, ptr + 5, ptr + 6, ptr + 7,
998 ptr + 8, ptr + 9, ptr + 10, ptr + 11);
1005 ptr + 0, ptr + 1, ptr + 2, ptr + 3, ptr + 4, ptr + 5, ptr + 6, ptr + 7,
1006 ptr + 8, ptr + 9, ptr + 10, ptr + 11, ptr + 12, ptr + 13, ptr + 14,
1007 ptr + 15, ptr + 16, ptr + 17, ptr + 18, ptr + 19, ptr + 20, ptr + 21,
1008 ptr + 22, ptr + 23, ptr + 24, ptr + 25, ptr + 26);
1022 static_assert(DIM,
"Such getFTensor2SymmetricFromPtr is not implemented");
1029 ptr + 0, ptr + 1, ptr + 2,
1040 &ptr[0], &ptr[1], &ptr[2]);
1056 static_assert(DIM,
"Such getFTensor2SymmetricFromPtr is not implemented");
1063 ptr + 0, ptr + 1, ptr + 2,
1074 ptr + 0, ptr + 1, ptr + 2);
1090 "Such getFTensor2SymmetricLowerFromPtr is not implemented");
1108 ptr + 0, ptr + 1, ptr + 3);
1115 template <
typename V>
static inline auto get(V &data) {
1116 using T =
typename std::remove_reference<decltype(data[0])>
::type;
1123 template <
typename V>
static inline auto get(V &data) {
1124 using T =
typename std::remove_reference<decltype(data[0])>
::type;
1131 template <
typename V>
static inline auto get(V &data) {
1132 using T =
typename std::remove_reference<decltype(data[0])>
::type;
1140 template <
typename V>
static inline auto get(V &data) {
1141 using T =
typename std::remove_reference<decltype(data[0])>
::type;
1143 &data[2], &data[3]};
1149 template <
typename V>
static inline auto get(V &data) {
1150 using T =
typename std::remove_reference<decltype(data[0])>
::type;
1152 &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]};
1158 template <
typename V>
static inline auto get(V &data) {
1159 using T =
typename std::remove_reference<decltype(data[0])>
::type;
1161 &data[0], &data[1], &data[2], &data[3], &data[4],
1162 &data[5], &data[6], &data[7], &data[8]};
1180 template <
int DIM,
int S = 0>
1187 template <
int DIM,
int S>
1202 &data(rr + 0, 0), &data(rr + 1, 0), &data(rr + 2, 0)};
1209 &data(rr + 0, 0), &data(rr + 1, 0), &data(rr + 2, 0), &data(rr + 3, 0)};
1216 &data(rr + 0, 0), &data(rr + 1, 0), &data(rr + 2, 0),
1217 &data(rr + 3, 0), &data(rr + 4, 0), &data(rr + 5, 0),
1218 &data(rr + 6, 0), &data(rr + 7, 0), &data(rr + 8, 0)};
1231 template <
int DIM,
int S>
1234 static_assert(DIM != DIM,
"not implemented");
1249 &data(rr + 0, 0), &data(rr + 1, 1), &data(rr + 2, 2)};
1263 template <
int DIM1,
int DIM2,
int S,
class T,
class L,
class A>
1266 template <
int DIM1,
int DIM2,
class T,
class L,
class A>
1269 template <
int S,
class T,
class L,
class A>
1272 inline static auto get(ublas::matrix<T, L, A> &data,
const size_t rr,
1275 &data(rr + 0, cc + 0), &data(rr + 0, cc + 1),
1277 &data(rr + 1, cc + 0), &data(rr + 1, cc + 1)};
1281 template <
int S,
class T,
class L,
class A>
1284 inline static auto get(ublas::matrix<T, L, A> &data,
const size_t rr,
1287 &data(rr + 0, cc + 0), &data(rr + 0, cc + 1), &data(rr + 0, cc + 2),
1288 &data(rr + 1, cc + 0), &data(rr + 1, cc + 1), &data(rr + 1, cc + 2),
1289 &data(rr + 2, cc + 0), &data(rr + 2, cc + 1), &data(rr + 2, cc + 2)};
1293 template <
class T,
class L,
class A>
1296 inline static auto get(ublas::matrix<T, L, A> &data,
const size_t rr,
1297 const size_t cc,
const int ss = 0) {
1299 &data(rr + 0, cc + 0), &data(rr + 0, cc + 1),
1301 &data(rr + 1, cc + 0), &data(rr + 1, cc + 1), ss);
1305 template <
class T,
class L,
class A>
1308 inline static auto get(ublas::matrix<T, L, A> &data,
const size_t rr,
1309 const size_t cc,
const int ss = 0) {
1311 &data(rr + 0, cc + 0), &data(rr + 0, cc + 1), &data(rr + 0, cc + 2),
1312 &data(rr + 1, cc + 0), &data(rr + 1, cc + 1), &data(rr + 1, cc + 2),
1313 &data(rr + 2, cc + 0), &data(rr + 2, cc + 1), &data(rr + 2, cc + 2),
1318 template <
int DIM1,
int DIM2,
int S>
1325 template <
int DIM1,
int DIM2>
1334 template <
int S,
typename T,
typename L,
typename A>
1337 const size_t rr,
const size_t cc = 0) {
1341 template <
int S,
typename T,
typename L,
typename A>
1344 const size_t rr,
const size_t cc = 0) {
1350 template <
int DIM1,
int DIM2,
int S>
1368 const size_t M = mat.size1();
1369 const size_t N = mat.size2();
1373 "The input matrix for inverse computation is not square %d != %d",
1376 int *ipv =
new int[
N];
1378 double *work =
new double[lwork];
1383 "lapack error info = %d", info);
1387 "lapack error info = %d", info);
1404 const size_t M = mat.size1();
1405 const size_t N = mat.size2();
1407 if (
M == 0 ||
M !=
N)
1409 "The input matrix for inverse computation is not square %d != %d",
1416 int *ipiv =
new int[
M];
1418 &*
f.data().begin(),
M);
1421 "error lapack solve dgesv info = %d", info);
1439 auto mat_copy = mat;
1457 const size_t M = mat.size1();
1458 const size_t N = mat.size2();
1460 if (
M == 0 ||
M !=
N)
1463 "The input matrix for eigen value computation is not square %d != %d",
1465 if (eig.size() !=
M)
1466 eig.resize(
M,
false);
1471 const int size = (
M + 2) *
M;
1473 double *work =
new double[size];
1475 if (
lapack_dsyev(
'V',
'U',
n, &*eigen_vec.data().begin(), lda,
1476 &*eig.data().begin(), work, lwork) > 0)
1478 "The algorithm failed to compute eigenvalues.");
1491 template <
int DIM,
typename T1,
typename T2>
1498 const int lda = DIM;
1499 const int lwork = (DIM + 2) * DIM;
1500 std::array<
double, (DIM + 2) * DIM> work;
1505 "The algorithm failed to compute eigenvalues.");
1518 template <
int DIM,
typename T1,
typename T2,
typename T3>
1524 for (
int ii = 0; ii != DIM; ii++)
1525 for (
int jj = 0; jj != DIM; jj++)
1526 eigen_vec(ii, jj) = mat(ii, jj);
1541 return t(0, 0) *
t(1, 1) *
t(2, 2) +
t(1, 0) *
t(2, 1) *
t(0, 2) +
1542 t(2, 0) *
t(0, 1) *
t(1, 2) -
t(0, 0) *
t(2, 1) *
t(1, 2) -
1543 t(2, 0) *
t(1, 1) *
t(0, 2) -
t(1, 0) *
t(0, 1) *
t(2, 2);
1554 return t(0, 0) *
t(1, 1) -
t(0, 1) *
t(1, 0);
1570 template <
typename T,
int DIM>
1578 template <
typename T,
int DIM>
1587 template <
int Tensor_Dim,
class T,
class L,
class A>
1589 ublas::vector<T, A> &det_data,
1590 ublas::matrix<T, L, A> &inv_jac_data) {
1593 "Specialization for this template not yet implemented");
1599 invertTensor3by3<3, double, ublas::row_major, DoubleAllocator>(
1606 template <
class T1,
class T2>
1617 template <
class T1,
class T2>
1628 template <
class T1,
class T2,
class T3>
1631 const auto inv_det = 1. / det;
1632 inv_t(0, 0) = (
t(1, 1) *
t(2, 2) -
t(1, 2) *
t(2, 1)) * inv_det;
1633 inv_t(0, 1) = (
t(0, 2) *
t(2, 1) -
t(0, 1) *
t(2, 2)) * inv_det;
1634 inv_t(0, 2) = (
t(0, 1) *
t(1, 2) -
t(0, 2) *
t(1, 1)) * inv_det;
1635 inv_t(1, 0) = (
t(1, 2) *
t(2, 0) -
t(1, 0) *
t(2, 2)) * inv_det;
1636 inv_t(1, 1) = (
t(0, 0) *
t(2, 2) -
t(0, 2) *
t(2, 0)) * inv_det;
1637 inv_t(1, 2) = (
t(0, 2) *
t(1, 0) -
t(0, 0) *
t(1, 2)) * inv_det;
1638 inv_t(2, 0) = (
t(1, 0) *
t(2, 1) -
t(1, 1) *
t(2, 0)) * inv_det;
1639 inv_t(2, 1) = (
t(0, 1) *
t(2, 0) -
t(0, 0) *
t(2, 1)) * inv_det;
1640 inv_t(2, 2) = (
t(0, 0) *
t(1, 1) -
t(0, 1) *
t(1, 0)) * inv_det;
1648 template <
class T1,
class T2,
class T3>
1651 const auto inv_det = 1. / det;
1652 inv_t(0, 0) =
t(1, 1) * inv_det;
1653 inv_t(0, 1) = -
t(0, 1) * inv_det;
1654 inv_t(1, 0) = -
t(1, 0) * inv_det;
1655 inv_t(1, 1) =
t(0, 0) * inv_det;
1671 inv_t(0, 0) = (
t(1, 1) *
t(2, 2) -
t(1, 2) *
t(2, 1)) / det;
1672 inv_t(0, 1) = (
t(0, 2) *
t(2, 1) -
t(0, 1) *
t(2, 2)) / det;
1673 inv_t(0, 2) = (
t(0, 1) *
t(1, 2) -
t(0, 2) *
t(1, 1)) / det;
1674 inv_t(1, 0) = (
t(1, 2) *
t(2, 0) -
t(1, 0) *
t(2, 2)) / det;
1675 inv_t(1, 1) = (
t(0, 0) *
t(2, 2) -
t(0, 2) *
t(2, 0)) / det;
1676 inv_t(1, 2) = (
t(0, 2) *
t(1, 0) -
t(0, 0) *
t(1, 2)) / det;
1677 inv_t(2, 0) = (
t(1, 0) *
t(2, 1) -
t(1, 1) *
t(2, 0)) / det;
1678 inv_t(2, 1) = (
t(0, 1) *
t(2, 0) -
t(0, 0) *
t(2, 1)) / det;
1679 inv_t(2, 2) = (
t(0, 0) *
t(1, 1) -
t(0, 1) *
t(1, 0)) / det;
1691 invertTensor3by3<FTensor::Tensor2_symmetric<double, 3>,
double,
1696 const auto inv_det = 1. / det;
1697 inv_t(0, 0) = (
t(1, 1) *
t(2, 2) -
t(1, 2) *
t(2, 1)) * inv_det;
1698 inv_t(0, 1) = (
t(0, 2) *
t(2, 1) -
t(0, 1) *
t(2, 2)) * inv_det;
1699 inv_t(0, 2) = (
t(0, 1) *
t(1, 2) -
t(0, 2) *
t(1, 1)) * inv_det;
1700 inv_t(1, 1) = (
t(0, 0) *
t(2, 2) -
t(0, 2) *
t(2, 0)) * inv_det;
1701 inv_t(1, 2) = (
t(0, 2) *
t(1, 0) -
t(0, 0) *
t(1, 2)) * inv_det;
1702 inv_t(2, 2) = (
t(0, 0) *
t(1, 1) -
t(0, 1) *
t(1, 0)) * inv_det;
1714 invertTensor3by3<FTensor::Tensor2_symmetric<adouble, 3>,
adouble,
1719 inv_t(0, 0) = (
t(1, 1) *
t(2, 2) -
t(1, 2) *
t(2, 1)) / det;
1720 inv_t(0, 1) = (
t(0, 2) *
t(2, 1) -
t(0, 1) *
t(2, 2)) / det;
1721 inv_t(0, 2) = (
t(0, 1) *
t(1, 2) -
t(0, 2) *
t(1, 1)) / det;
1722 inv_t(1, 1) = (
t(0, 0) *
t(2, 2) -
t(0, 2) *
t(2, 0)) / det;
1723 inv_t(1, 2) = (
t(0, 2) *
t(1, 0) -
t(0, 0) *
t(1, 2)) / det;
1724 inv_t(2, 2) = (
t(0, 0) *
t(1, 1) -
t(0, 1) *
t(1, 0)) / det;
1737 invertTensor3by3<FTensor::Tensor2_symmetric<double, 3>,
double,
1742 const auto inv_det = 1. / det;
1743 inv_t(0, 0) = (
t(1, 1) *
t(2, 2) -
t(1, 2) *
t(2, 1)) * inv_det;
1744 inv_t(0, 1) = (
t(0, 2) *
t(2, 1) -
t(0, 1) *
t(2, 2)) * inv_det;
1745 inv_t(0, 2) = (
t(0, 1) *
t(1, 2) -
t(0, 2) *
t(1, 1)) * inv_det;
1746 inv_t(1, 1) = (
t(0, 0) *
t(2, 2) -
t(0, 2) *
t(2, 0)) * inv_det;
1747 inv_t(1, 2) = (
t(0, 2) *
t(1, 0) -
t(0, 0) *
t(1, 2)) * inv_det;
1748 inv_t(2, 2) = (
t(0, 0) *
t(1, 1) -
t(0, 1) *
t(1, 0)) * inv_det;
1752 template <
typename T1,
typename T2,
typename T3,
int DIM>
1755 template <
typename T1,
typename T2,
typename T3>
1762 template <
typename T1,
typename T2,
typename T3>
1769 template <
typename T1,
typename T2,
typename T3,
int DIM>
1778 template <
typename T1,
typename T2,
typename T3,
int DIM>
1784 DIM>::invert(
t, det, inv_t);
1792 template <
typename Iterator>
1794 return (*it)->getEnt();
1816 template <
typename Extractor,
typename Iterator>
1818 Iterator end_iter) {
1819 moab::Range::iterator hint =
r.begin();
1820 while (begin_iter != end_iter) {
1822 auto bi = Extractor::extract(begin_iter);
1823 Iterator pj = begin_iter;
1824 while (pj != end_iter && (bi +
j) == Extractor::extract(pj)) {
1828 hint =
r.insert(hint, bi, bi + (
j - 1));
1852 template <
typename MI,
typename MO = Modify_change_nothing>
1856 for (
auto it = mi.begin(); it != mi.end(); ++it) {
1857 if (!
const_cast<MI &
>(mi).modify(it, mo))
1859 "Houston we have a problem");
1887 return boost::make_shared<TempMeshset>(moab);
1944 template <
typename I>
1951 if (tester(first)) {
1953 auto second = first;
1956 while (second != s) {
1963 CHKERR inserter(first, second);
1989 template <
typename Dest = void,
typename... Arg>
1991 if constexpr (std::is_same<void, Dest>::value)
1992 return std::array<std::common_type_t<std::decay_t<Arg>...>,
sizeof...(Arg)>{
1993 {std::forward<Arg>(arg)...}};
1995 return std::array<Dest,
sizeof...(Arg)>{{std::forward<Arg>(arg)...}};
2011 #define FTENSOR_INDEX(DIM, I) I##_FTIndex<DIM> I;
2015 #endif //__TEMPLATES_HPP__