BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FormFactorTetrahedron.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/FormFactorTetrahedron.cpp
6 //! @brief Implements class FormFactorTetrahedron.
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 FormFactorTetrahedron::topology = {{{{2, 1, 0}, false},
20  {{0, 1, 4, 3}, false},
21  {{1, 2, 5, 4}, false},
22  {{2, 0, 3, 5}, false},
23  {{3, 4, 5}, false}},
24  false};
25 
28  {"Tetrahedron",
29  "actually, not a tetrahedron, but a trigonal frustum",
30  {{"BaseEdge", "nm", "edge of base triangle", 0, +INF, 0},
31  {"Height", "nm", "height of frustum", 0, +INF, 0},
32  {"Alpha", "rad", "angle between base and a side face", 0., M_PI_2, 0}}},
33  P)
34  , m_base_edge(m_P[0])
35  , m_height(m_P[1])
36  , m_alpha(m_P[2])
37 {
38  onChange();
39 }
40 
41 FormFactorTetrahedron::FormFactorTetrahedron(double base_edge, double height, double alpha)
42  : FormFactorTetrahedron(std::vector<double>{base_edge, height, alpha})
43 {
44 }
45 
47  kvector_t translation) const
48 {
49  auto effects = computeSlicingEffects(limits, translation, m_height);
50  double dbase_edge = 2 * sqrt(3) * effects.dz_bottom * Math::cot(m_alpha);
51  FormFactorTetrahedron slicedff(m_base_edge - dbase_edge,
52  m_height - effects.dz_bottom - effects.dz_top, m_alpha);
53  return createTransformedFormFactor(slicedff, rot, effects.position);
54 }
55 
57 {
58  double cot_alpha = Math::cot(m_alpha);
59  if (!std::isfinite(cot_alpha) || cot_alpha < 0)
60  throw std::runtime_error("pyramid angle alpha out of bounds");
61  double r = cot_alpha * 2 * std::sqrt(3.) * m_height / m_base_edge; // L(top)/L(base)
62  if (r > 1) {
63  std::ostringstream ostr;
64  ostr << "Incompatible parameters in Tetrahedron: ";
65  ostr << "(base_edge=" << m_base_edge;
66  ostr << ", height:" << m_height;
67  ostr << ", alpha[rad]:" << m_alpha << ")";
68  throw std::runtime_error(ostr.str());
69  }
70 
71  double a = m_base_edge;
72  double as = a / 2;
73  double ac = a / sqrt(3) / 2;
74  double ah = a / sqrt(3);
75  double b = a * (1 - r);
76  double bs = b / 2;
77  double bc = b / sqrt(3) / 2;
78  double bh = b / sqrt(3);
79 
80  double zcom = m_height * (.5 - 2 * r / 3 + r * r / 4) / (1 - r + r * r / 3); // center of mass
81 
82  setPolyhedron(topology, -zcom,
83  {// base:
84  {-ac, as, -zcom},
85  {-ac, -as, -zcom},
86  {ah, 0., -zcom},
87  // top:
88  {-bc, bs, m_height - zcom},
89  {-bc, -bs, m_height - zcom},
90  {bh, 0., m_height - zcom}});
91 }
Defines M_PI and some more mathematical constants.
#define M_PI_2
Definition: Constants.h:45
Defines class FormFactorTetrahedron.
Defines functions in namespace Math.
const double INF
Definition: INode.h:25
A frustum with equilateral trigonal base.
static const PolyhedralTopology topology
IFormFactor * sliceFormFactor(ZLimits limits, const IRotation &rot, kvector_t translation) const final
Actually slices the form factor or throws an exception.
FormFactorTetrahedron(const std::vector< double > P)
void onChange() final
Action to be taken in inherited class when a parameter has changed.
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