BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
DiffuseElement.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Resample/Element/DiffuseElement.cpp
6 //! @brief Implements class DiffuseElement.
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 
16 #include "Base/Pixel/IPixel.h"
17 #include "Base/Vector/Direction.h"
19 #include "Resample/Flux/IFlux.h"
20 
21 DiffuseElement::DiffuseElement(double wavelength, double alpha_i, double phi_i,
22  std::unique_ptr<IPixel> pixel, const SpinMatrix& beam_polMatrices,
23  const SpinMatrix& analyzer, bool isSpecular_,
24  const Fluxes* const fluxes_in, const Fluxes* const fluxes_out)
25  : IElement({beam_polMatrices, analyzer})
26  , m_wavelength(wavelength)
27  , m_alpha_i(alpha_i)
28  , m_phi_i(phi_i)
29  , m_k_i(vecOfLambdaAlphaPhi(m_wavelength, m_alpha_i, m_phi_i))
30  , m_mean_kf(pixel->getK(0.5, 0.5, m_wavelength))
31  , m_pixel(std::move(pixel))
32  , m_is_specular(isSpecular_)
33  , m_fluxes_in(fluxes_in)
34  , m_fluxes_out(fluxes_out)
35  , m_intensity(0.0)
36 {
37 }
38 
40  : IElement(other.m_polMatrices)
41  , m_wavelength(other.m_wavelength)
42  , m_alpha_i(other.m_alpha_i)
43  , m_phi_i(other.m_phi_i)
44  , m_k_i(other.m_k_i)
45  , m_mean_kf(other.m_mean_kf)
46  , m_pixel(std::move(other.m_pixel))
47  , m_is_specular(other.m_is_specular)
48  , m_fluxes_in(other.m_fluxes_in)
49  , m_fluxes_out(other.m_fluxes_out)
50  , m_intensity(other.m_intensity)
51 {
52 }
53 
55 
56 void DiffuseElement::setFluxes(const Fluxes* fluxes_in, const Fluxes* fluxes_out)
57 {
58  m_fluxes_in = fluxes_in;
59  m_fluxes_out = fluxes_out;
60 }
61 
62 const IFlux* DiffuseElement::fluxIn(size_t i_layer) const
63 {
64  return (*m_fluxes_in)[i_layer].get();
65 }
66 
67 const IFlux* DiffuseElement::fluxOut(size_t i_layer) const
68 {
69  return (*m_fluxes_out)[i_layer].get();
70 }
71 
73 {
74  return {m_wavelength,
75  m_alpha_i,
76  m_phi_i,
77  std::unique_ptr<IPixel>(m_pixel->createZeroSizePixel(x, y)), // TODO simplify
82  m_fluxes_out};
83 }
84 
86 {
87  return m_k_i;
88 }
89 
91 {
92  return m_mean_kf;
93 }
94 
95 //! Returns outgoing wavevector Kf for in-pixel coordinates x,y.
96 //! In-pixel coordinates take values from 0 to 1.
97 R3 DiffuseElement::getKf(double x, double y) const
98 {
99  return m_pixel->getK(x, y, m_wavelength);
100 }
101 
103 {
104  return getKi() - meanKf();
105 }
106 
107 //! Returns scattering vector Q, with Kf determined from in-pixel coordinates x,y.
108 //! In-pixel coordinates take values from 0 to 1.
109 R3 DiffuseElement::getQ(double x, double y) const
110 {
111  return getKi() - m_pixel->getK(x, y, m_wavelength);
112 }
113 
114 double DiffuseElement::alpha(double x, double y) const
115 {
116  return M_PI_2 - R3Util::theta(getKf(x, y));
117 }
118 
119 double DiffuseElement::getPhi(double x, double y) const
120 {
121  return R3Util::phi(getKf(x, y));
122 }
123 
125 {
126  return WavevectorInfo(getKi(), meanKf(), wavelength());
127 }
128 
129 double DiffuseElement::integrationFactor(double x, double y) const
130 {
131  return m_pixel->integrationFactor(x, y);
132 }
133 
135 {
136  return m_pixel->solidAngle();
137 }
#define M_PI_2
Definition: Constants.h:45
Defines class DiffuseElement.
std::vector< std::unique_ptr< const IFlux > > Fluxes
R3 vecOfLambdaAlphaPhi(double _lambda, double _alpha, double _phi)
Definition: Direction.cpp:19
Defines class Direction.
Defines and implements class IFlux.
Defines and implements interface IPixel.
Defines WavevectorInfo.
Data stucture containing both input and output of a single detector cell.
double solidAngle() const
const Fluxes * m_fluxes_in
const R3 m_k_i
cached value of k_i
const IFlux * fluxIn(size_t i_layer) const
double getPhi(double x, double y) const
const double m_alpha_i
incident grazing angle
double integrationFactor(double x, double y) const
const Fluxes * m_fluxes_out
const IFlux * fluxOut(size_t i_layer) const
DiffuseElement pointElement(double x, double y) const
Returns copy of this DiffuseElement with k_f given by in-pixel coordinate x,y.
double wavelength() const
DiffuseElement(double wavelength, double alpha_i, double phi_i, std::unique_ptr< IPixel > pixel, const SpinMatrix &beam_polMatrices, const SpinMatrix &analyzer, bool isSpecular_, const Fluxes *fluxes_in=nullptr, const Fluxes *fluxes_out=nullptr)
const double m_wavelength
wavelength of beam
std::unique_ptr< IPixel > m_pixel
double alpha(double x, double y) const
WavevectorInfo wavevectorInfo() const
R3 getQ(double x, double y) const
Returns scattering vector Q, with Kf determined from in-pixel coordinates x,y. In-pixel coordinates t...
R3 getKi() const
R3 meanKf() const
const R3 m_mean_kf
cached value of mean_kf
void setFluxes(const Fluxes *fluxes_in, const Fluxes *fluxes_out)
const bool m_is_specular
R3 getKf(double x, double y) const
Returns outgoing wavevector Kf for in-pixel coordinates x,y. In-pixel coordinates take values from 0 ...
const double m_phi_i
incident angle in xy plane
const PolMatrices m_polMatrices
Definition: IElement.h:40
Interface to access reflection/transmission coefficients. Realized by ScalarFlux and MatrixFlux.
Definition: IFlux.h:30
const SpinMatrix & polarizerMatrix() const
Gets the polarization density matrix (in spin basis along z-axis)
Definition: PolMatrices.h:38
const SpinMatrix & analyzerMatrix() const
Gets the polarization analyzer operator (in spin basis along z-axis)
Definition: PolMatrices.h:44
Holds all wavevector information relevant for calculating form factors.