BornAgain  1.19.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 reflection and scattering
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/Utils/Assert.h"
18 #include <algorithm>
19 #include <iostream>
20 
22  : IInterferenceFunction(0), m_lattice(lattice), m_peak_shape(nullptr), m_rec_radius(0.0)
23 {
24  setName("Interference3DLattice");
25  initRecRadius();
26 }
27 
29 
31 {
33  ret->setPositionVariance(m_position_var);
34  if (m_peak_shape)
35  ret->setPeakShape(*m_peak_shape);
36  return ret;
37 }
38 
40 {
41  m_peak_shape.reset(peak_shape.clone());
42 }
43 
45 {
46  return m_lattice;
47 }
48 
49 std::vector<const INode*> InterferenceFunction3DLattice::getChildren() const
50 {
51  return {};
52 }
53 
55 {
56  initRecRadius();
57 }
58 
60 {
62  kvector_t center = q;
63  double radius = 2.1 * m_rec_radius;
64  double inner_radius = 0.0;
65  // if (m_peak_shape->angularDisorder()) {
66  // center = kvector_t(0.0, 0.0, 0.0);
67  // inner_radius = std::max(0.0, q.mag() - radius);
68  // radius += q.mag();
69  // }
70  const auto rec_vectors = m_lattice.reciprocalLatticeVectorsWithinRadius(center, radius);
71  // std::cout << "IWD: q=" << q << ", r=" << radius << ", ir=" << inner_radius <<
72  // ", disordered=" << m_peak_shape->angularDisorder() << " => nVec=" << rec_vectors.size()
73  // << std::endl;
74 
75  double result = 0.0;
76  for (const auto& q_rec : rec_vectors)
77  // if (!(q_rec.mag() < inner_radius)) {
78  // result += m_peak_shape->evaluate(q, q_rec);
79  result += exp(-(q - q_rec).mag2() / 2 / pow(.06, 2));
80  // std::cout << " INCR: qr=" << q_rec << " => " << result << std::endl;
81  // }
82  return result;
83 }
84 
86 {
90 
91  m_rec_radius = std::max(M_PI / a1.mag(), M_PI / a2.mag());
92  m_rec_radius = std::max(m_rec_radius, M_PI / a3.mag());
93 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:31
#define M_PI
Definition: Constants.h:44
Defines the interface IPeakShape and subclasses.
Defines class InterferenceFunction3DLattice.
double mag() const
Returns magnitude of the vector.
Abstract base class of interference functions.
void setName(const std::string &name)
Abstract base class class that defines the peak shape of a Bragg peak.
Definition: IPeakShape.h:25
virtual IPeakShape * clone() const =0
Returns a clone of this ISampleNode 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 * clone() const override
Returns a clone of this ISampleNode object.
void onChange() override
Action to be taken in inherited class when a parameter has changed.
std::vector< const INode * > getChildren() const override
Returns a vector of children.
~InterferenceFunction3DLattice() override
std::unique_ptr< IPeakShape > m_peak_shape
InterferenceFunction3DLattice(const Lattice3D &lattice)
double iff_without_dw(const kvector_t q) const override
Calculates the structure factor without Debye-Waller factor.
A Bravais lattice, characterized by three basis vectors, and optionally an ISelectionRule.
Definition: Lattice3D.h:29
kvector_t getBasisVectorC() const
Returns basis vector c.
Definition: Lattice3D.h:52
kvector_t getBasisVectorA() const
Returns basis vector a.
Definition: Lattice3D.h:46
std::vector< kvector_t > reciprocalLatticeVectorsWithinRadius(const kvector_t q, double dq) const
Returns a list of reciprocal lattice vectors within distance dq of a vector q.
Definition: Lattice3D.cpp:92
kvector_t getBasisVectorB() const
Returns basis vector b.
Definition: Lattice3D.h:49