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