BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FormFactorHollowSphere.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/FormFactorHollowSphere.cpp
6 //! @brief Implements class FormFactorHollowSphere.
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/Constants.h"
18 #include <limits>
19 
21  : IBornFF({"FormFactorHollowSphere",
22  "class_tooltip",
23  {{"MeanRadius", "nm", "para_tooltip", 0, +INF, 0},
24  {"FullWidth", "nm", "para_tooltip", 0, +INF, 0}}},
25  P)
26  , m_mean(m_P[0])
27  , m_full_width(m_P[1])
28 {
29  if (!checkParameters())
30  throw std::runtime_error("FormFactorHollowSphere::FormFactorHollowSphere:"
31  " mean radius must be bigger than the half width");
32  onChange();
33 }
34 
35 FormFactorHollowSphere::FormFactorHollowSphere(double mean, double full_width)
36  : FormFactorHollowSphere(std::vector<double>{mean, full_width})
37 {
38 }
39 
41 {
42  double R = m_mean;
43  double W = m_full_width;
44  double q2 = std::norm(q.x()) + std::norm(q.y()) + std::norm(q.z());
45  double q_r = std::sqrt(q2);
46  if (q_r * R < std::numeric_limits<double>::epsilon())
47  return (4.0 * M_PI * R * R * R + M_PI * R * W * W) / 3.0;
48  double qR = q_r * R;
49  double qW = q_r * W;
50  double nominator =
51  4 * M_PI
52  * (4 * std::sin(qR) * std::sin(qW / 2.0) - qW * std::cos(qW / 2.0) * std::sin(qR)
53  - 2.0 * qR * std::cos(qR) * std::sin(qW / 2.0));
54  return nominator / (q2 * q2 * W);
55 }
56 
58 {
59  m_shape3D = std::make_unique<TruncatedEllipsoid>(m_mean, m_mean, m_mean, 2.0 * m_mean, 0.0);
60 }
61 
63 {
64  if (m_full_width <= 0.0)
65  return false;
66  if (2.0 * m_mean < m_full_width)
67  return false;
68  return true;
69 }
std::complex< double > complex_t
Definition: Complex.h:20
Defines M_PI and some more mathematical constants.
#define M_PI
Definition: Constants.h:44
Defines class FormFactorHollowSphere.
const double INF
Definition: INode.h:25
Defines class TruncatedEllipsoid.
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
Integrated full sphere form factor over a uniform distribution of radii.
complex_t evaluate_for_q(cvector_t q) const final
Returns scattering amplitude for complex scattering wavevector q=k_i-k_f.
FormFactorHollowSphere(const std::vector< double > P)
const double & m_full_width
This is the full width of the radius distribution.
const double & m_mean
This is the mean radius.
void onChange() final
Action to be taken in inherited class when a parameter has changed.
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
Definition: filesystem.h:81