BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Pyramid6.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/Pyramid6.cpp
6 //! @brief Implements class Pyramid6.
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 ff::PolyhedralTopology Pyramid6::topology = {{{{5, 4, 3, 2, 1, 0}, true},
20  {{0, 1, 7, 6}, false},
21  {{1, 2, 8, 7}, false},
22  {{2, 3, 9, 8}, false},
23  {{3, 4, 10, 9}, false},
24  {{4, 5, 11, 10}, false},
25  {{5, 0, 6, 11}, false},
26  {{6, 7, 8, 9, 10, 11}, true}},
27  false};
28 
29 Pyramid6::Pyramid6(const std::vector<double> P)
31  , m_base_edge(m_P[0])
32  , m_height(m_P[1])
33  , m_alpha(m_P[2])
34 {
35  checkNodeArgs();
36  double cot_alpha = Math::cot(m_alpha);
37  if (!std::isfinite(cot_alpha) || cot_alpha < 0)
38  throw std::runtime_error("pyramid angle alpha out of bounds");
39  double r = cot_alpha * 2 / sqrt(3) * m_height / m_base_edge; // L(top)/L(base)
40  if (r > 1) {
41  std::ostringstream ostr;
42  ostr << "Incompatible parameters in Pyramid6 ";
43  ostr << "(base_edge=" << m_base_edge;
44  ostr << ", height:" << m_height;
45  ostr << ", alpha[rad]:" << m_alpha << ")";
46  throw std::runtime_error(ostr.str());
47  }
48 
49  double a = m_base_edge;
50  double as = a / 2;
51  double ac = a * sqrt(3) / 2;
52  double b = a * (1 - r);
53  double bs = b / 2;
54  double bc = b * sqrt(3) / 2;
55 
56  double zcom = m_height * (.5 - 2 * r / 3 + r * r / 4) / (1 - r + r * r / 3); // center of mass
57 
58  setPolyhedron(topology, -zcom,
59  {// base:
60  {a, 0., -zcom},
61  {as, ac, -zcom},
62  {-as, ac, -zcom},
63  {-a, 0., -zcom},
64  {-as, -ac, -zcom},
65  {as, -ac, -zcom},
66  // top:
67  {b, 0., m_height - zcom},
68  {bs, bc, m_height - zcom},
69  {-bs, bc, m_height - zcom},
70  {-b, 0., m_height - zcom},
71  {-bs, -bc, m_height - zcom},
72  {bs, -bc, m_height - zcom}});
73 }
74 
75 Pyramid6::Pyramid6(double base_edge, double height, double alpha)
76  : Pyramid6(std::vector<double>{base_edge, height, alpha})
77 {
78 }
Defines M_PI and some more mathematical constants.
Defines namespace Math.
Defines class Pyramid6.
A polyhedron, for form factor computation.
void setPolyhedron(const ff::PolyhedralTopology &topology, double z_bottom, const std::vector< R3 > &vertices)
Called by child classes to set faces and other internal variables.
void checkNodeArgs() const
Raises exception if a parameter value is invalid.
Definition: INode.cpp:27
A frustum (truncated pyramid) with regular hexagonal base.
Definition: Pyramid6.h:23
const double & m_height
Definition: Pyramid6.h:47
const double & m_alpha
Definition: Pyramid6.h:48
const double & m_base_edge
Definition: Pyramid6.h:46
Pyramid6(double base_edge, double height, double alpha)
Definition: Pyramid6.cpp:75
static const ff::PolyhedralTopology topology
Definition: Pyramid6.h:45
double alpha() const
Definition: Pyramid6.h:42
double height() const
Definition: Pyramid6.h:41
double cot(double x)
cotangent function:
Definition: Functions.cpp:47