BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
HorizontalCylinder.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/HorizontalCylinder.cpp
6 //! @brief Implements class HorizontalCylinder.
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 
22 HorizontalCylinder::HorizontalCylinder(const std::vector<double> P)
23  : IFormFactor(P)
24  , m_radius(m_P[0])
25  , m_length(m_P[1])
26  , m_slice_bottom(m_P[2])
27  , m_slice_top(m_P[3])
28 {
29  checkNodeArgs();
30  // TODO improve!
31  m_shape3D = std::make_unique<DoubleEllipseX>(-m_length / 2, m_radius, m_radius, m_slice_bottom,
34 }
35 
36 HorizontalCylinder::HorizontalCylinder(double radius, double length, double slice_bottom,
37  double slice_top)
38  : HorizontalCylinder(std::vector<double>{radius, length, slice_bottom, slice_top})
39 {
40 }
41 
42 HorizontalCylinder::HorizontalCylinder(double radius, double length)
43  : HorizontalCylinder(radius, length, -radius, +radius)
44 {
45 }
46 
48 {
49  const double R = m_radius;
50  const double L = m_length;
51 
52  const complex_t qL2 = q.x() * L / 2.;
53  const complex_t qR = std::sqrt(q.y() * q.y() + q.z() * q.z()) * R;
54 
55  const complex_t axial_part = L * Math::sinc(qL2);
56  complex_t radial_part;
57 
58  if (m_slice_bottom == -R && m_slice_top == +R)
59  radial_part = M_TWOPI * R * R * Math::Bessel::J1c(qR) * exp_I(q.z() * R);
60 
61  else
62  radial_part =
63  2.
65  [=](double z) {
66  double y = sqrt(R * R - z * z);
67  return y * Math::sinc(q.y() * y) * exp_I(q.z() * (z - m_slice_bottom));
68  },
70 
71  return radial_part * axial_part;
72 }
Defines Bessel functions in namespace Math.
Defines M_PI and some more mathematical constants.
#define M_TWOPI
Definition: Constants.h:54
Defines class DoubleEllipse.
Defines namespace Math.
Defines class Cylinder.
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 circular cylinder.
complex_t formfactor_at_bottom(C3 q) const override
const double & m_slice_top
const double & m_radius
const double & m_length
double length() const
double slice_top() const
double radius() const
double slice_bottom() const
const double & m_slice_bottom
HorizontalCylinder(double radius, double length, double slice_bottom, double slice_top)
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 sinc(double x)
sinc function:
Definition: Functions.cpp:52
constexpr Double_t R()
Definition: TMath.h:213