BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Cone.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/Cone.cpp
6 //! @brief Implements class Cone.
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/Functions.h"
19 #include "Base/Math/IntegratorGK.h"
21 #include <limits>
22 
23 Cone::Cone(const std::vector<double> P)
24  : IFormFactor(P)
25  , m_radius(m_P[0])
26  , m_height(m_P[1])
27  , m_alpha(m_P[2])
28 {
29  checkNodeArgs();
31  if (!std::isfinite(m_cot_alpha) || m_cot_alpha < 0)
32  throw std::runtime_error("pyramid angle alpha out of bounds");
33  if (m_cot_alpha * m_height > m_radius) {
34  std::ostringstream ostr;
35  ostr << "Cone() -> Error in class initialization ";
36  ostr << "with parameters radius:" << m_radius;
37  ostr << " m_height:" << m_height;
38  ostr << " alpha[rad]:" << m_alpha << "\n\n";
39  ostr << "Check for 'height <= radius*tan(alpha)' failed.";
40  throw std::runtime_error(ostr.str());
41  }
43  double radius2 = m_radius - m_height * m_cot_alpha;
44  m_shape3D = std::make_unique<DoubleEllipseZ>(m_radius, m_radius, m_height, radius2, radius2);
45 }
46 
47 Cone::Cone(double radius, double height, double alpha)
48  : Cone(std::vector<double>{radius, height, alpha})
49 {
50 }
51 
52 complex_t Cone::formfactor_at_bottom(C3 q) const
53 {
54  if (std::abs(q.mag()) < std::numeric_limits<double>::epsilon()) {
55  double R = m_radius;
56  double H = m_height;
57  if (m_cot_alpha == 0.0)
58  return M_PI * R * R * H; // cylinder case
59  double R2 = R - H * m_cot_alpha;
60  double apex_height = R / m_cot_alpha;
61  return M_PI / 3. * (R * R * H + (R * R - R2 * R2) * (apex_height - H));
62  }
63  complex_t integral = ComplexIntegrator().integrate(
64  [=](double Z) {
65  double Rz = m_radius - Z * m_cot_alpha;
66  complex_t q_p = std::sqrt(q.x() * q.x() + q.y() * q.y()); // sqrt(x*x + y*y)
67  return Rz * Rz * Math::Bessel::J1c(q_p * Rz) * exp_I(q.z() * Z);
68  },
69  0., m_height);
70  return M_TWOPI * integral;
71 }
Defines Bessel functions in namespace Math.
Defines class Cone.
Defines M_PI and some more mathematical constants.
#define M_TWOPI
Definition: Constants.h:54
#define M_PI
Definition: Constants.h:44
Defines class DoubleEllipse.
Defines namespace Math.
Defines classes RealIntegrator, ComplexIntegrator.
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)
A conical frustum (cone truncated parallel to the base) with circular base.
Definition: Cone.h:23
double m_cot_alpha
Definition: Cone.h:52
const double & m_height
Definition: Cone.h:50
double radius() const
Definition: Cone.h:41
complex_t formfactor_at_bottom(C3 q) const override
Definition: Cone.cpp:52
double height() const
Definition: Cone.h:39
double alpha() const
Definition: Cone.h:40
Cone(double radius, double height, double alpha)
Definition: Cone.cpp:47
const double & m_radius
Definition: Cone.h:49
const double & m_alpha
Definition: Cone.h:51
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
double J1c(double x)
Bessel function J1(x)/x.
Definition: Bessel.cpp:172
double cot(double x)
cotangent function:
Definition: Functions.cpp:47
constexpr Double_t H()
Definition: TMath.h:140
constexpr Double_t R()
Definition: TMath.h:213