BornAgain  1.18.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 scattering at grazing incidence
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 
17 #include "Base/Types/Exceptions.h"
18 #include "Base/Utils/Integrator.h"
21 
22 #include <limits>
23 
25 
26 //! Constructor of two-dimensional finite lattice interference function.
27 //! @param lattice: object specifying a 2d lattice structure
28 //! @param N_1: number of lattice cells in the first lattice direction
29 //! @param N_2: number of lattice cells in the second lattice direction
31  unsigned N_1, unsigned N_2)
32  : IInterferenceFunction(0), m_integrate_xi(false), m_N_1(N_1), m_N_2(N_2)
33 {
34  setName("InterferenceFinite2DLattice");
36 }
37 
38 //! Constructor of two-dimensional finite lattice interference function.
39 //! @param length_1: length of first lattice vector in nanometers
40 //! @param length_2: length of second lattice vector in nanometers
41 //! @param alpha: angle between lattice vectors in radians
42 //! @param xi: rotation of lattice with respect to x-axis (beam direction) in radians
43 //! @param N_1: number of lattice cells in the first lattice direction
44 //! @param N_2: number of lattice cells in the second lattice direction
46  double length_2,
47  double alpha, double xi,
48  unsigned N_1, unsigned N_2)
49  : InterferenceFunctionFinite2DLattice(BasicLattice(length_1, length_2, alpha, xi), N_1, N_2)
50 {
51 }
52 
54 
56 {
58  ret->setPositionVariance(m_position_var);
59  ret->setIntegrationOverXi(integrationOverXi());
60  return ret;
61 }
62 
63 //! Creates square lattice.
64 //! @param lattice_length: length of first and second lattice vectors in nanometers
65 //! @param xi: rotation of lattice with respect to x-axis in radians
66 //! @param N_1: number of lattice cells in the first lattice direction
67 //! @param N_2: number of lattice cells in the second lattice direction
69 InterferenceFunctionFinite2DLattice::createSquare(double lattice_length, double xi, unsigned N_1,
70  unsigned N_2)
71 {
72  return new InterferenceFunctionFinite2DLattice(SquareLattice(lattice_length, xi), N_1, N_2);
73 }
74 
75 //! Creates hexagonal lattice.
76 //! @param lattice_length: length of first and second lattice vectors in nanometers
77 //! @param xi: rotation of lattice with respect to x-axis in radians
78 //! @param N_1: number of lattice cells in the first lattice direction
79 //! @param N_2: number of lattice cells in the second lattice direction
81 InterferenceFunctionFinite2DLattice::createHexagonal(double lattice_length, double xi, unsigned N_1,
82  unsigned N_2)
83 {
84  return new InterferenceFunctionFinite2DLattice(HexagonalLattice(lattice_length, xi), N_1, N_2);
85 }
86 
88 {
89  m_integrate_xi = integrate_xi;
90  mP_lattice->setRotationEnabled(!m_integrate_xi); // deregister Xi in the case of integration
91 }
92 
94 {
95  if (!mP_lattice)
96  throw std::runtime_error("InterferenceFunctionFinite2DLattice::lattice() -> Error. "
97  "No lattice defined.");
98  return *mP_lattice;
99 }
100 
102 {
103  double area = mP_lattice->unitCellArea();
104  return area == 0.0 ? 0.0 : 1.0 / area;
105 }
106 
107 std::vector<const INode*> InterferenceFunctionFinite2DLattice::getChildren() const
108 {
109  return std::vector<const INode*>() << mP_lattice;
110 }
111 
113 {
114  m_qx = q.x();
115  m_qy = q.y();
116  if (!m_integrate_xi)
117  return interferenceForXi(mP_lattice->rotationAngle());
118  return RealIntegrator().integrate([&](double xi) -> double { return interferenceForXi(xi); },
119  0.0, M_TWOPI)
120  / M_TWOPI;
121 }
122 
124 {
125  mP_lattice.reset(lattice.clone());
126  registerChild(mP_lattice.get());
127 }
128 
130 {
131  double a = mP_lattice->length1();
132  double b = mP_lattice->length2();
133  double xialpha = xi + mP_lattice->latticeAngle();
134 
135  double qadiv2 = (m_qx * a * std::cos(xi) + m_qy * a * std::sin(xi)) / 2.0;
136  double qbdiv2 = (m_qx * b * std::cos(xialpha) + m_qy * b * std::sin(xialpha)) / 2.0;
137  double ampl = Laue(qadiv2, m_N_1) * Laue(qbdiv2, m_N_2);
138  double lattice_factor = ampl * ampl / (m_N_1 * m_N_2);
139 
140  return lattice_factor;
141 }
Defines many exception classes in namespace Exceptionss.
Defines classes RealIntegrator, ComplexIntegrator.
Defines class InterferenceFunctionFinite2DLattice.
Defines M_PI and some more mathematical constants.
#define M_TWOPI
Definition: MathConstants.h:49
Defines namespace MathFunctions.
Defines class RealParameter.
T y() const
Returns y-component in cartesian coordinate system.
Definition: BasicVector3D.h:66
T x() const
Returns x-component in cartesian coordinate system.
Definition: BasicVector3D.h:64
Pure virtual base class of interference functions.
void registerChild(INode *node)
Definition: INode.cpp:58
void setName(const std::string &name)
Interference function of a finite 2D lattice.
bool m_integrate_xi
Integrate over the orientation xi.
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.
InterferenceFunctionFinite2DLattice * clone() const override final
Returns a clone of this ISample object.
double getParticleDensity() const override final
Returns the particle density associated with this 2d lattice.
static InterferenceFunctionFinite2DLattice * createSquare(double lattice_length, double xi, unsigned N_1, unsigned N_2)
Creates square lattice.
static InterferenceFunctionFinite2DLattice * createHexagonal(double lattice_length, double xi, unsigned N_1, unsigned N_2)
Creates hexagonal lattice.
std::vector< const INode * > getChildren() const override final
Returns a vector of children (const).
double iff_without_dw(const kvector_t q) const override final
Calculates the structure factor without Debye-Waller factor.
virtual Lattice2D * clone() const =0
To integrate a real function of a real variable.
Definition: Integrator.h:24
double integrate(const std::function< double(double)> &f, double lmin, double lmax)
Definition: Integrator.cpp:27
double Laue(const double x, size_t N)
Real Laue function: .