BornAgain  1.18.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 scattering at grazing incidence
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/Utils/Integrator.h"
19 #include <cmath>
20 
21 namespace
22 {
23 const double p = 7.0 / 3.0 - 4.0 * std::sqrt(3.0) / M_PI;
24 double Czero(double packing); // TODO ASAP why these variables?
25 double S2(double packing);
26 double W2(double x);
27 } // namespace
28 
30  double position_var)
31  : IInterferenceFunction(position_var), m_radius(radius), m_density(density)
32 {
33  setName("InterferenceHardDisk");
34  if (m_radius < 0.0 || m_density < 0.0 || packingRatio() > 0.65)
35  throw std::runtime_error("InterferenceFunctionHardDisk::validateParameters: "
36  "radius and density must be positive and packing ratio between "
37  "0 and 0.65");
39  registerParameter("TotalParticleDensity", &m_density).setUnit("nm").setNonnegative();
40 }
41 
43 {
45  return ret;
46 }
47 
49 {
50  return m_density;
51 }
52 
54 {
55  return m_radius;
56 }
57 
59 {
60  return m_density;
61 }
62 
64 {
65  double qx = q.x();
66  double qy = q.y();
67  m_q = 2.0 * std::sqrt(qx * qx + qy * qy) * m_radius;
70  m_s2 = S2(m_packing);
71  double c_q =
72  2.0 * M_PI
73  * RealIntegrator().integrate([&](double x) -> double { return integrand(x); }, 0.0, 1.0);
74  double rho = 4.0 * m_packing / M_PI;
75  return 1.0 / (1.0 - rho * c_q);
76 }
77 
79 {
80  return M_PI * m_radius * m_radius * m_density;
81 }
82 
84 {
85  double cx = m_c_zero * (1.0 + 4.0 * m_packing * (W2(x / 2.0) - 1.0) + m_s2 * x);
86  return x * cx * MathFunctions::Bessel_J0(m_q * x);
87 }
88 
89 namespace
90 {
91 double Czero(double packing)
92 {
93  double numerator = 1.0 + packing + 3.0 * p * packing * packing - p * std::pow(packing, 3);
94  double denominator = std::pow(1.0 - packing, 3);
95  return -numerator / denominator;
96 }
97 
98 double S2(double packing)
99 {
100  double factor = 3.0 * packing * packing / 8.0;
101  double numerator = 8.0 * (1.0 - 2.0 * p) + (25.0 - 9.0 * p) * p * packing
102  - (7.0 - 3.0 * p) * p * packing * packing;
103  double denominator = 1.0 + packing + 3.0 * p * packing * packing - p * std::pow(packing, 3);
104  return factor * numerator / denominator;
105 }
106 
107 double W2(double x)
108 {
109  return 2.0 * (std::acos(x) - x * std::sqrt(1.0 - x * x)) / M_PI;
110 }
111 } // namespace
Defines classes RealIntegrator, ComplexIntegrator.
Defines class InterferenceFunctionHardDisk.
#define M_PI
Definition: MathConstants.h:39
Defines namespace MathFunctions.
Defines class RealParameter.
T y() const
Returns y-component in cartesian coordinate system.
Definition: BasicVector3D.h:66
T x() const
Returns x-component in cartesian coordinate system.
Definition: BasicVector3D.h:64
Pure virtual base class of interference functions.
RealParameter & registerParameter(const std::string &name, double *parpointer)
void setName(const std::string &name)
Percus-Yevick hard disk interference function.
InterferenceFunctionHardDisk * clone() const override final
Returns a clone of this ISample object.
InterferenceFunctionHardDisk(double radius, double density, double position_var=0)
double iff_without_dw(const kvector_t q) const override final
Calculates the structure factor without Debye-Waller factor.
double getParticleDensity() const override final
If defined by this interference function's parameters, returns the particle density (per area).
To integrate a real function of a real variable.
Definition: Integrator.h:24
double integrate(const std::function< double(double)> &f, double lmin, double lmax)
Definition: Integrator.cpp:27
RealParameter & setNonnegative()
RealParameter & setUnit(const std::string &name)
double Bessel_J0(double x)
Bessel function of the first kind and order 0.
const double radius(5 *Units::nanometer)