BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
InterferenceFunction2DSuperLattice.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Aggregate/InterferenceFunction2DSuperLattice.cpp
6 //! @brief Implements class InterferenceFunction2DSuperLattice.
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"
18 #include "Base/Math/IntegratorGK.h"
21 
22 #include <limits>
23 
25  unsigned size_1,
26  unsigned size_2)
28  , m_integrate_xi(false)
29  , m_substructure(nullptr)
30  , m_size_1(size_1)
31  , m_size_2(size_2)
32 {
33  setName("Interference2DSuperLattice");
34  m_lattice.reset(lattice.clone());
35  registerChild(m_lattice.get());
37 }
38 
39 //! Constructor of two-dimensional interference function.
40 //! @param length_1: length of first lattice vector in nanometers
41 //! @param length_2: length of second lattice vector in nanometers
42 //! @param alpha: angle between lattice vectors in radians
43 //! @param xi: rotation of lattice with respect to x-axis (beam direction) in radians
44 //! @param size_1: correlation length in direction 1
45 //! @param size_2: correlation length in direction 2
47  double length_1, double length_2, double alpha, double xi, unsigned size_1, unsigned size_2)
48  : InterferenceFunction2DSuperLattice(BasicLattice2D(length_1, length_2, alpha, xi), size_1,
49  size_2)
50 {
51 }
52 
54 
56 {
58  ret->setPositionVariance(m_position_var);
59  ret->setSubstructureIFF(*m_substructure);
60  ret->setIntegrationOverXi(integrationOverXi());
61  return ret;
62 }
63 
65 {
66  m_substructure.reset(sub_iff.clone());
68 }
69 
71 {
72  return *m_substructure;
73 }
74 
75 double InterferenceFunction2DSuperLattice::evaluate(const kvector_t q, double outer_iff) const
76 {
77  m_outer_iff = outer_iff;
78  m_qx = q.x();
79  m_qy = q.y();
80  if (!m_integrate_xi)
81  return interferenceForXi(m_lattice->rotationAngle());
82  return RealIntegrator().integrate([&](double xi) -> double { return interferenceForXi(xi); },
83  0.0, M_TWOPI)
84  / M_TWOPI;
85 }
86 
88 {
89  m_integrate_xi = integrate_xi;
90  m_lattice->setRotationEnabled(!m_integrate_xi); // deregister Xi in the case of integration
91 }
92 
94 {
95  if (!m_lattice)
96  throw std::runtime_error("InterferenceFunctionFinite2DLattice::lattice() -> Error. "
97  "No lattice defined.");
98  return *m_lattice;
99 }
100 
101 std::vector<const INode*> InterferenceFunction2DSuperLattice::getChildren() const
102 {
103  return std::vector<const INode*>() << m_lattice << m_substructure;
104 }
105 
107 {
108  using Math::Laue;
109 
110  const double a = m_lattice->length1();
111  const double b = m_lattice->length2();
112  const double xialpha = m_xi + m_lattice->latticeAngle();
113 
114  const double qadiv2 = (q.x() * a * std::cos(m_xi) + q.y() * a * std::sin(m_xi)) / 2.0;
115  const double qbdiv2 = (q.x() * b * std::cos(xialpha) + q.y() * b * std::sin(xialpha)) / 2.0;
116  const double ampl = Laue(qadiv2, m_size_1) * Laue(qbdiv2, m_size_2);
117  return ampl * ampl / (m_size_1 * m_size_2);
118 }
119 
121 {
122  m_xi = xi; // TODO ASAP don't set as collateratel effect; rm mutable
123  const kvector_t q = kvector_t(m_qx, m_qy, 0.0);
124  const double outer_iff = iff_no_inner(q, m_outer_iff);
125  const double delta_xi = xi - m_lattice->rotationAngle();
126  return m_substructure->evaluate(q.rotatedZ(-delta_xi), outer_iff);
127 }
Defines M_PI and some more mathematical constants.
#define M_TWOPI
Definition: Constants.h:54
Defines functions in namespace Math.
Defines classes RealIntegrator, ComplexIntegrator.
Defines class InterferenceFunction2DSuperLattice.
Defines class InterferenceFunctionNone.
Defines class RealParameter.
BasicVector3D< double > kvector_t
Definition: Vectors3D.h:21
A two-dimensional Bravais lattice with no special symmetry.
Definition: Lattice2D.h:53
BasicVector3D< T > rotatedZ(double a) const
Returns result of rotation around z-axis.
T y() const
Returns y-component in cartesian coordinate system.
Definition: BasicVector3D.h:65
T x() const
Returns x-component in cartesian coordinate system.
Definition: BasicVector3D.h:63
Abstract base class of interference functions.
double iff_no_inner(const kvector_t q, double outer_iff) const
Calculates the structure factor in the absence of extra inner structure.
virtual IInterferenceFunction * clone() const =0
Returns a clone of this ISampleNode object.
void registerChild(INode *node)
Definition: INode.cpp:57
void setName(const std::string &name)
Interference function of a 2D superlattice with a configurable interference function for each lattice...
InterferenceFunction2DSuperLattice * clone() const override
Returns a clone of this ISampleNode object.
unsigned m_size_2
Size of the finite lattice in lattice units.
InterferenceFunction2DSuperLattice(const Lattice2D &lattice, unsigned size_1, unsigned size_2)
void setSubstructureIFF(const IInterferenceFunction &sub_iff)
std::vector< const INode * > getChildren() const override
Returns a vector of children.
double evaluate(const kvector_t q, double outer_iff=1.0) const override
Evaluates the interference function for a given wavevector transfer.
std::unique_ptr< IInterferenceFunction > m_substructure
IFF of substructure.
double iff_without_dw(const kvector_t q) const override
Calculates the structure factor without Debye-Waller factor.
bool m_integrate_xi
Integrate over the orientation xi.
const IInterferenceFunction & substructureIFF() const
Default interference function (i.e.
A two-dimensional Bravais lattice.
Definition: Lattice2D.h:23
virtual Lattice2D * clone() const =0
To integrate a real function of a real variable.
Definition: IntegratorGK.h:28
double integrate(const std::function< double(double)> &f, double lmin, double lmax)
double Laue(const double x, size_t N)
Real Laue function: .
Definition: Functions.cpp:76