BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Bipyramid4.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/Bipyramid4.cpp
6 //! @brief Implements class Bipyramid4.
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"
19 
20 const ff::PolyhedralTopology Bipyramid4::topology = {{{{3, 2, 1, 0}, 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, 9, 8}, false},
26  {{5, 6, 10, 9}, false},
27  {{6, 7, 11, 10}, false},
28  {{7, 4, 8, 11}, false},
29  {{8, 9, 10, 11}, true}},
30  false};
31 
32 Bipyramid4::Bipyramid4(const std::vector<double> P)
34  , m_length(m_P[0])
35  , m_height(m_P[1])
36  , m_height_ratio(m_P[2])
37  , m_alpha(m_P[3])
38 {
39  checkNodeArgs();
40  double cot_alpha = Math::cot(m_alpha);
41  if (!std::isfinite(cot_alpha) || cot_alpha < 0)
42  throw std::runtime_error("pyramid angle alpha out of bounds");
43  double x = m_height_ratio;
44  double r = cot_alpha * 2 * m_height / m_length;
45  if (std::max(1., x) * r > 1) {
46  std::ostringstream ostr;
47  ostr << "Bipyramid4() -> Error in class initialization with parameters";
48  ostr << " height:" << m_height;
49  ostr << " length:" << m_length;
50  ostr << " height_ratio:" << m_height_ratio;
51  ostr << " alpha[rad]:" << m_alpha << "\n\n";
52  ostr << "Check for '2.*height <= length*tan(alpha)*min(1.,1.0/height_ratio)' failed.";
53  throw std::runtime_error(ostr.str());
54  }
55 
56  double a = m_length / 2 * (1 - r);
57  double b = m_length / 2;
58  double c = m_length / 2 * (1 - r * x);
59 
60  double dzcom =
61  m_height * ((x * x - 1) / 2 - 2 * r * (x * x * x - 1) / 3 + r * r * (x * x * x * x - 1) / 4)
62  / ((x + 1) - r * (x * x + 1) + r * r * (x * x * x + 1) / 3);
63  double za = -dzcom - m_height;
64  double zb = -dzcom;
65  double zc = -dzcom + x * m_height;
66 
68  {// base:
69  {-a, -a, za},
70  {a, -a, za},
71  {a, a, za},
72  {-a, a, za},
73  // middle
74  {-b, -b, zb},
75  {b, -b, zb},
76  {b, b, zb},
77  {-b, b, zb},
78  // top
79  {-c, -c, zc},
80  {c, -c, zc},
81  {c, c, zc},
82  {-c, c, zc}});
83 }
84 
85 Bipyramid4::Bipyramid4(double length, double height, double height_ratio, double alpha)
86  : Bipyramid4(std::vector<double>{length, height, height_ratio, alpha})
87 {
88 }
Defines class Bipyramid4.
Defines M_PI and some more mathematical constants.
Defines namespace Math.
Defines class Pyramid4.
A truncated bifrustum with quadratic base.
Definition: Bipyramid4.h:23
Bipyramid4(double length, double height, double height_ratio, double alpha)
Definition: Bipyramid4.cpp:85
double alpha() const
Definition: Bipyramid4.h:45
double length() const
Definition: Bipyramid4.h:42
const double & m_height
Definition: Bipyramid4.h:52
double height() const
Definition: Bipyramid4.h:43
static const ff::PolyhedralTopology topology
Definition: Bipyramid4.h:49
const double & m_height_ratio
Definition: Bipyramid4.h:53
const double & m_length
Definition: Bipyramid4.h:51
const double & m_alpha
Definition: Bipyramid4.h:54
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
double cot(double x)
cotangent function:
Definition: Functions.cpp:47