BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SimulationElement.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Base/Pixel/SimulationElement.cpp
6 //! @brief Implements class SimulationElement.
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 
17 SimulationElement::SimulationElement(double wavelength, double alpha_i, double phi_i,
18  std::unique_ptr<IPixel> pixel)
19  : m_wavelength(wavelength), m_alpha_i(alpha_i), m_phi_i(phi_i),
20  m_k_i(vecOfLambdaAlphaPhi(m_wavelength, m_alpha_i, m_phi_i)),
21  m_mean_kf(pixel->getK(0.5, 0.5, m_wavelength)), m_intensity(0.0), mP_pixel(std::move(pixel)),
22  m_is_specular(false)
23 {
24 }
25 
26 SimulationElement::SimulationElement(const SimulationElement& other)
27  : m_polarization(other.m_polarization), m_wavelength(other.m_wavelength),
28  m_alpha_i(other.m_alpha_i), m_phi_i(other.m_phi_i), m_k_i(other.m_k_i),
29  m_mean_kf(other.m_mean_kf), m_intensity(other.m_intensity), m_is_specular(other.isSpecular())
30 {
31  mP_pixel.reset(other.mP_pixel->clone());
32 }
33 
34 SimulationElement::SimulationElement(const SimulationElement& other, double x, double y)
35  : m_polarization(other.m_polarization), m_wavelength(other.m_wavelength),
36  m_alpha_i(other.m_alpha_i), m_phi_i(other.m_phi_i), m_k_i(other.m_k_i),
37  m_mean_kf(other.m_mean_kf), m_intensity(other.m_intensity), m_is_specular(other.isSpecular())
38 {
39  mP_pixel.reset(other.mP_pixel->createZeroSizePixel(x, y));
40  m_mean_kf = mP_pixel->getK(0.5, 0.5, m_wavelength);
41 }
42 
43 SimulationElement::SimulationElement(SimulationElement&& other) noexcept
44  : m_polarization(std::move(other.m_polarization)), m_wavelength(other.m_wavelength),
45  m_alpha_i(other.m_alpha_i), m_phi_i(other.m_phi_i), m_k_i(std::move(other.m_k_i)),
46  m_mean_kf(other.m_mean_kf), m_intensity(other.m_intensity),
47  mP_pixel(std::move(other.mP_pixel)), m_is_specular(other.isSpecular())
48 {
49 }
50 
51 SimulationElement::~SimulationElement() = default; // here because of forward declared members
52 
53 SimulationElement& SimulationElement::operator=(const SimulationElement& other)
54 {
55  if (this != &other) {
56  SimulationElement tmp(other);
57  tmp.swapContent(*this);
58  }
59  return *this;
60 }
61 
62 kvector_t SimulationElement::getKi() const
63 {
64  return m_k_i;
65 }
66 
67 kvector_t SimulationElement::getMeanKf() const
68 {
69  return m_mean_kf;
70 }
71 
72 //! Returns outgoing wavevector Kf for in-pixel coordinates x,y.
73 //! In-pixel coordinates take values from 0 to 1.
74 kvector_t SimulationElement::getKf(double x, double y) const
75 {
76  return mP_pixel->getK(x, y, m_wavelength);
77 }
78 
79 kvector_t SimulationElement::getMeanQ() const
80 {
81  return getKi() - getMeanKf();
82 }
83 
84 //! Returns scattering vector Q, with Kf determined from in-pixel coordinates x,y.
85 //! In-pixel coordinates take values from 0 to 1.
86 kvector_t SimulationElement::getQ(double x, double y) const
87 {
88  return getKi() - mP_pixel->getK(x, y, m_wavelength);
89 }
90 
91 void SimulationElement::swapContent(SimulationElement& other)
92 {
93  m_polarization.swapContent(other.m_polarization);
94  std::swap(m_wavelength, other.m_wavelength);
95  std::swap(m_alpha_i, other.m_alpha_i);
96  std::swap(m_phi_i, other.m_phi_i);
97  std::swap(m_k_i, other.m_k_i);
98  std::swap(m_mean_kf, other.m_mean_kf);
99  std::swap(m_intensity, other.m_intensity);
100  std::swap(mP_pixel, other.mP_pixel);
101  std::swap(m_is_specular, other.m_is_specular);
102 }
103 
104 double SimulationElement::getAlpha(double x, double y) const
105 {
106  return M_PI_2 - getKf(x, y).theta();
107 }
108 
109 double SimulationElement::getPhi(double x, double y) const
110 {
111  return getKf(x, y).phi();
112 }
113 
114 double SimulationElement::getIntegrationFactor(double x, double y) const
115 {
116  return mP_pixel->getIntegrationFactor(x, y);
117 }
118 
119 double SimulationElement::getSolidAngle() const
120 {
121  return mP_pixel->getSolidAngle();
122 }
BasicVector3D< double > vecOfLambdaAlphaPhi(double _lambda, double _alpha, double _phi)
Creates a vector<double> as a wavevector with given wavelength and angles.
void swap(OutputDataIterator< TValue, TContainer > &left, OutputDataIterator< TValue, TContainer > &right)
make Swappable
Defines class SimulationElement.
double theta() const
Returns polar angle.
double phi() const
Returns azimuth angle.
Data stucture containing both input and output of a single detector cell.
kvector_t getQ(double x, double y) const
Returns scattering vector Q, with Kf determined from in-pixel coordinates x,y.
bool isSpecular() const
Tells if simulation element corresponds to a specular peak.