14 using namespace MoFEM;
23 template <
typename T1,
typename T2,
int DIM>
25 constexpr
double eps = 1e-4;
26 for (
int ii = 0; ii != DIM; ++ii)
27 for (
int jj = 0; jj != DIM; ++jj)
28 for (
int kk = 0; kk != DIM; ++kk)
29 for (
int ll = 0; ll != DIM; ++ll) {
31 if (std::abs(t_1(ii, jj, kk, ll) - t_2(ii, jj, kk, ll)) >
eps)
33 <<
"Error " << ii <<
" " << jj <<
" " << kk <<
" " << ll <<
" "
34 << t_1(ii, jj, kk, ll) <<
" " << t_2(ii, jj, kk, ll);
37 for (
int ii = 0; ii != DIM; ++ii)
38 for (
int jj = 0; jj != DIM; ++jj)
39 for (
int kk = 0; kk != DIM; ++kk)
40 for (
int ll = 0; ll != DIM; ++ll)
41 t_1(ii, jj, kk, ll) -= t_2(ii, jj, kk, ll);
44 template <
typename T1,
typename T2,
int DIM>
54 t_d_a(
i,
j,
k,
l) = 0;
56 for (
int ii = 0; ii != DIM; ++ii)
57 for (
int jj = 0; jj != DIM; ++jj)
58 for (
int kk = 0; kk != DIM; ++kk)
59 for (
int ll = 0; ll != DIM; ++ll)
60 for (
int zz = 0; zz != DIM; ++zz) {
62 auto diff = [&](
auto ii,
auto jj,
auto kk,
auto ll,
int zz) {
65 t_a(ii, zz) *
t_kd(zz, kk) *
t_kd(jj, ll)
69 t_kd(ii, kk) *
t_kd(zz, ll) * t_a(zz, jj);
72 t_d_a(ii, jj, kk, ll) +=
73 (diff(ii, jj, kk, ll, zz) + diff(ii, jj, ll, kk, zz)) / 2.;
81 template <
typename T1,
typename T2,
int DIM>
91 t_dd_a(
i,
j,
k,
l) = 0;
93 for (
int ii = 0; ii != DIM; ++ii)
94 for (
int jj = 0; jj != DIM; ++jj)
95 for (
int kk = 0; kk != DIM; ++kk)
96 for (
int ll = 0; ll != DIM; ++ll)
97 for (
int mm = 0; mm != DIM; ++mm)
98 for (
int nn = 0; nn != DIM; ++nn)
99 for (
int zz = 0; zz != DIM; ++zz) {
101 auto diff = [&](
auto ii,
auto jj,
auto kk,
auto ll,
int mm,
114 t_dd_a(kk, ll, mm, nn) += (
116 diff(ii, jj, kk, ll, mm, nn, zz)
120 diff(ii, jj, ll, kk, mm, nn, zz)
124 diff(ii, jj, kk, ll, nn, mm, zz)
128 diff(ii, jj, ll, kk, nn, mm, zz)
139 template <
typename T1,
int DIM>
149 t_d_a(
i,
j,
k,
l) = 0;
151 for (
int ii = 0; ii != DIM; ++ii)
152 for (
int jj = 0; jj != DIM; ++jj)
153 for (
int kk = 0; kk != DIM; ++kk)
154 for (
int ll = 0; ll != DIM; ++ll) {
156 auto diff = [&](
auto ii,
auto jj,
auto kk,
auto ll) {
160 t_d_a(ii, jj, kk, ll) =
161 (diff(ii, jj, kk, ll) + diff(ii, jj, ll, kk)) / 2.;
169 template <
typename T,
int DIM>
172 for (
int ii = 0; ii != DIM; ++ii)
173 for (
int jj = 0; jj != DIM; ++jj)
174 for (
int kk = 0; kk != DIM; ++kk)
175 for (
int ll = 0; ll != DIM; ++ll)
176 r +=
t(ii, jj, kk, ll) *
t(ii, jj, kk, ll);
180 static char help[] =
"...\n\n";
182 int main(
int argc,
char *argv[]) {
186 auto core_log = logging::core::get();
190 BOOST_LOG_SCOPED_THREAD_ATTR(
"Timeline", attrs::timer());
195 auto print_ddg = [](
auto &
t,
auto str =
"") {
196 constexpr
double eps = 1e-6;
197 for (
int ii = 0; ii != 3; ++ii)
198 for (
int jj = 0; jj != 3; ++jj)
199 for (
int kk = 0; kk != 3; ++kk)
200 for (
int ll = 0; ll != 3; ++ll) {
201 double v =
t(ii, jj, kk, ll);
202 double w = std::abs(
v) <
eps ? 0 :
v;
204 << str << std::fixed << std::setprecision(3) << std::showpos
205 << ii + 1 <<
" " << jj + 1 <<
" " << kk + 1 <<
" " << ll + 1
210 auto print_ddg_direction = [](
auto &
t,
auto kk,
int ll) {
211 for (
int ii = 0; ii != 3; ++ii)
212 for (
int jj = 0; jj <= ii; ++jj)
214 << ii + 1 <<
" " << jj + 1 <<
" " << kk + 1 <<
" " << ll + 1
215 <<
" : " <<
t(ii, jj, kk, ll);
219 for (
int ii = 0; ii != 3; ++ii)
220 for (
int jj = 0; jj != 3; ++jj)
222 << ii + 1 <<
" " << jj + 1 <<
" : " <<
t(ii, jj);
225 enum swap { swap12, swap01 };
226 auto run_lapack = [](
auto &
a, swap s = swap12) {
243 THROW_MESSAGE(
"The algorithm failed to compute eigenvalues.");
245 std::vector<double> work(lwork);
247 info =
lapack_dsyev(
'V',
'U', 3,
a.data(), 3,
w, &*work.begin(), lwork);
249 THROW_MESSAGE(
"The algorithm failed to compute eigenvalues.");
254 a[0 * 3 + 0],
a[0 * 3 + 1],
a[0 * 3 + 2],
256 a[2 * 3 + 0],
a[2 * 3 + 1],
a[2 * 3 + 2],
258 a[1 * 3 + 0],
a[1 * 3 + 1],
a[1 * 3 + 2]};
261 return std::make_tuple(t_a, t_eig_vec, t_eig_vals);
266 a[1 * 3 + 0],
a[1 * 3 + 1],
a[1 * 3 + 2],
268 a[0 * 3 + 0],
a[0 * 3 + 1],
a[0 * 3 + 2],
270 a[2 * 3 + 0],
a[2 * 3 + 1],
a[2 * 3 + 2],
275 return std::make_tuple(t_a, t_eig_vec, t_eig_vals);
290 0.969837, -0.0860972, 0.228042,
292 0.0790574, 0.996073, 0.0398449,
294 -0.230577, -0.0206147, 0.972836};
307 t_S_sym(
i,
j) = (t_S(
i,
j) || t_S(
j,
i)) / 2.;
309 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"Diff A";
314 auto f = [](
double v) {
return exp(
v); };
315 auto d_f = [](
double v) {
return exp(
v); };
316 auto dd_f = [](
double v) {
return exp(
v); };
319 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"Reconstruct mat";
324 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"Diff";
325 print_ddg_direction(t_d, 0, 2);
330 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"Diff Diff";
331 print_ddg_direction(t_dd, 0, 2);
333 auto norm2_t_b = t_b(
i,
j) * t_b(
i,
j);
334 MOFEM_LOG(
"ATOM_TEST", Sev::inform) <<
"norm2_t_b " << norm2_t_b;
337 MOFEM_LOG(
"ATOM_TEST", Sev::inform) <<
"norm2_t_d " << norm2_t_d;
340 MOFEM_LOG(
"ATOM_TEST", Sev::inform) <<
"norm2_t_dd " << norm2_t_dd;
342 constexpr
double regression_t_b = 572.543;
343 constexpr
double regression_t_d = 859.939;
344 constexpr
double regression_t_dd = 859.939;
346 constexpr
double eps = 1e-2;
347 if (std::abs(norm2_t_b - regression_t_b) >
eps)
349 if (std::abs(norm2_t_d - regression_t_d) >
eps)
351 if (std::abs(norm2_t_dd - regression_t_dd) >
eps)
360 std::array<double, 9>
a{1., 0.1, -0.5,
366 auto tuple = run_lapack(
a);
368 auto &t_eig_vec = std::get<1>(tuple);
369 auto &t_eig_vals = std::get<2>(tuple);
371 auto t_eig_val_diff =
372 (t_eig_vals(
i) - t_L(
i)) * (t_eig_vals(
i) - t_L(
i));
374 <<
"t_eig_val_diff " << t_eig_val_diff;
376 auto f = [](
double v) {
return exp(
v); };
380 t_c(
i,
j) -= t_b(
i,
j);
383 auto norm2_t_c = t_c(
i,
j) * t_c(
i,
j);
385 <<
"Reconstruct mat difference with lapack eigen valyes and "
389 constexpr
double eps = 1e-8;
390 if (fabs(norm2_t_c) >
eps)
392 "Matrix not reeconstructed");
401 auto f = [](
double v) {
return v; };
402 auto d_f = [](
double v) {
return 1; };
403 auto dd_f = [](
double v) {
return 0; };
405 constexpr
double eps = 1e-10;
408 t_b(
i,
j) -= (t_A(
i,
j) || t_A(
j,
i)) / 2;
409 auto norm2_t_b = t_b(
i,
j) * t_b(
i,
j);
411 <<
"Result should be matrix itself " << norm2_t_b;
414 "This norm should be zero");
422 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_d_a";
423 print_ddg(t_d_a,
"hand ");
424 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_d";
425 print_ddg(t_d,
"code ");
429 <<
"Direvarive hand calculation minus code " << nrm2_t_d_a;
430 if (nrm2_t_d_a >
eps)
432 "This norm should be zero");
445 t_S_sym(
i,
j) = t_S(
i,
j) || t_S(
j,
i);
451 MOFEM_LOG(
"ATOM_TEST", Sev::inform) <<
"norm2_t_dd " << norm2_t_dd;
452 if (norm2_t_dd >
eps)
454 "This norm should be zero");
460 auto f = [](
double v) {
return v *
v; };
461 auto d_f = [](
double v) {
return 2 *
v; };
462 auto dd_f = [](
double v) {
return 2; };
464 constexpr
double eps = 1e-9;
470 t_a(
i,
j) = t_b(
i,
j) - t_A(
i,
k) * t_A(
k,
j);
472 auto norm2_t_a = t_a(
i,
j) * t_a(
i,
j);
474 <<
"Result should be matrix times matrix " << norm2_t_a;
477 "This norm should be zero");
483 print_ddg_direction(t_d, 0, 2);
485 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_d_a";
486 print_ddg(t_d_a,
"hand ");
487 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_d";
488 print_ddg(t_d,
"code ");
491 <<
"Direvarive hand calculation minus code " << nrm2_t_d_a;
492 if (nrm2_t_d_a >
eps)
494 "This norm should be zero");
501 1., 1. / 2., 1. / 3.,
503 2. / 2., 1., 2. / 3.,
505 3. / 2., 1., 3. / 3.};
508 t_S_sym(
i,
j) = t_S(
i,
j) || t_S(
j,
i);
514 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_dd_a";
515 print_ddg(t_dd_a,
"hand ");
516 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_dd";
517 print_ddg(t_dd,
"code ");
521 <<
"Direvarive hand calculation minus code " << nrm2_t_dd_a;
522 if (nrm2_t_dd_a >
eps)
524 "This norm should be zero");
532 std::array<double, 9>
a{5., 4., 0,
538 auto tuple = run_lapack(
a, swap01);
539 auto &t_a = std::get<0>(tuple);
540 auto &t_eig_vecs = std::get<1>(tuple);
541 auto &t_eig_vals = std::get<2>(tuple);
543 auto f = [](
double v) {
return v; };
544 auto d_f = [](
double v) {
return 1; };
546 constexpr
double eps = 1e-10;
549 t_b(
i,
j) -= (t_a(
i,
j) || t_a(
j,
i)) / 2;
550 auto norm2_t_b = t_b(
i,
j) * t_b(
i,
j);
552 <<
"Result should be matrix itself " << norm2_t_b;
555 "This norm should be zero");
561 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_d_a";
562 print_ddg(t_d_a,
"hand ");
563 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_d";
564 print_ddg(t_d,
"code ");
567 <<
"Direvarive hand calculation minus code " << nrm2_t_d_a;
568 if (nrm2_t_d_a >
eps)
570 "This norm should be zero");
574 auto f = [](
double v) {
return v *
v; };
575 auto d_f = [](
double v) {
return 2 *
v; };
578 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_d_a";
579 print_ddg(t_d_a,
"hand ");
580 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_d";
581 print_ddg(t_d,
"code ");
584 <<
"Direvarive hand calculation minus code " << nrm2_t_d_a;
585 if (nrm2_t_d_a >
eps)
587 "This norm should be zero");
594 std::array<double, 9>
a{4., 0., 0,
600 auto f = [](
double v) {
return v; };
601 auto d_f = [](
double v) {
return 1; };
603 auto tuple = run_lapack(
a);
604 auto &t_a = std::get<0>(tuple);
605 auto &t_eig_vecs = std::get<1>(tuple);
606 auto &t_eig_vals = std::get<2>(tuple);
608 constexpr
double eps = 1e-10;
611 t_b(
i,
j) -= (t_a(
i,
j) || t_a(
j,
i)) / 2;
612 auto norm2_t_b = t_b(
i,
j) * t_b(
i,
j);
614 <<
"Result should be matrix itself " << norm2_t_b;
617 "This norm should be zero");
623 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_d_a";
624 print_ddg(t_d_a,
"hand ");
625 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_d";
626 print_ddg(t_d,
"code ");
629 <<
"Direvarive hand calculation minus code " << nrm2_t_d_a;
630 if (nrm2_t_d_a >
eps)
632 "This norm should be zero");
636 auto f = [](
double v) {
return v *
v; };
637 auto d_f = [](
double v) {
return 2 *
v; };
640 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_d_a";
641 print_ddg(t_d_a,
"hand ");
642 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_d";
643 print_ddg(t_d,
"code ");
646 <<
"Direvarive hand calculation minus code " << nrm2_t_d_a;
647 if (nrm2_t_d_a >
eps)
649 "This norm should be zero");
656 std::array<double, 9>
a{0.1, 0., 0.,
662 auto tuple = run_lapack(
a);
664 auto &t_eig_vecs = std::get<1>(tuple);
665 auto &t_eig_vals = std::get<2>(tuple);
667 t_eig_vals(0) -= 1e-4;
668 t_eig_vals(2) += 1e-4;
670 constexpr
double eps = 1e-10;
672 auto f = [](
double v) {
return v; };
673 auto d_f = [](
double v) {
return 1; };
674 auto dd_f = [](
double v) {
return 0; };
678 1., 1. / 2., 1. / 3.,
680 2. / 2., 1., 2. / 3.,
682 3. / 2., 1., 3. / 3.};
685 t_S_sym(
i,
j) = t_S(
i,
j) || t_S(
j,
i);
690 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_dd";
691 print_ddg(t_dd,
"test ");
695 <<
"Direvarive hand calculation minus code " << nrm2_t_dd;
698 "This norm should be zero");
704 std::array<double, 9>
a{2, 0., 0.,
710 auto tuple = run_lapack(
a);
712 auto &t_eig_vecs = std::get<1>(tuple);
713 auto &t_eig_vals = std::get<2>(tuple);
715 constexpr
double eps = 1e-10;
717 auto f = [](
double v) {
return v *
v; };
718 auto d_f = [](
double v) {
return 2 *
v; };
719 auto dd_f = [](
double v) {
return 2; };
722 1., 1. / 2., 1. / 3.,
724 2. / 1., 1., 2. / 3.,
726 3. / 1., 3. / 1., 1.};
729 t_S_sym(
i,
j) = t_S(
i,
j) || t_S(
j,
i);
739 <<
"Direvarive hand calculation minus code " << nrm2_t_dd_a;
740 if (nrm2_t_dd_a >
eps)
742 "This norm should be zero");
748 std::array<double, 9>
a{5., 4., 0.,
754 auto tuple = run_lapack(
a, swap01);
756 auto &t_eig_vecs = std::get<1>(tuple);
757 auto &t_eig_vals = std::get<2>(tuple);
759 constexpr
double eps = 1e-10;
761 auto f = [](
double v) {
return v *
v; };
762 auto d_f = [](
double v) {
return 2 *
v; };
763 auto dd_f = [](
double v) {
return 2; };
767 1., 1. / 2., 1. / 3.,
769 2. / 1., 1., 2. / 3.,
771 3. / 1., 3. / 1., 1.};
774 t_S_sym(
i,
j) = t_S(
i,
j) || t_S(
j,
i);
778 print_ddg(t_dd,
"test ");
784 <<
"Direvarive hand calculation minus code " << nrm2_t_dd_a;
785 if (nrm2_t_dd_a >
eps)
787 "This norm should be zero");
793 std::array<double, 9>
a{2, 0., 0.,
799 auto tuple = run_lapack(
a);
801 auto &t_eig_vecs = std::get<1>(tuple);
802 auto &t_eig_vals = std::get<2>(tuple);
804 t_eig_vals(0) -= 1e-5;
805 t_eig_vals(2) += 1e-5;
807 constexpr
double eps = 1e-7;
809 auto f = [](
double v) {
return exp(
v); };
810 auto d_f = [](
double v) {
return exp(
v); };
811 auto dd_f = [](
double v) {
return exp(
v); };
814 1., 1. / 2., 1. / 3.,
816 2. / 1., 1., 2. / 3.,
818 3. / 1., 3. / 1., 1.};
821 t_S_sym(
i,
j) = t_S(
i,
j) || t_S(
j,
i);
830 <<
"Direvarive nor t_dd_1 " << nrm2_t_dd_t1;
834 <<
"Direvarive norm t_dd_2 " << nrm2_t_dd_t2;
836 print_ddg(t_dd_1,
"t_dd_1 ");
837 print_ddg(t_dd_2,
"t_dd_2 ");
840 t_dd_3(
i,
j,
k,
l) = t_dd_1(
i,
j,
k,
l) - t_dd_2(
i,
j,
k,
l);
842 for (
int ii = 0; ii != 3; ++ii)
843 for (
int jj = 0; jj != 3; ++jj)
844 for (
int kk = 0; kk != 3; ++kk)
845 for (
int ll = 0; ll != 3; ++ll) {
846 constexpr
double eps = 1e-4;
847 if (std::abs(t_dd_3(ii, jj, kk, ll)) >
eps)
849 <<
"Error " << ii <<
" " << jj <<
" " << kk <<
" " << ll
850 <<
" " << t_dd_1(ii, jj, kk, ll) <<
" "
851 << t_dd_2(ii, jj, kk, ll);
856 <<
"Direvarive approx. calculation minus code " << nrm2_t_dd_3;
857 if (nrm2_t_dd_3 >
eps)
859 "This norm should be zero");
865 std::array<double, 9>
a{5., 4., 0.,
871 auto tuple = run_lapack(
a, swap01);
873 auto &t_eig_vecs = std::get<1>(tuple);
874 auto &t_eig_vals = std::get<2>(tuple);
876 t_eig_vals(0) -= 1e-4;
877 t_eig_vals(2) += 1e-4;
879 constexpr
double eps = 1e-4;
881 auto f = [](
double v) {
return v *
v; };
882 auto d_f = [](
double v) {
return 2 *
v; };
883 auto dd_f = [](
double v) {
return 2; };
887 1., 1. / 2., 1. / 3.,
889 2. / 1., 1., 2. / 3.,
891 3. / 1., 3. / 1., 1.};
894 t_S_sym(
i,
j) = t_S(
i,
j) || t_S(
j,
i);
903 <<
"Direvarive nor t_dd_1 " << nrm2_t_dd_t1;
907 <<
"Direvarive norm t_dd_2 " << nrm2_t_dd_t2;
909 print_ddg(t_dd_1,
"t_dd_1 ");
910 print_ddg(t_dd_2,
"t_dd_2 ");
913 t_dd_3(
i,
j,
k,
l) = t_dd_1(
i,
j,
k,
l) - t_dd_2(
i,
j,
k,
l);
915 for (
int ii = 0; ii != 3; ++ii)
916 for (
int jj = 0; jj != 3; ++jj)
917 for (
int kk = 0; kk != 3; ++kk)
918 for (
int ll = 0; ll != 3; ++ll) {
919 constexpr
double eps = 1e-3;
920 if (std::abs(t_dd_3(ii, jj, kk, ll)) >
eps)
922 <<
"Error " << ii <<
" " << jj <<
" " << kk <<
" " << ll
923 <<
" " << t_dd_1(ii, jj, kk, ll) <<
" "
924 << t_dd_2(ii, jj, kk, ll);
929 <<
"Direvarive approx. calculation minus code " << nrm2_t_dd_3;
930 if (nrm2_t_dd_3 >
eps)
932 "This norm should be zero");
938 std::array<double, 9>
a{5., 4., 0.,
944 auto tuple = run_lapack(
a, swap01);
946 auto &t_eig_vecs = std::get<1>(tuple);
947 auto &t_eig_vals = std::get<2>(tuple);
949 constexpr
double eps = 1e-4;
952 auto f = [](
double v) {
return pow(
v, p); };
953 auto d_f = [](
double v) {
return p * pow(
v, p - 1); };
954 auto dd_f = [](
double v) {
955 return p * (p - 1) * pow(
v, std::max(0, p - 2));
960 1., 1. / 2., 1. / 3.,
962 2. / 1., 1., 2. / 3.,
964 3. / 1., 3. / 1., 1.};
969 t_eig_vals(0) += 2e-5;
970 t_eig_vals(2) -= 2e-5;
978 <<
"Direvarive nor t_dd_1 " << nrm2_t_dd_t1;
982 <<
"Direvarive norm t_dd_2 " << nrm2_t_dd_t2;
984 print_ddg(t_dd_1,
"t_dd_1 ");
985 print_ddg(t_dd_2,
"t_dd_2 ");
988 t_dd_3(
i,
j,
k,
l) = t_dd_1(
i,
j,
k,
l) - t_dd_2(
i,
j,
k,
l);
990 for (
int ii = 0; ii != 3; ++ii)
991 for (
int jj = 0; jj != 3; ++jj)
992 for (
int kk = 0; kk != 3; ++kk)
993 for (
int ll = 0; ll != 3; ++ll) {
994 constexpr
double eps = 1e-3;
995 if (std::abs(t_dd_3(ii, jj, kk, ll)) >
eps)
997 <<
"Error " << ii <<
" " << jj <<
" " << kk <<
" " << ll
998 <<
" " << t_dd_1(ii, jj, kk, ll) <<
" "
999 << t_dd_2(ii, jj, kk, ll) <<
" " << t_dd_3(ii, jj, kk, ll);
1004 <<
"Direvarive approx. calculation minus code " << nrm2_t_dd_3;
1005 if (nrm2_t_dd_3 >
eps)
1007 "This norm should be zero");
1013 std::array<double, 9>
a{1., 0.1, -0.5,
1019 auto tuple = run_lapack(
a);
1021 auto &t_eig_vecs = std::get<1>(tuple);
1022 auto &t_eig_vals = std::get<2>(tuple);
1024 auto f = [](
double v) {
return exp(
v); };
1025 auto d_f = [](
double v) {
return exp(
v); };
1026 auto dd_f = [](
double v) {
return exp(
v); };
1030 1., 1. / 2., 1. / 3.,
1032 2. / 1., 1., 2. / 3.,
1034 3. / 1., 3. / 1., 1.};
1037 t_S_sym(
i,
j) = t_S(
i,
j) || t_S(
j,
i);
1039 MOFEM_LOG(
"ATOM_TEST", Sev::inform) <<
"Start";
1040 for (
int ii = 0; ii != 1000; ++ii) {
1047 MOFEM_LOG(
"ATOM_TEST", Sev::inform) <<
"End";
1052 auto run_lapack_2d = [](
auto &
a) {
1067 THROW_MESSAGE(
"The algorithm failed to compute eigenvalues.");
1069 std::vector<double> work(lwork);
1071 info =
lapack_dsyev(
'V',
'U', 2,
a.data(), 2,
w, &*work.begin(), lwork);
1073 THROW_MESSAGE(
"The algorithm failed to compute eigenvalues.");
1077 a[0 * 2 + 0],
a[0 * 2 + 1],
1079 a[1 * 2 + 0],
a[1 * 2 + 1]};
1083 return std::make_tuple(t_a, t_eig_vecs, t_eig_vals);
1089 std::array<double, 9>
a{1., 0.1,
1093 auto tuple = run_lapack_2d(
a);
1094 auto &t_A = std::get<0>(tuple);
1095 auto &t_eig_vecs = std::get<1>(tuple);
1096 auto &t_eig_vals = std::get<2>(tuple);
1098 auto f = [](
double v) {
return v *
v; };
1099 auto d_f = [](
double v) {
return 2 *
v; };
1100 auto dd_f = [](
double v) {
return 2; };
1102 constexpr
double eps = 1e-6;
1113 t_a(
i,
j) = t_b(
i,
j) - t_A(
i,
k) * t_A(
k,
j);
1115 auto norm2_t_a = t_a(
i,
j) * t_a(
i,
j);
1117 <<
"Result should be matrix times matrix " << norm2_t_a;
1118 if (norm2_t_a >
eps)
1120 "This norm should be zero");
1129 <<
"Direvarive hand calculation minus code " << nrm2_t_d_a;
1130 if (nrm2_t_d_a >
eps)
1132 "This norm should be zero");
1152 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_dd_a";
1153 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_dd";
1157 <<
"Direvarive hand calculation minus code " << nrm2_t_dd_a;
1158 if (nrm2_t_dd_a >
eps)
1160 "This norm should be zero");
1167 std::array<double, 9>
a{2., 0,
1171 auto tuple = run_lapack_2d(
a);
1172 auto &t_A = std::get<0>(tuple);
1173 auto &t_eig_vecs = std::get<1>(tuple);
1174 auto &t_eig_vals = std::get<2>(tuple);
1176 auto f = [](
double v) {
return v *
v; };
1177 auto d_f = [](
double v) {
return 2 *
v; };
1178 auto dd_f = [](
double v) {
return 2; };
1180 constexpr
double eps = 1e-6;
1191 t_a(
i,
j) = t_b(
i,
j) - t_A(
i,
k) * t_A(
k,
j);
1193 auto norm2_t_a = t_a(
i,
j) * t_a(
i,
j);
1195 <<
"Result should be matrix times matrix " << norm2_t_a;
1196 if (norm2_t_a >
eps)
1198 "This norm should be zero");
1207 <<
"Direvarive hand calculation minus code " << nrm2_t_d_a;
1208 if (nrm2_t_d_a >
eps)
1210 "This norm should be zero");
1224 t_S_sym(
i,
j) = t_S(
i,
j) || t_S(
j,
i);
1230 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_dd_a";
1231 MOFEM_LOG(
"ATOM_TEST", Sev::verbose) <<
"t_dd";
1235 <<
"Direvarive hand calculation minus code " << nrm2_t_dd_a;
1236 if (nrm2_t_dd_a >
eps)
1238 "This norm should be zero");