BornAgain  1.18.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 scattering at grazing incidence
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 
17 #include "Base/Types/Exceptions.h"
19 #include <limits>
20 
22  : IFormFactorBorn({"FormFactorHollowSphere",
23  "class_tooltip",
24  {{"MeanRadius", "nm", "para_tooltip", 0, +INF, 0},
25  {"FullWidth", "nm", "para_tooltip", 0, +INF, 0}}},
26  P),
27  m_mean(m_P[0]), m_full_width(m_P[1])
28 {
29  if (!checkParameters())
31  "FormFactorHollowSphere::FormFactorHollowSphere:"
32  " mean radius must be bigger than the half width");
33  onChange();
34 }
35 
36 FormFactorHollowSphere::FormFactorHollowSphere(double mean, double full_width)
37  : FormFactorHollowSphere(std::vector<double>{mean, full_width})
38 {
39 }
40 
42 {
43  double R = m_mean;
44  double W = m_full_width;
45  double q2 = std::norm(q.x()) + std::norm(q.y()) + std::norm(q.z());
46  double q_r = std::sqrt(q2);
47  if (q_r * R < std::numeric_limits<double>::epsilon())
48  return (4.0 * M_PI * R * R * R + M_PI * R * W * W) / 3.0;
49  double qR = q_r * R;
50  double qW = q_r * W;
51  double nominator =
52  4 * M_PI
53  * (4 * std::sin(qR) * std::sin(qW / 2.0) - qW * std::cos(qW / 2.0) * std::sin(qR)
54  - 2.0 * qR * std::cos(qR) * std::sin(qW / 2.0));
55  return nominator / (q2 * q2 * W);
56 }
57 
59 {
60  mP_shape = std::make_unique<TruncatedEllipsoid>(m_mean, m_mean, m_mean, 2.0 * m_mean, 0.0);
61 }
62 
64 {
65  if (m_full_width <= 0.0)
66  return false;
67  if (2.0 * m_mean < m_full_width)
68  return false;
69  return true;
70 }
std::complex< double > complex_t
Definition: Complex.h:20
Defines many exception classes in namespace Exceptionss.
Defines class FormFactorHollowSphere.
const double INF
Definition: INode.h:24
Defines M_PI and some more mathematical constants.
#define M_PI
Definition: MathConstants.h:39
Defines class TruncatedEllipsoid.
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
Integrated full sphere form factor over a uniform distribution of radii.
FormFactorHollowSphere(const std::vector< double > P)
complex_t evaluate_for_q(cvector_t q) const override final
Returns scattering amplitude for complex scattering wavevector q=k_i-k_f.
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() override final
Action to be taken in inherited class when a parameter has changed.
Pure virtual base class for Born form factors.
std::unique_ptr< IShape > mP_shape
IShape object, used to retrieve vertices (which may be approximate in the case of round shapes).