BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FormFactorTruncatedSpheroid.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/FormFactorTruncatedSpheroid.cpp
6 //! @brief Implements class FormFactorTruncatedSpheroid.
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 
23  : IBornFF({"TruncatedSpheroid",
24  "class_tooltip",
25  {{"Radius", "nm", "horizontal radius", 0, +INF, 0},
26  {"Height", "nm", "height before removal of cap", 0, +INF, 0},
27  {"HeightFlattening", "", "ratio of vertical to horizontal radius", 0, +INF, 0},
28  {"DeltaHeight", "nm", "height of removed cap", 0, +INF, 0}}},
29  P)
30  , m_radius(m_P[0])
31  , m_height(m_P[1])
32  , m_height_flattening(m_P[2])
33  , m_dh(m_P[3])
34 {
35  check_initialization();
36  onChange();
37 }
38 
40  double height_flattening, double dh)
41  : FormFactorTruncatedSpheroid(std::vector<double>{radius, height, height_flattening, dh})
42 {
43 }
44 
46 {
47  bool result(true);
49  std::ostringstream ostr;
50  ostr << "::FormFactorTruncatedSpheroid() -> Error in class initialization with parameters ";
51  ostr << " radius:" << m_radius;
52  ostr << " height:" << m_height;
53  ostr << " height_flattening:" << m_height_flattening << "\n\n";
54  ostr << "Check for 'height <= 2.*radius*height_flattening' failed.";
55  throw std::runtime_error(ostr.str());
56  }
57  return result;
58 }
59 
60 //! Integrand for complex form factor.
62 {
63  double R = m_radius;
64  double fp = m_height_flattening;
65 
66  double Rz = std::sqrt(R * R - Z * Z / (fp * fp));
67  complex_t qrRz = std::sqrt(m_q.x() * m_q.x() + m_q.y() * m_q.y()) * Rz;
68  complex_t J1_qrRz_div_qrRz = Math::Bessel::J1c(qrRz);
69 
70  return Rz * Rz * J1_qrRz_div_qrRz * exp_I(m_q.z() * Z);
71 }
72 
74 {
75  double H = m_height;
76  double R = m_radius;
77  double fp = m_height_flattening;
78  m_q = q;
79 
80  if (std::abs(m_q.mag()) <= std::numeric_limits<double>::epsilon())
81  return M_PI / 3. / fp * (H * H * (3. * R - H / fp) - m_dh * m_dh * (3. * R - m_dh / fp));
82  complex_t z_part = exp_I(m_q.z() * (H - fp * R));
83  return M_TWOPI * z_part
84  * ComplexIntegrator().integrate([&](double Z) { return Integrand(Z); }, fp * R - H,
85  fp * R - m_dh);
86 }
87 
89  kvector_t translation) const
90 {
91  double height = m_height - m_dh;
92  auto effects = computeSlicingEffects(limits, translation, height);
93  FormFactorTruncatedSpheroid slicedff(m_radius, height - effects.dz_bottom, m_height_flattening,
94  effects.dz_top + m_dh);
95  return createTransformedFormFactor(slicedff, rot, effects.position);
96 }
97 
99 {
100  m_shape3D.reset(
102 }
Defines Bessel functions in namespace Math.
std::complex< double > complex_t
Definition: Complex.h:20
complex_t exp_I(complex_t z)
Returns exp(I*z), where I is the imaginary unit.
Definition: Complex.h:30
Defines M_PI and some more mathematical constants.
#define M_TWOPI
Definition: Constants.h:54
#define M_PI
Definition: Constants.h:44
Defines class FormFactorTruncatedSpheroid.
const double INF
Definition: INode.h:25
Defines classes RealIntegrator, ComplexIntegrator.
Defines class TruncatedEllipsoid.
double mag() const
Returns magnitude of the vector.
T z() const
Returns z-component in cartesian coordinate system.
Definition: BasicVector3D.h:67
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
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)
complex_t Integrand(double Z) const
Integrand for complex form factor.
FormFactorTruncatedSpheroid(const std::vector< double > P)
IFormFactor * sliceFormFactor(ZLimits limits, const IRotation &rot, kvector_t translation) const final
Actually slices the form factor or throws an exception.
void onChange() final
Action to be taken in inherited class when a parameter has changed.
complex_t evaluate_for_q(cvector_t q) const final
Returns scattering amplitude for complex scattering wavevector q=k_i-k_f.
Abstract base class for Born form factors.
Definition: IBornFF.h:41
std::unique_ptr< IShape3D > m_shape3D
IShape3D object, used to retrieve vertices (which may be approximate in the case of round shapes).
Definition: IBornFF.h:77
static SlicingEffects computeSlicingEffects(ZLimits limits, const kvector_t &position, double height)
Helper method for slicing.
Definition: IBornFF.cpp:66
Abstract base class for all form factors.
Definition: IFormFactor.h:36
static IFormFactor * createTransformedFormFactor(const IFormFactor &formfactor, const IRotation &rot, kvector_t translation)
Definition: IFormFactor.cpp:99
Abstract base class for rotations.
Definition: Rotations.h:28
Class that contains upper and lower limits of the z-coordinate for the slicing of form factors.
Definition: ZLimits.h:45
double J1c(double x)
Bessel function J1(x)/x.
Definition: Bessel.cpp:172
Definition: filesystem.h:81