BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Interference2DSuperLattice.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Aggregate/Interference2DSuperLattice.cpp
6 //! @brief Implements class Interference2DSuperLattice.
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"
19 #include "Base/Util/Assert.h"
21 
22 #include <limits>
23 
25  unsigned size_2)
26  : IInterference(0)
27  , m_integrate_xi(false)
28  , m_substructure(nullptr)
29  , m_size_1(size_1)
30  , m_size_2(size_2)
31 {
32  m_lattice.reset(lattice.clone());
34 }
35 
36 //! Constructor of two-dimensional interference function.
37 //! @param length_1: length of first lattice vector in nanometers
38 //! @param length_2: length of second lattice vector in nanometers
39 //! @param alpha: angle between lattice vectors in radians
40 //! @param xi: rotation of lattice with respect to x-axis (beam direction) in radians
41 //! @param size_1: correlation length in direction 1
42 //! @param size_2: correlation length in direction 2
44  double alpha, double xi, unsigned size_1,
45  unsigned size_2)
46  : Interference2DSuperLattice(BasicLattice2D(length_1, length_2, alpha, xi), size_1, size_2)
47 {
48 }
49 
51 
53 {
55  result->setPositionVariance(m_position_var);
56  result->setSubstructureIFF(*m_substructure);
57  result->setIntegrationOverXi(integrationOverXi());
58  return result;
59 }
60 
62 {
63  m_substructure.reset(sub_iff.clone());
64 }
65 
67 {
68  return *m_substructure;
69 }
70 
71 double Interference2DSuperLattice::structureFactor(const R3 q, double outer_iff) const
72 {
73  if (!m_integrate_xi)
74  return interferenceForXi(m_lattice->rotationAngle(), q.x(), q.y(), outer_iff);
75  return RealIntegrator().integrate(
76  [&](double xi) -> double { return interferenceForXi(xi, q.x(), q.y(), outer_iff); },
77  0.0, M_TWOPI)
78  / M_TWOPI;
79 }
80 
82 {
83  m_integrate_xi = integrate_xi;
84  m_lattice->setRotationEnabled(!m_integrate_xi); // deregister Xi in the case of integration
85 }
86 
88 {
89  if (!m_lattice)
90  throw std::runtime_error("InterferenceFinite2DLattice::lattice() -> Error. "
91  "No lattice defined.");
92  return *m_lattice;
93 }
94 
95 std::vector<const INode*> Interference2DSuperLattice::nodeChildren() const
96 {
97  return std::vector<const INode*>() << m_lattice << m_substructure;
98 }
99 
101 {
102  ASSERT(0);
103 }
104 
105 double Interference2DSuperLattice::iff_without_dw(const R3 q, double xi) const
106 {
107  using Math::Laue;
108 
109  const double a = m_lattice->length1();
110  const double b = m_lattice->length2();
111  const double xialpha = xi + m_lattice->latticeAngle();
112 
113  const double qadiv2 = (q.x() * a * std::cos(xi) + q.y() * a * std::sin(xi)) / 2.0;
114  const double qbdiv2 = (q.x() * b * std::cos(xialpha) + q.y() * b * std::sin(xialpha)) / 2.0;
115  const double ampl = Laue(qadiv2, m_size_1) * Laue(qbdiv2, m_size_2);
116  return ampl * ampl / (m_size_1 * m_size_2);
117 }
118 
119 double Interference2DSuperLattice::interferenceForXi(double xi, double qx, double qy,
120  double outer_iff) const
121 {
122  const R3 q = R3(qx, qy, 0.0);
123  const double sub_iff = DWfactor(q) * (iff_without_dw(q, xi) * outer_iff - 1.0) + 1.0;
124  const double delta_xi = xi - m_lattice->rotationAngle();
125  return m_substructure->structureFactor(q.rotatedZ(-delta_xi), sub_iff);
126 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:45
Defines M_PI and some more mathematical constants.
#define M_TWOPI
Definition: Constants.h:54
Defines namespace Math.
Defines classes RealIntegrator, ComplexIntegrator.
Defines class Interference2DSuperLattice.
Defines class InterferenceNone.
A two-dimensional Bravais lattice with no special symmetry.
Definition: Lattice2D.h:51
Abstract base class of interference functions.
Definition: IInterference.h:24
IInterference * clone() const override=0
double DWfactor(R3 q) const
structureFactors the Debye-Waller factor for a given wavevector transfer
double m_position_var
Definition: IInterference.h:53
Interference function of a 2D superlattice with a configurable interference function for each lattice...
~Interference2DSuperLattice() override
void setSubstructureIFF(const IInterference &sub_iff)
std::vector< const INode * > nodeChildren() const override
Returns all children.
double iff_without_dw(R3 q) const override
Calculates the structure factor without Debye-Waller factor.
Interference2DSuperLattice * clone() const override
std::unique_ptr< IInterference > m_substructure
IFF of substructure.
void setIntegrationOverXi(bool integrate_xi)
unsigned m_size_2
Size of the finite lattice in lattice units.
bool m_integrate_xi
Integrate over the orientation xi.
double interferenceForXi(double xi, double qx, double qy, double outer_iff) const
const IInterference & substructureIFF() const
Interference2DSuperLattice(const Lattice2D &lattice, unsigned size_1, unsigned size_2)
std::unique_ptr< Lattice2D > m_lattice
double structureFactor(R3 q, double outer_iff=1.0) const override
The interference function for a given wavevector transfer.
Default interference function (i.e. absence of any interference).
A two-dimensional Bravais lattice.
Definition: Lattice2D.h:23
Lattice2D * clone() const override=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(double x, size_t N)
Real Laue function: .
Definition: Functions.cpp:77