BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
InterferenceFinite2DLattice.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Aggregate/InterferenceFinite2DLattice.cpp
6 //! @brief Implements class InterferenceFinite2DLattice.
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 
20 #include <limits>
21 
22 using Math::Laue;
23 
24 //! Constructor of two-dimensional finite lattice interference function.
25 //! @param lattice: object specifying a 2d lattice structure
26 //! @param N_1: number of lattice cells in the first lattice direction
27 //! @param N_2: number of lattice cells in the second lattice direction
29  unsigned N_2)
30  : IInterference(0)
31  , m_integrate_xi(false)
32  , m_N_1(N_1)
33  , m_N_2(N_2)
34 {
35  m_lattice.reset(lattice.clone());
36 }
37 
39 
41 {
42  auto* result = new InterferenceFinite2DLattice(*m_lattice, m_N_1, m_N_2);
43  result->setPositionVariance(m_position_var);
44  result->setIntegrationOverXi(integrationOverXi());
45  return result;
46 }
47 
49 {
50  m_integrate_xi = integrate_xi;
51  m_lattice->setRotationEnabled(!m_integrate_xi); // deregister Xi in the case of integration
52 }
53 
55 {
56  if (!m_lattice)
57  throw std::runtime_error("InterferenceFinite2DLattice::lattice() -> Error. "
58  "No lattice defined.");
59  return *m_lattice;
60 }
61 
63 {
64  double area = m_lattice->unitCellArea();
65  return area == 0.0 ? 0.0 : 1.0 / area;
66 }
67 
68 std::vector<const INode*> InterferenceFinite2DLattice::nodeChildren() const
69 {
70  return std::vector<const INode*>() << m_lattice;
71 }
72 
74 {
75  if (!m_integrate_xi)
76  return interferenceForXi(m_lattice->rotationAngle(), q.x(), q.y());
77  return RealIntegrator().integrate(
78  [&](double xi) -> double { return interferenceForXi(xi, q.x(), q.y()); }, 0.0,
79  M_TWOPI)
80  / M_TWOPI;
81 }
82 
83 double InterferenceFinite2DLattice::interferenceForXi(double xi, double qx, double qy) const
84 {
85  double a = m_lattice->length1();
86  double b = m_lattice->length2();
87  double xialpha = xi + m_lattice->latticeAngle();
88 
89  double qadiv2 = (qx * a * std::cos(xi) + qy * a * std::sin(xi)) / 2.0;
90  double qbdiv2 = (qx * b * std::cos(xialpha) + qy * b * std::sin(xialpha)) / 2.0;
91  double ampl = Laue(qadiv2, m_N_1) * Laue(qbdiv2, m_N_2);
92  double lattice_factor = ampl * ampl / (m_N_1 * m_N_2);
93 
94  return lattice_factor;
95 }
Defines M_PI and some more mathematical constants.
#define M_TWOPI
Definition: Constants.h:54
Defines namespace Math.
Defines classes RealIntegrator, ComplexIntegrator.
Defines class InterferenceFinite2DLattice.
Abstract base class of interference functions.
Definition: IInterference.h:24
double m_position_var
Definition: IInterference.h:53
Interference function of a finite 2D lattice.
unsigned m_N_2
Size of the finite lattice in lattice units.
bool m_integrate_xi
Integrate over the orientation xi.
~InterferenceFinite2DLattice() override
double particleDensity() const override
Returns the particle density associated with this 2d lattice.
InterferenceFinite2DLattice(const Lattice2D &lattice, unsigned N_1, unsigned N_2)
Constructor of two-dimensional finite lattice interference function.
InterferenceFinite2DLattice * clone() const override
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.
std::unique_ptr< Lattice2D > m_lattice
double interferenceForXi(double xi, double qx, double qy) const
void setIntegrationOverXi(bool integrate_xi)
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