BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SpecularMagneticTanhStrategy.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Specular/SpecularMagneticTanhStrategy.cpp
6 //! @brief Implements class SpecularMagneticTanhStrategy.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include "Base/Math/Constants.h"
17 #include "Base/Math/Functions.h"
18 
19 namespace {
20 const double pi2_15 = std::pow(M_PI_2, 1.5);
21 } // namespace
22 
23 Eigen::Matrix2cd
25  double sigma, bool inverse) const
26 {
27  if (sigma < 10 * std::numeric_limits<double>::epsilon())
28  return Eigen::Matrix2cd{Eigen::Matrix2cd::Identity()};
29 
30  const double sigeff = pi2_15 * sigma;
31  const auto b = coeff.m_b;
32 
33  if (std::abs(b.mag() - 1.) < std::numeric_limits<double>::epsilon() * 10.) {
34  Eigen::Matrix2cd Q;
35  const double factor1 = 2. * (1. + b.z());
36  Q << (1. + b.z()), (I * b.y() - b.x()), (b.x() + I * b.y()), (b.z() + 1.);
37 
38  complex_t l1 = std::sqrt(Math::tanhc(sigeff * coeff.m_lambda(1)));
39  complex_t l2 = std::sqrt(Math::tanhc(sigeff * coeff.m_lambda(0)));
40 
41  if (inverse) {
42  l1 = 1. / l1;
43  l2 = 1. / l2;
44  }
45 
46  const Eigen::Matrix2cd lambda = Eigen::DiagonalMatrix<complex_t, 2>({l1, l2});
47 
48  return Q * lambda * Q.adjoint() / factor1;
49 
50  } else if (b.mag() < 10 * std::numeric_limits<double>::epsilon()) {
51  complex_t alpha =
52  std::sqrt(Math::tanhc(0.5 * sigeff * (coeff.m_lambda(1) + coeff.m_lambda(0))));
53  if (inverse)
54  alpha = 1. / alpha;
55  const Eigen::Matrix2cd lambda = Eigen::DiagonalMatrix<complex_t, 2>({alpha, alpha});
56 
57  return lambda;
58  }
59 
60  throw std::runtime_error("Broken magnetic field vector");
61 }
62 
63 std::pair<Eigen::Matrix2cd, Eigen::Matrix2cd>
65  const MatrixRTCoefficients& coeff_i1,
66  double sigma) const
67 {
68  Eigen::Matrix2cd R{Eigen::Matrix2cd::Identity()};
69  Eigen::Matrix2cd RInv{Eigen::Matrix2cd::Identity()};
70 
71  if (sigma != 0.) {
72  R = computeRoughnessMatrix(coeff_i1, sigma, false)
73  * computeRoughnessMatrix(coeff_i, sigma, true);
74 
75  RInv = computeRoughnessMatrix(coeff_i, sigma, false)
76  * computeRoughnessMatrix(coeff_i1, sigma, true);
77  }
78 
79  const Eigen::Matrix2cd mproduct = coeff_i.computeInverseP() * coeff_i1.computeP();
80  const Eigen::Matrix2cd mp = 0.5 * (RInv + mproduct * R);
81  const Eigen::Matrix2cd mm = 0.5 * (RInv - mproduct * R);
82 
83  return {mp, mm};
84 }
constexpr complex_t I
Definition: Complex.h:21
std::complex< double > complex_t
Definition: Complex.h:20
Defines M_PI and some more mathematical constants.
#define M_PI_2
Definition: Constants.h:45
Defines functions in namespace Math.
Defines class SpecularMagneticTanhStrategy.
Specular reflection and transmission coefficients in a layer in case of magnetic interactions between...
Eigen::Matrix2cd computeInverseP() const
Eigen::Vector2cd m_lambda
wave propagation direction (-1 for direct one, 1 for time reverse)
kvector_t m_b
unit magnetic field vector
Eigen::Matrix2cd computeP() const
virtual std::pair< Eigen::Matrix2cd, Eigen::Matrix2cd > computeBackwardsSubmatrices(const MatrixRTCoefficients &coeff_i, const MatrixRTCoefficients &coeff_i1, double sigma) const
Eigen::Matrix2cd computeRoughnessMatrix(const MatrixRTCoefficients &coeff, double sigma, bool inverse=false) const
complex_t tanhc(const complex_t z)
Complex tanhc function: .
Definition: Functions.cpp:69