BornAgain  1.18.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 scattering at grazing incidence
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 
17 #include "Base/Types/Exceptions.h"
19 
21  {{3, 2, 1, 0}, true}, // TODO -> true
22  {{0, 1, 5, 4}, false},
23  {{1, 2, 6, 5}, false},
24  {{2, 3, 7, 6}, false},
25  {{3, 0, 4, 7}, false},
26  {{4, 5, 6, 7}, true} // TODO -> true
27  },
28  false};
29 
30 FormFactorPyramid::FormFactorPyramid(const std::vector<double> P)
31  : IFormFactorPolyhedron({"Pyramid",
32  "frustum with quadratic 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, 0}}},
36  P),
37  m_base_edge(m_P[0]), m_height(m_P[1]), m_alpha(m_P[2])
38 {
39  onChange();
40 }
41 
42 FormFactorPyramid::FormFactorPyramid(double base_edge, double height, double alpha)
43  : FormFactorPyramid(std::vector<double>{base_edge, height, alpha})
44 {
45 }
46 
48  kvector_t translation) const
49 {
50  auto effects = computeSlicingEffects(limits, translation, m_height);
51  double dbase_edge = 2 * effects.dz_bottom * MathFunctions::cot(m_alpha);
52  FormFactorPyramid slicedff(m_base_edge - dbase_edge,
53  m_height - effects.dz_bottom - effects.dz_top, m_alpha);
54  return createTransformedFormFactor(slicedff, rot, effects.position);
55 }
56 
58 {
59  double cot_alpha = MathFunctions::cot(m_alpha);
60  if (!std::isfinite(cot_alpha))
61  throw Exceptions::OutOfBoundsException("pyramid angle alpha out of bounds");
62  double r = cot_alpha * 2 * m_height / m_base_edge; // [L(base)-L(top)]/L(base)
63  if (r > 1) {
64  std::ostringstream ostr;
65  ostr << "FormFactorPyramid() -> Error in class initialization with parameters";
66  ostr << " base_edge:" << m_base_edge;
67  ostr << " height:" << m_height;
68  ostr << " alpha[rad]:" << m_alpha << "\n\n";
69  ostr << "Check for 'height <= base_edge*tan(alpha)' failed.";
71  }
72 
73  double a = m_base_edge / 2;
74  double b = a * (1 - r);
75 
76  double zcom = m_height * (.5 - 2 * r / 3 + r * r / 4) / (1 - r + r * r / 3); // center of mass
77 
78  setPolyhedron(topology, -zcom,
79  {// base:
80  {-a, -a, -zcom},
81  {a, -a, -zcom},
82  {a, a, -zcom},
83  {-a, a, -zcom},
84  // top:
85  {-b, -b, m_height - zcom},
86  {b, -b, m_height - zcom},
87  {b, b, m_height - zcom},
88  {-b, b, m_height - zcom}});
89 }
Defines many exception classes in namespace Exceptionss.
Defines class FormFactorPyramid.
IFormFactor * createTransformedFormFactor(const IFormFactor &formfactor, const IRotation &rot, kvector_t translation)
Definition: IFormFactor.cpp:77
const double INF
Definition: INode.h:24
Defines M_PI and some more mathematical constants.
#define M_PI
Definition: MathConstants.h:39
Defines namespace MathFunctions.
A frustum with a quadratic base.
static const PolyhedralTopology topology
IFormFactor * sliceFormFactor(ZLimits limits, const IRotation &rot, kvector_t translation) const override final
Actually slices the form factor or throws an exception.
FormFactorPyramid(const std::vector< double > P)
const double & m_alpha
const double & m_base_edge
const double & m_height
void onChange() override final
Action to be taken in inherited class when a parameter has changed.
SlicingEffects computeSlicingEffects(ZLimits limits, const kvector_t &position, double height) const
Helper method for slicing.
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.
Pure virtual base class for all form factors.
Definition: IFormFactor.h:40
Pure virtual interface for rotations.
Definition: Rotations.h:27
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:41
double cot(double x)
cotangent function: