BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FormFactorCrystal.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Particle/FormFactorCrystal.cpp
6 //! @brief Implements class FormFactorCrystal.
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/Math/Constants.h"
18 
19 FormFactorCrystal::FormFactorCrystal(const Lattice3D& lattice, const IFormFactor& basis_form_factor,
20  const IFormFactor& meso_form_factor, double position_variance)
21  : m_lattice(lattice)
22  , m_basis_form_factor(basis_form_factor.clone())
23  , m_meso_form_factor(meso_form_factor.clone())
24  , m_position_variance(position_variance)
25 {
26  setName("FormFactorCrystal");
28 }
29 
31 {
32  delete m_basis_form_factor;
33  delete m_meso_form_factor;
34 }
35 
36 double FormFactorCrystal::bottomZ(const IRotation& rotation) const
37 {
38  return m_meso_form_factor->bottomZ(rotation);
39 }
40 
41 double FormFactorCrystal::topZ(const IRotation& rotation) const
42 {
43  return m_meso_form_factor->topZ(rotation);
44 }
45 
47 {
48  // retrieve reciprocal lattice vectors within reasonable radius
49  cvector_t q = wavevectors.getQ();
50  double radius = 2.1 * m_max_rec_length;
51  std::vector<kvector_t> rec_vectors =
53 
54  // perform convolution on these lattice vectors
55  complex_t result(0.0, 0.0);
56  for (const auto& rec : rec_vectors) {
57  auto dw_factor = debyeWallerFactor(rec);
58  WavevectorInfo basis_wavevectors(kvector_t(), -rec, wavevectors.wavelength());
59  complex_t basis_factor = m_basis_form_factor->evaluate(basis_wavevectors);
60  WavevectorInfo meso_wavevectors(cvector_t(), rec.complex() - q, wavevectors.wavelength());
61  complex_t meso_factor = m_meso_form_factor->evaluate(meso_wavevectors);
62  result += dw_factor * basis_factor * meso_factor;
63  }
64  // the transformed delta train gets a factor of (2pi)^3/V, but the (2pi)^3
65  // is canceled by the convolution of Fourier transforms :
66  return result / m_lattice.unitCellVolume();
67 }
68 
69 Eigen::Matrix2cd FormFactorCrystal::evaluatePol(const WavevectorInfo& wavevectors) const
70 {
71  // retrieve reciprocal lattice vectors within reasonable radius
72  cvector_t q = wavevectors.getQ();
73  double radius = 2.1 * m_max_rec_length;
74  std::vector<kvector_t> rec_vectors =
76 
77  // perform convolution on these lattice vectors
78  Eigen::Matrix2cd result = Eigen::Matrix2cd::Zero();
79  for (const auto& rec : rec_vectors) {
80  auto dw_factor = debyeWallerFactor(rec);
81  WavevectorInfo basis_wavevectors(kvector_t(), -rec, wavevectors.wavelength());
82  Eigen::Matrix2cd basis_factor = m_basis_form_factor->evaluatePol(basis_wavevectors);
83  WavevectorInfo meso_wavevectors(cvector_t(), rec.complex() - q, wavevectors.wavelength());
84  complex_t meso_factor = m_meso_form_factor->evaluate(meso_wavevectors);
85  result += dw_factor * basis_factor * meso_factor;
86  }
87  // the transformed delta train gets a factor of (2pi)^3/V, but the (2pi)^3
88  // is canceled by the convolution of Fourier transforms :
89  return result / m_lattice.unitCellVolume();
90 }
91 
93 {
97 
98  m_max_rec_length = std::max(M_PI / a1.mag(), M_PI / a2.mag());
99  m_max_rec_length = std::max(m_max_rec_length, M_PI / a3.mag());
100 }
101 
103 {
104  auto q2 = q_i.mag2();
105  return std::exp(-q2 * m_position_variance / 2.0);
106 }
std::complex< double > complex_t
Definition: Complex.h:20
Defines M_PI and some more mathematical constants.
#define M_PI
Definition: Constants.h:44
Defines class FormFactorCrystal.
BasicVector3D< double > kvector_t
Definition: Vectors3D.h:21
BasicVector3D< complex_t > cvector_t
Definition: Vectors3D.h:22
Defines WavevectorInfo.
double mag2() const
Returns magnitude squared of the vector.
double mag() const
Returns magnitude of the vector.
BasicVector3D< complex_t > complex() const
Returns this, trivially converted to complex type.
BasicVector3D< double > real() const
Returns real parts.
IFormFactor * m_meso_form_factor
The outer shape of this mesocrystal.
double bottomZ(const IRotation &rotation) const override
Returns the z-coordinate of the lowest point in this shape after a given rotation.
Eigen::Matrix2cd evaluatePol(const WavevectorInfo &wavevectors) const override
Returns scattering amplitude for matrix interactions.
double topZ(const IRotation &rotation) const override
Returns the z-coordinate of the lowest point in this shape after a given rotation.
FormFactorCrystal(const Lattice3D &lattice, const IFormFactor &basis_form_factor, const IFormFactor &meso_form_factor, double position_variance=0.0)
~FormFactorCrystal() override
IFormFactor * m_basis_form_factor
complex_t evaluate(const WavevectorInfo &wavevectors) const override
Returns scattering amplitude for complex wavevectors ki, kf.
void calculateLargestReciprocalDistance()
complex_t debyeWallerFactor(const kvector_t &q_i) const
Abstract base class for all form factors.
Definition: IFormFactor.h:36
virtual complex_t evaluate(const WavevectorInfo &wavevectors) const =0
Returns scattering amplitude for complex wavevectors ki, kf.
virtual double topZ(const IRotation &rotation) const =0
Returns the z-coordinate of the lowest point in this shape after a given rotation.
virtual double bottomZ(const IRotation &rotation) const =0
Returns the z-coordinate of the lowest point in this shape after a given rotation.
virtual Eigen::Matrix2cd evaluatePol(const WavevectorInfo &wavevectors) const
Returns scattering amplitude for matrix interactions.
Definition: IFormFactor.cpp:72
void setName(const std::string &name)
Abstract base class for rotations.
Definition: Rotations.h:28
A Bravais lattice, characterized by three basis vectors, and optionally an ISelectionRule.
Definition: Lattice3D.h:29
double unitCellVolume() const
Returns the volume of the unit cell.
Definition: Lattice3D.cpp:73
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
Holds all wavevector information relevant for calculating form factors.
double wavelength() const
cvector_t getQ() const