BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
InterferenceFunction1DLattice.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Aggregate/InterferenceFunction1DLattice.cpp
6 //! @brief Implements class InterferenceFunction1DLattice.
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/Types/Exceptions.h"
17 #include "Base/Utils/Assert.h"
21 #include <algorithm>
22 
23 namespace
24 {
25 // maximum value for qx*Lambdax
26 const int nmax = 20;
27 // minimum number of neighboring reciprocal lattice points to use
28 const int min_points = 4;
29 } // namespace
30 
31 //! Constructor of interference function of one-dimensional lattice.
32 //! @param length: lattice constant in nanometers
33 //! @param xi: rotation of lattice with respect to x-axis in radians
35  : IInterferenceFunction(0), m_length(length), m_xi(xi), m_na{0}
36 {
37  setName("Interference1DLattice");
39  registerParameter("Xi", &m_xi).setUnit("rad");
40 }
41 
43 
45 {
47  ret->setPositionVariance(m_position_var);
48  ret->m_na = m_na;
49  if (mP_decay)
50  ret->setDecayFunction(*mP_decay);
51  return ret;
52 }
53 
54 //! Sets one-dimensional decay function.
55 //! @param decay: one-dimensional decay function in reciprocal space
57 {
58  mP_decay.reset(decay.clone());
59  registerChild(mP_decay.get());
60  double decay_length = mP_decay->decayLength();
61  double qa_max = m_length * nmax / decay_length / M_TWOPI;
62  m_na = static_cast<int>(std::lround(std::abs(qa_max) + 0.5));
63  m_na = std::max(m_na, min_points);
64 }
65 
66 std::vector<const INode*> InterferenceFunction1DLattice::getChildren() const
67 {
68  return std::vector<const INode*>() << mP_decay;
69 }
70 
72 {
74  double result = 0.0;
75  double qxr = q.x();
76  double qyr = q.y();
77  double qx_frac;
78  double xi = m_xi;
79  double a = m_length;
80  double a_rec = M_TWOPI / a;
81 
82  // rotate the q vector to xi angle
83  // so that qx_prime is along the a axis of lattice
84  double qx_prime = qxr * std::cos(xi) + qyr * std::sin(xi);
85 
86  // calculate reciprocal vector fraction
87  int qa_int = static_cast<int>(qx_prime / a_rec);
88  qx_frac = qx_prime - qa_int * a_rec;
89 
90  for (int i = -m_na; i < m_na + 1; ++i) {
91  double qx = qx_frac + i * a_rec;
92  result += mP_decay->evaluate(qx);
93  }
94  return result / a;
95 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:26
Defines many exception classes in namespace Exceptionss.
Defines classes IFTDecayFunction1D, IFTDecayFunction2D,.
Defines classes IFTDecayFunction1D, IFTDecayFunction2D,.
Defines class InterferenceFunction1DLattice.
#define M_TWOPI
Definition: MathConstants.h:49
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
Interface for a one-dimensional decay function, with evaluate(q) returning the Fourier transform,...
Definition: FTDecay1D.h:28
virtual IFTDecayFunction1D * clone() const =0
Pure virtual base class of interference functions.
void registerChild(INode *node)
Definition: INode.cpp:58
RealParameter & registerParameter(const std::string &name, double *parpointer)
void setName(const std::string &name)
Interference function of a 1D lattice.
std::vector< const INode * > getChildren() const override final
Returns a vector of children (const).
InterferenceFunction1DLattice * clone() const override final
Returns a clone of this ISample object.
InterferenceFunction1DLattice(double length, double xi)
Constructor of interference function of one-dimensional lattice.
int m_na
determines the number of reciprocal lattice points to use
void setDecayFunction(const IFTDecayFunction1D &decay)
Sets one-dimensional decay function.
std::unique_ptr< IFTDecayFunction1D > mP_decay
double iff_without_dw(const kvector_t q) const override final
Calculates the structure factor without Debye-Waller factor.
RealParameter & setNonnegative()
RealParameter & setUnit(const std::string &name)