BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Spheroid.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/Spheroid.cpp
6 //! @brief Implements class Spheroid.
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"
17 #include "Base/Math/Functions.h"
20 #include <limits>
21 
22 Spheroid::Spheroid(const std::vector<double> P)
23  : IFormFactor(P)
24  , m_radius(m_P[0])
25  , m_height(m_P[1])
26 {
27  checkNodeArgs();
28  m_shape3D =
29  std::make_unique<TruncatedEllipsoidNet>(m_radius, m_radius, m_height / 2.0, m_height, 0.0);
30 }
31 
32 Spheroid::Spheroid(double radius, double height)
33  : Spheroid(std::vector<double>{radius, height})
34 {
35 }
36 
37 complex_t Spheroid::formfactor_at_bottom(C3 q) const
38 {
39  double h = m_height / 2;
40  double R = m_radius;
41 
42  // complex length of q (not a sesquilinear dot product!),
43  // xy components multiplied with R, z component multiplied with h
44  complex_t qR = sqrt(R * R * (q.x() * q.x() + q.y() * q.y()) + h * h * q.z() * q.z());
45 
46  complex_t zFactor = exp_I(h * q.z());
47 
48  if (std::abs(qR) < 1e-4)
49  // expand sin(qR)-qR*cos(qR) up to qR^5
50  return 4 * M_PI / 3 * R * R * h * (1. - 0.1 * pow(qR, 2)) * zFactor;
51 
52  return 4 * M_PI / pow(qR, 3) * R * R * h * (sin(qR) - qR * cos(qR)) * zFactor;
53 }
Defines M_PI and some more mathematical constants.
#define M_PI
Definition: Constants.h:44
Defines namespace Math.
Defines class Spheroid.
Defines class TruncatedEllipsoidNet.
Defines class TruncatedSpheroid.
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
A full spheroid (an ellipsoid with two equal axes, hence with circular cross section)
Definition: Spheroid.h:23
const double & m_height
Definition: Spheroid.h:48
double radius() const
Definition: Spheroid.h:40
Spheroid(double radius, double height)
Definition: Spheroid.cpp:32
const double & m_radius
Definition: Spheroid.h:47
double height() const
Definition: Spheroid.h:39
complex_t formfactor_at_bottom(C3 q) const override
Definition: Spheroid.cpp:37
constexpr Double_t R()
Definition: TMath.h:213