BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Pyramid4.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/Pyramid4.cpp
6 //! @brief Implements class Pyramid4.
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 Pyramid4::topology = {{
20  {{3, 2, 1, 0}, true}, // TODO -> 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} // TODO -> true
26  },
27  false};
28 
29 Pyramid4::Pyramid4(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))
38  throw std::runtime_error("pyramid angle alpha out of bounds");
39  double r = cot_alpha * 2 * m_height / m_base_edge; // [L(base)-L(top)]/L(base)
40  if (r > 1) {
41  std::ostringstream ostr;
42  ostr << "Pyramid4() -> Error in class initialization with parameters";
43  ostr << " base_edge:" << m_base_edge;
44  ostr << " height:" << m_height;
45  ostr << " alpha[rad]:" << m_alpha << "\n\n";
46  ostr << "Check for 'height <= base_edge*tan(alpha)' failed.";
47  throw std::runtime_error(ostr.str());
48  }
49 
50  double a = m_base_edge / 2;
51  double b = a * (1 - r);
52 
53  double zcom = m_height * (.5 - 2 * r / 3 + r * r / 4) / (1 - r + r * r / 3); // center of mass
54 
55  setPolyhedron(topology, -zcom,
56  {// base:
57  {-a, -a, -zcom},
58  {a, -a, -zcom},
59  {a, a, -zcom},
60  {-a, a, -zcom},
61  // top:
62  {-b, -b, m_height - zcom},
63  {b, -b, m_height - zcom},
64  {b, b, m_height - zcom},
65  {-b, b, m_height - zcom}});
66 }
67 
68 Pyramid4::Pyramid4(double base_edge, double height, double alpha)
69  : Pyramid4(std::vector<double>{base_edge, height, alpha})
70 {
71 }
Defines M_PI and some more mathematical constants.
Defines namespace Math.
Defines class Pyramid4.
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 a quadratic base.
Definition: Pyramid4.h:23
double height() const
Definition: Pyramid4.h:39
double alpha() const
Definition: Pyramid4.h:41
const double & m_height
Definition: Pyramid4.h:47
const double & m_base_edge
Definition: Pyramid4.h:46
Pyramid4(double base_edge, double height, double alpha)
Definition: Pyramid4.cpp:68
const double & m_alpha
Definition: Pyramid4.h:48
static const ff::PolyhedralTopology topology
Definition: Pyramid4.h:44
double cot(double x)
cotangent function:
Definition: Functions.cpp:47