BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Interference1DLattice.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Aggregate/Interference1DLattice.cpp
6 //! @brief Implements class Interference1DLattice.
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/Util/Assert.h"
17 #include "Fit/Param/RealLimits.h"
20 #include <algorithm>
21 
22 namespace {
23 
24 // maximum value for qx*Lambdax
25 const int nmax = 20;
26 // minimum number of neighboring reciprocal lattice points to use
27 const int min_points = 4;
28 
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  : IInterference(0)
36  , m_length(length)
37  , m_xi(xi)
38  , m_na{0}
39 {
41 }
42 
44 
46 {
47  auto* result = new Interference1DLattice(m_length, m_xi);
48  result->setPositionVariance(m_position_var);
49  result->m_na = m_na;
50  if (m_decay)
51  result->setDecayFunction(*m_decay);
52  return result;
53 }
54 
55 //! Sets one-dimensional decay function.
56 //! @param decay: one-dimensional decay function in reciprocal space
58 {
59  m_decay.reset(decay.clone());
60  double decay_length = m_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*> Interference1DLattice::nodeChildren() const
67 {
68  return std::vector<const INode*>() << m_decay;
69 }
70 
71 double Interference1DLattice::iff_without_dw(const R3 q) const
72 {
73  ASSERT(m_decay);
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 += m_decay->decayFT(qx);
93  }
94  return result / a;
95 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:45
#define M_TWOPI
Definition: Constants.h:54
Defines class Interference1DLattice.
Defines interface class IProfile1D, and children thereof.
Defines interface class IProfile2D, and children thereof.
Defines class RealLimits.
Abstract base class of interference functions.
Definition: IInterference.h:24
double m_position_var
Definition: IInterference.h:53
Interface for a one-dimensional distribution, with normalization adjusted so that the Fourier transfo...
Definition: Profiles1D.h:29
IProfile1D * clone() const override=0
Interference function of a 1D lattice.
int m_na
determines the number of reciprocal lattice points to use
void setDecayFunction(const IProfile1D &decay)
Sets one-dimensional decay function.
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.
Interference1DLattice * clone() const override
std::unique_ptr< IProfile1D > m_decay
~Interference1DLattice() override
Interference1DLattice(double length, double xi)
Constructor of interference function of one-dimensional lattice.
void check(const std::string &name, double value) const
Throws if value is outside limits. Parameter 'name' is for exception message.
Definition: RealLimits.cpp:170
static RealLimits nonnegative()
Creates an object which can have only positive values with 0. included.
Definition: RealLimits.cpp:124