BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FTDecay1D.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Correlations/FTDecay1D.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 IFTDecayFunction1D::IFTDecayFunction1D(const NodeMeta& meta, const std::vector<double>& PValues)
24  : INode(nodeMetaUnion({{"DecayLength", "nm", "half width", 0, INF, 1.}}, meta), PValues),
25  m_decay_length(m_P[0])
26 {
27 }
28 
29 // ************************************************************************** //
30 // class FTDecayFunction1DCauchy
31 // ************************************************************************** //
32 
33 FTDecayFunction1DCauchy::FTDecayFunction1DCauchy(const std::vector<double> P)
34  : IFTDecayFunction1D({"FTDecayFunction1DCauchy", "class_tooltip", {}}, P)
35 {
36 }
37 
38 FTDecayFunction1DCauchy::FTDecayFunction1DCauchy(double decay_length)
39  : FTDecayFunction1DCauchy(std::vector<double>{decay_length})
40 {
41 }
42 
43 FTDecayFunction1DCauchy* FTDecayFunction1DCauchy::clone() const
44 {
45  return new FTDecayFunction1DCauchy(m_decay_length);
46 }
47 
48 double FTDecayFunction1DCauchy::evaluate(double q) const
49 {
50  double sum_sq = q * q * m_decay_length * m_decay_length;
51  return m_decay_length * 2.0 / (1.0 + sum_sq);
52 }
53 
54 // ************************************************************************** //
55 // class FTDecayFunction1DGauss
56 // ************************************************************************** //
57 
58 FTDecayFunction1DGauss::FTDecayFunction1DGauss(const std::vector<double> P)
59  : IFTDecayFunction1D({"FTDecayFunction1DGauss", "class_tooltip", {}}, P)
60 {
61 }
62 
63 FTDecayFunction1DGauss::FTDecayFunction1DGauss(double decay_length)
64  : FTDecayFunction1DGauss(std::vector<double>{decay_length})
65 {
66 }
67 
68 FTDecayFunction1DGauss* FTDecayFunction1DGauss::clone() const
69 {
70  return new FTDecayFunction1DGauss(m_decay_length);
71 }
72 
73 double FTDecayFunction1DGauss::evaluate(double q) const
74 {
75  double sum_sq = q * q * m_decay_length * m_decay_length;
76  return m_decay_length * std::sqrt(M_TWOPI) * std::exp(-sum_sq / 2.0);
77 }
78 
79 // ************************************************************************** //
80 // class FTDecayFunction1DTriangle
81 // ************************************************************************** //
82 
83 FTDecayFunction1DTriangle::FTDecayFunction1DTriangle(const std::vector<double> P)
84  : IFTDecayFunction1D({"FTDecayFunction1DTriangle", "class_tooltip", {}}, P)
85 {
86 }
87 
88 FTDecayFunction1DTriangle::FTDecayFunction1DTriangle(double decay_length)
89  : FTDecayFunction1DTriangle(std::vector<double>{decay_length})
90 {
91 }
92 
93 FTDecayFunction1DTriangle* FTDecayFunction1DTriangle::clone() const
94 {
95  return new FTDecayFunction1DTriangle(m_decay_length);
96 }
97 
98 double FTDecayFunction1DTriangle::evaluate(double q) const
99 {
100  double sincqw2 = MathFunctions::sinc(q * m_decay_length / 2.0);
101  return m_decay_length * sincqw2 * sincqw2;
102 }
103 
104 // ************************************************************************** //
105 // class FTDecayFunction1DVoigt
106 // ************************************************************************** //
107 
108 FTDecayFunction1DVoigt::FTDecayFunction1DVoigt(const std::vector<double> P)
110  {"FTDecayFunction1DVoigt",
111  "class_tooltip",
112  {{"Eta", "", "balances between Gauss (eta=0) and Cauchy (eta=1) limiting cases", -INF,
113  +INF, 0}}},
114  P),
115  m_eta(m_P[0])
116 {
117 }
118 
119 FTDecayFunction1DVoigt::FTDecayFunction1DVoigt(double decay_length, double eta)
120  : FTDecayFunction1DVoigt(std::vector<double>{decay_length, eta})
121 {
122 }
123 
124 FTDecayFunction1DVoigt* FTDecayFunction1DVoigt::clone() const
125 {
126  return new FTDecayFunction1DVoigt(m_decay_length, m_eta);
127 }
128 
129 double FTDecayFunction1DVoigt::evaluate(double q) const
130 {
131  double sum_sq = q * q * m_decay_length * m_decay_length;
132  return m_eta * m_decay_length * std::sqrt(M_TWOPI) * std::exp(-sum_sq / 2.0)
133  + (1.0 - m_eta) * m_decay_length * 2.0 / (1.0 + sum_sq);
134 }
Defines classes IFTDecayFunction1D, IFTDecayFunction2D,.
Defines namespace MathFunctions.
One-dimensional Cauchy decay function in reciprocal space; corresponds to exp(-|x|/decay_length) in r...
Definition: FTDecay1D.h:44
One-dimensional Gauss decay function in reciprocal space; corresponds to exp[-x^2/(2*decay_length^2)]...
Definition: FTDecay1D.h:58
One-dimensional triangle decay function in reciprocal space; corresponds to 1-|x|/decay_length if |x|...
Definition: FTDecay1D.h:72
One-dimensional pseudo-Voigt decay function in reciprocal space; corresponds to eta*Gauss + (1-eta)*C...
Definition: FTDecay1D.h:86
Interface for a one-dimensional decay function, with evaluate(q) returning the Fourier transform,...
Definition: FTDecay1D.h:28
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:49
double sinc(double x)
sinc function:
Metadata of one model node.
Definition: INode.h:37