BornAgain  1.18.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 scattering at grazing incidence
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 
17 #include "Base/Types/Exceptions.h"
19 
20 const PolyhedralTopology FormFactorAnisoPyramid::topology = {{{{3, 2, 1, 0}, 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}},
26  false};
27 
30  {"AnisoPyramid",
31  "frsutum with rectangular base",
32  {{"Length", "nm", "side length of base in x direction", 0, +INF, 0},
33  {"Width", "nm", "side length of base in y direction", 0, +INF, 0},
34  {"Height", "nm", "height", 0, +INF, 0},
35  {"Alpha", "rad", "angle between base and any side face", 0., M_PI_2, 0}}},
36  P),
37  m_length(m_P[0]), m_width(m_P[1]), m_height(m_P[2]), m_alpha(m_P[3])
38 {
39  onChange();
40 }
41 
43  double alpha)
44  : FormFactorAnisoPyramid(std::vector<double>{length, width, 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 * MathFunctions::cot(m_alpha);
53  FormFactorAnisoPyramid slicedff(m_length - dbase_edge, m_width - 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 = MathFunctions::cot(m_alpha);
61  if (!std::isfinite(cot_alpha) || cot_alpha < 0)
62  throw Exceptions::OutOfBoundsException("AnisoPyramid: angle alpha out of bounds");
63  double r = cot_alpha * 2 * m_height / m_length;
64  double s = cot_alpha * 2 * m_height / m_width;
65  if (r > 1 || s > 1) {
66  std::ostringstream ostr;
67  ostr << "FormFactorAnisoPyramid() -> Error in class initialization with parameters";
68  ostr << " length:" << m_length;
69  ostr << " width:" << m_width;
70  ostr << " height:" << m_height;
71  ostr << " alpha[rad]:" << m_alpha << "\n\n";
72  ostr << "Check for '2*height <= (length,width)*tan(alpha)' failed.";
74  }
75 
76  double D = m_length / 2;
77  double d = m_length / 2 * (1 - r);
78  double W = m_width / 2;
79  double w = m_width / 2 * (1 - s);
80 
81  double zcom =
82  m_height * (.5 - (r + s) / 3 + r * s / 4) / (1 - (r + s) / 2 + r * s / 3); // center of mass
83 
84  setPolyhedron(topology, -zcom,
85  {// base:
86  {-D, -W, -zcom},
87  {D, -W, -zcom},
88  {D, W, -zcom},
89  {-D, W, -zcom},
90  // top:
91  {-d, -w, m_height - zcom},
92  {d, -w, m_height - zcom},
93  {d, w, m_height - zcom},
94  {-d, w, m_height - zcom}});
95 }
Defines many exception classes in namespace Exceptionss.
Defines class FormFactorAnisoPyramid.
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_2
Definition: MathConstants.h:40
Defines namespace MathFunctions.
A frustum (truncated pyramid) with rectangular base.
IFormFactor * sliceFormFactor(ZLimits limits, const IRotation &rot, kvector_t translation) const override final
Actually slices the form factor or throws an exception.
void onChange() override final
Action to be taken in inherited class when a parameter has changed.
FormFactorAnisoPyramid(const std::vector< double > P)
static const PolyhedralTopology topology
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: