BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
InterferenceHardDisk.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Aggregate/InterferenceHardDisk.cpp
6 //! @brief Implements class InterferenceHardDisk.
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"
18 #include "Fit/Param/RealLimits.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 
25 double Czero(double packing)
26 {
27  double numerator = 1.0 + packing + 3.0 * p * packing * packing - p * std::pow(packing, 3);
28  double denominator = std::pow(1.0 - packing, 3);
29  return -numerator / denominator;
30 }
31 
32 double S2(double packing)
33 {
34  double factor = 3.0 * packing * packing / 8.0;
35  double numerator = 8.0 * (1.0 - 2.0 * p) + (25.0 - 9.0 * p) * p * packing
36  - (7.0 - 3.0 * p) * p * packing * packing;
37  double denominator = 1.0 + packing + 3.0 * p * packing * packing - p * std::pow(packing, 3);
38  return factor * numerator / denominator;
39 }
40 
41 double W2(double x)
42 {
43  return 2.0 * (std::acos(x) - x * std::sqrt(1.0 - x * x)) / M_PI;
44 }
45 
46 } // namespace
47 
48 
49 InterferenceHardDisk::InterferenceHardDisk(double radius, double density, double position_var)
50  : IInterference(position_var)
51  , m_radius(radius)
52  , m_density(density)
53 {
54  if (m_radius < 0.0 || m_density < 0.0 || packingRatio() > 0.65)
55  throw std::runtime_error("InterferenceHardDisk::validateParameters: "
56  "radius and density must be positive and packing ratio between "
57  "0 and 0.65");
59  RealLimits::nonnegative().check("TotalParticleDensity", m_density);
60 }
61 
63 {
65  return result;
66 }
67 
69 {
70  return m_density;
71 }
72 
74 {
75  return m_radius;
76 }
77 
79 {
80  return m_density;
81 }
82 
83 double InterferenceHardDisk::iff_without_dw(const R3 q) const
84 {
85  const double qx = q.x();
86  const double qy = q.y();
87  const double q2r = 2.0 * std::sqrt(qx * qx + qy * qy) * m_radius;
88  const double packing = packingRatio();
89  const double c_zero = Czero(packing);
90  const double s2 = S2(packing);
91  const double c_q = 2.0 * M_PI
93  [=](double x) -> double {
94  double cx =
95  c_zero * (1.0 + 4.0 * packing * (W2(x / 2.0) - 1.0) + s2 * x);
96  return x * cx * Math::Bessel::J0(q2r * x);
97  },
98  0.0, 1.0);
99  const double rho = 4.0 * packing / M_PI;
100  return 1.0 / (1.0 - rho * c_q);
101 }
102 
104 {
105  return M_PI * m_radius * m_radius * m_density;
106 }
Defines Bessel functions in namespace Math.
#define M_PI
Definition: Constants.h:44
Defines classes RealIntegrator, ComplexIntegrator.
Defines class InterferenceHardDisk.
Defines class RealLimits.
Abstract base class of interference functions.
Definition: IInterference.h:24
double m_position_var
Definition: IInterference.h:53
Percus-Yevick hard disk interference function.
double iff_without_dw(R3 q) const override
Calculates the structure factor without Debye-Waller factor.
InterferenceHardDisk * clone() const override
InterferenceHardDisk(double radius, double density, double position_var=0)
double particleDensity() 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)
void check(const std::string &name, double value) const
Throws if value is outside limits. Parameter 'name' is for exception message.
Definition: RealLimits.cpp:170
static RealLimits nonnegative()
Creates an object which can have only positive values with 0. included.
Definition: RealLimits.cpp:124
double J0(double x)
Bessel function of the first kind and order 0.
Definition: Bessel.cpp:162