BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IFormFactorBorn.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Scattering/IFormFactorBorn.cpp
6 //! @brief Implements interface class IFormFactorBorn.
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/Types/Exceptions.h"
17 #include "Base/Utils/Algorithms.h"
20 #include "Sample/Shapes/IShape.h"
21 
23 
24 IFormFactorBorn::IFormFactorBorn(const NodeMeta& meta, const std::vector<double>& PValues)
25  : IFormFactor(meta, PValues)
26 {
27 }
28 
30 
32 {
33  return evaluate_for_q(wavevectors.getQ());
34 }
35 
36 Eigen::Matrix2cd IFormFactorBorn::evaluatePol(const WavevectorInfo& wavevectors) const
37 {
38  return evaluate_for_q_pol(wavevectors.getQ());
39 }
40 
41 double IFormFactorBorn::bottomZ(const IRotation& rotation) const
42 {
43  if (!mP_shape)
44  return 0;
45  return BottomZ(mP_shape->vertices(), rotation);
46 }
47 
48 double IFormFactorBorn::topZ(const IRotation& rotation) const
49 {
50  if (!mP_shape)
51  return 0;
52  return TopZ(mP_shape->vertices(), rotation);
53 }
54 
56 {
57  if (rot.zInvariant())
58  return true;
59  return false;
60 }
61 
63 {
64  return evaluate_for_q(q) * Eigen::Matrix2cd::Identity();
65 }
66 
68  double height) const
69 {
70  kvector_t new_position(position);
71  double z_bottom = position.z();
72  double z_top = position.z() + height;
73  OneSidedLimit lower_limit = limits.lowerLimit();
74  OneSidedLimit upper_limit = limits.upperLimit();
75  if (!upper_limit.m_limitless && !lower_limit.m_limitless
76  && lower_limit.m_value > upper_limit.m_value)
77  throw std::runtime_error(getName()
78  + "::sliceFormFactor error: "
79  "upperlimit < lowerlimit.");
80  double dz_top = upper_limit.m_limitless ? -1 : z_top - upper_limit.m_value;
81  double dz_bottom = lower_limit.m_limitless ? -1 : lower_limit.m_value - z_bottom;
82  if (dz_top < 0 && dz_bottom < 0)
83  throw std::runtime_error(getName()
84  + "::sliceFormFactor error: "
85  "shape didn't need to be sliced.");
86  if (dz_bottom > height)
87  throw std::runtime_error(getName()
88  + "::sliceFormFactor error: "
89  "interface outside shape.");
90  if (dz_top > height)
91  throw std::runtime_error(getName()
92  + "::sliceFormFactor error: "
93  "interface outside shape.");
94  if (dz_bottom < 0)
95  dz_bottom = 0;
96  if (dz_top < 0)
97  dz_top = 0;
98  if (dz_bottom > 0)
99  new_position.setZ(lower_limit.m_value);
100  return {new_position, dz_bottom, dz_top};
101 }
102 
103 double IFormFactorBorn::BottomZ(const std::vector<kvector_t>& vertices, const IRotation& rotation)
104 {
105  ASSERT(vertices.size());
106  return algo::min_value(
107  vertices.begin(), vertices.end(),
108  [&](const kvector_t& vertex) -> double { return rotation.transformed(vertex).z(); });
109 }
110 
111 double IFormFactorBorn::TopZ(const std::vector<kvector_t>& vertices, const IRotation& rotation)
112 {
113  ASSERT(vertices.size());
114  return algo::max_value(
115  vertices.begin(), vertices.end(),
116  [&](const kvector_t& vertex) -> double { return rotation.transformed(vertex).z(); });
117 }
Defines and implements namespace algo with some algorithms.
#define ASSERT(condition)
Definition: Assert.h:26
std::complex< double > complex_t
Definition: Complex.h:20
Defines many exception classes in namespace Exceptionss.
Defines pure virtual interface class IFormFactorBorn.
Defines interface IShape.
Defines IRotation classes.
Defines WavevectorInfo.
T z() const
Returns z-component in cartesian coordinate system.
Definition: BasicVector3D.h:68
void setZ(const T &a)
Sets z-component in cartesian coordinate system.
Definition: BasicVector3D.h:75
SlicingEffects computeSlicingEffects(ZLimits limits, const kvector_t &position, double height) const
Helper method for slicing.
bool canSliceAnalytically(const IRotation &rot) const override
Default implementation only allows rotations along z-axis.
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...
virtual complex_t evaluate_for_q(cvector_t q) const =0
Returns scattering amplitude for complex scattering wavevector q=k_i-k_f.
static double TopZ(const std::vector< kvector_t > &vertices, const IRotation &rotation)
Calculates the z-coordinate of the highest vertex after rotation.
virtual double bottomZ(const IRotation &rotation) const override
Returns the z-coordinate of the lowest point in this shape after a given rotation.
complex_t evaluate(const WavevectorInfo &wavevectors) const override
Returns scattering amplitude for complex wavevectors ki, kf.
Eigen::Matrix2cd evaluatePol(const WavevectorInfo &wavevectors) const override
Returns scattering amplitude for matrix interactions.
static double BottomZ(const std::vector< kvector_t > &vertices, const IRotation &rotation)
Calculates the z-coordinate of the lowest vertex after rotation.
std::unique_ptr< IShape > mP_shape
IShape object, used to retrieve vertices (which may be approximate in the case of round shapes).
virtual double topZ(const IRotation &rotation) const override
Returns the z-coordinate of the lowest point in this shape after a given rotation.
Pure virtual base class for all form factors.
Definition: IFormFactor.h:40
const std::string & getName() const
Pure virtual interface for rotations.
Definition: Rotations.h:27
bool zInvariant() const
Definition: Rotations.cpp:68
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:41
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:65
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:54
Metadata of one model node.
Definition: INode.h:37
Helper class that represents a onesided limit.
Definition: ZLimits.h:30
double m_value
Definition: ZLimits.h:32
bool m_limitless
Definition: ZLimits.h:31
Nested structure that holds slicing effects on position and removed parts.