BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
InterferenceFunctionHardDisk.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Aggregate/InterferenceFunctionHardDisk.cpp
6 //! @brief Implements class InterferenceFunctionHardDisk.
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/Bessel.h"
17 #include "Base/Math/IntegratorGK.h"
19 #include <cmath>
20 
21 namespace {
22 const double p = 7.0 / 3.0 - 4.0 * std::sqrt(3.0) / M_PI;
23 double Czero(double packing); // TODO ASAP why these variables?
24 double S2(double packing);
25 double W2(double x);
26 } // namespace
27 
29  double position_var)
30  : IInterferenceFunction(position_var), m_radius(radius), m_density(density)
31 {
32  setName("InterferenceHardDisk");
33  if (m_radius < 0.0 || m_density < 0.0 || packingRatio() > 0.65)
34  throw std::runtime_error("InterferenceFunctionHardDisk::validateParameters: "
35  "radius and density must be positive and packing ratio between "
36  "0 and 0.65");
38  registerParameter("TotalParticleDensity", &m_density).setUnit("nm").setNonnegative();
39 }
40 
42 {
44  return ret;
45 }
46 
48 {
49  return m_density;
50 }
51 
53 {
54  return m_radius;
55 }
56 
58 {
59  return m_density;
60 }
61 
63 {
64  double qx = q.x();
65  double qy = q.y();
66  m_q = 2.0 * std::sqrt(qx * qx + qy * qy) * m_radius;
68  m_c_zero = Czero(m_packing);
69  m_s2 = S2(m_packing);
70  double c_q =
71  2.0 * M_PI
72  * RealIntegrator().integrate([&](double x) -> double { return integrand(x); }, 0.0, 1.0);
73  double rho = 4.0 * m_packing / M_PI;
74  return 1.0 / (1.0 - rho * c_q);
75 }
76 
78 {
79  return M_PI * m_radius * m_radius * m_density;
80 }
81 
83 {
84  double cx = m_c_zero * (1.0 + 4.0 * m_packing * (W2(x / 2.0) - 1.0) + m_s2 * x);
85  return x * cx * Math::Bessel::J0(m_q * x);
86 }
87 
88 namespace {
89 double Czero(double packing)
90 {
91  double numerator = 1.0 + packing + 3.0 * p * packing * packing - p * std::pow(packing, 3);
92  double denominator = std::pow(1.0 - packing, 3);
93  return -numerator / denominator;
94 }
95 
96 double S2(double packing)
97 {
98  double factor = 3.0 * packing * packing / 8.0;
99  double numerator = 8.0 * (1.0 - 2.0 * p) + (25.0 - 9.0 * p) * p * packing
100  - (7.0 - 3.0 * p) * p * packing * packing;
101  double denominator = 1.0 + packing + 3.0 * p * packing * packing - p * std::pow(packing, 3);
102  return factor * numerator / denominator;
103 }
104 
105 double W2(double x)
106 {
107  return 2.0 * (std::acos(x) - x * std::sqrt(1.0 - x * x)) / M_PI;
108 }
109 } // namespace
Defines Bessel functions in namespace Math.
#define M_PI
Definition: Constants.h:44
Defines classes RealIntegrator, ComplexIntegrator.
Defines class InterferenceFunctionHardDisk.
Defines class RealParameter.
T y() const
Returns y-component in cartesian coordinate system.
Definition: BasicVector3D.h:65
T x() const
Returns x-component in cartesian coordinate system.
Definition: BasicVector3D.h:63
Abstract base class of interference functions.
void setName(const std::string &name)
RealParameter & registerParameter(const std::string &name, double *parpointer)
Percus-Yevick hard disk interference function.
InterferenceFunctionHardDisk * clone() const override
Returns a clone of this ISampleNode object.
double iff_without_dw(const kvector_t q) const override
Calculates the structure factor without Debye-Waller factor.
InterferenceFunctionHardDisk(double radius, double density, double position_var=0)
double getParticleDensity() const override
If defined by this interference function's parameters, returns the particle density (per area).
To integrate a real function of a real variable.
Definition: IntegratorGK.h:28
double integrate(const std::function< double(double)> &f, double lmin, double lmax)
RealParameter & setNonnegative()
RealParameter & setUnit(const std::string &name)
double J0(double x)
Bessel function of the first kind and order 0.
Definition: Bessel.cpp:162