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