BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IBornFF.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Scattering/IBornFF.cpp
6 //! @brief Implements interface class IBornFF.
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/Utils/Algorithms.h"
19 #include "Sample/Shapes/IShape3D.h"
20 
21 IBornFF::IBornFF() = default;
22 
23 IBornFF::IBornFF(const NodeMeta& meta, const std::vector<double>& PValues)
24  : IFormFactor(meta, PValues)
25 {
26 }
27 
28 IBornFF::~IBornFF() = default;
29 
30 complex_t IBornFF::evaluate(const WavevectorInfo& wavevectors) const
31 {
32  return evaluate_for_q(wavevectors.getQ());
33 }
34 
35 Eigen::Matrix2cd IBornFF::evaluatePol(const WavevectorInfo& wavevectors) const
36 {
37  return evaluate_for_q_pol(wavevectors.getQ());
38 }
39 
40 double IBornFF::bottomZ(const IRotation& rotation) const
41 {
42  if (!m_shape3D)
43  return 0;
44  return BottomZ(m_shape3D->vertices(), rotation);
45 }
46 
47 double IBornFF::topZ(const IRotation& rotation) const
48 {
49  if (!m_shape3D)
50  return 0;
51  return TopZ(m_shape3D->vertices(), rotation);
52 }
53 
55 {
56  if (rot.zInvariant())
57  return true;
58  return false;
59 }
60 
61 Eigen::Matrix2cd IBornFF::evaluate_for_q_pol(cvector_t q) const
62 {
63  return evaluate_for_q(q) * Eigen::Matrix2cd::Identity();
64 }
65 
67  double height)
68 {
69  kvector_t new_position(position);
70  double z_bottom = position.z();
71  double z_top = position.z() + height;
72  OneSidedLimit lower_limit = limits.lowerLimit();
73  OneSidedLimit upper_limit = limits.upperLimit();
74  ASSERT(upper_limit.m_limitless || lower_limit.m_limitless
75  || lower_limit.m_value <= upper_limit.m_value);
76  double dz_top = upper_limit.m_limitless ? -1 : z_top - upper_limit.m_value;
77  double dz_bottom = lower_limit.m_limitless ? -1 : lower_limit.m_value - z_bottom;
78  ASSERT(dz_top >= 0 || dz_bottom >= 0);
79  ASSERT(dz_bottom <= height);
80  ASSERT(dz_top <= height);
81  if (dz_bottom < 0)
82  dz_bottom = 0;
83  if (dz_top < 0)
84  dz_top = 0;
85  if (dz_bottom > 0)
86  new_position.setZ(lower_limit.m_value);
87  return {new_position, dz_bottom, dz_top};
88 }
89 
90 double IBornFF::BottomZ(const std::vector<kvector_t>& vertices, const IRotation& rotation)
91 {
92  ASSERT(vertices.size());
93  return algo::min_value(
94  vertices.begin(), vertices.end(),
95  [&](const kvector_t& vertex) -> double { return rotation.transformed(vertex).z(); });
96 }
97 
98 double IBornFF::TopZ(const std::vector<kvector_t>& vertices, const IRotation& rotation)
99 {
100  ASSERT(vertices.size());
101  return algo::max_value(
102  vertices.begin(), vertices.end(),
103  [&](const kvector_t& vertex) -> double { return rotation.transformed(vertex).z(); });
104 }
Defines and implements namespace algo with some algorithms.
#define ASSERT(condition)
Definition: Assert.h:31
std::complex< double > complex_t
Definition: Complex.h:20
Defines interface IBornFF.
Defines interface IShape3D.
Defines IRotation classes.
Defines WavevectorInfo.
T z() const
Returns z-component in cartesian coordinate system.
Definition: BasicVector3D.h:67
void setZ(const T &a)
Sets z-component in cartesian coordinate system.
Definition: BasicVector3D.h:74
std::unique_ptr< IShape3D > m_shape3D
IShape3D object, used to retrieve vertices (which may be approximate in the case of round shapes).
Definition: IBornFF.h:77
virtual Eigen::Matrix2cd evaluate_for_q_pol(cvector_t q) const
Returns scattering amplitude for complex scattering wavevector q=k_i-k_f in case of matrix interactio...
Definition: IBornFF.cpp:61
Eigen::Matrix2cd evaluatePol(const WavevectorInfo &wavevectors) const override
Returns scattering amplitude for matrix interactions.
Definition: IBornFF.cpp:35
static double TopZ(const std::vector< kvector_t > &vertices, const IRotation &rotation)
Calculates the z-coordinate of the highest vertex after rotation.
Definition: IBornFF.cpp:98
bool canSliceAnalytically(const IRotation &rot) const override
Default implementation only allows rotations along z-axis.
Definition: IBornFF.cpp:54
virtual double bottomZ(const IRotation &rotation) const override
Returns the z-coordinate of the lowest point in this shape after a given rotation.
Definition: IBornFF.cpp:40
virtual double topZ(const IRotation &rotation) const override
Returns the z-coordinate of the lowest point in this shape after a given rotation.
Definition: IBornFF.cpp:47
virtual complex_t evaluate_for_q(cvector_t q) const =0
Returns scattering amplitude for complex scattering wavevector q=k_i-k_f.
complex_t evaluate(const WavevectorInfo &wavevectors) const override
Returns scattering amplitude for complex wavevectors ki, kf.
Definition: IBornFF.cpp:30
static double BottomZ(const std::vector< kvector_t > &vertices, const IRotation &rotation)
Calculates the z-coordinate of the lowest vertex after rotation.
Definition: IBornFF.cpp:90
static SlicingEffects computeSlicingEffects(ZLimits limits, const kvector_t &position, double height)
Helper method for slicing.
Definition: IBornFF.cpp:66
Abstract base class for all form factors.
Definition: IFormFactor.h:36
Abstract base class for rotations.
Definition: Rotations.h:28
bool zInvariant() const
Definition: Rotations.cpp:63
Holds all wavevector information relevant for calculating form factors.
cvector_t getQ() const
Class that contains upper and lower limits of the z-coordinate for the slicing of form factors.
Definition: ZLimits.h:45
OneSidedLimit lowerLimit() const
Definition: ZLimits.cpp:39
OneSidedLimit upperLimit() const
Definition: ZLimits.cpp:44
double max_value(const Iterator &begin, const Iterator &end, const Evaluator &evaluate)
Returns the maximum value of function evaluate as applied to the elements of an iterator range.
Definition: Algorithms.h:69
double min_value(const Iterator &begin, const Iterator &end, const Evaluator &evaluate)
Returns the minimum value of function evaluate as applied to the elements of an iterator range.
Definition: Algorithms.h:58
Metadata of one model node.
Definition: INode.h:38
Helper class that represents a onesided limit.
Definition: ZLimits.h:35
double m_value
Definition: ZLimits.h:37
bool m_limitless
Definition: ZLimits.h:36
Nested structure that holds slicing effects on position and removed parts.
Definition: IBornFF.h:27