BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FormFactorTruncatedSphere.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/HardParticle/FormFactorTruncatedSphere.cpp
6 //! @brief Implements class FormFactorTruncatedSphere.
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 
17 #include "Base/Types/Exceptions.h"
18 #include "Base/Utils/Integrator.h"
20 #include "Fit/Tools/RealLimits.h"
22 #include <limits>
23 
25  : IFormFactorBorn({"TruncatedSphere",
26  "class_tooltip",
27  {{"Radius", "nm", "radius", 0, +INF, 0},
28  {"Height", "nm", "height before removal of cap", 0, +INF, 0},
29  {"DeltaHeight", "nm", "height of removed cap", 0, +INF, 0}}},
30  P),
31  m_radius(m_P[0]), m_height(m_P[1]), m_dh(m_P[2])
32 {
33  check_initialization();
34  onChange();
35 }
36 
38  : FormFactorTruncatedSphere(std::vector<double>{radius, height, dh})
39 {
40 }
41 
43 {
44  bool result(true);
45  if (m_height > 2. * m_radius || m_dh > m_height) {
46  std::ostringstream ostr;
47  ostr << "::FormFactorTruncatedSphere() -> Error in class initialization ";
48  ostr << "with parameters 'radius':" << m_radius << " 'height':" << m_height
49  << " 'delta_height':" << m_dh << "\n\n";
50  ostr << "Check for height <= 2.*radius AND delta_height < height failed.";
52  }
53  return result;
54 }
55 
56 //! Integrand for complex form factor.
58 {
59  double Rz = std::sqrt(m_radius * m_radius - Z * Z);
60  complex_t qx = m_q.x();
61  complex_t qy = m_q.y();
62  complex_t q_p = std::sqrt(qx * qx + qy * qy); // NOT the modulus!
63  return Rz * Rz * MathFunctions::Bessel_J1c(q_p * Rz) * exp_I(m_q.z() * Z);
64 }
65 
66 //! Complex form factor.
68 {
69  m_q = q;
70  if (std::abs(q.mag()) < std::numeric_limits<double>::epsilon()) {
71  return M_PI / 3.
72  * (m_height * m_height * (3. * m_radius - m_height)
73  - m_dh * m_dh * (3. * m_radius - m_dh));
74  }
75  // else
76  complex_t integral = ComplexIntegrator().integrate([&](double Z) { return Integrand(Z); },
78  return M_TWOPI * integral * exp_I(q.z() * (m_height - m_radius));
79 }
80 
82  kvector_t translation) const
83 {
84  double height = m_height - m_dh;
85  auto effects = computeSlicingEffects(limits, translation, height);
86  FormFactorTruncatedSphere slicedff(m_radius, m_height - effects.dz_bottom,
87  effects.dz_top + m_dh);
88  return createTransformedFormFactor(slicedff, rot, effects.position);
89 }
90 
92 {
93  mP_shape = std::make_unique<TruncatedEllipsoid>(m_radius, m_radius, m_radius, m_height, m_dh);
94 }
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 many exception classes in namespace Exceptionss.
Defines class FormFactorTruncatedSphere.
IFormFactor * createTransformedFormFactor(const IFormFactor &formfactor, const IRotation &rot, kvector_t translation)
Definition: IFormFactor.cpp:77
const double INF
Definition: INode.h:24
Defines classes RealIntegrator, ComplexIntegrator.
Defines M_PI and some more mathematical constants.
#define M_TWOPI
Definition: MathConstants.h:49
#define M_PI
Definition: MathConstants.h:39
Defines namespace MathFunctions.
Defines class RealLimits.
Defines class TruncatedEllipsoid.
double mag() const
Returns magnitude of the vector.
T z() const
Returns z-component in cartesian coordinate system.
Definition: BasicVector3D.h:68
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
To integrate a complex function of a real variable.
Definition: Integrator.h:41
complex_t integrate(const std::function< complex_t(double)> &f, double lmin, double lmax)
Definition: Integrator.cpp:36
void onChange() override final
Action to be taken in inherited class when a parameter has changed.
complex_t Integrand(double Z) const
Integrand for complex form factor.
complex_t evaluate_for_q(cvector_t q) const override final
Complex form factor.
FormFactorTruncatedSphere(const std::vector< double > P)
IFormFactor * sliceFormFactor(ZLimits limits, const IRotation &rot, kvector_t translation) const override final
Actually slices the form factor or throws an exception.
Pure virtual base class for Born form factors.
SlicingEffects computeSlicingEffects(ZLimits limits, const kvector_t &position, double height) const
Helper method for slicing.
std::unique_ptr< IShape > mP_shape
IShape object, used to retrieve vertices (which may be approximate in the case of round shapes).
Pure virtual base class for all form factors.
Definition: IFormFactor.h:40
Pure virtual interface for rotations.
Definition: Rotations.h:27
Class that contains upper and lower limits of the z-coordinate for the slicing of form factors.
Definition: ZLimits.h:41
double Bessel_J1c(double x)
Bessel function Bessel_J1(x)/x.
const double radius(5 *Units::nanometer)