BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Prism.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/HardParticle/Prism.cpp
6 //! @brief Implements class Prism.
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 
15 //! The mathematics implemented here is described in full detail in a paper
16 //! by Joachim Wuttke, entitled
17 //! "Form factor (Fourier shape transform) of polygon and polyhedron."
18 
21 #include <stdexcept> // need overlooked by g++ 5.4
22 
23 Prism::Prism(bool symmetry_Ci, double height, const std::vector<kvector_t>& vertices)
24 {
25  m_height = height;
26  m_vertices.clear();
27  for (const kvector_t& vertex : vertices) {
28  m_vertices.push_back(vertex);
29  m_vertices.push_back(vertex + kvector_t{0, 0, m_height});
30  }
31 
32  try {
33  m_base = std::unique_ptr<PolyhedralFace>(new PolyhedralFace(vertices, symmetry_Ci));
34  } catch (std::invalid_argument& e) {
35  throw std::invalid_argument(std::string("Invalid parameterization of Prism: ") + e.what());
36  } catch (std::logic_error& e) {
37  throw std::logic_error(std::string("Bug in Prism: ") + e.what()
38  + " [please report to the maintainers]");
39  } catch (std::exception& e) {
40  throw std::runtime_error(std::string("Unexpected exception in Prism: ") + e.what()
41  + " [please report to the maintainers]");
42  }
43 }
44 
45 double Prism::area() const
46 {
47  return m_base->area();
48 }
49 
50 const std::vector<kvector_t>& Prism::vertices()
51 {
52  return m_vertices;
53 }
54 
56 {
57  try {
58 #ifdef POLYHEDRAL_DIAGNOSTIC
59  diagnosis.maxOrder = 0;
60  diagnosis.nExpandedFaces = 0;
61 #endif
62  cvector_t qxy(q.x(), q.y(), 0.);
63  return m_height * exp_I(m_height / 2 * q.z()) * MathFunctions::sinc(m_height / 2 * q.z())
64  * m_base->ff_2D(qxy);
65  } catch (std::logic_error& e) {
66  throw std::logic_error(std::string("Bug in Prism: ") + e.what()
67  + " [please report to the maintainers]");
68  } catch (std::runtime_error& e) {
69  throw std::runtime_error(std::string("Numeric computation failed in Prism: ") + e.what()
70  + " [please report to the maintainers]");
71  } catch (std::exception& e) {
72  throw std::runtime_error(std::string("Unexpected exception in Prism: ") + e.what()
73  + " [please report to the maintainers]");
74  }
75 }
std::complex< double > complex_t
Definition: Complex.h:20
complex_t exp_I(complex_t z)
Returns exp(I*z), where I is the imaginary unit.
Definition: Complex.h:30
Defines namespace MathFunctions.
Defines class Prism.
T z() const
Returns z-component in cartesian coordinate system.
Definition: BasicVector3D.h:68
T y() const
Returns y-component in cartesian coordinate system.
Definition: BasicVector3D.h:66
T x() const
Returns x-component in cartesian coordinate system.
Definition: BasicVector3D.h:64
A polygon, for form factor computation.
Prism()=delete
complex_t evaluate_for_q(const cvector_t &q) const
needed for topZ, bottomZ computation
Definition: Prism.cpp:55
std::unique_ptr< PolyhedralFace > m_base
Definition: Prism.h:33
double m_height
Definition: Prism.h:34
double area() const
Definition: Prism.cpp:45
std::vector< kvector_t > m_vertices
Definition: Prism.h:35
const std::vector< kvector_t > & vertices()
Definition: Prism.cpp:50
double sinc(double x)
sinc function: