BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
PolyhedralComponents.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/HardParticle/PolyhedralComponents.h
6 //! @brief Defines classes PolyhedralEdge, PolyhedralFace
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 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_SAMPLE_HARDPARTICLE_POLYHEDRALCOMPONENTS_H
21 #define BORNAGAIN_SAMPLE_HARDPARTICLE_POLYHEDRALCOMPONENTS_H
22 
23 #include "Base/Vector/Vectors3D.h"
24 #include <vector>
25 
26 #ifdef ALGORITHM_DIAGNOSTIC
27 #include <string>
28 struct PolyhedralDiagnosis {
29  int algo;
30  int order;
31  std::string msg;
32  void reset();
33  std::string message() const;
34  bool operator==(const PolyhedralDiagnosis&) const;
35  bool operator!=(const PolyhedralDiagnosis&) const;
36 };
37 inline PolyhedralDiagnosis polyhedralDiagnosis;
38 #endif
39 
40 //! One edge of a polygon, for form factor computation.
41 
43 public:
44  PolyhedralEdge(const kvector_t _Vlow, const kvector_t _Vhig);
45 
46  kvector_t E() const { return m_E; }
47  kvector_t R() const { return m_R; }
48  complex_t qE(cvector_t q) const { return m_E.dot(q); }
49  complex_t qR(cvector_t q) const { return m_R.dot(q); }
50 
51  complex_t contrib(int m, cvector_t qpa, complex_t qrperp) const;
52 
53 private:
54  kvector_t m_E; //!< vector pointing from mid of edge to upper vertex
55  kvector_t m_R; //!< position vector of edge midpoint
56 };
57 
58 //! A polygon, for form factor computation.
59 
61 public:
62  static double diameter(const std::vector<kvector_t>& V);
63 
64  PolyhedralFace(const std::vector<kvector_t>& _V = std::vector<kvector_t>(),
65  bool _sym_S2 = false);
66 
67  double area() const { return m_area; }
68  double pyramidalVolume() const { return m_rperp * m_area / 3; }
69  double radius3d() const { return m_radius_3d; }
70  //! Returns conj(q)*normal [BasicVector3D::dot is antilinear in 'this' argument]
72  complex_t ff_n(int m, cvector_t q) const;
73  complex_t ff(cvector_t q, bool sym_Ci) const;
74  complex_t ff_2D(cvector_t qpa) const;
75  complex_t ff_2D_direct(cvector_t qpa) const; // for TestTriangle
76  complex_t ff_2D_expanded(cvector_t qpa) const; // for TestTriangle
77  void assert_Ci(const PolyhedralFace& other) const;
78 
79 private:
80  static double qpa_limit_series; //!< determines when use power series
81  static int n_limit_series;
82 
83  bool sym_S2; //!< if true, then edges obtainable by inversion are not provided
84  std::vector<PolyhedralEdge> edges;
85  double m_area;
86  kvector_t m_normal; //!< normal vector of this polygon's plane
87  double m_rperp; //!< distance of this polygon's plane from the origin, along 'm_normal'
88  double m_radius_2d; //!< radius of enclosing cylinder
89  double m_radius_3d; //!< radius of enclosing sphere
90 
91  void decompose_q(cvector_t q, complex_t& qperp, cvector_t& qpa) const;
92  complex_t ff_n_core(int m, cvector_t qpa, complex_t qperp) const;
93  complex_t edge_sum_ff(cvector_t q, cvector_t qpa, bool sym_Ci) const;
94  complex_t expansion(complex_t fac_even, complex_t fac_odd, cvector_t qpa,
95  double abslevel) const;
96 };
97 
98 #endif // BORNAGAIN_SAMPLE_HARDPARTICLE_POLYHEDRALCOMPONENTS_H
99 #endif // USER_API
std::complex< double > complex_t
Definition: Complex.h:20
bool operator!=(const Material &left, const Material &right)
Comparison operator for material wrapper (inequality check)
Definition: Material.cpp:126
bool operator==(const Material &left, const Material &right)
Comparison operator for material wrapper (equality check)
Definition: Material.cpp:113
Defines basic vectors in Z^3, R^3, C^3.
auto dot(const BasicVector3D< U > &v) const
Returns dot product of vectors (antilinear in the first [=self] argument).
One edge of a polygon, for form factor computation.
PolyhedralEdge(const kvector_t _Vlow, const kvector_t _Vhig)
kvector_t E() const
kvector_t m_R
position vector of edge midpoint
kvector_t R() const
complex_t qE(cvector_t q) const
complex_t qR(cvector_t q) const
complex_t contrib(int m, cvector_t qpa, complex_t qrperp) const
Returns sum_l=0^M/2 u^2l v^(M-2l) / (2l+1)!(M-2l)! - vperp^M/M!
kvector_t m_E
vector pointing from mid of edge to upper vertex
A polygon, for form factor computation.
complex_t ff_2D_direct(cvector_t qpa) const
Two-dimensional form factor, for use in prism, from sum over edge form factors.
complex_t ff_n(int m, cvector_t q) const
Returns contribution qn*f_n [of order q^(n+1)] from this face to the polyhedral form factor.
complex_t normalProjectionConj(cvector_t q) const
Returns conj(q)*normal [BasicVector3D::dot is antilinear in 'this' argument].
bool sym_S2
if true, then edges obtainable by inversion are not provided
complex_t ff_n_core(int m, cvector_t qpa, complex_t qperp) const
Returns core contribution to f_n.
static int n_limit_series
static double qpa_limit_series
determines when use power series
double radius3d() const
double m_radius_2d
radius of enclosing cylinder
double m_rperp
distance of this polygon's plane from the origin, along 'm_normal'
complex_t ff_2D_expanded(cvector_t qpa) const
Two-dimensional form factor, for use in prism, from power series.
static double diameter(const std::vector< kvector_t > &V)
Static method, returns diameter of circle that contains all vertices.
double pyramidalVolume() const
complex_t ff_2D(cvector_t qpa) const
Returns the two-dimensional form factor of this face, for use in a prism.
complex_t expansion(complex_t fac_even, complex_t fac_odd, cvector_t qpa, double abslevel) const
Returns sum of n>=1 terms of qpa expansion of 2d form factor.
PolyhedralFace(const std::vector< kvector_t > &_V=std::vector< kvector_t >(), bool _sym_S2=false)
Sets internal variables for given vertex chain.
std::vector< PolyhedralEdge > edges
void decompose_q(cvector_t q, complex_t &qperp, cvector_t &qpa) const
Sets qperp and qpa according to argument q and to this polygon's normal.
double area() const
kvector_t m_normal
normal vector of this polygon's plane
void assert_Ci(const PolyhedralFace &other) const
Throws if deviation from inversion symmetry is detected. Does not check vertices.
complex_t edge_sum_ff(cvector_t q, cvector_t qpa, bool sym_Ci) const
Returns core contribution to analytic 2d form factor.
complex_t ff(cvector_t q, bool sym_Ci) const
Returns the contribution ff(q) of this face to the polyhedral form factor.
double m_radius_3d
radius of enclosing sphere
Some additions to standard library algorithms.
Definition: Algorithms.h:31