BornAgain  1.19.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 reflection and scattering
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 
16 #include "Base/Math/Functions.h"
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])
31  , m_decay_length_y(m_P[1])
32  , m_gamma(m_P[2])
33 {
34 }
35 
36 //! Calculates bounding values of reciprocal lattice coordinates that contain the centered
37 //! rectangle with a corner defined by qX and qY
38 std::pair<double, double>
39 IFTDecayFunction2D::boundingReciprocalLatticeCoordinates(double qX, double qY, double a, double b,
40  double alpha) const
41 {
42  auto q_bounds_1 = transformToRecLatticeCoordinates(qX, qY, a, b, alpha);
43  auto q_bounds_2 = transformToRecLatticeCoordinates(qX, -qY, a, b, alpha);
44  double qa_max = std::max(std::abs(q_bounds_1.first), std::abs(q_bounds_2.first));
45  double qb_max = std::max(std::abs(q_bounds_1.second), std::abs(q_bounds_2.second));
46  return {qa_max, qb_max};
47 }
48 
49 std::pair<double, double> IFTDecayFunction2D::transformToRecLatticeCoordinates(double qX, double qY,
50  double a, double b,
51  double alpha) const
52 {
53  double qa = (a * qX * std::cos(m_gamma) - a * qY * std::sin(m_gamma)) / M_TWOPI;
54  double qb = (b * qX * std::cos(alpha - m_gamma) + b * qY * std::sin(alpha - m_gamma)) / M_TWOPI;
55  return {qa, qb};
56 }
57 
58 // ************************************************************************************************
59 // class FTDecayFunction2DCauchy
60 // ************************************************************************************************
61 
63  : IFTDecayFunction2D({"FTDecayFunction2DCauchy", "class_tooltip", {}}, P)
64 {
65 }
66 
67 FTDecayFunction2DCauchy::FTDecayFunction2DCauchy(double decay_length_x, double decay_length_y,
68  double gamma)
69  : FTDecayFunction2DCauchy(std::vector<double>{decay_length_x, decay_length_y, gamma})
70 {
71 }
72 
74 {
76 }
77 
78 double FTDecayFunction2DCauchy::evaluate(double qx, double qy) const
79 {
80  double sum_sq = qx * qx * m_decay_length_x * m_decay_length_x
81  + qy * qy * m_decay_length_y * m_decay_length_y;
82  return M_TWOPI * m_decay_length_x * m_decay_length_y * std::pow(1.0 + sum_sq, -1.5);
83 }
84 
85 // ************************************************************************************************
86 // class FTDecayFunction2DGauss
87 // ************************************************************************************************
88 
90  : IFTDecayFunction2D({"FTDecayFunction2DGauss", "class_tooltip", {}}, P)
91 {
92 }
93 
94 FTDecayFunction2DGauss::FTDecayFunction2DGauss(double decay_length_x, double decay_length_y,
95  double gamma)
96  : FTDecayFunction2DGauss(std::vector<double>{decay_length_x, decay_length_y, gamma})
97 {
98 }
99 
101 {
103 }
104 
105 double FTDecayFunction2DGauss::evaluate(double qx, double qy) const
106 {
107  double sum_sq = qx * qx * m_decay_length_x * m_decay_length_x
108  + qy * qy * m_decay_length_y * m_decay_length_y;
109  return M_TWOPI * m_decay_length_x * m_decay_length_y * std::exp(-sum_sq / 2.0);
110 }
111 
112 // ************************************************************************************************
113 // class FTDecayFunction2DVoigt
114 // ************************************************************************************************
115 
118  {"FTDecayFunction2DVoigt",
119  "class_tooltip",
120  {{"Eta", "", "balances between Gauss (eta=0) and Cauchy (eta=1) limiting cases", -INF,
121  +INF, 0}}},
122  P)
123  , m_eta(m_P[0])
124 {
125 }
126 
127 FTDecayFunction2DVoigt::FTDecayFunction2DVoigt(double decay_length_x, double decay_length_y,
128  double gamma, double eta)
129  : FTDecayFunction2DVoigt(std::vector<double>{decay_length_x, decay_length_y, gamma, eta})
130 {
131 }
132 
134 {
136 }
137 
138 double FTDecayFunction2DVoigt::evaluate(double qx, double qy) const
139 {
140  double sum_sq = qx * qx * m_decay_length_x * m_decay_length_x
141  + qy * qy * m_decay_length_y * m_decay_length_y;
143  * (m_eta * std::exp(-sum_sq / 2.0) + (1.0 - m_eta) * std::pow(1.0 + sum_sq, -1.5));
144 }
#define M_TWOPI
Definition: Constants.h:54
#define M_PI_2
Definition: Constants.h:45
Defines classes IFTDecayFunction1D, IFTDecayFunction2D,.
Defines functions in namespace Math.
NodeMeta nodeMetaUnion(const std::vector< ParaMeta > &base, const NodeMeta &other)
Definition: INode.cpp:23
const double INF
Definition: INode.h:25
Two-dimensional Cauchy decay function in reciprocal space; corresponds to exp(-r) in real space,...
Definition: FTDecay2D.h:65
FTDecayFunction2DCauchy(const std::vector< double > P)
Definition: FTDecay2D.cpp:62
double evaluate(double qx, double qy) const final
evaluate Fourier transformed decay function for q in X,Y coordinates
Definition: FTDecay2D.cpp:78
FTDecayFunction2DCauchy * clone() const
Definition: FTDecay2D.cpp:73
Two-dimensional Gauss decay function in reciprocal space; corresponds to exp(-r^2/2) in real space,...
Definition: FTDecay2D.h:79
FTDecayFunction2DGauss * clone() const
Definition: FTDecay2D.cpp:100
double evaluate(double qx, double qy) const final
evaluate Fourier transformed decay function for q in X,Y coordinates
Definition: FTDecay2D.cpp:105
FTDecayFunction2DGauss(const std::vector< double > P)
Definition: FTDecay2D.cpp:89
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:116
FTDecayFunction2DVoigt * clone() const
Definition: FTDecay2D.cpp:133
double evaluate(double qx, double qy) const final
evaluate Fourier transformed decay function for q in X,Y coordinates
Definition: FTDecay2D.cpp:138
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:27
const double & m_gamma
Definition: FTDecay2D.h:50
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:38
const double & m_decay_length_x
Definition: FTDecay2D.h:48
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:49
const double & m_decay_length_y
Definition: FTDecay2D.h:49
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:39
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:49
Definition: filesystem.h:81
Metadata of one model node.
Definition: INode.h:38