BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Pyramid2.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/Pyramid2.cpp
6 //! @brief Implements class Pyramid2.
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 Pyramid2::topology = {{{{3, 2, 1, 0}, true},
20  {{0, 1, 5, 4}, false},
21  {{1, 2, 6, 5}, false},
22  {{2, 3, 7, 6}, false},
23  {{3, 0, 4, 7}, false},
24  {{4, 5, 6, 7}, true}},
25  false};
26 
27 Pyramid2::Pyramid2(const std::vector<double> P)
29  , m_length(m_P[0])
30  , m_width(m_P[1])
31  , m_height(m_P[2])
32  , m_alpha(m_P[3])
33 {
34  checkNodeArgs();
35  double cot_alpha = Math::cot(m_alpha);
36  if (!std::isfinite(cot_alpha) || cot_alpha < 0)
37  throw std::runtime_error("Pyramid2: angle alpha out of bounds");
38  double r = cot_alpha * 2 * m_height / m_length;
39  double s = cot_alpha * 2 * m_height / m_width;
40  if (r > 1 || s > 1) {
41  std::ostringstream ostr;
42  ostr << "Pyramid2() -> Error in class initialization with parameters";
43  ostr << " length:" << m_length;
44  ostr << " width:" << m_width;
45  ostr << " height:" << m_height;
46  ostr << " alpha[rad]:" << m_alpha << "\n\n";
47  ostr << "Check for '2*height <= (length,width)*tan(alpha)' failed.";
48  throw std::runtime_error(ostr.str());
49  }
50 
51  double D = m_length / 2;
52  double d = m_length / 2 * (1 - r);
53  double W = m_width / 2;
54  double w = m_width / 2 * (1 - s);
55 
56  double zcom =
57  m_height * (.5 - (r + s) / 3 + r * s / 4) / (1 - (r + s) / 2 + r * s / 3); // center of mass
58 
59  setPolyhedron(topology, -zcom,
60  {// base:
61  {-D, -W, -zcom},
62  {D, -W, -zcom},
63  {D, W, -zcom},
64  {-D, W, -zcom},
65  // top:
66  {-d, -w, m_height - zcom},
67  {d, -w, m_height - zcom},
68  {d, w, m_height - zcom},
69  {-d, w, m_height - zcom}});
70 }
71 
72 Pyramid2::Pyramid2(double length, double width, double height, double alpha)
73  : Pyramid2(std::vector<double>{length, width, height, alpha})
74 {
75 }
Defines M_PI and some more mathematical constants.
Defines namespace Math.
Defines class Pyramid2.
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 rectangular base.
Definition: Pyramid2.h:23
Pyramid2(double length, double width, double height, double alpha)
Definition: Pyramid2.cpp:72
double width() const
Definition: Pyramid2.h:41
const double & m_length
Definition: Pyramid2.h:48
double length() const
Definition: Pyramid2.h:40
const double & m_alpha
Definition: Pyramid2.h:51
double height() const
Definition: Pyramid2.h:42
const double & m_width
Definition: Pyramid2.h:49
const double & m_height
Definition: Pyramid2.h:50
static const ff::PolyhedralTopology topology
Definition: Pyramid2.h:46
double alpha() const
Definition: Pyramid2.h:43
double cot(double x)
cotangent function:
Definition: Functions.cpp:47