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

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

Functions

std::vector< complex_tcomputeKzFromRefIndices (const std::vector< Slice > &slices, kvector_t k)
 
std::vector< complex_tcomputeKzFromSLDs (const std::vector< Slice > &slices, double kz)
 
std::vector< complex_tcomputeReducedKz (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

◆ computeKzFromRefIndices()

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

Definition at line 74 of file KzComputation.cpp.

76 {
77  const size_t N = slices.size();
78  const double kz = k.z();
79  const double k_sign = kz > 0.0 ? -1 : 1;
80  const double k2 = k.mag2();
81  const double kz2 = kz * kz;
82  const double wl = 2 * M_PI / std::sqrt(k2);
83  const complex_t n2_ref = slices[0].material().refractiveIndex2(wl);
84 
85  std::vector<complex_t> result(N);
86  result[0] = -kz;
87  for (size_t i = 1; i < N; ++i) {
88  const complex_t n2_norm = slices[i].material().refractiveIndex2(wl) - n2_ref;
89  result[i] = k_sign * std::sqrt(checkForUnderflow(k2 * n2_norm + kz2));
90  }
91  return result;
92 }
std::complex< double > complex_t
Definition: Complex.h:20
#define M_PI
Definition: Constants.h:44
double mag2() const
Returns magnitude squared of the vector.
T z() const
Returns z-component in cartesian coordinate system.
Definition: BasicVector3D.h:67

References M_PI, BasicVector3D< T >::mag2(), and BasicVector3D< T >::z().

Referenced by SpecularSimulationElement::SpecularSimulationElement().

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 58 of file KzComputation.cpp.

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

Referenced by SpecularSimulationElement::SpecularSimulationElement(), and gui2::SpecularToySimulation::runSimulation().

◆ computeReducedKz()

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

Definition at line 40 of file KzComputation.cpp.

42 {
43  const size_t N = slices.size();
44  const double n_ref = slices[0].material().refractiveIndex(2 * M_PI / k.mag()).real();
45  const double k_base = k.mag() * (k.z() > 0.0 ? -1 : 1);
46 
47  std::vector<complex_t> result(N);
48  // Calculate refraction angle, expressed as k_z, for each layer.
49  complex_t rad = slices[0].scalarReducedPotential(k, n_ref);
50  result[0] = k_base * std::sqrt(rad);
51  for (size_t i = 1; i < N; ++i) {
52  rad = checkForUnderflow(slices[i].scalarReducedPotential(k, n_ref));
53  result[i] = k_base * std::sqrt(rad);
54  }
55  return result;
56 }
double mag() const
Returns magnitude of the vector.
static constexpr double rad
Radian, internal unit for angles.
Definition: Units.h:45

References M_PI, BasicVector3D< T >::mag(), Units::rad, and BasicVector3D< T >::z().

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

Here is the call graph for this function: