BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
KzComputation Namespace Reference

Functions

std::vector< complex_tcomputeReducedKz (const std::vector< Slice > &slices, kvector_t k)
 
std::vector< complex_tcomputeKzFromSLDs (const std::vector< Slice > &slices, double kz)
 
std::vector< complex_tcomputeKzFromRefIndices (const std::vector< Slice > &slices, kvector_t k)
 

Detailed Description

Namespace containing functions for computing kz values for given multilayer and k (or kz) value on the surface of the sample.

Function Documentation

◆ computeReducedKz()

std::vector< complex_t > KzComputation::computeReducedKz ( const std::vector< Slice > &  slices,
kvector_t  k 
)

Definition at line 41 of file KzComputation.cpp.

43 {
44  const size_t N = slices.size();
45  const double n_ref = slices[0].material().refractiveIndex(2 * M_PI / k.mag()).real();
46  const double k_base = k.mag() * (k.z() > 0.0 ? -1 : 1);
47 
48  std::vector<complex_t> result(N);
49  // Calculate refraction angle, expressed as k_z, for each layer.
50  complex_t rad = slices[0].scalarReducedPotential(k, n_ref);
51  result[0] = k_base * std::sqrt(rad);
52  for (size_t i = 1; i < N; ++i) {
53  rad = checkForUnderflow(slices[i].scalarReducedPotential(k, n_ref));
54  result[i] = k_base * std::sqrt(rad);
55  }
56  return result;
57 }
std::complex< double > complex_t
Definition: Complex.h:20
#define M_PI
Definition: MathConstants.h:39
double mag() const
Returns magnitude of the vector.
T z() const
Returns z-component in cartesian coordinate system.
Definition: BasicVector3D.h:68
static constexpr double rad
Definition: Units.h:53
complex_t checkForUnderflow(complex_t val)

References anonymous_namespace{KzComputation.cpp}::checkForUnderflow(), M_PI, BasicVector3D< T >::mag(), Units::rad, and BasicVector3D< T >::z().

Referenced by SpecularMagneticNewStrategy::Execute(), SpecularMagneticStrategy::Execute(), and SpecularScalarStrategy::Execute().

Here is the call graph for this function:

◆ computeKzFromSLDs()

std::vector< complex_t > KzComputation::computeKzFromSLDs ( const std::vector< Slice > &  slices,
double  kz 
)

Definition at line 59 of file KzComputation.cpp.

60 {
61  const size_t N = slices.size();
62  const double k_sign = kz > 0.0 ? -1 : 1;
63  complex_t kz2_base = kz * kz + normalizedSLD(slices[0].material());
64 
65  std::vector<complex_t> result(N);
66  result[0] = -kz;
67  // Calculate refraction angle, expressed as k_z, for each layer.
68  for (size_t i = 1; i < N; ++i) {
69  complex_t kz2 = checkForUnderflow(kz2_base - normalizedSLD(slices[i].material()));
70  result[i] = k_sign * std::sqrt(kz2);
71  }
72  return result;
73 }
complex_t normalizedSLD(const Material &material)

References anonymous_namespace{KzComputation.cpp}::checkForUnderflow(), and anonymous_namespace{KzComputation.cpp}::normalizedSLD().

Referenced by SpecularSimulationElement::SpecularSimulationElement().

Here is the call graph for this function:

◆ computeKzFromRefIndices()

std::vector< complex_t > KzComputation::computeKzFromRefIndices ( const std::vector< Slice > &  slices,
kvector_t  k 
)

Definition at line 75 of file KzComputation.cpp.

77 {
78  const size_t N = slices.size();
79  const double kz = k.z();
80  const double k_sign = kz > 0.0 ? -1 : 1;
81  const double k2 = k.mag2();
82  const double kz2 = kz * kz;
83  const double wl = 2 * M_PI / std::sqrt(k2);
84  const complex_t n2_ref = slices[0].material().refractiveIndex2(wl);
85 
86  std::vector<complex_t> result(N);
87  result[0] = -kz;
88  for (size_t i = 1; i < N; ++i) {
89  const complex_t n2_norm = slices[i].material().refractiveIndex2(wl) - n2_ref;
90  result[i] = k_sign * std::sqrt(checkForUnderflow(k2 * n2_norm + kz2));
91  }
92  return result;
93 }
double mag2() const
Returns magnitude squared of the vector.

References anonymous_namespace{KzComputation.cpp}::checkForUnderflow(), M_PI, BasicVector3D< T >::mag2(), and BasicVector3D< T >::z().

Referenced by SpecularSimulationElement::SpecularSimulationElement().

Here is the call graph for this function: