BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
TruncatedSphere.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/TruncatedSphere.cpp
6 //! @brief Implements class TruncatedSphere.
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/Constants.h"
18 #include "Base/Math/IntegratorGK.h"
20 #include <limits>
21 
22 TruncatedSphere::TruncatedSphere(const std::vector<double> P)
23  : IFormFactor(P)
24  , m_radius(m_P[0])
25  , m_height(m_P[1])
26  , m_dh(m_P[2])
27 {
28  checkNodeArgs();
29  if (m_height > 2. * m_radius || m_dh > m_height) {
30  std::ostringstream ostr;
31  ostr << "TruncatedSphere: -> Error in class initialization ";
32  ostr << "with parameters 'radius':" << m_radius << " 'height':" << m_height
33  << " 'delta_height':" << m_dh << "\n\n";
34  ostr << "Check for height <= 2.*radius AND delta_height < height failed.";
35  throw std::runtime_error(ostr.str());
36  }
37  m_shape3D =
38  std::make_unique<TruncatedEllipsoidNet>(m_radius, m_radius, m_radius, m_height, m_dh);
39 }
40 
41 TruncatedSphere::TruncatedSphere(double radius, double height, double dh)
42  : TruncatedSphere(std::vector<double>{radius, height, dh})
43 {
44 }
45 
46 //! Complex form factor.
48 {
49  if (std::abs(q.mag()) < std::numeric_limits<double>::epsilon())
50  return M_PI / 3.
51  * (m_height * m_height * (3. * m_radius - m_height)
52  - m_dh * m_dh * (3. * m_radius - m_dh));
53 
54  complex_t integral = ComplexIntegrator().integrate(
55  [=](double Z) {
56  double Rz = std::sqrt(m_radius * m_radius - Z * Z);
57  complex_t qx = q.x();
58  complex_t qy = q.y();
59  complex_t q_p = std::sqrt(qx * qx + qy * qy); // NOT the modulus!
60  return Rz * Rz * Math::Bessel::J1c(q_p * Rz) * exp_I(q.z() * Z);
61  },
63  return M_TWOPI * integral * exp_I(q.z() * (m_height - m_radius));
64 }
Defines Bessel functions in namespace Math.
Defines M_PI and some more mathematical constants.
#define M_TWOPI
Definition: Constants.h:54
#define M_PI
Definition: Constants.h:44
Defines classes RealIntegrator, ComplexIntegrator.
Defines class TruncatedEllipsoidNet.
Defines class TruncatedSphere.
To integrate a complex function of a real variable.
Definition: IntegratorGK.h:44
complex_t integrate(const std::function< complex_t(double)> &f, double lmin, double lmax)
Abstract base class for Born form factors.
Definition: IFormFactor.h:36
std::unique_ptr< IShape3D > m_shape3D
IShape3D object, used to retrieve vertices (which may be approximate in the case of round shapes)....
Definition: IFormFactor.h:74
void checkNodeArgs() const
Raises exception if a parameter value is invalid.
Definition: INode.cpp:27
A truncated Sphere.
const double & m_radius
const double & m_height
double height() const
const double & m_dh
complex_t formfactor_at_bottom(C3 q) const override
Complex form factor.
double radius() const
TruncatedSphere(double radius, double height, double dh)
double J1c(double x)
Bessel function J1(x)/x.
Definition: Bessel.cpp:172