BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FormFactorCuboctahedron.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/HardParticle/FormFactorCuboctahedron.cpp
6 //! @brief Implements class FormFactorCuboctahedron.
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"
20 
21 const PolyhedralTopology FormFactorCuboctahedron::topology = {{{{3, 2, 1, 0}, 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, 9, 8}, false},
27  {{5, 6, 10, 9}, false},
28  {{6, 7, 11, 10}, false},
29  {{7, 4, 8, 11}, false},
30  {{8, 9, 10, 11}, true}},
31  false};
32 
35  {"Cuboctahedron",
36  "truncated quadratic bipyramid",
37  {{"Length", "nm", "edge length of base square (common face of both pyramids)", 0, +INF, 0},
38  {"Height", "nm", "height of the lower pyramid", 0, +INF, 0},
39  {"HeightRatio", "nm", "height ratio of upper to lower pyramid", 0, +INF, 0},
40  {"Alpha", "rad", "angle between the base and a side face", 0., M_PI_2, 0}}},
41  P),
42  m_length(m_P[0]), m_height(m_P[1]), m_height_ratio(m_P[2]), m_alpha(m_P[3])
43 {
44  onChange();
45 }
46 
48  double alpha)
49  : FormFactorCuboctahedron(std::vector<double>{length, height, height_ratio, alpha})
50 {
51 }
52 
54  kvector_t translation) const
55 {
56  auto effects = computeSlicingEffects(limits, translation, m_height * (1 + m_height_ratio));
57  if (effects.dz_bottom > m_height) {
58  double dbase_edge = 2 * (effects.dz_bottom - m_height) * MathFunctions::cot(m_alpha);
59  FormFactorPyramid slicedff(
60  m_length - dbase_edge,
61  m_height * (1 + m_height_ratio) - effects.dz_bottom - effects.dz_top, m_alpha);
62  return createTransformedFormFactor(slicedff, rot, effects.position);
63  } else if (effects.dz_top > m_height_ratio * m_height) {
64  double dbase_edge = 2 * (m_height - effects.dz_bottom) * MathFunctions::cot(m_alpha);
65  FormFactorPyramid slicedff(
66  m_length - dbase_edge,
67  m_height * (1 + m_height_ratio) - effects.dz_bottom - effects.dz_top, M_PI - m_alpha);
68  return createTransformedFormFactor(slicedff, rot, effects.position);
69  } else {
70  FormFactorCuboctahedron slicedff(m_length, m_height - effects.dz_bottom,
71  m_height_ratio * m_height - effects.dz_top, m_alpha);
72  return createTransformedFormFactor(slicedff, rot, effects.position);
73  }
74 }
75 
77 {
78  double cot_alpha = MathFunctions::cot(m_alpha);
79  if (!std::isfinite(cot_alpha) || cot_alpha < 0)
80  throw Exceptions::OutOfBoundsException("pyramid angle alpha out of bounds");
81  double x = m_height_ratio;
82  double r = cot_alpha * 2 * m_height / m_length;
83  if (std::max(1., x) * r > 1) {
84  std::ostringstream ostr;
85  ostr << "FormFactorCuboctahedron() -> Error in class initialization with parameters";
86  ostr << " height:" << m_height;
87  ostr << " length:" << m_length;
88  ostr << " height_ratio:" << m_height_ratio;
89  ostr << " alpha[rad]:" << m_alpha << "\n\n";
90  ostr << "Check for '2.*height <= length*tan(alpha)*min(1.,1.0/height_ratio)' failed.";
92  }
93 
94  double a = m_length / 2 * (1 - r);
95  double b = m_length / 2;
96  double c = m_length / 2 * (1 - r * x);
97 
98  double dzcom =
99  m_height * ((x * x - 1) / 2 - 2 * r * (x * x * x - 1) / 3 + r * r * (x * x * x * x - 1) / 4)
100  / ((x + 1) - r * (x * x + 1) + r * r * (x * x * x + 1) / 3);
101  double za = -dzcom - m_height;
102  double zb = -dzcom;
103  double zc = -dzcom + x * m_height;
104 
106  {// base:
107  {-a, -a, za},
108  {a, -a, za},
109  {a, a, za},
110  {-a, a, za},
111  // middle
112  {-b, -b, zb},
113  {b, -b, zb},
114  {b, b, zb},
115  {-b, b, zb},
116  // top
117  {-c, -c, zc},
118  {c, -c, zc},
119  {c, c, zc},
120  {-c, c, zc}});
121 }
Defines many exception classes in namespace Exceptionss.
Defines class FormFactorCuboctahedron.
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_2
Definition: MathConstants.h:40
#define M_PI
Definition: MathConstants.h:39
Defines namespace MathFunctions.
A truncated bifrustum with quadratic 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.
FormFactorCuboctahedron(const std::vector< double > P)
static const PolyhedralTopology topology
A frustum with a quadratic base.
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: