BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FormFactorCone6.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/HardParticle/FormFactorCone6.cpp
6 //! @brief Implements class FormFactorCone6.
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 FormFactorCone6::topology = {{{{5, 4, 3, 2, 1, 0}, true},
21  {{0, 1, 7, 6}, false},
22  {{1, 2, 8, 7}, false},
23  {{2, 3, 9, 8}, false},
24  {{3, 4, 10, 9}, false},
25  {{4, 5, 11, 10}, false},
26  {{5, 0, 6, 11}, false},
27  {{6, 7, 8, 9, 10, 11}, true}},
28  false};
29 
30 FormFactorCone6::FormFactorCone6(const std::vector<double> P)
32  {"Cone6",
33  "frustum with regular hexagonal base",
34  {{"BaseEdge", "nm", "base edge length", 0, +INF, 0},
35  {"Height", "nm", "height", 0, +INF, 0},
36  {"Alpha", "rad", "angle between base and a side face", 0., M_PI_2, 0}}},
37  P),
38  m_base_edge(m_P[0]), m_height(m_P[1]), m_alpha(m_P[2])
39 {
40  onChange();
41 }
42 
43 FormFactorCone6::FormFactorCone6(double base_edge, double height, double alpha)
44  : FormFactorCone6(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 = effects.dz_bottom * MathFunctions::cot(m_alpha);
53  FormFactorCone6 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 = MathFunctions::cot(m_alpha);
61  if (!std::isfinite(cot_alpha) || cot_alpha < 0)
62  throw Exceptions::OutOfBoundsException("pyramid angle alpha out of bounds");
63  double r = cot_alpha * 2 / sqrt(3) * m_height / m_base_edge; // L(top)/L(base)
64  if (r > 1) {
65  std::ostringstream ostr;
66  ostr << "Incompatible parameters in Cone6 ";
67  ostr << "(base_edge=" << m_base_edge;
68  ostr << ", height:" << m_height;
69  ostr << ", alpha[rad]:" << m_alpha << ")";
71  }
72 
73  double a = m_base_edge;
74  double as = a / 2;
75  double ac = a * sqrt(3) / 2;
76  double b = a * (1 - r);
77  double bs = b / 2;
78  double bc = b * sqrt(3) / 2;
79 
80  double zcom = m_height * (.5 - 2 * r / 3 + r * r / 4) / (1 - r + r * r / 3); // center of mass
81 
82  setPolyhedron(topology, -zcom,
83  {// base:
84  {a, 0., -zcom},
85  {as, ac, -zcom},
86  {-as, ac, -zcom},
87  {-a, 0., -zcom},
88  {-as, -ac, -zcom},
89  {as, -ac, -zcom},
90  // top:
91  {b, 0., m_height - zcom},
92  {bs, bc, m_height - zcom},
93  {-bs, bc, m_height - zcom},
94  {-b, 0., m_height - zcom},
95  {-bs, -bc, m_height - zcom},
96  {bs, -bc, m_height - zcom}});
97 }
Defines many exception classes in namespace Exceptionss.
Defines class FormFactorCone6.
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 regular hexagonal base.
void onChange() override final
Action to be taken in inherited class when a parameter has changed.
static const PolyhedralTopology topology
const double & m_base_edge
FormFactorCone6(const std::vector< double > P)
IFormFactor * sliceFormFactor(ZLimits limits, const IRotation &rot, kvector_t translation) const override final
Actually slices the form factor or throws an exception.
const double & m_alpha
const double & m_height
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: