BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FormFactorAnisoPyramid.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/FormFactorAnisoPyramid.cpp
6 //! @brief Implements class FormFactorAnisoPyramid.
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 FormFactorAnisoPyramid::topology = {{{{3, 2, 1, 0}, true},
20  {{0, 1, 5, 4}, false},
21  {{1, 2, 6, 5}, false},
22  {{2, 3, 7, 6}, false},
23  {{3, 0, 4, 7}, false},
24  {{4, 5, 6, 7}, true}},
25  false};
26 
29  {"AnisoPyramid",
30  "frsutum with rectangular base",
31  {{"Length", "nm", "side length of base in x direction", 0, +INF, 0},
32  {"Width", "nm", "side length of base in y direction", 0, +INF, 0},
33  {"Height", "nm", "height", 0, +INF, 0},
34  {"Alpha", "rad", "angle between base and any side face", 0., M_PI_2, 0}}},
35  P)
36  , m_length(m_P[0])
37  , m_width(m_P[1])
38  , m_height(m_P[2])
39  , m_alpha(m_P[3])
40 {
41  onChange();
42 }
43 
44 FormFactorAnisoPyramid::FormFactorAnisoPyramid(double length, double width, double height,
45  double alpha)
46  : FormFactorAnisoPyramid(std::vector<double>{length, width, height, alpha})
47 {
48 }
49 
51  kvector_t translation) const
52 {
53  auto effects = computeSlicingEffects(limits, translation, m_height);
54  double dbase_edge = 2 * effects.dz_bottom * Math::cot(m_alpha);
55  FormFactorAnisoPyramid slicedff(m_length - dbase_edge, m_width - dbase_edge,
56  m_height - effects.dz_bottom - effects.dz_top, m_alpha);
57  return createTransformedFormFactor(slicedff, rot, effects.position);
58 }
59 
61 {
62  double cot_alpha = Math::cot(m_alpha);
63  if (!std::isfinite(cot_alpha) || cot_alpha < 0)
64  throw std::runtime_error("AnisoPyramid: angle alpha out of bounds");
65  double r = cot_alpha * 2 * m_height / m_length;
66  double s = cot_alpha * 2 * m_height / m_width;
67  if (r > 1 || s > 1) {
68  std::ostringstream ostr;
69  ostr << "FormFactorAnisoPyramid() -> Error in class initialization with parameters";
70  ostr << " length:" << m_length;
71  ostr << " width:" << m_width;
72  ostr << " height:" << m_height;
73  ostr << " alpha[rad]:" << m_alpha << "\n\n";
74  ostr << "Check for '2*height <= (length,width)*tan(alpha)' failed.";
75  throw std::runtime_error(ostr.str());
76  }
77 
78  double D = m_length / 2;
79  double d = m_length / 2 * (1 - r);
80  double W = m_width / 2;
81  double w = m_width / 2 * (1 - s);
82 
83  double zcom =
84  m_height * (.5 - (r + s) / 3 + r * s / 4) / (1 - (r + s) / 2 + r * s / 3); // center of mass
85 
86  setPolyhedron(topology, -zcom,
87  {// base:
88  {-D, -W, -zcom},
89  {D, -W, -zcom},
90  {D, W, -zcom},
91  {-D, W, -zcom},
92  // top:
93  {-d, -w, m_height - zcom},
94  {d, -w, m_height - zcom},
95  {d, w, m_height - zcom},
96  {-d, w, m_height - zcom}});
97 }
Defines M_PI and some more mathematical constants.
#define M_PI_2
Definition: Constants.h:45
Defines class FormFactorAnisoPyramid.
Defines functions in namespace Math.
const double INF
Definition: INode.h:25
A frustum (truncated pyramid) with rectangular base.
void onChange() final
Action to be taken in inherited class when a parameter has changed.
FormFactorAnisoPyramid(const std::vector< double > P)
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.
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