BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Compute::Kz Namespace Reference

Functions

std::vector< complex_t > computeKzFromRefIndices (const SliceStack &slices, R3 k)
 Computes kz values from k-vector of the incoming beam known at a distant point in vacuum. It is assumed, that the beam penetrates fronting medium from a side. More...
 
std::vector< complex_t > computeKzFromSLDs (const SliceStack &slices, double kz)
 Computes kz values from kz of the incoming beam known at a distant point in vacuum. It is assumed, that the beam penetrates fronting medium from a side. More...
 
std::vector< complex_t > computeReducedKz (const SliceStack &slices, R3 k)
 Computes kz values from known k vector and slices with the following assumptions: More...
 

Function Documentation

◆ computeKzFromRefIndices()

std::vector< complex_t > Compute::Kz::computeKzFromRefIndices ( const SliceStack slices,
R3  k 
)

Computes kz values from k-vector of the incoming beam known at a distant point in vacuum. It is assumed, that the beam penetrates fronting medium from a side.

Definition at line 78 of file KzComputation.cpp.

79 {
80  const size_t N = slices.size();
81  const double kz = k.z();
82  const double k_sign = kz > 0.0 ? -1 : 1;
83  const double k2 = k.mag2();
84  const double kz2 = kz * kz;
85  const double wl = M_TWOPI / std::sqrt(k2);
86  const complex_t n2_ref = slices[0].material().refractiveIndex2(wl);
87 
88  std::vector<complex_t> result(N);
89  result[0] = -kz;
90  for (size_t i = 1; i < N; ++i) {
91  const complex_t n2_norm = slices[i].material().refractiveIndex2(wl) - n2_ref;
92  result[i] = k_sign * std::sqrt(checkForUnderflow(k2 * n2_norm + kz2));
93  }
94  return result;
95 }
#define M_TWOPI
Definition: Constants.h:54
#define N
Definition: mixmax.h:31

References M_TWOPI, and N.

Referenced by SpecularElement::FromAlphaScan().

◆ computeKzFromSLDs()

std::vector< complex_t > Compute::Kz::computeKzFromSLDs ( const SliceStack slices,
double  kz 
)

Computes kz values from kz of the incoming beam known at a distant point in vacuum. It is assumed, that the beam penetrates fronting medium from a side.

Definition at line 62 of file KzComputation.cpp.

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

References N.

Referenced by SpecularElement::FromQzScan().

◆ computeReducedKz()

std::vector< complex_t > Compute::Kz::computeReducedKz ( const SliceStack slices,
R3  k 
)

Computes kz values from known k vector and slices with the following assumptions:

  • the beam penetrates fronting medium from a side
  • the wavelength is known for a distant point in vacuum (ref. index = 1)
  • the incident angle is known for the sample surface

This function is used in GISAS and off-spec computations mainly for back-compatibility reasons and should be replaced with computeKzFromRefIndices.

Definition at line 43 of file KzComputation.cpp.

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

References M_TWOPI, N, and Units::rad.

Referenced by Compute::SpecularScalar::fluxes(), and Compute::SpecularMagnetic::fluxes().