BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SpecularMagneticNewTanhStrategy Class Reference
Inheritance diagram for SpecularMagneticNewTanhStrategy:
Collaboration diagram for SpecularMagneticNewTanhStrategy:

Public Types

using coeffs_t = std::vector< std::unique_ptr< const ILayerRTCoefficients > >
 

Public Member Functions

ISpecularStrategy::coeffs_t Execute (const std::vector< Slice > &slices, const kvector_t &k) const
 
ISpecularStrategy::coeffs_t Execute (const std::vector< Slice > &slices, const std::vector< complex_t > &kz) const
 

Private Member Functions

virtual std::pair< Eigen::Matrix2cd, Eigen::Matrix2cd > computeBackwardsSubmatrices (const MatrixRTCoefficients_v3 &coeff_i, const MatrixRTCoefficients_v3 &coeff_i1, double sigma) const
 
Eigen::Matrix2cd computeRoughnessMatrix (const MatrixRTCoefficients_v3 &coeff, double sigma, bool inverse=false) const
 
std::vector< MatrixRTCoefficients_v3computeTR (const std::vector< Slice > &slices, const std::vector< complex_t > &kzs) const
 
void calculateUpwards (std::vector< MatrixRTCoefficients_v3 > &coeff, const std::vector< Slice > &slices) const
 

Detailed Description

Implements the magnetic Fresnel computation with the analytical Tanh roughness.

Implements the transfer matrix formalism for the calculation of wave amplitudes of the coherent wave solution in a multilayer with magnetization. For a description, see internal document "Polarized Implementation of the Transfer Matrix Method"

Definition at line 28 of file SpecularMagneticNewTanhStrategy.h.

Member Typedef Documentation

◆ coeffs_t

using ISpecularStrategy::coeffs_t = std::vector<std::unique_ptr<const ILayerRTCoefficients> >
inherited

Definition at line 40 of file ISpecularStrategy.h.

Member Function Documentation

◆ computeBackwardsSubmatrices()

std::pair< Eigen::Matrix2cd, Eigen::Matrix2cd > SpecularMagneticNewTanhStrategy::computeBackwardsSubmatrices ( const MatrixRTCoefficients_v3 coeff_i,
const MatrixRTCoefficients_v3 coeff_i1,
double  sigma 
) const
privatevirtual

Implements SpecularMagneticNewStrategy.

Definition at line 65 of file SpecularMagneticNewTanhStrategy.cpp.

68 {
69  Eigen::Matrix2cd R{Eigen::Matrix2cd::Identity()};
70  Eigen::Matrix2cd RInv{Eigen::Matrix2cd::Identity()};
71 
72  if (sigma != 0.) {
73  R = computeRoughnessMatrix(coeff_i1, sigma, false)
74  * computeRoughnessMatrix(coeff_i, sigma, true);
75 
76  RInv = computeRoughnessMatrix(coeff_i, sigma, false)
77  * computeRoughnessMatrix(coeff_i1, sigma, true);
78  }
79 
80  const Eigen::Matrix2cd mproduct = coeff_i.computeInverseP() * coeff_i1.computeP();
81  const Eigen::Matrix2cd mp = 0.5 * (RInv + mproduct * R);
82  const Eigen::Matrix2cd mm = 0.5 * (RInv - mproduct * R);
83 
84  return {mp, mm};
85 }
Eigen::Matrix2cd computeInverseP() const
Eigen::Matrix2cd computeP() const
Eigen::Matrix2cd computeRoughnessMatrix(const MatrixRTCoefficients_v3 &coeff, double sigma, bool inverse=false) const

References MatrixRTCoefficients_v3::computeInverseP(), MatrixRTCoefficients_v3::computeP(), and computeRoughnessMatrix().

Here is the call graph for this function:

◆ computeRoughnessMatrix()

Eigen::Matrix2cd SpecularMagneticNewTanhStrategy::computeRoughnessMatrix ( const MatrixRTCoefficients_v3 coeff,
double  sigma,
bool  inverse = false 
) const
private

Definition at line 25 of file SpecularMagneticNewTanhStrategy.cpp.

27 {
28  if (sigma < 10 * std::numeric_limits<double>::epsilon())
29  return Eigen::Matrix2cd{Eigen::Matrix2cd::Identity()};
30 
31  const double sigeff = pi2_15 * sigma;
32  const auto b = coeff.m_b;
33 
34  if (std::abs(b.mag() - 1.) < std::numeric_limits<double>::epsilon() * 10.) {
35  Eigen::Matrix2cd Q;
36  const double factor1 = 2. * (1. + b.z());
37  Q << (1. + b.z()), (I * b.y() - b.x()), (b.x() + I * b.y()), (b.z() + 1.);
38 
39  complex_t l1 = std::sqrt(MathFunctions::tanhc(sigeff * coeff.m_lambda(1)));
40  complex_t l2 = std::sqrt(MathFunctions::tanhc(sigeff * coeff.m_lambda(0)));
41 
42  if (inverse) {
43  l1 = 1. / l1;
44  l2 = 1. / l2;
45  }
46 
47  const Eigen::Matrix2cd lambda = Eigen::DiagonalMatrix<complex_t, 2>({l1, l2});
48 
49  return Q * lambda * Q.adjoint() / factor1;
50 
51  } else if (b.mag() < 10 * std::numeric_limits<double>::epsilon()) {
52  complex_t alpha =
53  std::sqrt(MathFunctions::tanhc(0.5 * sigeff * (coeff.m_lambda(1) + coeff.m_lambda(0))));
54  if (inverse)
55  alpha = 1. / alpha;
56  const Eigen::Matrix2cd lambda = Eigen::DiagonalMatrix<complex_t, 2>({alpha, alpha});
57 
58  return lambda;
59  }
60 
61  throw std::runtime_error("Broken magnetic field vector");
62 }
constexpr complex_t I
Definition: Complex.h:21
std::complex< double > complex_t
Definition: Complex.h:20
Eigen::Vector2cd m_lambda
wave propagation direction (-1 for direct one, 1 for time reverse)
kvector_t m_b
unit magnetic field vector
complex_t tanhc(const complex_t z)
Complex tanhc function: .

References I, MatrixRTCoefficients_v3::m_b, MatrixRTCoefficients_v3::m_lambda, anonymous_namespace{SpecularMagneticNewTanhStrategy.cpp}::pi2_15, and MathFunctions::tanhc().

Referenced by computeBackwardsSubmatrices().

Here is the call graph for this function:

◆ Execute() [1/2]

ISpecularStrategy::coeffs_t SpecularMagneticNewStrategy::Execute ( const std::vector< Slice > &  slices,
const kvector_t k 
) const
virtualinherited

Computes refraction angle reflection/transmission coefficients for given sliced multilayer and wavevector k.

Implements ISpecularStrategy.

Definition at line 35 of file SpecularMagneticNewStrategy.cpp.

37 {
38  return Execute(slices, KzComputation::computeReducedKz(slices, k));
39 }
ISpecularStrategy::coeffs_t Execute(const std::vector< Slice > &slices, const kvector_t &k) const
Computes refraction angle reflection/transmission coefficients for given sliced multilayer and waveve...
std::vector< complex_t > computeReducedKz(const std::vector< Slice > &slices, kvector_t k)

References KzComputation::computeReducedKz(), and SpecularMagneticNewStrategy::Execute().

Referenced by SpecularMagneticNewStrategy::Execute().

Here is the call graph for this function:

◆ Execute() [2/2]

ISpecularStrategy::coeffs_t SpecularMagneticNewStrategy::Execute ( const std::vector< Slice > &  slices,
const std::vector< complex_t > &  kz 
) const
virtualinherited

Computes refraction angle reflection/transmission coefficients for given sliced multilayer and a set of kz projections corresponding to each slice.

Implements ISpecularStrategy.

Definition at line 42 of file SpecularMagneticNewStrategy.cpp.

44 {
45  if (slices.size() != kz.size())
46  throw std::runtime_error("Number of slices does not match the size of the kz-vector");
47 
49  for (auto& coeff : computeTR(slices, kz))
50  result.push_back(std::make_unique<MatrixRTCoefficients_v3>(coeff));
51 
52  return result;
53 }
std::vector< std::unique_ptr< const ILayerRTCoefficients > > coeffs_t
std::vector< MatrixRTCoefficients_v3 > computeTR(const std::vector< Slice > &slices, const std::vector< complex_t > &kzs) const

References SpecularMagneticNewStrategy::computeTR().

Here is the call graph for this function:

◆ computeTR()

std::vector< MatrixRTCoefficients_v3 > SpecularMagneticNewStrategy::computeTR ( const std::vector< Slice > &  slices,
const std::vector< complex_t > &  kzs 
) const
privateinherited

Definition at line 56 of file SpecularMagneticNewStrategy.cpp.

58 {
59  const size_t N = slices.size();
60 
61  if (slices.size() != kzs.size())
62  throw std::runtime_error(
63  "Error in SpecularMagnetic_::execute: kz vector and slices size shall coinside.");
64  if (slices.empty())
65  return {};
66 
67  std::vector<MatrixRTCoefficients_v3> result;
68  result.reserve(N);
69 
70  const double kz_sign = kzs.front().real() >= 0.0 ? 1.0 : -1.0; // save sign to restore it later
71 
72  auto B_0 = slices.front().bField();
73  result.emplace_back(kz_sign, eigenvalues(kzs.front(), 0.0), kvector_t{0.0, 0.0, 0.0}, 0.0);
74  for (size_t i = 1, size = slices.size(); i < size; ++i) {
75  auto B = slices[i].bField() - B_0;
76  auto magnetic_SLD = magneticSLD(B);
77  result.emplace_back(kz_sign, checkForUnderflow(eigenvalues(kzs[i], magnetic_SLD)),
78  B.mag() > eps ? B / B.mag() : kvector_t{0.0, 0.0, 0.0}, magnetic_SLD);
79  }
80 
81  if (N == 1) {
82  result[0].m_T = Eigen::Matrix2cd::Identity();
83  result[0].m_R = Eigen::Matrix2cd::Zero();
84  return result;
85 
86  } else if (kzs[0] == 0.) {
87  result[0].m_T = Eigen::Matrix2cd::Identity();
88  result[0].m_R = -Eigen::Matrix2cd::Identity();
89  for (size_t i = 1; i < N; ++i) {
90  result[i].m_T.setZero();
91  result[i].m_R.setZero();
92  }
93  return result;
94  }
95 
96  calculateUpwards(result, slices);
97 
98  return result;
99 }
void calculateUpwards(std::vector< MatrixRTCoefficients_v3 > &coeff, const std::vector< Slice > &slices) const
Eigen::Vector2cd eigenvalues(complex_t kz, double b_mag)
Eigen::Vector2cd checkForUnderflow(const Eigen::Vector2cd &eigenvs)

References SpecularMagneticNewStrategy::calculateUpwards(), anonymous_namespace{SpecularMagneticNewStrategy.cpp}::checkForUnderflow(), anonymous_namespace{SpecularMagneticNewStrategy.cpp}::eigenvalues(), anonymous_namespace{SpecularMagneticNewStrategy.cpp}::eps, and anonymous_namespace{SpecularMagneticNewStrategy.cpp}::magneticSLD().

Referenced by SpecularMagneticNewStrategy::Execute().

Here is the call graph for this function:

◆ calculateUpwards()

void SpecularMagneticNewStrategy::calculateUpwards ( std::vector< MatrixRTCoefficients_v3 > &  coeff,
const std::vector< Slice > &  slices 
) const
privateinherited

Definition at line 101 of file SpecularMagneticNewStrategy.cpp.

103 {
104  const auto N = slices.size();
105  std::vector<Eigen::Matrix2cd> SMatrices(N - 1);
106  std::vector<complex_t> Normalization(N - 1);
107 
108  // bottom boundary condition
109  coeff.back().m_T = Eigen::Matrix2cd::Identity();
110  coeff.back().m_R = Eigen::Matrix2cd::Zero();
111 
112  for (int i = N - 2; i >= 0; --i) {
113  double sigma = 0.;
114  if (const auto roughness = GetBottomRoughness(slices, i))
115  sigma = roughness->getSigma();
116 
117  // compute the 2x2 submatrices in the write-up denoted as P+, P- and delta
118  const auto mpmm = computeBackwardsSubmatrices(coeff[i], coeff[i + 1], sigma);
119  const Eigen::Matrix2cd mp = mpmm.first;
120  const Eigen::Matrix2cd mm = mpmm.second;
121 
122  const Eigen::Matrix2cd delta = coeff[i].computeDeltaMatrix(slices[i].thickness());
123 
124  // compute the rotation matrix
125  Eigen::Matrix2cd S, Si;
126  Si = mp + mm * coeff[i + 1].m_R;
127  S << Si(1, 1), -Si(0, 1), -Si(1, 0), Si(0, 0);
128  const complex_t norm = S(0, 0) * S(1, 1) - S(0, 1) * S(1, 0);
129  S = S * delta;
130 
131  // store the rotation matrix and normalization constant in order to rotate
132  // the coefficients for all lower slices at the end of the computation
133  SMatrices[i] = S;
134  Normalization[i] = norm;
135 
136  // compute the reflection matrix and
137  // rotate the polarization such that we have pure incoming states (T = I)
138  S /= norm;
139 
140  // T is always equal to the identity at this point, no need to store
141  coeff[i].m_R = delta * (mm + mp * coeff[i + 1].m_R) * S;
142  }
143 
144  // now correct all amplitudes in forward direction by dividing with the remaining
145  // normalization constants. In addition rotate the polarization by the amount
146  // that was rotated above the current interface
147  // if the normalization overflows, all amplitudes below that point are set to zero
148  complex_t dumpingFactor = 1;
149  Eigen::Matrix2cd S = Eigen::Matrix2cd::Identity();
150  for (size_t i = 1; i < N; ++i) {
151  dumpingFactor = dumpingFactor * Normalization[i - 1];
152  S = SMatrices[i - 1] * S;
153 
154  if (std::isinf(std::norm(dumpingFactor))) {
155  std::for_each(coeff.begin() + i, coeff.end(), [](auto& coeff) {
156  coeff.m_T = Eigen::Matrix2cd::Zero();
157  coeff.m_R = Eigen::Matrix2cd::Zero();
158  });
159  break;
160  }
161 
162  coeff[i].m_T = S / dumpingFactor; // T * S omitted, since T is always I
163  coeff[i].m_R *= S / dumpingFactor;
164  }
165 }
virtual std::pair< Eigen::Matrix2cd, Eigen::Matrix2cd > computeBackwardsSubmatrices(const MatrixRTCoefficients_v3 &coeff_i, const MatrixRTCoefficients_v3 &coeff_i1, double sigma) const =0
double Si(double x)
Sine integral function: .
const LayerRoughness * GetBottomRoughness(const std::vector< Slice > &slices, const size_t slice_index)

References SpecularMagneticNewStrategy::computeBackwardsSubmatrices(), anonymous_namespace{SpecularMagneticNewStrategy.cpp}::GetBottomRoughness(), and MathFunctions::Si().

Referenced by SpecularMagneticNewStrategy::computeTR().

Here is the call graph for this function:

The documentation for this class was generated from the following files: