BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
MaterialUtils.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Material/MaterialUtils.cpp
6 //! @brief Implements functions in namespace MaterialUtils
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
17 #include "Base/Spin/SpinMatrix.h"
18 
20 using PhysConsts::h_bar;
21 using PhysConsts::m_n;
22 using PhysConsts::mu_N;
23 // The factor 1e-18 is here to have unit: 1/T*nm^-2
24 constexpr double magnetic_prefactor = (m_n * g_factor_n * mu_N / h_bar / h_bar) * 1e-18;
25 
26 namespace {
27 
28 // Pauli matrices
29 const SpinMatrix Pauli_X(0, 1, 1, 0);
30 const SpinMatrix Pauli_Y(0, -I, I, 0);
31 const SpinMatrix Pauli_Z(1, 0, 0, -1);
32 
33 } // namespace
34 
35 template <typename T>
36 SpinMatrix MaterialUtils::MagnetizationCorrection(complex_t unit_factor, double magnetic_factor,
37  Vec3<T> polarization)
38 {
39  SpinMatrix result = unit_factor * SpinMatrix::One()
40  + magnetic_factor
41  * (Pauli_X * polarization.x() + Pauli_Y * polarization.y()
42  + Pauli_Z * polarization.z());
43  return result;
44 }
45 
46 // Prompt compilation for real and complex vectors:
47 template SpinMatrix MaterialUtils::MagnetizationCorrection(complex_t unit_factor,
48  double magnetic_factor, R3 polarization);
49 template SpinMatrix MaterialUtils::MagnetizationCorrection(complex_t unit_factor,
50  double magnetic_factor, C3 polarization);
51 
52 complex_t MaterialUtils::ScalarReducedPotential(complex_t n, R3 k, double n_ref)
53 {
54  return n * n - n_ref * n_ref * R3Util::sin2Theta(k);
55 }
56 
57 SpinMatrix MaterialUtils::PolarizedReducedPotential(complex_t n, R3 b_field, R3 k, double n_ref)
58 {
59  double factor = magnetic_prefactor / k.mag2();
60  complex_t unit_factor = ScalarReducedPotential(n, k, n_ref);
61  return MagnetizationCorrection(unit_factor, factor, b_field);
62 }
63 
64 MATERIAL_TYPES MaterialUtils::checkMaterialTypes(const std::vector<const Material*>& materials)
65 {
67  bool isDefault = true;
68  for (const Material* mat : materials) {
69  if (isDefault) {
70  result = mat->typeID();
71  isDefault = mat->isDefaultMaterial();
72  continue;
73  }
74  if (mat->typeID() != result && !mat->isDefaultMaterial())
76  }
77  return result;
78 }
MATERIAL_TYPES
constexpr double magnetic_prefactor
Declares functions in namespace MaterialUtils.
Defines the values of physical constants (SI)
Defines class SpinMatrix.
A wrapper for underlying material implementation.
Definition: Material.h:35
static SpinMatrix One()
Definition: SpinMatrix.cpp:36
MATERIAL_TYPES checkMaterialTypes(const std::vector< const Material * > &materials)
Checks if all non-default materials in materials are of the same type and returns this type....
SpinMatrix PolarizedReducedPotential(complex_t n, R3 b_field, R3 k, double n_ref)
Function for calculating the reduced potential, used for obtaining the Fresnel coefficients (polarize...
complex_t ScalarReducedPotential(complex_t n, R3 k, double n_ref)
Function for calculating the reduced potential, used for obtaining the Fresnel coefficients (non-pola...
SpinMatrix MagnetizationCorrection(complex_t unit_factor, double magnetic_factor, Vec3< T > polarization)
constexpr double g_factor_n
neutron g-factor
constexpr double h_bar
Reduced Plank constant, J s.
constexpr double m_n
Neutron mass, kg.
constexpr double mu_N
Nuclear magneton ( ), J/T.