BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FormFactorCone6.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/FormFactorCone6.cpp
6 //! @brief Implements class FormFactorCone6.
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"
18 
19 const PolyhedralTopology FormFactorCone6::topology = {{{{5, 4, 3, 2, 1, 0}, true},
20  {{0, 1, 7, 6}, false},
21  {{1, 2, 8, 7}, false},
22  {{2, 3, 9, 8}, false},
23  {{3, 4, 10, 9}, false},
24  {{4, 5, 11, 10}, false},
25  {{5, 0, 6, 11}, false},
26  {{6, 7, 8, 9, 10, 11}, true}},
27  false};
28 
29 FormFactorCone6::FormFactorCone6(const std::vector<double> P)
31  {"Cone6",
32  "frustum with regular hexagonal base",
33  {{"BaseEdge", "nm", "base edge length", 0, +INF, 0},
34  {"Height", "nm", "height", 0, +INF, 0},
35  {"Alpha", "rad", "angle between base and a side face", 0., M_PI_2, 0}}},
36  P)
37  , m_base_edge(m_P[0])
38  , m_height(m_P[1])
39  , m_alpha(m_P[2])
40 {
41  onChange();
42 }
43 
44 FormFactorCone6::FormFactorCone6(double base_edge, double height, double alpha)
45  : FormFactorCone6(std::vector<double>{base_edge, height, alpha})
46 {
47 }
48 
50  kvector_t translation) const
51 {
52  auto effects = computeSlicingEffects(limits, translation, m_height);
53  double dbase_edge = effects.dz_bottom * Math::cot(m_alpha);
54  FormFactorCone6 slicedff(m_base_edge - dbase_edge,
55  m_height - effects.dz_bottom - effects.dz_top, m_alpha);
56  return createTransformedFormFactor(slicedff, rot, effects.position);
57 }
58 
60 {
61  double cot_alpha = Math::cot(m_alpha);
62  if (!std::isfinite(cot_alpha) || cot_alpha < 0)
63  throw std::runtime_error("pyramid angle alpha out of bounds");
64  double r = cot_alpha * 2 / sqrt(3) * m_height / m_base_edge; // L(top)/L(base)
65  if (r > 1) {
66  std::ostringstream ostr;
67  ostr << "Incompatible parameters in Cone6 ";
68  ostr << "(base_edge=" << m_base_edge;
69  ostr << ", height:" << m_height;
70  ostr << ", alpha[rad]:" << m_alpha << ")";
71  throw std::runtime_error(ostr.str());
72  }
73 
74  double a = m_base_edge;
75  double as = a / 2;
76  double ac = a * sqrt(3) / 2;
77  double b = a * (1 - r);
78  double bs = b / 2;
79  double bc = b * sqrt(3) / 2;
80 
81  double zcom = m_height * (.5 - 2 * r / 3 + r * r / 4) / (1 - r + r * r / 3); // center of mass
82 
83  setPolyhedron(topology, -zcom,
84  {// base:
85  {a, 0., -zcom},
86  {as, ac, -zcom},
87  {-as, ac, -zcom},
88  {-a, 0., -zcom},
89  {-as, -ac, -zcom},
90  {as, -ac, -zcom},
91  // top:
92  {b, 0., m_height - zcom},
93  {bs, bc, m_height - zcom},
94  {-bs, bc, m_height - zcom},
95  {-b, 0., m_height - zcom},
96  {-bs, -bc, m_height - zcom},
97  {bs, -bc, m_height - zcom}});
98 }
Defines M_PI and some more mathematical constants.
#define M_PI_2
Definition: Constants.h:45
Defines class FormFactorCone6.
Defines functions in namespace Math.
const double INF
Definition: INode.h:25
A frustum (truncated pyramid) with regular hexagonal base.
static const PolyhedralTopology topology
const double & m_base_edge
IFormFactor * sliceFormFactor(ZLimits limits, const IRotation &rot, kvector_t translation) const final
Actually slices the form factor or throws an exception.
FormFactorCone6(const std::vector< double > P)
const double & m_alpha
void onChange() final
Action to be taken in inherited class when a parameter has changed.
const double & m_height
static SlicingEffects computeSlicingEffects(ZLimits limits, const kvector_t &position, double height)
Helper method for slicing.
Definition: IBornFF.cpp:66
A polyhedron, for form factor computation.
void setPolyhedron(const PolyhedralTopology &topology, double z_bottom, const std::vector< kvector_t > &vertices)
Called by child classes to set faces and other internal variables.
Abstract base class for all form factors.
Definition: IFormFactor.h:36
static IFormFactor * createTransformedFormFactor(const IFormFactor &formfactor, const IRotation &rot, kvector_t translation)
Definition: IFormFactor.cpp:99
Abstract base class for rotations.
Definition: Rotations.h:28
For internal use in IFormFactorPolyhedron.
Class that contains upper and lower limits of the z-coordinate for the slicing of form factors.
Definition: ZLimits.h:45
double cot(double x)
cotangent function:
Definition: Functions.cpp:48
Definition: filesystem.h:81