BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
HollowSphere.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/HollowSphere.cpp
6 //! @brief Implements class HollowSphere.
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 
20 HollowSphere::HollowSphere(const std::vector<double> P)
21  : IFormFactor(P)
22  , m_mean(m_P[0])
23  , m_full_width(m_P[1])
24 {
25  checkNodeArgs();
26  if (!checkParameters())
27  throw std::runtime_error("HollowSphere::HollowSphere:"
28  " mean radius must be bigger than the half width");
29  m_shape3D = std::make_unique<TruncatedEllipsoidNet>(m_mean, m_mean, m_mean, 2.0 * m_mean, 0.0);
30 }
31 
32 HollowSphere::HollowSphere(double mean, double full_width)
33  : HollowSphere(std::vector<double>{mean, full_width})
34 {
35 }
36 
38 {
39  double R = m_mean;
40  double W = m_full_width;
41  double q2 = std::norm(q.x()) + std::norm(q.y()) + std::norm(q.z());
42  double q_r = std::sqrt(q2);
43  if (q_r * R < std::numeric_limits<double>::epsilon())
44  return (4.0 * M_PI * R * R * R + M_PI * R * W * W) / 3.0;
45  double qR = q_r * R;
46  double qW = q_r * W;
47  double nominator =
48  4 * M_PI
49  * (4 * std::sin(qR) * std::sin(qW / 2.0) - qW * std::cos(qW / 2.0) * std::sin(qR)
50  - 2.0 * qR * std::cos(qR) * std::sin(qW / 2.0));
51  return nominator / (q2 * q2 * W);
52 }
53 
55 {
56  if (m_full_width <= 0.0)
57  return false;
58  if (2.0 * m_mean < m_full_width)
59  return false;
60  return true;
61 }
Defines M_PI and some more mathematical constants.
#define M_PI
Definition: Constants.h:44
Defines class HollowSphere.
Defines class TruncatedEllipsoidNet.
Integrated full sphere form factor over a uniform distribution of radii.
Definition: HollowSphere.h:23
bool checkParameters() const
const double & m_full_width
This is the full width of the radius distribution.
Definition: HollowSphere.h:45
const double & m_mean
This is the mean radius.
Definition: HollowSphere.h:44
HollowSphere(double mean, double full_width)
complex_t formfactor_at_bottom(C3 q) const override
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
constexpr Double_t R()
Definition: TMath.h:213