BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FTDecay2D.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Correlations/FTDecay2D.cpp
6 //! @brief Implements class FTDistribution2DCauchy.
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 <algorithm>
18 
19 // ************************************************************************** //
20 // interface IIFTDecayFunction1D
21 // ************************************************************************** //
22 
23 IFTDecayFunction2D::IFTDecayFunction2D(const NodeMeta& meta, const std::vector<double>& PValues)
24  : INode(nodeMetaUnion({{"DecayLengthX", "nm", "Half-width along x axis", 0, INF, 1.},
25  {"DecayLengthY", "nm", "Half-width along y axis", 0, INF, 1.},
26  {"Gamma", "rad", "orientation with respect to the first lattice vector",
27  -M_PI_2, +M_PI_2, 0}},
28  meta),
29  PValues),
30  m_decay_length_x(m_P[0]), m_decay_length_y(m_P[1]), m_gamma(m_P[2])
31 {
32 }
33 
34 //! Calculates bounding values of reciprocal lattice coordinates that contain the centered
35 //! rectangle with a corner defined by qX and qY
36 std::pair<double, double>
37 IFTDecayFunction2D::boundingReciprocalLatticeCoordinates(double qX, double qY, double a, double b,
38  double alpha) const
39 {
40  auto q_bounds_1 = transformToRecLatticeCoordinates(qX, qY, a, b, alpha);
41  auto q_bounds_2 = transformToRecLatticeCoordinates(qX, -qY, a, b, alpha);
42  double qa_max = std::max(std::abs(q_bounds_1.first), std::abs(q_bounds_2.first));
43  double qb_max = std::max(std::abs(q_bounds_1.second), std::abs(q_bounds_2.second));
44  return {qa_max, qb_max};
45 }
46 
47 std::pair<double, double> IFTDecayFunction2D::transformToRecLatticeCoordinates(double qX, double qY,
48  double a, double b,
49  double alpha) const
50 {
51  double qa = (a * qX * std::cos(m_gamma) - a * qY * std::sin(m_gamma)) / M_TWOPI;
52  double qb = (b * qX * std::cos(alpha - m_gamma) + b * qY * std::sin(alpha - m_gamma)) / M_TWOPI;
53  return {qa, qb};
54 }
55 
56 // ************************************************************************** //
57 // class FTDecayFunction2DCauchy
58 // ************************************************************************** //
59 
61  : IFTDecayFunction2D({"FTDecayFunction2DCauchy", "class_tooltip", {}}, P)
62 {
63 }
64 
65 FTDecayFunction2DCauchy::FTDecayFunction2DCauchy(double decay_length_x, double decay_length_y,
66  double gamma)
67  : FTDecayFunction2DCauchy(std::vector<double>{decay_length_x, decay_length_y, gamma})
68 {
69 }
70 
72 {
74 }
75 
76 double FTDecayFunction2DCauchy::evaluate(double qx, double qy) const
77 {
78  double sum_sq = qx * qx * m_decay_length_x * m_decay_length_x
79  + qy * qy * m_decay_length_y * m_decay_length_y;
80  return M_TWOPI * m_decay_length_x * m_decay_length_y * std::pow(1.0 + sum_sq, -1.5);
81 }
82 
83 // ************************************************************************** //
84 // class FTDecayFunction2DGauss
85 // ************************************************************************** //
86 
88  : IFTDecayFunction2D({"FTDecayFunction2DGauss", "class_tooltip", {}}, P)
89 {
90 }
91 
92 FTDecayFunction2DGauss::FTDecayFunction2DGauss(double decay_length_x, double decay_length_y,
93  double gamma)
94  : FTDecayFunction2DGauss(std::vector<double>{decay_length_x, decay_length_y, gamma})
95 {
96 }
97 
99 {
101 }
102 
103 double FTDecayFunction2DGauss::evaluate(double qx, double qy) const
104 {
105  double sum_sq = qx * qx * m_decay_length_x * m_decay_length_x
106  + qy * qy * m_decay_length_y * m_decay_length_y;
107  return M_TWOPI * m_decay_length_x * m_decay_length_y * std::exp(-sum_sq / 2.0);
108 }
109 
110 // ************************************************************************** //
111 // class FTDecayFunction2DVoigt
112 // ************************************************************************** //
113 
116  {"FTDecayFunction2DVoigt",
117  "class_tooltip",
118  {{"Eta", "", "balances between Gauss (eta=0) and Cauchy (eta=1) limiting cases", -INF,
119  +INF, 0}}},
120  P),
121  m_eta(m_P[0])
122 {
123 }
124 
125 FTDecayFunction2DVoigt::FTDecayFunction2DVoigt(double decay_length_x, double decay_length_y,
126  double gamma, double eta)
127  : FTDecayFunction2DVoigt(std::vector<double>{decay_length_x, decay_length_y, gamma, eta})
128 {
129 }
130 
132 {
134 }
135 
136 double FTDecayFunction2DVoigt::evaluate(double qx, double qy) const
137 {
138  double sum_sq = qx * qx * m_decay_length_x * m_decay_length_x
139  + qy * qy * m_decay_length_y * m_decay_length_y;
141  * (m_eta * std::exp(-sum_sq / 2.0) + (1.0 - m_eta) * std::pow(1.0 + sum_sq, -1.5));
142 }
Defines classes IFTDecayFunction1D, IFTDecayFunction2D,.
NodeMeta nodeMetaUnion(const std::vector< ParaMeta > &base, const NodeMeta &other)
Definition: INode.cpp:24
const double INF
Definition: INode.h:24
#define M_TWOPI
Definition: MathConstants.h:49
#define M_PI_2
Definition: MathConstants.h:40
Defines namespace MathFunctions.
Two-dimensional Cauchy decay function in reciprocal space; corresponds to exp(-r) in real space,...
Definition: FTDecay2D.h:63
FTDecayFunction2DCauchy(const std::vector< double > P)
Definition: FTDecay2D.cpp:60
double evaluate(double qx, double qy) const final
evaluate Fourier transformed decay function for q in X,Y coordinates
Definition: FTDecay2D.cpp:76
FTDecayFunction2DCauchy * clone() const
Definition: FTDecay2D.cpp:71
Two-dimensional Gauss decay function in reciprocal space; corresponds to exp(-r^2/2) in real space,...
Definition: FTDecay2D.h:78
FTDecayFunction2DGauss * clone() const
Definition: FTDecay2D.cpp:98
double evaluate(double qx, double qy) const final
evaluate Fourier transformed decay function for q in X,Y coordinates
Definition: FTDecay2D.cpp:103
FTDecayFunction2DGauss(const std::vector< double > P)
Definition: FTDecay2D.cpp:87
Two-dimensional pseudo-Voigt decay function in reciprocal space; corresponds to eta*Gauss + (1-eta)*C...
Definition: FTDecay2D.h:92
FTDecayFunction2DVoigt(const std::vector< double > P)
Definition: FTDecay2D.cpp:114
FTDecayFunction2DVoigt * clone() const
Definition: FTDecay2D.cpp:131
double evaluate(double qx, double qy) const final
evaluate Fourier transformed decay function for q in X,Y coordinates
Definition: FTDecay2D.cpp:136
const double & m_eta
Definition: FTDecay2D.h:103
double eta() const
Definition: FTDecay2D.h:100
Interface for two-dimensional decay function in reciprocal space.
Definition: FTDecay2D.h:26
const double & m_gamma
Definition: FTDecay2D.h:49
IFTDecayFunction2D(const NodeMeta &meta, const std::vector< double > &PValues)
Definition: FTDecay2D.cpp:23
double gamma() const
get angle between first lattice vector and X-axis of distribution (both in direct space)
Definition: FTDecay2D.h:37
const double & m_decay_length_x
Definition: FTDecay2D.h:47
std::pair< double, double > transformToRecLatticeCoordinates(double qX, double qY, double a, double b, double alpha) const
transform reciprocal coordinate system of this decay function to the reciprocal lattice system
Definition: FTDecay2D.cpp:47
const double & m_decay_length_y
Definition: FTDecay2D.h:48
std::pair< double, double > boundingReciprocalLatticeCoordinates(double qX, double qY, double a, double b, double alpha) const
transform back to a*, b* basis:
Definition: FTDecay2D.cpp:37
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:49
Metadata of one model node.
Definition: INode.h:37