BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Interference3DLattice.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Aggregate/Interference3DLattice.cpp
6 //! @brief Implements class Interference3DLattice.
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"
18 #include <algorithm>
19 #include <iostream>
20 
22  : IInterference(0)
23  , m_lattice(lattice)
24  , m_peak_shape(nullptr)
25  , m_rec_radius(0.0)
26 {
27  R3 a1 = m_lattice.basisVectorA();
28  R3 a2 = m_lattice.basisVectorB();
29  R3 a3 = m_lattice.basisVectorC();
30 
31  m_rec_radius = std::max(M_PI / a1.mag(), M_PI / a2.mag());
32  m_rec_radius = std::max(m_rec_radius, M_PI / a3.mag());
33 }
34 
36 
38 {
39  auto* result = new Interference3DLattice(m_lattice);
40  result->setPositionVariance(m_position_var);
41  if (m_peak_shape)
42  result->setPeakShape(*m_peak_shape);
43  return result;
44 }
45 
47 {
48  m_peak_shape.reset(peak_shape.clone());
49 }
50 
52 {
53  return m_lattice;
54 }
55 
56 std::vector<const INode*> Interference3DLattice::nodeChildren() const
57 {
58  return {};
59 }
60 
61 double Interference3DLattice::iff_without_dw(const R3 q) const
62 {
64  R3 center = q;
65  double radius = 2.1 * m_rec_radius;
66  // double inner_radius = 0.0;
67  // if (m_peak_shape->angularDisorder()) {
68  // center = R3(0.0, 0.0, 0.0);
69  // inner_radius = std::max(0.0, q.mag() - radius);
70  // radius += q.mag();
71  // }
72  const auto rec_vectors = m_lattice.reciprocalLatticeVectorsWithinRadius(center, radius);
73  // std::cout << "IWD: q=" << q << ", r=" << radius << ", ir=" << inner_radius <<
74  // ", disordered=" << m_peak_shape->angularDisorder() << " => nVec=" << rec_vectors.size()
75  // << std::endl;
76 
77  double result = 0.0;
78  for (const auto& q_rec : rec_vectors)
79  // if (!(q_rec.mag() < inner_radius)) {
80  // result += m_peak_shape->evaluate(q, q_rec);
81  result += exp(-(q - q_rec).mag2() / 2 / pow(.06, 2));
82  // std::cout << " INCR: qr=" << q_rec << " => " << result << std::endl;
83  // }
84  return result;
85 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:45
#define M_PI
Definition: Constants.h:44
Defines the interface IPeakShape and subclasses.
Defines class Interference3DLattice.
Abstract base class of interference functions.
Definition: IInterference.h:24
double m_position_var
Definition: IInterference.h:53
Abstract base class class that defines the peak shape of a Bragg peak.
Definition: IPeakShape.h:25
IPeakShape * clone() const override=0
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
Interference3DLattice(const Lattice3D &lattice)
~Interference3DLattice() override
Interference3DLattice * clone() const override
const Lattice3D & lattice() const
double iff_without_dw(R3 q) const override
Calculates the structure factor without Debye-Waller factor.
std::vector< const INode * > nodeChildren() const override
Returns all children.
std::unique_ptr< IPeakShape > m_peak_shape
A Bravais lattice, characterized by three basis vectors, and optionally an ISelectionRule.
Definition: Lattice3D.h:30
R3 basisVectorB() const
Returns basis vector b.
Definition: Lattice3D.h:46
R3 basisVectorC() const
Returns basis vector c.
Definition: Lattice3D.h:49
R3 basisVectorA() const
Returns basis vector a.
Definition: Lattice3D.h:43
std::vector< R3 > reciprocalLatticeVectorsWithinRadius(R3 q, double dq) const
Returns a list of reciprocal lattice vectors within distance dq of a vector q.
Definition: Lattice3D.cpp:75