BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Pyramid3.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/Pyramid3.cpp
6 //! @brief Implements class Pyramid3.
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 Pyramid3::topology = {{{{2, 1, 0}, false},
20  {{0, 1, 4, 3}, false},
21  {{1, 2, 5, 4}, false},
22  {{2, 0, 3, 5}, false},
23  {{3, 4, 5}, false}},
24  false};
25 
26 Pyramid3::Pyramid3(const std::vector<double> P)
28  , m_base_edge(m_P[0])
29  , m_height(m_P[1])
30  , m_alpha(m_P[2])
31 {
32  checkNodeArgs();
33  double cot_alpha = Math::cot(m_alpha);
34  if (!std::isfinite(cot_alpha) || cot_alpha < 0)
35  throw std::runtime_error("pyramid angle alpha out of bounds");
36  double r = cot_alpha * 2 * std::sqrt(3.) * m_height / m_base_edge; // L(top)/L(base)
37  if (r > 1) {
38  std::ostringstream ostr;
39  ostr << "Incompatible parameters in Pyramid3: ";
40  ostr << "(base_edge=" << m_base_edge;
41  ostr << ", height:" << m_height;
42  ostr << ", alpha[rad]:" << m_alpha << ")";
43  throw std::runtime_error(ostr.str());
44  }
45 
46  double a = m_base_edge;
47  double as = a / 2;
48  double ac = a / sqrt(3) / 2;
49  double ah = a / sqrt(3);
50  double b = a * (1 - r);
51  double bs = b / 2;
52  double bc = b / sqrt(3) / 2;
53  double bh = b / sqrt(3);
54 
55  double zcom = m_height * (.5 - 2 * r / 3 + r * r / 4) / (1 - r + r * r / 3); // center of mass
56 
57  setPolyhedron(topology, -zcom,
58  {// base:
59  {-ac, as, -zcom},
60  {-ac, -as, -zcom},
61  {ah, 0., -zcom},
62  // top:
63  {-bc, bs, m_height - zcom},
64  {-bc, -bs, m_height - zcom},
65  {bh, 0., m_height - zcom}});
66 }
67 
68 Pyramid3::Pyramid3(double base_edge, double height, double alpha)
69  : Pyramid3(std::vector<double>{base_edge, height, alpha})
70 {
71 }
Defines M_PI and some more mathematical constants.
Defines namespace Math.
Defines class Pyramid3.
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 with equilateral trigonal base.
Definition: Pyramid3.h:23
const double & m_alpha
Definition: Pyramid3.h:48
const double & m_base_edge
Definition: Pyramid3.h:46
static const ff::PolyhedralTopology topology
Definition: Pyramid3.h:45
Pyramid3(double base_edge, double height, double alpha)
Definition: Pyramid3.cpp:68
double alpha() const
Definition: Pyramid3.h:42
const double & m_height
Definition: Pyramid3.h:47
double height() const
Definition: Pyramid3.h:41
double cot(double x)
cotangent function:
Definition: Functions.cpp:47