BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
InterferenceFunctionFinite2DLattice.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Aggregate/InterferenceFunctionFinite2DLattice.cpp
6 //! @brief Implements class InterferenceFunctionFinite2DLattice.
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"
20 
21 #include <limits>
22 
23 using Math::Laue;
24 
25 //! Constructor of two-dimensional finite lattice interference function.
26 //! @param lattice: object specifying a 2d lattice structure
27 //! @param N_1: number of lattice cells in the first lattice direction
28 //! @param N_2: number of lattice cells in the second lattice direction
30  unsigned N_1, unsigned N_2)
31  : IInterferenceFunction(0), m_integrate_xi(false), m_N_1(N_1), m_N_2(N_2)
32 {
33  setName("InterferenceFinite2DLattice");
34  m_lattice.reset(lattice.clone());
35  registerChild(m_lattice.get());
36 }
37 
39 
41 {
43  ret->setPositionVariance(m_position_var);
44  ret->setIntegrationOverXi(integrationOverXi());
45  return ret;
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("InterferenceFunctionFinite2DLattice::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*> InterferenceFunctionFinite2DLattice::getChildren() const
69 {
70  return std::vector<const INode*>() << m_lattice;
71 }
72 
74 {
75  m_qx = q.x();
76  m_qy = q.y();
77  if (!m_integrate_xi)
78  return interferenceForXi(m_lattice->rotationAngle());
79  return RealIntegrator().integrate([&](double xi) -> double { return interferenceForXi(xi); },
80  0.0, M_TWOPI)
81  / M_TWOPI;
82 }
83 
85 {
86  double a = m_lattice->length1();
87  double b = m_lattice->length2();
88  double xialpha = xi + m_lattice->latticeAngle();
89 
90  double qadiv2 = (m_qx * a * std::cos(xi) + m_qy * a * std::sin(xi)) / 2.0;
91  double qbdiv2 = (m_qx * b * std::cos(xialpha) + m_qy * b * std::sin(xialpha)) / 2.0;
92  double ampl = Laue(qadiv2, m_N_1) * Laue(qbdiv2, m_N_2);
93  double lattice_factor = ampl * ampl / (m_N_1 * m_N_2);
94 
95  return lattice_factor;
96 }
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 InterferenceFunctionFinite2DLattice.
Defines class RealParameter.
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.
void registerChild(INode *node)
Definition: INode.cpp:57
void setName(const std::string &name)
Interference function of a finite 2D lattice.
bool m_integrate_xi
Integrate over the orientation xi.
std::vector< const INode * > getChildren() const override
Returns a vector of children.
unsigned m_N_2
Size of the finite lattice in lattice units.
InterferenceFunctionFinite2DLattice(const Lattice2D &lattice, unsigned N_1, unsigned N_2)
Constructor of two-dimensional finite lattice interference function.
double iff_without_dw(const kvector_t q) const override
Calculates the structure factor without Debye-Waller factor.
double getParticleDensity() const override
Returns the particle density associated with this 2d lattice.
InterferenceFunctionFinite2DLattice * clone() const override
Returns a clone of this ISampleNode object.
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