43 return dS.Kjj()[i] + da.Kjj()[i] * B[i] + a.Kjj()[i] * dB_dT[i];
45 return dS.Kjj()[i] + da.Kjj()[i] * B[i];
56 return Eigen::Vector2d(
57 dS.Kjj()[i] + da.Kjj()[i] * B[i] + a.Kjj()[i] * dB_dT[i],
58 dS.K12()[i] + da.K12()[i] * B[i] + a.K12()[i] * dB_dT[i]);
60 return Eigen::Vector2d(dS.Kjj()[i] + da.Kjj()[i] * B[i],
61 dS.K12()[i] + da.K12()[i] * B[i]);
72 return Eigen::Vector3d(
73 dS.Kjj()[i] + da.Kjj()[i] * B[i] + a.Kjj()[i] * dB_dT[i],
74 dS.K12()[i] + da.K12()[i] * B[i] + a.K12()[i] * dB_dT[i],
75 dS.K13()[i] + da.K13()[i] * B[i] + a.K13()[i] * dB_dT[i]);
77 return Eigen::Vector3d(dS.Kjj()[i] + da.Kjj()[i] * B[i],
78 dS.K12()[i] + da.K12()[i] * B[i],
79 dS.K13()[i] + da.K13()[i] * B[i]);
90 return Eigen::Vector4d(
91 dS.Kjj()[i] + da.Kjj()[i] * B[i] + a.Kjj()[i] * dB_dT[i],
92 dS.K12()[i] + da.K12()[i] * B[i] + a.K12()[i] * dB_dT[i],
93 dS.K13()[i] + da.K13()[i] * B[i] + a.K13()[i] * dB_dT[i],
94 dS.K14()[i] + da.K14()[i] * B[i] + a.K14()[i] * dB_dT[i]);
96 return Eigen::Vector4d(dS.Kjj()[i] + da.Kjj()[i] * B[i],
97 dS.K12()[i] + da.K12()[i] * B[i],
98 dS.K13()[i] + da.K13()[i] * B[i],
99 dS.K14()[i] + da.K14()[i] * B[i]);
103 return Eigen::Matrix<double, 1, 1>(a);
107 return (Eigen::Matrix2d() << a, b, b, a).finished();
114 return (Eigen::Matrix3d() << a, b, c, b, a, u, c, -u, a).finished();
124 return (Eigen::Matrix4d() << a,
144 return Eigen::Matrix<double, 1, 1>(m(0, 0));
148 return (Eigen::Matrix2d() << m(0, 0), m(0, 1), m(1, 0), m(1, 1)).finished();
152 return (Eigen::Matrix3d() << m(0, 0),
165 return (Eigen::Matrix4d() << m(0, 0),
184 inline Eigen::Matrix<double, 1, 1>
inv1(
const Numeric& a) noexcept {
185 return Eigen::Matrix<double, 1, 1>(1 / a);
189 return (Eigen::Matrix2d() << a, -b, -b, a).finished() / (a * a - b * b);
196 return (Eigen::Matrix3d() << a * a + u * u,
206 (a * a * a - a * b * b - a * c * c + a * u * u);
216 return (Eigen::Matrix4d() << a * a * a + a * u * u + a * v * v + a *
w *
w,
217 -a * a * b - a * c * u - a * d * v - b *
w *
w + c * v *
w -
219 -a * a * c + a * b * u - a * d *
w + b * v *
w - c * v * v +
221 -a * a * d + a * b * v + a * c *
w - b * u *
w + c * u * v -
223 -a * a * b + a * c * u + a * d * v - b *
w *
w + c * v *
w -
225 a * a * a - a * c * c - a * d * d + a *
w *
w,
226 -a * a * u + a * b * c - a * v *
w + b * d *
w - c * d * v +
228 -a * a * v + a * b * d + a * u *
w - b * c *
w + c * c * v -
230 -a * a * c - a * b * u + a * d *
w + b * v *
w - c * v * v +
232 a * a * u + a * b * c - a * v *
w - b * d *
w + c * d * v - d * d * u,
233 a * a * a - a * b * b - a * d * d + a * v * v,
234 -a * a *
w + a * c * d - a * u * v + b * b *
w - b * c * v +
236 -a * a * d - a * b * v - a * c *
w - b * u *
w + c * u * v -
238 a * a * v + a * b * d + a * u *
w + b * c *
w - c * c * v + c * d * u,
239 a * a *
w + a * c * d - a * u * v - b * b *
w + b * c * v - b * d * u,
240 a * a * a - a * b * b - a * c * c + a * u * u)
242 (a * a * a * a - a * a * b * b - a * a * c * c - a * a * d * d +
243 a * a * u * u + a * a * v * v + a * a *
w *
w - b * b *
w *
w +
244 2 * b * c * v *
w - 2 * b * d * u *
w - c * c * v * v +
245 2 * c * d * u * v - d * d * u * u);
253 const Index ia = 0) noexcept {
256 std::exp(-0.5 * r * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i]));
264 const Index ia = 0) noexcept {
266 const Numeric a = -0.5 * r * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i]),
267 b = -0.5 * r * (K1.
K12(iz, ia)[i] + K2.
K12(iz, ia)[i]);
268 const Numeric exp_a = std::exp(a);
269 const Numeric cb = std::cosh(b), sb = std::sinh(b);
270 T.
Mat2(i).noalias() =
271 (Eigen::Matrix2d() << cb, sb, sb, cb).finished() * exp_a;
280 const Index ia = 0) noexcept {
282 const Numeric a = -0.5 * r * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i]),
283 b = -0.5 * r * (K1.
K12(iz, ia)[i] + K2.
K12(iz, ia)[i]),
284 c = -0.5 * r * (K1.
K13(iz, ia)[i] + K2.
K13(iz, ia)[i]),
285 u = -0.5 * r * (K1.
K23(iz, ia)[i] + K2.
K23(iz, ia)[i]);
286 const Numeric exp_a = std::exp(a);
288 if (b == 0. and c == 0. and u == 0.)
291 const Numeric a2 = a * a,
b2 = b * b, c2 = c * c, u2 = u * u;
294 const bool real = Const > 0;
295 const bool imag = Const < 0;
296 const bool either = real or imag;
301 (real ? 1 : -1) *
x *
x;
307 real ? std::sinh(
x) : std::sin(-
x);
309 real ? std::cosh(
x) : std::cos(+
x);
318 either ?
a2 * (cx - 1.0) - a *
x * sx +
x2 : 1.0 + 0.5 *
a2 - a;
319 const Numeric C1 = either ? 2.0 * a * (1.0 - cx) +
x * sx : 1.0 - a;
320 const Numeric C2 = either ? cx - 1.0 : 0.5;
322 T.
Mat3(i).noalias() =
324 (Eigen::Matrix3d() << C0 + C1 * a + C2 * (
a2 +
b2 + c2),
325 C1 * b + C2 * (2 * a * b - c * u),
326 C1 * c + C2 * (2 * a * c + b * u),
327 C1 * b + C2 * (2 * a * b + c * u),
328 C0 + C1 * a + C2 * (
a2 +
b2 - u2),
329 C1 * u + C2 * (2 * a * u + b * c),
330 C1 * c + C2 * (2 * a * c - b * u),
331 -C1 * u - C2 * (2 * a * u - b * c),
332 C0 + C1 * a + C2 * (
a2 + c2 - u2))
343 const Index ia = 0) noexcept {
344 static constexpr
Numeric sqrt_05 = Constant::inv_sqrt_2;
346 const Numeric a = -0.5 * r * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i]),
347 b = -0.5 * r * (K1.
K12(iz, ia)[i] + K2.
K12(iz, ia)[i]),
348 c = -0.5 * r * (K1.
K13(iz, ia)[i] + K2.
K13(iz, ia)[i]),
349 d = -0.5 * r * (K1.
K14(iz, ia)[i] + K2.
K14(iz, ia)[i]),
350 u = -0.5 * r * (K1.
K23(iz, ia)[i] + K2.
K23(iz, ia)[i]),
351 v = -0.5 * r * (K1.
K24(iz, ia)[i] + K2.
K24(iz, ia)[i]),
352 w = -0.5 * r * (K1.
K34(iz, ia)[i] + K2.
K34(iz, ia)[i]);
353 const Numeric exp_a = std::exp(a);
355 if (b == 0. and c == 0. and d == 0. and u == 0. and v == 0. and
w == 0.)
358 const Numeric b2 = b * b, c2 = c * c, d2 = d * d, u2 = u * u, v2 = v * v,
362 w2 * w2 + 2 * (
b2 * (
b2 * 0.5 + c2 + d2 - u2 - v2 + w2) +
363 c2 * (c2 * 0.5 + d2 - u2 + v2 - w2) +
364 d2 * (d2 * 0.5 + u2 - v2 - w2) +
365 u2 * (u2 * 0.5 + v2 + w2) + v2 * (v2 * 0.5 + w2) +
366 4 * (b * d * u *
w - b * c * v *
w - c * d * u * v));
368 const Numeric Const2 =
b2 + c2 + d2 - u2 - v2 - w2;
381 const bool both_zero = y_zero and x_zero;
382 const bool either_zero = y_zero or x_zero;
392 const Complex ix = x_zero ? 0.0 : 1.0 /
x;
401 either_zero ? 1.0 : ((cy *
x2 + cx * y2) * inv_x2y2).real();
403 either_zero ? 1.0 : ((sy *
x2 *
iy + sx * y2 * ix) * inv_x2y2).real();
404 const Numeric C2 = both_zero ? 0.5 : ((cx - cy) * inv_x2y2).real();
406 both_zero ? 1.0 / 6.0
407 : ((x_zero ? 1.0 - sy *
iy
408 : y_zero ? sx * ix - 1.0 : sx * ix - sy *
iy) *
411 T.
Mat4(i).noalias() =
412 exp_a * (Eigen::Matrix4d() << C0 + C2 * (
b2 + c2 + d2),
413 C1 * b + C2 * (-c * u - d * v) +
414 C3 * (b * (
b2 + c2 + d2) - u * (b * u - d *
w) -
415 v * (b * v + c *
w)),
416 C1 * c + C2 * (b * u - d *
w) +
417 C3 * (c * (
b2 + c2 + d2) - u * (c * u + d * v) -
418 w * (b * v + c *
w)),
419 C1 * d + C2 * (b * v + c *
w) +
420 C3 * (d * (
b2 + c2 + d2) - v * (c * u + d * v) +
421 w * (b * u - d *
w)),
423 C1 * b + C2 * (c * u + d * v) +
424 C3 * (-b * (-
b2 + u2 + v2) + c * (b * c - v *
w) +
425 d * (b * d + u *
w)),
426 C0 + C2 * (
b2 - u2 - v2),
427 C2 * (b * c - v *
w) + C1 * u +
428 C3 * (c * (c * u + d * v) - u * (-
b2 + u2 + v2) -
429 w * (b * d + u *
w)),
430 C2 * (b * d + u *
w) + C1 * v +
431 C3 * (d * (c * u + d * v) - v * (-
b2 + u2 + v2) +
432 w * (b * c - v *
w)),
434 C1 * c + C2 * (-b * u + d *
w) +
435 C3 * (b * (b * c - v *
w) - c * (-c2 + u2 + w2) +
436 d * (c * d - u * v)),
437 C2 * (b * c - v *
w) - C1 * u +
438 C3 * (-b * (b * u - d *
w) + u * (-c2 + u2 + w2) -
439 v * (c * d - u * v)),
440 C0 + C2 * (c2 - u2 - w2),
441 C2 * (c * d - u * v) + C1 *
w +
442 C3 * (-d * (b * u - d *
w) + v * (b * c - v *
w) -
443 w * (-c2 + u2 + w2)),
445 C1 * d + C2 * (-b * v - c *
w) +
446 C3 * (b * (b * d + u *
w) + c * (c * d - u * v) -
447 d * (-d2 + v2 + w2)),
448 C2 * (b * d + u *
w) - C1 * v +
449 C3 * (-b * (b * v + c *
w) - u * (c * d - u * v) +
450 v * (-d2 + v2 + w2)),
451 C2 * (c * d - u * v) - C1 *
w +
452 C3 * (-c * (b * v + c *
w) + u * (b * d + u *
w) +
453 w * (-d2 + v2 + w2)),
454 C0 + C2 * (d2 - v2 - w2))
472 const Index ia) noexcept {
475 std::exp(-0.5 * r * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i]));
476 for (
Index j = 0; j < dT1.nelem(); j++) {
477 if (dK1[j].NumberOfFrequencies())
478 dT1[j].Mat1(i)(0, 0) =
481 (r * dK1[j].Kjj(iz, ia)[i] +
482 ((j == it) ? dr_dT1 * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i])
484 if (dK2[j].NumberOfFrequencies())
485 dT2[j].Mat1(i)(0, 0) =
488 (r * dK2[j].Kjj(iz, ia)[i] +
489 ((j == it) ? dr_dT2 * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i])
507 const Index ia) noexcept {
509 const Numeric a = -0.5 * r * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i]),
510 b = -0.5 * r * (K1.
K12(iz, ia)[i] + K2.
K12(iz, ia)[i]);
511 const Numeric exp_a = std::exp(a);
512 const Numeric cb = std::cosh(b), sb = std::sinh(b);
513 T.
Mat2(i).noalias() =
514 (Eigen::Matrix2d() << cb, sb, sb, cb).finished() * exp_a;
515 for (
Index j = 0; j < dT1.nelem(); j++) {
516 if (dK1[j].NumberOfFrequencies()) {
517 const Numeric da = -0.5 * (r * dK1[j].Kjj(iz, ia)[i] +
518 ((j == it) ? dr_dT1 * (K1.
Kjj(iz, ia)[i] +
521 db = -0.5 * (r * dK1[j].K12(iz, ia)[i] +
522 ((j == it) ? dr_dT1 * (K1.
K12(iz, ia)[i] +
525 dT1[j].Mat2(i).noalias() =
527 (Eigen::Matrix2d() << sb, cb, cb, sb).finished() * exp_a * db;
529 if (dK2[j].NumberOfFrequencies()) {
530 const Numeric da = -0.5 * (r * dK2[j].Kjj(iz, ia)[i] +
531 ((j == it) ? dr_dT2 * (K1.
Kjj(iz, ia)[i] +
534 db = -0.5 * (r * dK2[j].K12(iz, ia)[i] +
535 ((j == it) ? dr_dT2 * (K1.
K12(iz, ia)[i] +
538 dT2[j].Mat2(i).noalias() =
540 (Eigen::Matrix2d() << sb, cb, cb, sb).finished() * exp_a * db;
558 const Index ia) noexcept {
560 const Numeric a = -0.5 * r * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i]),
561 b = -0.5 * r * (K1.
K12(iz, ia)[i] + K2.
K12(iz, ia)[i]),
562 c = -0.5 * r * (K1.
K13(iz, ia)[i] + K2.
K13(iz, ia)[i]),
563 u = -0.5 * r * (K1.
K23(iz, ia)[i] + K2.
K23(iz, ia)[i]);
564 const Numeric exp_a = std::exp(a);
566 if (b == 0. and c == 0. and u == 0.) {
568 for (
Index j = 0; j < dT1.nelem(); j++) {
569 if (dK1[j].NumberOfFrequencies())
570 dT1[j].Mat3(i).noalias() =
573 (r * dK1[j].Kjj(iz, ia)[i] +
574 ((j == it) ? dr_dT1 * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i])
576 if (dK2[j].NumberOfFrequencies())
577 dT2[j].Mat3(i).noalias() =
580 (r * dK2[j].Kjj(iz, ia)[i] +
581 ((j == it) ? dr_dT2 * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i])
585 const Numeric a2 = a * a,
b2 = b * b, c2 = c * c, u2 = u * u;
588 const bool real = Const > 0;
589 const bool imag = Const < 0;
590 const bool either = real or imag;
595 (real ? 1 : -1) *
x *
x;
599 const Numeric inv_x2 = inv_x * inv_x;
602 real ? std::sinh(
x) : std::sin(-
x);
604 real ? std::cosh(
x) : std::cos(+
x);
613 either ?
a2 * (cx - 1.0) - a *
x * sx +
x2 : 1.0 + 0.5 *
a2 - a;
614 const Numeric C1 = either ? 2.0 * a * (1.0 - cx) +
x * sx : 1.0 - a;
615 const Numeric C2 = either ? cx - 1.0 : 0.5;
617 T.
Mat3(i).noalias() =
619 (Eigen::Matrix3d() << C0 + C1 * a + C2 * (
a2 +
b2 + c2),
620 C1 * b + C2 * (2 * a * b - c * u),
621 C1 * c + C2 * (2 * a * c + b * u),
622 C1 * b + C2 * (2 * a * b + c * u),
623 C0 + C1 * a + C2 * (
a2 +
b2 - u2),
624 C1 * u + C2 * (2 * a * u + b * c),
625 C1 * c + C2 * (2 * a * c - b * u),
626 -C1 * u - C2 * (2 * a * u - b * c),
627 C0 + C1 * a + C2 * (
a2 + c2 - u2))
630 for (
Index j = 0; j < dT1.nelem(); j++) {
631 if (dK1[j].NumberOfFrequencies()) {
632 const Numeric da = -0.5 * (r * dK1[j].Kjj(iz, ia)[i] +
633 ((j == it) ? dr_dT1 * (K1.
Kjj(iz, ia)[i] +
636 db = -0.5 * (r * dK1[j].K12(iz, ia)[i] +
637 ((j == it) ? dr_dT1 * (K1.
K12(iz, ia)[i] +
640 dc = -0.5 * (r * dK1[j].K13(iz, ia)[i] +
641 ((j == it) ? dr_dT1 * (K1.
K13(iz, ia)[i] +
644 du = -0.5 * (r * dK1[j].K23(iz, ia)[i] +
645 ((j == it) ? dr_dT1 * (K1.
K23(iz, ia)[i] +
648 const Numeric da2 = 2 * a * da, db2 = 2 * b * db, dc2 = 2 * c * dc,
650 const Numeric dx = either ? ((db2 + dc2 - du2) * inv_x * 0.5) : 0,
652 const Numeric dsx = (real ? 1 : -1) * cx *
dx;
655 const Numeric dC0 = either ? da2 * (cx - 1.0) + da2 * (dcx - 1.0) -
656 da *
x * sx - a *
dx * sx -
660 either ? 2.0 * (da * (1.0 - cx) - a * dcx) +
dx * sx +
x * dsx
662 const Numeric dC2 = either ? dcx : 0;
664 dT1[j].Mat3(i).noalias() =
665 T.
Mat3(i) * (da + dx2 * inv_x2) +
667 (Eigen::Matrix3d() << dC0 + dC1 * a + C1 * da +
668 dC2 * (
a2 +
b2 + c2) +
669 C2 * (da2 + db2 + dc2),
670 dC1 * b + C1 * db + dC2 * (2 * a * b - c * u) +
671 C2 * (2 * da * b - dc * u + 2 * a * db - c * du),
672 dC1 * c + C1 * dc + dC2 * (2 * a * c + b * u) +
673 C2 * (2 * da * c + db * u + 2 * a * dc + b * du),
674 dC1 * b + C1 * db + dC2 * (2 * a * b + c * u) +
675 C2 * (2 * da * b + dc * u + 2 * a * db + c * du),
676 dC0 + dC1 * a + C1 * da + dC2 * (
a2 +
b2 - u2) +
677 C2 * (da2 + db2 - du2),
678 dC1 * u + C1 * du + dC2 * (2 * a * u + b * c) +
679 C2 * (2 * da * u + db * c + 2 * a * du + b * dc),
680 dC1 * c + C1 * dc + dC2 * (2 * a * c - b * u) +
681 C2 * (2 * da * c - db * u + 2 * a * dc - b * du),
682 -dC1 * u - C1 * du - dC2 * (2 * a * u - b * c) -
683 C2 * (2 * da * u - db * c + 2 * a * du - b * dc),
684 dC0 + dC1 * a + C1 * da + dC2 * (
a2 + c2 - u2) +
685 C2 * (da2 + dc2 - du2))
688 if (dK2[j].NumberOfFrequencies()) {
689 const Numeric da = -0.5 * (r * dK2[j].Kjj(iz, ia)[i] +
690 ((j == it) ? dr_dT2 * (K1.
Kjj(iz, ia)[i] +
693 db = -0.5 * (r * dK2[j].K12(iz, ia)[i] +
694 ((j == it) ? dr_dT2 * (K1.
K12(iz, ia)[i] +
697 dc = -0.5 * (r * dK2[j].K13(iz, ia)[i] +
698 ((j == it) ? dr_dT2 * (K1.
K13(iz, ia)[i] +
701 du = -0.5 * (r * dK2[j].K23(iz, ia)[i] +
702 ((j == it) ? dr_dT2 * (K1.
K23(iz, ia)[i] +
705 const Numeric da2 = 2 * a * da, db2 = 2 * b * db, dc2 = 2 * c * dc,
707 const Numeric dx = either ? ((db2 + dc2 - du2) * inv_x * 0.5) : 0,
709 const Numeric dsx = (real ? 1 : -1) * cx *
dx;
712 const Numeric dC0 = either ? da2 * (cx - 1.0) + da2 * (dcx - 1.0) -
713 da *
x * sx - a *
dx * sx -
717 either ? 2.0 * (da * (1.0 - cx) - a * dcx) +
dx * sx +
x * dsx
719 const Numeric dC2 = either ? dcx : 0;
721 dT2[j].Mat3(i).noalias() =
722 T.
Mat3(i) * (da + dx2 * inv_x2) +
724 (Eigen::Matrix3d() << dC0 + dC1 * a + C1 * da +
725 dC2 * (
a2 +
b2 + c2) +
726 C2 * (da2 + db2 + dc2),
727 dC1 * b + C1 * db + dC2 * (2 * a * b - c * u) +
728 C2 * (2 * da * b - dc * u + 2 * a * db - c * du),
729 dC1 * c + C1 * dc + dC2 * (2 * a * c + b * u) +
730 C2 * (2 * da * c + db * u + 2 * a * dc + b * du),
731 dC1 * b + C1 * db + dC2 * (2 * a * b + c * u) +
732 C2 * (2 * da * b + dc * u + 2 * a * db + c * du),
733 dC0 + dC1 * a + C1 * da + dC2 * (
a2 +
b2 - u2) +
734 C2 * (da2 + db2 - du2),
735 dC1 * u + C1 * du + dC2 * (2 * a * u + b * c) +
736 C2 * (2 * da * u + db * c + 2 * a * du + b * dc),
737 dC1 * c + C1 * dc + dC2 * (2 * a * c - b * u) +
738 C2 * (2 * da * c - db * u + 2 * a * dc - b * du),
739 -dC1 * u - C1 * du - dC2 * (2 * a * u - b * c) -
740 C2 * (2 * da * u - db * c + 2 * a * du - b * dc),
741 dC0 + dC1 * a + C1 * da + dC2 * (
a2 + c2 - u2) +
742 C2 * (da2 + dc2 - du2))
762 const Index ia) noexcept {
763 static constexpr
Numeric sqrt_05 = Constant::inv_sqrt_2;
765 const Numeric a = -0.5 * r * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i]),
766 b = -0.5 * r * (K1.
K12(iz, ia)[i] + K2.
K12(iz, ia)[i]),
767 c = -0.5 * r * (K1.
K13(iz, ia)[i] + K2.
K13(iz, ia)[i]),
768 d = -0.5 * r * (K1.
K14(iz, ia)[i] + K2.
K14(iz, ia)[i]),
769 u = -0.5 * r * (K1.
K23(iz, ia)[i] + K2.
K23(iz, ia)[i]),
770 v = -0.5 * r * (K1.
K24(iz, ia)[i] + K2.
K24(iz, ia)[i]),
771 w = -0.5 * r * (K1.
K34(iz, ia)[i] + K2.
K34(iz, ia)[i]);
772 const Numeric exp_a = std::exp(a);
774 if (b == 0. and c == 0. and d == 0. and u == 0. and v == 0. and
w == 0.) {
776 for (
Index j = 0; j < dK1.nelem(); j++) {
777 if (dK1[j].NumberOfFrequencies())
778 dT1[j].Mat4(i).noalias() =
781 (r * dK1[j].Kjj(iz, ia)[i] +
782 ((j == it) ? dr_dT1 * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i])
784 if (dK2[j].NumberOfFrequencies())
785 dT2[j].Mat4(i).noalias() =
788 (r * dK2[j].Kjj(iz, ia)[i] +
789 ((j == it) ? dr_dT2 * (K1.
Kjj(iz, ia)[i] + K2.
Kjj(iz, ia)[i])
793 const Numeric b2 = b * b, c2 = c * c, d2 = d * d, u2 = u * u, v2 = v * v,
796 w2 * w2 + 2 * (
b2 * (
b2 * 0.5 + c2 + d2 - u2 - v2 + w2) +
797 c2 * (c2 * 0.5 + d2 - u2 + v2 - w2) +
798 d2 * (d2 * 0.5 + u2 - v2 - w2) +
799 u2 * (u2 * 0.5 + v2 + w2) + v2 * (v2 * 0.5 + w2) +
800 4 * (b * d * u *
w - b * c * v *
w - c * d * u * v));
802 const Numeric Const2 =
b2 + c2 + d2 - u2 - v2 - w2;
805 const Complex x = tmp_x_sqrt * sqrt_05;
816 const bool both_zero = y_zero and x_zero;
817 const bool either_zero = y_zero or x_zero;
827 const Complex ix = x_zero ? 0.0 : 1.0 /
x;
834 const Complex C0c = either_zero ? 1.0 : (cy *
x2 + cx * y2) * inv_x2y2;
836 either_zero ? 1.0 : (sy *
x2 *
iy + sx * y2 * ix) * inv_x2y2;
837 const Complex C2c = both_zero ? 0.5 : (cx - cy) * inv_x2y2;
839 both_zero ? 1.0 / 6.0
840 : (x_zero ? 1.0 - sy *
iy
841 : y_zero ? sx * ix - 1.0 : sx * ix - sy *
iy) *
844 const Numeric& C0 =
reinterpret_cast<const Numeric(&)[2]
>(C0c)[0];
845 const Numeric& C1 =
reinterpret_cast<const Numeric(&)[2]
>(C1c)[0];
846 const Numeric& C2 =
reinterpret_cast<const Numeric(&)[2]
>(C2c)[0];
847 const Numeric& C3 =
reinterpret_cast<const Numeric(&)[2]
>(C3c)[0];
848 T.
Mat4(i).noalias() =
849 exp_a * (Eigen::Matrix4d() << C0 + C2 * (
b2 + c2 + d2),
850 C1 * b + C2 * (-c * u - d * v) +
851 C3 * (b * (
b2 + c2 + d2) - u * (b * u - d *
w) -
852 v * (b * v + c *
w)),
853 C1 * c + C2 * (b * u - d *
w) +
854 C3 * (c * (
b2 + c2 + d2) - u * (c * u + d * v) -
855 w * (b * v + c *
w)),
856 C1 * d + C2 * (b * v + c *
w) +
857 C3 * (d * (
b2 + c2 + d2) - v * (c * u + d * v) +
858 w * (b * u - d *
w)),
860 C1 * b + C2 * (c * u + d * v) +
861 C3 * (-b * (-
b2 + u2 + v2) + c * (b * c - v *
w) +
862 d * (b * d + u *
w)),
863 C0 + C2 * (
b2 - u2 - v2),
864 C2 * (b * c - v *
w) + C1 * u +
865 C3 * (c * (c * u + d * v) - u * (-
b2 + u2 + v2) -
866 w * (b * d + u *
w)),
867 C2 * (b * d + u *
w) + C1 * v +
868 C3 * (d * (c * u + d * v) - v * (-
b2 + u2 + v2) +
869 w * (b * c - v *
w)),
871 C1 * c + C2 * (-b * u + d *
w) +
872 C3 * (b * (b * c - v *
w) - c * (-c2 + u2 + w2) +
873 d * (c * d - u * v)),
874 C2 * (b * c - v *
w) - C1 * u +
875 C3 * (-b * (b * u - d *
w) + u * (-c2 + u2 + w2) -
876 v * (c * d - u * v)),
877 C0 + C2 * (c2 - u2 - w2),
878 C2 * (c * d - u * v) + C1 *
w +
879 C3 * (-d * (b * u - d *
w) + v * (b * c - v *
w) -
880 w * (-c2 + u2 + w2)),
882 C1 * d + C2 * (-b * v - c *
w) +
883 C3 * (b * (b * d + u *
w) + c * (c * d - u * v) -
884 d * (-d2 + v2 + w2)),
885 C2 * (b * d + u *
w) - C1 * v +
886 C3 * (-b * (b * v + c *
w) - u * (c * d - u * v) +
887 v * (-d2 + v2 + w2)),
888 C2 * (c * d - u * v) - C1 *
w +
889 C3 * (-c * (b * v + c *
w) + u * (b * d + u *
w) +
890 w * (-d2 + v2 + w2)),
891 C0 + C2 * (d2 - v2 - w2))
894 for (
Index j = 0; j < dK1.nelem(); j++) {
895 if (dK1[j].NumberOfFrequencies()) {
896 const Numeric da = -0.5 * (r * dK1[j].Kjj(iz, ia)[i] +
897 ((j == it) ? dr_dT1 * (K1.
Kjj(iz, ia)[i] +
900 db = -0.5 * (r * dK1[j].K12(iz, ia)[i] +
901 ((j == it) ? dr_dT1 * (K1.
K12(iz, ia)[i] +
904 dc = -0.5 * (r * dK1[j].K13(iz, ia)[i] +
905 ((j == it) ? dr_dT1 * (K1.
K13(iz, ia)[i] +
908 dd = -0.5 * (r * dK1[j].K14(iz, ia)[i] +
909 ((j == it) ? dr_dT1 * (K1.
K14(iz, ia)[i] +
912 du = -0.5 * (r * dK1[j].K23(iz, ia)[i] +
913 ((j == it) ? dr_dT1 * (K1.
K23(iz, ia)[i] +
916 dv = -0.5 * (r * dK1[j].K24(iz, ia)[i] +
917 ((j == it) ? dr_dT1 * (K1.
K24(iz, ia)[i] +
920 dw = -0.5 * (r * dK1[j].K34(iz, ia)[i] +
921 ((j == it) ? dr_dT1 * (K1.
K34(iz, ia)[i] +
924 const Numeric db2 = 2 * db * b, dc2 = 2 * dc * c, dd2 = 2 * dd * d,
925 du2 = 2 * du * u, dv2 = 2 * dv * v, dw2 = 2 *
dw *
w;
928 2 * (db2 * (
b2 * 0.5 + c2 + d2 - u2 - v2 + w2) +
929 b2 * (db2 * 0.5 + dc2 + dd2 - du2 - dv2 + dw2) +
930 dc2 * (c2 * 0.5 + d2 - u2 + v2 - w2) +
931 c2 * (dc2 * 0.5 + dd2 - du2 + dv2 - dw2) +
932 dd2 * (d2 * 0.5 + u2 - v2 - w2) +
933 d2 * (dd2 * 0.5 + du2 - dv2 - dw2) +
934 du2 * (u2 * 0.5 + v2 + w2) + u2 * (du2 * 0.5 + dv2 + dw2) +
935 dv2 * (v2 * 0.5 + w2) + v2 * (dv2 * 0.5 + dw2) +
936 4 * (db * d * u *
w - db * c * v *
w - dc * d * u * v +
937 b * dd * u *
w - b * dc * v *
w - c * dd * u * v +
938 b * d * du *
w - b * c * dv *
w - c * d * du * v +
939 b * d * u *
dw - b * c * v *
dw - c * d * u * dv));
940 const Complex dConst1 = 0.5 * dtmp / Const1;
941 const Numeric dConst2 = db2 + dc2 + dd2 - du2 - dv2 - dw2;
943 x_zero ? 0 : (0.5 * (dConst2 + dConst1) / tmp_x_sqrt) * sqrt_05;
945 : (0.5 * (dConst2 - dConst1) / tmp_y_sqrt) *
955 const Complex dx2dy2 = dx2 + dy2;
959 : (dcy *
x2 + cy * dx2 + dcx * y2 + cx * dy2 - C0c * dx2dy2) *
963 : (dsy *
x2 *
iy + sy * dx2 *
iy + sy *
x2 * diy +
964 dsx * y2 * ix + sx * dy2 * ix + sx * y2 * dix -
968 both_zero ? 0.0 : (dcx - dcy - C2c * dx2dy2) * inv_x2y2;
971 : ((x_zero ? -dsy *
iy - sy * diy
972 : y_zero ? dsx * ix + sx * dix
973 : dsx * ix + sx * dix - dsy *
iy -
978 const Numeric& dC0 =
reinterpret_cast<const Numeric(&)[2]
>(dC0c)[0];
979 const Numeric& dC1 =
reinterpret_cast<const Numeric(&)[2]
>(dC1c)[0];
980 const Numeric& dC2 =
reinterpret_cast<const Numeric(&)[2]
>(dC2c)[0];
981 const Numeric& dC3 =
reinterpret_cast<const Numeric(&)[2]
>(dC3c)[0];
982 dT1[j].Mat4(i).noalias() =
986 << dC0 + dC2 * (
b2 + c2 + d2) + C2 * (db2 + dc2 + dd2),
987 db * C1 + b * dC1 + dC2 * (-c * u - d * v) +
988 C2 * (-dc * u - dd * v - c * du - d * dv) +
989 dC3 * (b * (
b2 + c2 + d2) - u * (b * u - d *
w) -
990 v * (b * v + c *
w)) +
991 C3 * (db * (
b2 + c2 + d2) - du * (b * u - d *
w) -
992 dv * (b * v + c *
w) + b * (db2 + dc2 + dd2) -
993 u * (db * u - dd *
w) - v * (db * v + dc *
w) -
994 u * (b * du - d *
dw) - v * (b * dv + c *
dw)),
995 dC1 * c + C1 * dc + dC2 * (b * u - d *
w) +
996 C2 * (db * u - dd *
w + b * du - d *
dw) +
997 dC3 * (c * (
b2 + c2 + d2) - u * (c * u + d * v) -
998 w * (b * v + c *
w)) +
999 C3 * (dc * (
b2 + c2 + d2) - du * (c * u + d * v) -
1000 dw * (b * v + c *
w) + c * (db2 + dc2 + dd2) -
1001 u * (dc * u + dd * v) -
w * (db * v + dc *
w) -
1002 u * (c * du + d * dv) -
w * (b * dv + c *
dw)),
1003 dC1 * d + C1 * dd + dC2 * (b * v + c *
w) +
1004 C2 * (db * v + dc *
w + b * dv + c *
dw) +
1005 dC3 * (d * (
b2 + c2 + d2) - v * (c * u + d * v) +
1006 w * (b * u - d *
w)) +
1007 C3 * (dd * (
b2 + c2 + d2) - dv * (c * u + d * v) +
1008 dw * (b * u - d *
w) + d * (db2 + dc2 + dd2) -
1009 v * (dc * u + dd * v) +
w * (db * u - dd *
w) -
1010 v * (c * du + d * dv) +
w * (b * du - d *
dw)),
1012 db * C1 + b * dC1 + dC2 * (c * u + d * v) +
1013 C2 * (dc * u + dd * v + c * du + d * dv) +
1014 dC3 * (-b * (-
b2 + u2 + v2) + c * (b * c - v *
w) +
1015 d * (b * d + u *
w)) +
1016 C3 * (-db * (-
b2 + u2 + v2) + dc * (b * c - v *
w) +
1017 dd * (b * d + u *
w) - b * (-db2 + du2 + dv2) +
1018 c * (db * c - dv *
w) + d * (db * d + du *
w) +
1019 c * (b * dc - v *
dw) + d * (b * dd + u *
dw)),
1020 dC0 + dC2 * (
b2 - u2 - v2) + C2 * (db2 - du2 - dv2),
1021 dC2 * (b * c - v *
w) +
1022 C2 * (db * c + b * dc - dv *
w - v *
dw) + dC1 * u +
1024 dC3 * (c * (c * u + d * v) - u * (-
b2 + u2 + v2) -
1025 w * (b * d + u *
w)) +
1026 C3 * (dc * (c * u + d * v) - du * (-
b2 + u2 + v2) -
1027 dw * (b * d + u *
w) + c * (dc * u + dd * v) -
1028 u * (-db2 + du2 + dv2) -
w * (db * d + du *
w) +
1029 c * (c * du + d * dv) -
w * (b * dd + u *
dw)),
1030 dC2 * (b * d + u *
w) +
1031 C2 * (db * d + b * dd + du *
w + u *
dw) + dC1 * v +
1033 dC3 * (d * (c * u + d * v) - v * (-
b2 + u2 + v2) +
1034 w * (b * c - v *
w)) +
1035 C3 * (dd * (c * u + d * v) - dv * (-
b2 + u2 + v2) +
1036 dw * (b * c - v *
w) + d * (dc * u + dd * v) -
1037 v * (-db2 + du2 + dv2) +
w * (db * c - dv *
w) +
1038 d * (c * du + d * dv) +
w * (b * dc - v *
dw)),
1040 dC1 * c + C1 * dc + dC2 * (-b * u + d *
w) +
1041 C2 * (-db * u + dd *
w - b * du + d *
dw) +
1042 dC3 * (b * (b * c - v *
w) - c * (-c2 + u2 + w2) +
1043 d * (c * d - u * v)) +
1044 C3 * (db * (b * c - v *
w) - dc * (-c2 + u2 + w2) +
1045 dd * (c * d - u * v) + b * (db * c - dv *
w) -
1046 c * (-dc2 + du2 + dw2) + d * (dc * d - du * v) +
1047 b * (b * dc - v *
dw) + d * (c * dd - u * dv)),
1048 dC2 * (b * c - v *
w) +
1049 C2 * (db * c + b * dc - dv *
w - v *
dw) - dC1 * u -
1051 dC3 * (-b * (b * u - d *
w) + u * (-c2 + u2 + w2) -
1052 v * (c * d - u * v)) +
1053 C3 * (-db * (b * u - d *
w) + du * (-c2 + u2 + w2) -
1054 dv * (c * d - u * v) - b * (db * u - dd *
w) +
1055 u * (-dc2 + du2 + dw2) - v * (dc * d - du * v) -
1056 b * (b * du - d *
dw) - v * (c * dd - u * dv)),
1057 dC0 + dC2 * (c2 - u2 - w2) + C2 * (dc2 - du2 - dw2),
1058 dC2 * (c * d - u * v) +
1059 C2 * (dc * d + c * dd - du * v - u * dv) + dC1 *
w +
1061 dC3 * (-d * (b * u - d *
w) + v * (b * c - v *
w) -
1062 w * (-c2 + u2 + w2)) +
1063 C3 * (-dd * (b * u - d *
w) + dv * (b * c - v *
w) -
1064 dw * (-c2 + u2 + w2) - d * (db * u - dd *
w) +
1065 v * (db * c - dv *
w) -
w * (-dc2 + du2 + dw2) -
1066 d * (b * du - d *
dw) + v * (b * dc - v *
dw)),
1068 dC1 * d + C1 * dd + dC2 * (-b * v - c *
w) +
1069 C2 * (-db * v - dc *
w - b * dv - c *
dw) +
1070 dC3 * (b * (b * d + u *
w) + c * (c * d - u * v) -
1071 d * (-d2 + v2 + w2)) +
1072 C3 * (db * (b * d + u *
w) + dc * (c * d - u * v) -
1073 dd * (-d2 + v2 + w2) + b * (db * d + du *
w) +
1074 c * (dc * d - du * v) - d * (-dd2 + dv2 + dw2) +
1075 b * (b * dd + u *
dw) + c * (c * dd - u * dv)),
1076 dC2 * (b * d + u *
w) +
1077 C2 * (db * d + b * dd + du *
w + u *
dw) - dC1 * v -
1079 dC3 * (-b * (b * v + c *
w) - u * (c * d - u * v) +
1080 v * (-d2 + v2 + w2)) +
1081 C3 * (-db * (b * v + c *
w) - du * (c * d - u * v) +
1082 dv * (-d2 + v2 + w2) - b * (db * v + dc *
w) -
1083 u * (dc * d - du * v) + v * (-dd2 + dv2 + dw2) -
1084 b * (b * dv + c *
dw) - u * (c * dd - u * dv)),
1085 dC2 * (c * d - u * v) +
1086 C2 * (dc * d + c * dd - du * v - u * dv) - dC1 *
w -
1088 dC3 * (-c * (b * v + c *
w) + u * (b * d + u *
w) +
1089 w * (-d2 + v2 + w2)) +
1090 C3 * (-dc * (b * v + c *
w) + du * (b * d + u *
w) +
1091 dw * (-d2 + v2 + w2) - c * (db * v + dc *
w) +
1092 u * (db * d + du *
w) +
w * (-dd2 + dv2 + dw2) -
1093 c * (b * dv + c *
dw) + u * (b * dd + u *
dw)),
1094 dC0 + dC2 * (d2 - v2 - w2) + C2 * (dd2 - dv2 - dw2))
1097 if (dK2[j].NumberOfFrequencies()) {
1098 const Numeric da = -0.5 * (r * dK2[j].Kjj(iz, ia)[i] +
1099 ((j == it) ? dr_dT2 * (K1.
Kjj(iz, ia)[i] +
1102 db = -0.5 * (r * dK2[j].K12(iz, ia)[i] +
1103 ((j == it) ? dr_dT2 * (K1.
K12(iz, ia)[i] +
1106 dc = -0.5 * (r * dK2[j].K13(iz, ia)[i] +
1107 ((j == it) ? dr_dT2 * (K1.
K13(iz, ia)[i] +
1110 dd = -0.5 * (r * dK2[j].K14(iz, ia)[i] +
1111 ((j == it) ? dr_dT2 * (K1.
K14(iz, ia)[i] +
1114 du = -0.5 * (r * dK2[j].K23(iz, ia)[i] +
1115 ((j == it) ? dr_dT2 * (K1.
K23(iz, ia)[i] +
1118 dv = -0.5 * (r * dK2[j].K24(iz, ia)[i] +
1119 ((j == it) ? dr_dT2 * (K1.
K24(iz, ia)[i] +
1122 dw = -0.5 * (r * dK2[j].K34(iz, ia)[i] +
1123 ((j == it) ? dr_dT2 * (K1.
K34(iz, ia)[i] +
1126 const Numeric db2 = 2 * db * b, dc2 = 2 * dc * c, dd2 = 2 * dd * d,
1127 du2 = 2 * du * u, dv2 = 2 * dv * v, dw2 = 2 *
dw *
w;
1130 2 * (db2 * (
b2 * 0.5 + c2 + d2 - u2 - v2 + w2) +
1131 b2 * (db2 * 0.5 + dc2 + dd2 - du2 - dv2 + dw2) +
1132 dc2 * (c2 * 0.5 + d2 - u2 + v2 - w2) +
1133 c2 * (dc2 * 0.5 + dd2 - du2 + dv2 - dw2) +
1134 dd2 * (d2 * 0.5 + u2 - v2 - w2) +
1135 d2 * (dd2 * 0.5 + du2 - dv2 - dw2) +
1136 du2 * (u2 * 0.5 + v2 + w2) + u2 * (du2 * 0.5 + dv2 + dw2) +
1137 dv2 * (v2 * 0.5 + w2) + v2 * (dv2 * 0.5 + dw2) +
1138 4 * (db * d * u *
w - db * c * v *
w - dc * d * u * v +
1139 b * dd * u *
w - b * dc * v *
w - c * dd * u * v +
1140 b * d * du *
w - b * c * dv *
w - c * d * du * v +
1141 b * d * u *
dw - b * c * v *
dw - c * d * u * dv));
1142 const Complex dConst1 = 0.5 * dtmp / Const1;
1143 const Numeric dConst2 = db2 + dc2 + dd2 - du2 - dv2 - dw2;
1145 x_zero ? 0 : (0.5 * (dConst2 + dConst1) / tmp_x_sqrt) * sqrt_05;
1147 : (0.5 * (dConst2 - dConst1) / tmp_y_sqrt) *
1157 const Complex dx2dy2 = dx2 + dy2;
1161 : (dcy *
x2 + cy * dx2 + dcx * y2 + cx * dy2 - C0c * dx2dy2) *
1165 : (dsy *
x2 *
iy + sy * dx2 *
iy + sy *
x2 * diy +
1166 dsx * y2 * ix + sx * dy2 * ix + sx * y2 * dix -
1170 both_zero ? 0.0 : (dcx - dcy - C2c * dx2dy2) * inv_x2y2;
1173 : ((x_zero ? -dsy *
iy - sy * diy
1174 : y_zero ? dsx * ix + sx * dix
1175 : dsx * ix + sx * dix - dsy *
iy -
1180 const Numeric& dC0 =
reinterpret_cast<const Numeric(&)[2]
>(dC0c)[0];
1181 const Numeric& dC1 =
reinterpret_cast<const Numeric(&)[2]
>(dC1c)[0];
1182 const Numeric& dC2 =
reinterpret_cast<const Numeric(&)[2]
>(dC2c)[0];
1183 const Numeric& dC3 =
reinterpret_cast<const Numeric(&)[2]
>(dC3c)[0];
1184 dT2[j].Mat4(i).noalias() =
1188 << dC0 + dC2 * (
b2 + c2 + d2) + C2 * (db2 + dc2 + dd2),
1189 db * C1 + b * dC1 + dC2 * (-c * u - d * v) +
1190 C2 * (-dc * u - dd * v - c * du - d * dv) +
1191 dC3 * (b * (
b2 + c2 + d2) - u * (b * u - d *
w) -
1192 v * (b * v + c *
w)) +
1193 C3 * (db * (
b2 + c2 + d2) - du * (b * u - d *
w) -
1194 dv * (b * v + c *
w) + b * (db2 + dc2 + dd2) -
1195 u * (db * u - dd *
w) - v * (db * v + dc *
w) -
1196 u * (b * du - d *
dw) - v * (b * dv + c *
dw)),
1197 dC1 * c + C1 * dc + dC2 * (b * u - d *
w) +
1198 C2 * (db * u - dd *
w + b * du - d *
dw) +
1199 dC3 * (c * (
b2 + c2 + d2) - u * (c * u + d * v) -
1200 w * (b * v + c *
w)) +
1201 C3 * (dc * (
b2 + c2 + d2) - du * (c * u + d * v) -
1202 dw * (b * v + c *
w) + c * (db2 + dc2 + dd2) -
1203 u * (dc * u + dd * v) -
w * (db * v + dc *
w) -
1204 u * (c * du + d * dv) -
w * (b * dv + c *
dw)),
1205 dC1 * d + C1 * dd + dC2 * (b * v + c *
w) +
1206 C2 * (db * v + dc *
w + b * dv + c *
dw) +
1207 dC3 * (d * (
b2 + c2 + d2) - v * (c * u + d * v) +
1208 w * (b * u - d *
w)) +
1209 C3 * (dd * (
b2 + c2 + d2) - dv * (c * u + d * v) +
1210 dw * (b * u - d *
w) + d * (db2 + dc2 + dd2) -
1211 v * (dc * u + dd * v) +
w * (db * u - dd *
w) -
1212 v * (c * du + d * dv) +
w * (b * du - d *
dw)),
1214 db * C1 + b * dC1 + dC2 * (c * u + d * v) +
1215 C2 * (dc * u + dd * v + c * du + d * dv) +
1216 dC3 * (-b * (-
b2 + u2 + v2) + c * (b * c - v *
w) +
1217 d * (b * d + u *
w)) +
1218 C3 * (-db * (-
b2 + u2 + v2) + dc * (b * c - v *
w) +
1219 dd * (b * d + u *
w) - b * (-db2 + du2 + dv2) +
1220 c * (db * c - dv *
w) + d * (db * d + du *
w) +
1221 c * (b * dc - v *
dw) + d * (b * dd + u *
dw)),
1222 dC0 + dC2 * (
b2 - u2 - v2) + C2 * (db2 - du2 - dv2),
1223 dC2 * (b * c - v *
w) +
1224 C2 * (db * c + b * dc - dv *
w - v *
dw) + dC1 * u +
1226 dC3 * (c * (c * u + d * v) - u * (-
b2 + u2 + v2) -
1227 w * (b * d + u *
w)) +
1228 C3 * (dc * (c * u + d * v) - du * (-
b2 + u2 + v2) -
1229 dw * (b * d + u *
w) + c * (dc * u + dd * v) -
1230 u * (-db2 + du2 + dv2) -
w * (db * d + du *
w) +
1231 c * (c * du + d * dv) -
w * (b * dd + u *
dw)),
1232 dC2 * (b * d + u *
w) +
1233 C2 * (db * d + b * dd + du *
w + u *
dw) + dC1 * v +
1235 dC3 * (d * (c * u + d * v) - v * (-
b2 + u2 + v2) +
1236 w * (b * c - v *
w)) +
1237 C3 * (dd * (c * u + d * v) - dv * (-
b2 + u2 + v2) +
1238 dw * (b * c - v *
w) + d * (dc * u + dd * v) -
1239 v * (-db2 + du2 + dv2) +
w * (db * c - dv *
w) +
1240 d * (c * du + d * dv) +
w * (b * dc - v *
dw)),
1242 dC1 * c + C1 * dc + dC2 * (-b * u + d *
w) +
1243 C2 * (-db * u + dd *
w - b * du + d *
dw) +
1244 dC3 * (b * (b * c - v *
w) - c * (-c2 + u2 + w2) +
1245 d * (c * d - u * v)) +
1246 C3 * (db * (b * c - v *
w) - dc * (-c2 + u2 + w2) +
1247 dd * (c * d - u * v) + b * (db * c - dv *
w) -
1248 c * (-dc2 + du2 + dw2) + d * (dc * d - du * v) +
1249 b * (b * dc - v *
dw) + d * (c * dd - u * dv)),
1250 dC2 * (b * c - v *
w) +
1251 C2 * (db * c + b * dc - dv *
w - v *
dw) - dC1 * u -
1253 dC3 * (-b * (b * u - d *
w) + u * (-c2 + u2 + w2) -
1254 v * (c * d - u * v)) +
1255 C3 * (-db * (b * u - d *
w) + du * (-c2 + u2 + w2) -
1256 dv * (c * d - u * v) - b * (db * u - dd *
w) +
1257 u * (-dc2 + du2 + dw2) - v * (dc * d - du * v) -
1258 b * (b * du - d *
dw) - v * (c * dd - u * dv)),
1259 dC0 + dC2 * (c2 - u2 - w2) + C2 * (dc2 - du2 - dw2),
1260 dC2 * (c * d - u * v) +
1261 C2 * (dc * d + c * dd - du * v - u * dv) + dC1 *
w +
1263 dC3 * (-d * (b * u - d *
w) + v * (b * c - v *
w) -
1264 w * (-c2 + u2 + w2)) +
1265 C3 * (-dd * (b * u - d *
w) + dv * (b * c - v *
w) -
1266 dw * (-c2 + u2 + w2) - d * (db * u - dd *
w) +
1267 v * (db * c - dv *
w) -
w * (-dc2 + du2 + dw2) -
1268 d * (b * du - d *
dw) + v * (b * dc - v *
dw)),
1270 dC1 * d + C1 * dd + dC2 * (-b * v - c *
w) +
1271 C2 * (-db * v - dc *
w - b * dv - c *
dw) +
1272 dC3 * (b * (b * d + u *
w) + c * (c * d - u * v) -
1273 d * (-d2 + v2 + w2)) +
1274 C3 * (db * (b * d + u *
w) + dc * (c * d - u * v) -
1275 dd * (-d2 + v2 + w2) + b * (db * d + du *
w) +
1276 c * (dc * d - du * v) - d * (-dd2 + dv2 + dw2) +
1277 b * (b * dd + u *
dw) + c * (c * dd - u * dv)),
1278 dC2 * (b * d + u *
w) +
1279 C2 * (db * d + b * dd + du *
w + u *
dw) - dC1 * v -
1281 dC3 * (-b * (b * v + c *
w) - u * (c * d - u * v) +
1282 v * (-d2 + v2 + w2)) +
1283 C3 * (-db * (b * v + c *
w) - du * (c * d - u * v) +
1284 dv * (-d2 + v2 + w2) - b * (db * v + dc *
w) -
1285 u * (dc * d - du * v) + v * (-dd2 + dv2 + dw2) -
1286 b * (b * dv + c *
dw) - u * (c * dd - u * dv)),
1287 dC2 * (c * d - u * v) +
1288 C2 * (dc * d + c * dd - du * v - u * dv) - dC1 *
w -
1290 dC3 * (-c * (b * v + c *
w) + u * (b * d + u *
w) +
1291 w * (-d2 + v2 + w2)) +
1292 C3 * (-dc * (b * v + c *
w) + du * (b * d + u *
w) +
1293 dw * (-d2 + v2 + w2) - c * (db * v + dc *
w) +
1294 u * (db * d + du *
w) +
w * (-dd2 + dv2 + dw2) -
1295 c * (b * dv + c *
dw) + u * (b * dd + u *
dw)),
1296 dC0 + dC2 * (d2 - v2 - w2) + C2 * (dd2 - dv2 - dw2))
1334 const Index it = -1,
1336 const Index ia = 0) noexcept {
1339 dtransmat4(T, dT1, dT2, K1, K2, dK1, dK2, r, dr_dT1, dr_dT2, it, iz, ia);
1342 dtransmat3(T, dT1, dT2, K1, K2, dK1, dK2, r, dr_dT1, dr_dT2, it, iz, ia);
1345 dtransmat2(T, dT1, dT2, K1, K2, dK1, dK2, r, dr_dT1, dr_dT2, it, iz, ia);
1348 dtransmat1(T, dT1, dT2, K1, K2, dK1, dK2, r, dr_dT1, dr_dT2, it, iz, ia);
1363 const Index temp_deriv_pos) {
1364 if (not dT1.
nelem())
1368 T, dT1, dT2, K1, K2, dK1, dK2, r, dr_dtemp1, dr_dtemp2, temp_deriv_pos);
1394 const auto invK =
inv4(K.
Kjj()[i],
1405 dJ[j].Vec4(i).noalias() =
1430 dJ[j].Vec3(i).noalias() =
1446 const auto invK =
inv2(K.
Kjj()[i], K.
K12()[i]);
1451 dJ[j].Vec2(i).noalias() =
1460 matrix2(dK[j].Kjj()[i], dK[j].K12()[i]) * J.
Vec2(i));
1463 const auto invK = 1 / K.
Kjj()[i];
1464 J.
Vec1(i)[0] *= invK;
1477 dK[j].Kjj()[i] * J.
Vec1(i)[0]);
1497 case RadiativeTransferSolver::Emission: {
1499 for (
size_t i = 0; i < dI1.size(); i++) {
1500 dI1[i].addDerivEmission(PiT, dT1[i], T, I, dJ1[i]);
1501 dI2[i].addDerivEmission(PiT, dT2[i], T, I, dJ2[i]);
1507 case RadiativeTransferSolver::Transmission: {
1508 for (
size_t i = 0; i < dI1.size(); i++) {
1509 dI1[i].addDerivTransmission(PiT, dT1[i], I);
1510 dI2[i].addDerivTransmission(PiT, dT2[i], I);
1532 const Index nf = n ? T[0].Frequencies() : 1;
1533 const Index ns = n ? T[0].StokesDim() : 1;
1536 case CumulativeTransmission::Forward: {
1537 for (
Index i = 1; i < n; i++) PiT[i].mul(PiT[i - 1], T[i]);
1540 for (
Index i = 1; i < n; i++) PiT[i].mul(T[i], PiT[i - 1]);
1561 const Index nv = np ? I[0].Frequencies() : 0;
1562 const Index ns = np ? I[0].StokesDim() : 1;
1566 for (
Index ip = 0; ip < np; ip++)
1567 I[ip].setBackscatterTransmission(I_incoming, PiTr[ip], PiTf[ip], Z[ip]);
1569 for (
Index ip = 0; ip < np; ip++) {
1570 for (
Index iq = 0; iq < nq; iq++) {
1571 dI[ip][ip][iq].setBackscatterTransmissionDerivative(
1572 I_incoming, PiTr[ip], PiTf[ip], dZ[ip][iq]);
1577 case BackscatterSolver::CommutativeTransmission: {
1581 BackscatterSolverCommutativeTransmissionStokesDimOne:
1582 for (
Index ip = 0; ip < np; ip++) {
1583 for (
Index j = ip; j < np; j++) {
1584 for (
Index iq = 0; iq < nq; iq++) {
1585 for (
Index iv = 0; iv < nv; iv++) {
1586 dI[ip][j][iq].Vec1(iv).noalias() +=
1587 T[ip].Mat1(iv).inverse() *
1588 (dT1[ip][iq].Mat1(iv) + dT2[ip][iq].Mat1(iv)) *
1591 if (j < np - 1 and j > ip)
1592 dI[ip][j][iq].Vec1(iv).noalias() +=
1593 T[ip+1].Mat1(iv).inverse() *
1594 (dT1[ip][iq].Mat1(iv) + dT2[ip][iq].Mat1(iv)) *
1602 for (
Index ip = 0; ip < np; ip++) {
1603 for (
Index j = ip; j < np; j++) {
1604 for (
Index iq = 0; iq < nq; iq++) {
1605 for (
Index iv = 0; iv < nv; iv++) {
1606 dI[ip][j][iq].Vec2(iv).noalias() +=
1607 T[ip].Mat2(iv).inverse() *
1608 (dT1[ip][iq].Mat2(iv) + dT2[ip][iq].Mat2(iv)) *
1611 if (j < np - 1 and j > ip)
1612 dI[ip][j][iq].Vec2(iv).noalias() +=
1613 T[ip+1].Mat2(iv).inverse() *
1614 (dT1[ip][iq].Mat2(iv) + dT2[ip][iq].Mat2(iv)) *
1622 for (
Index ip = 0; ip < np; ip++) {
1623 for (
Index j = ip; j < np; j++) {
1624 for (
Index iq = 0; iq < nq; iq++) {
1625 for (
Index iv = 0; iv < nv; iv++) {
1626 dI[ip][j][iq].Vec3(iv).noalias() +=
1627 T[ip].Mat3(iv).inverse() *
1628 (dT1[ip][iq].Mat3(iv) + dT2[ip][iq].Mat3(iv)) *
1631 if (j < np - 1 and j > ip)
1632 dI[ip][j][iq].Vec3(iv).noalias() +=
1633 T[ip+1].Mat3(iv).inverse() *
1634 (dT1[ip][iq].Mat3(iv) + dT2[ip][iq].Mat3(iv)) *
1642 for (
Index ip = 0; ip < np; ip++) {
1643 for (
Index j = ip; j < np; j++) {
1644 for (
Index iq = 0; iq < nq; iq++) {
1645 for (
Index iv = 0; iv < nv; iv++) {
1646 dI[ip][j][iq].Vec4(iv).noalias() +=
1647 T[ip].Mat4(iv).inverse() *
1648 (dT1[ip][iq].Mat4(iv) + dT2[ip][iq].Mat4(iv)) *
1651 if (j < np - 1 and j > ip)
1652 dI[ip][j][iq].Vec4(iv).noalias() +=
1653 T[ip+1].Mat4(iv).inverse() *
1654 (dT1[ip][iq].Mat4(iv) + dT2[ip][iq].Mat4(iv)) *
1664 std::runtime_error(
"Do not activate this code. It is not ready yet");
1668 goto BackscatterSolverCommutativeTransmissionStokesDimOne;
1671 for (
Index ip = 0; ip < np; ip++) {
1672 for (
Index j = ip; j < np; j++) {
1673 for (
Index iq = 0; iq < nq; iq++) {
1674 for (
Index iv = 0; iv < nv; iv++) {
1676 dI[ip][j][iq].Vec2(iv).noalias() +=
1677 PiTr[ip-2].Mat2(iv) *
1678 (dT1[ip-1][iq].Mat2(iv) + dT2[ip][iq].Mat2(iv)) *
1679 PiTr[ip-1].Mat2(iv).inverse() * I[j].Vec2(iv);
1682 dI[ip][j][iq].Vec2(iv).noalias() +=
1683 PiTr[ip].Mat2(iv) * Z[ip].Mat2(iv) * PiTf[ip-2].Mat2(iv) *
1684 (dT1[ip][iq].Mat2(iv) + dT2[ip+1][iq].Mat2(iv)) *
1685 PiTf[ip-1].Mat2(iv).inverse() * PiTf[ip].Mat2(iv) *
1689 dI[ip][j][iq].Vec2(iv).noalias() +=
1690 (dT1[ip-1][iq].Mat2(iv) + dT2[ip][iq].Mat2(iv)) *
1691 PiTr[ip-1].Mat2(iv).inverse() * I[j].Vec2(iv);
1694 dI[ip][j][iq].Vec2(iv).noalias() +=
1695 PiTr[ip].Mat2(iv) * Z[ip].Mat2(iv) *
1696 (dT1[ip][iq].Mat2(iv) + dT2[ip+1][iq].Mat2(iv)) *
1697 PiTf[ip-1].Mat2(iv).inverse() * PiTf[ip].Mat2(iv) *
1722 for (
Index ip = 0; ip < np; ip++) {
1727 for (
Index iv = 0; iv < nv; iv++)
1728 for (
Index id = 0;
id < nd;
id++)
1729 aotm[ip].Mat4(iv).noalias() +=
1733 for (
Index iv = 0; iv < nv; iv++)
1734 for (
Index id = 0;
id < nd;
id++)
1735 aotm[ip].Mat3(iv).noalias() +=
1739 for (
Index iv = 0; iv < nv; iv++)
1740 for (
Index id = 0;
id < nd;
id++)
1741 aotm[ip].Mat2(iv).noalias() +=
1745 for (
Index iv = 0; iv < nv; iv++)
1746 for (
Index id = 0;
id < nd;
id++)
1747 aotm[ip].Mat1(iv).noalias() +=
1765 for (
Index ip = 0; ip < np; ip++) {
1766 for (
Index iq = 0; iq < nq; iq++) {
1767 aoaotm[ip][iq].setZero();
1769 if(not aom[iq].empty()) {
1772 for (
Index iv = 0; iv < nv; iv++)
1773 for (
Index id = 0;
id < nd;
id++)
1774 aoaotm[ip][iq].Mat4(iv).noalias() +=
1778 for (
Index iv = 0; iv < nv; iv++)
1779 for (
Index id = 0;
id < nd;
id++)
1780 aoaotm[ip][iq].Mat3(iv).noalias() +=
1784 for (
Index iv = 0; iv < nv; iv++)
1785 for (
Index id = 0;
id < nd;
id++)
1786 aoaotm[ip][iq].Mat2(iv).noalias() +=
1790 for (
Index iv = 0; iv < nv; iv++)
1791 for (
Index id = 0;
id < nd;
id++)
1792 aoaotm[ip][iq].Mat1(iv).noalias() +=
1805 for (
const auto& T : tm.
T4) os << T <<
'\n';
1806 for (
const auto& T : tm.
T3) os << T <<
'\n';
1807 for (
const auto& T : tm.
T2) os << T <<
'\n';
1808 for (
const auto& T : tm.
T1) os << T <<
'\n';
1814 for (
const auto& T : atm) os << T <<
'\n';
1820 for (
const auto& T : aatm) os << T <<
'\n';
1826 for (
const auto& R : rv.
R4) os << R.transpose() <<
'\n';
1827 for (
const auto& R : rv.
R3) os << R.transpose() <<
'\n';
1828 for (
const auto& R : rv.
R2) os << R.transpose() <<
'\n';
1829 for (
const auto& R : rv.
R1) os << R.transpose() <<
'\n';
1834 for (
const auto& R : arv) os << R <<
'\n';
1840 for (
const auto& R : aarv) os << R <<
'\n';
1845 for (
auto& T : tm.
T4)
1846 is >> T(0, 0) >> T(0, 1) >> T(0, 2) >> T(0, 3) >>
1847 T(1, 0) >> T(1, 1) >> T(1, 2) >> T(1, 3) >>
1848 T(2, 0) >> T(2, 1) >> T(2, 2) >> T(2, 3) >>
1849 T(3, 0) >> T(3, 1) >> T(3, 2) >> T(3, 3);
1850 for (
auto& T : tm.
T3)
1851 is >> T(0, 0) >> T(0, 1) >> T(0, 2) >>
1852 T(1, 0) >> T(1, 1) >> T(1, 2) >>
1853 T(2, 0) >> T(2, 1) >> T(2, 2);
1854 for (
auto& T : tm.
T2) is >> T(0, 0) >> T(0, 1) >>
1856 for (
auto& T : tm.
T1) is >> T(0, 0);
1861 for (
auto& R : rv.
R4) is >> R[0] >> R[1] >> R[2] >> R[3];
1862 for (
auto& R : rv.
R3) is >> R[0] >> R[1] >> R[2];
1863 for (
auto& R : rv.
R2) is >> R[0] >> R[1] >> R[2];
1864 for (
auto& R : rv.
R1) is >> R[0];