BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
InterferenceFunction3DLattice.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Aggregate/InterferenceFunction3DLattice.cpp
6 //! @brief Implements class InterferenceFunction3DLattice.
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"
18 #include <algorithm>
19 
21  : IInterferenceFunction(0), m_lattice(lattice), mP_peak_shape(nullptr), m_rec_radius(0.0)
22 {
23  setName("Interference3DLattice");
24  initRecRadius();
25 }
26 
28 
30 {
32  ret->setPositionVariance(m_position_var);
33  if (mP_peak_shape)
34  ret->setPeakShape(*mP_peak_shape);
35  return ret;
36 }
37 
39 {
40  mP_peak_shape.reset(peak_shape.clone());
41 }
42 
44 {
45  return m_lattice;
46 }
47 
48 std::vector<const INode*> InterferenceFunction3DLattice::getChildren() const
49 {
50  return {};
51 }
52 
54 {
55  initRecRadius();
56 }
57 
59 {
60  if (!mP_peak_shape)
61  throw std::runtime_error("InterferenceFunction3DLattice::evaluate: "
62  "no peak shape defined");
63  kvector_t center = q;
64  double radius = 2.1 * m_rec_radius;
65  double inner_radius = 0.0;
66  if (mP_peak_shape->angularDisorder()) {
67  center = kvector_t(0.0, 0.0, 0.0);
68  inner_radius = std::max(0.0, q.mag() - radius);
69  radius += q.mag();
70  }
71  auto rec_vectors = m_lattice.reciprocalLatticeVectorsWithinRadius(center, radius);
72  double result = 0.0;
73  for (const auto& q_rec : rec_vectors) {
74  if (!(q_rec.mag() < inner_radius)) {
75  result += mP_peak_shape->evaluate(q, q_rec);
76  }
77  }
78  return result;
79 }
80 
82 {
86 
87  m_rec_radius = std::max(M_PI / a1.mag(), M_PI / a2.mag());
88  m_rec_radius = std::max(m_rec_radius, M_PI / a3.mag());
89 }
Defines many exception classes in namespace Exceptionss.
Defines the interface IPeakShape and subclasses.
Defines class InterferenceFunction3DLattice.
#define M_PI
Definition: MathConstants.h:39
BasicVector3D< double > kvector_t
Definition: Vectors3D.h:21
double mag() const
Returns magnitude of the vector.
Pure virtual base class of interference functions.
void setName(const std::string &name)
Pure virtual interface class that defines the peak shape of a Bragg peak.
Definition: IPeakShape.h:25
virtual IPeakShape * clone() const =0
Returns a clone of this ISample object.
Interference function of a 3D lattice.
void setPeakShape(const IPeakShape &peak_shape)
double m_rec_radius
radius in reciprocal space defining the nearest q vectors to use
InterferenceFunction3DLattice(const Lattice &lattice)
void onChange() override final
Action to be taken in inherited class when a parameter has changed.
double iff_without_dw(const kvector_t q) const override final
Calculates the structure factor without Debye-Waller factor.
InterferenceFunction3DLattice * clone() const override final
Returns a clone of this ISample object.
std::vector< const INode * > getChildren() const override final
Returns a vector of children (const).
std::unique_ptr< IPeakShape > mP_peak_shape
A lattice with three basis vectors.
Definition: Lattice.h:28
kvector_t getBasisVectorB() const
Returns basis vector b.
Definition: Lattice.h:47
std::vector< kvector_t > reciprocalLatticeVectorsWithinRadius(const kvector_t input_vector, double radius) const
Computes a list of reciprocal lattice vectors within a specified distance of a given vector.
Definition: Lattice.cpp:126
kvector_t getBasisVectorC() const
Returns basis vector c.
Definition: Lattice.h:50
kvector_t getBasisVectorA() const
Returns basis vector a.
Definition: Lattice.h:44
const double radius(5 *Units::nanometer)