BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
TruncatedSpheroid.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/TruncatedSpheroid.cpp
6 //! @brief Implements class TruncatedSpheroid.
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 TruncatedSpheroid::TruncatedSpheroid(const std::vector<double> P)
23  : IFormFactor(P)
24  , m_radius(m_P[0])
25  , m_height(m_P[1])
26  , m_height_flattening(m_P[2])
27  , m_dh(m_P[3])
28 {
29  checkNodeArgs();
31  std::ostringstream ostr;
32  ostr << "::TruncatedSpheroid() -> Error in class initialization with parameters ";
33  ostr << " radius:" << m_radius;
34  ostr << " height:" << m_height;
35  ostr << " height_flattening:" << m_height_flattening << "\n\n";
36  ostr << "Check for 'height <= 2.*radius*height_flattening' failed.";
37  throw std::runtime_error(ostr.str());
38  }
39  m_shape3D = std::make_unique<TruncatedEllipsoidNet>(
41 }
42 
43 TruncatedSpheroid::TruncatedSpheroid(double radius, double height, double height_flattening,
44  double dh)
45  : TruncatedSpheroid(std::vector<double>{radius, height, height_flattening, dh})
46 {
47 }
48 
50 {
51  double H = m_height;
52  double R = m_radius;
53  double fp = m_height_flattening;
54 
55  if (std::abs(q.mag()) <= std::numeric_limits<double>::epsilon())
56  return M_PI / 3. / fp * (H * H * (3. * R - H / fp) - m_dh * m_dh * (3. * R - m_dh / fp));
57 
58  complex_t z_part = exp_I(q.z() * (H - fp * R));
59  return M_TWOPI * z_part
61  [=](double Z) {
62  double R = m_radius;
63  double fp = m_height_flattening;
64 
65  double Rz = std::sqrt(R * R - Z * Z / (fp * fp));
66  complex_t qrRz = std::sqrt(q.x() * q.x() + q.y() * q.y()) * Rz;
67  complex_t J1_qrRz_div_qrRz = Math::Bessel::J1c(qrRz);
68 
69  return Rz * Rz * J1_qrRz_div_qrRz * exp_I(q.z() * Z);
70  },
71  fp * R - H, fp * R - m_dh);
72 }
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 TruncatedSpheroid.
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 spheroid. An ellipsoid with two equal axis, truncated by a plane perpendicular to the thi...
const double & m_dh
double height() const
const double & m_height_flattening
const double & m_radius
double radius() const
const double & m_height
complex_t formfactor_at_bottom(C3 q) const override
TruncatedSpheroid(double radius, double height, double height_flattening, double dh)
double J1c(double x)
Bessel function J1(x)/x.
Definition: Bessel.cpp:172
constexpr Double_t H()
Definition: TMath.h:140
constexpr Double_t R()
Definition: TMath.h:213