BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ReMesocrystal.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Resample/Particle/ReMesocrystal.cpp
6 //! @brief Implements class ReMesocrystal.
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"
17 #include "Base/Spin/SpinMatrix.h"
20 
21 ReMesocrystal::ReMesocrystal(const Lattice3D& lattice, const IReParticle& basis,
22  const ReParticle& outer_shape, double position_variance)
23  : m_lattice(lattice)
24  , m_basis(basis.clone())
25  , m_outer_shape(outer_shape.clone())
26  , m_position_variance(position_variance)
27 {
29 }
30 
32 {
33  delete m_basis;
34  delete m_outer_shape;
35 }
36 
37 double ReMesocrystal::volume() const
38 {
39  return m_outer_shape->volume();
40 }
41 
43 {
45 }
46 
47 double ReMesocrystal::bottomZ(const IRotation* rotation) const
48 {
49  return m_outer_shape->bottomZ(rotation);
50 }
51 
52 double ReMesocrystal::topZ(const IRotation* rotation) const
53 {
54  return m_outer_shape->topZ(rotation);
55 }
56 
57 complex_t ReMesocrystal::theFF(const WavevectorInfo& wavevectors) const
58 {
59  // retrieve reciprocal lattice vectors within reasonable radius
60  C3 q = wavevectors.getQ();
61  double radius = 2.1 * m_max_rec_length;
62  std::vector<R3> rec_vectors = m_lattice.reciprocalLatticeVectorsWithinRadius(q.real(), radius);
63 
64  // perform convolution on these lattice vectors
65  complex_t result(0.0, 0.0);
66  for (const auto& rec : rec_vectors) {
67  auto dw_factor = debyeWallerFactor(rec);
68  WavevectorInfo basis_wavevectors(R3(), -rec, wavevectors.vacuumLambda());
69  complex_t basis_factor = m_basis->theFF(basis_wavevectors);
70  WavevectorInfo meso_wavevectors(C3(), rec.complex() - q, wavevectors.vacuumLambda());
71  complex_t meso_factor = m_outer_shape->theFF(meso_wavevectors);
72  result += dw_factor * basis_factor * meso_factor;
73  }
74  // the transformed delta train gets a factor of (2pi)^3/V, but the (2pi)^3
75  // is canceled by the convolution of Fourier transforms :
76  return result / m_lattice.unitCellVolume();
77 }
78 
80 {
81  // retrieve reciprocal lattice vectors within reasonable radius
82  C3 q = wavevectors.getQ();
83  double radius = 2.1 * m_max_rec_length;
84  std::vector<R3> rec_vectors = m_lattice.reciprocalLatticeVectorsWithinRadius(q.real(), radius);
85 
86  // perform convolution on these lattice vectors
87  SpinMatrix result;
88  for (const auto& rec : rec_vectors) {
89  auto dw_factor = debyeWallerFactor(rec);
90  WavevectorInfo basis_wavevectors(R3(), -rec, wavevectors.vacuumLambda());
91  SpinMatrix basis_factor = m_basis->thePolFF(basis_wavevectors);
92  WavevectorInfo meso_wavevectors(C3(), rec.complex() - q, wavevectors.vacuumLambda());
93  complex_t meso_factor = m_outer_shape->theFF(meso_wavevectors);
94  result += dw_factor * basis_factor * meso_factor;
95  }
96  // the transformed delta train gets a factor of (2pi)^3/V, but the (2pi)^3
97  // is canceled by the convolution of Fourier transforms :
98  return result / m_lattice.unitCellVolume();
99 }
100 
102 {
103  R3 a1 = m_lattice.basisVectorA();
104  R3 a2 = m_lattice.basisVectorB();
105  R3 a3 = m_lattice.basisVectorC();
106 
107  m_max_rec_length = std::max(M_PI / a1.mag(), M_PI / a2.mag());
108  m_max_rec_length = std::max(m_max_rec_length, M_PI / a3.mag());
109 }
110 
111 complex_t ReMesocrystal::debyeWallerFactor(const R3& q_i) const
112 {
113  auto q2 = q_i.mag2();
114  return std::exp(-q2 * m_position_variance / 2.0);
115 }
Defines M_PI and some more mathematical constants.
#define M_PI
Definition: Constants.h:44
Defines class ReMesocrystal.
Defines interface class ReParticle.
Defines class SpinMatrix.
Defines WavevectorInfo.
Abstract base class for reprocessed particles.
Definition: IReParticle.h:37
virtual SpinMatrix thePolFF(const WavevectorInfo &wavevectors) const
Returns scattering amplitude for matrix interactions.
Definition: IReParticle.cpp:20
virtual complex_t theFF(const WavevectorInfo &wavevectors) const =0
Returns scattering amplitude for complex wavevectors ki, kf.
Abstract base class for rotations.
Definition: Rotations.h:29
A Bravais lattice, characterized by three basis vectors, and optionally an ISelectionRule.
Definition: Lattice3D.h:30
double unitCellVolume() const
Returns the volume of the unit cell.
Definition: Lattice3D.cpp:56
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
complex_t theFF(const WavevectorInfo &wavevectors) const override
Returns scattering amplitude for complex wavevectors ki, kf.
void calculateLargestReciprocalDistance()
double m_max_rec_length
Definition: ReMesocrystal.h:63
Lattice3D m_lattice
Definition: ReMesocrystal.h:59
double radialExtension() const override
Returns the (approximate in some cases) radial size of the particle of this form factor's shape....
double topZ(const IRotation *rotation) const override
Returns the z-coordinate of the lowest point in this shape after a given rotation.
double m_position_variance
Definition: ReMesocrystal.h:62
SpinMatrix thePolFF(const WavevectorInfo &wavevectors) const override
Returns scattering amplitude for matrix interactions.
double bottomZ(const IRotation *rotation) const override
Returns the z-coordinate of the lowest point in this shape after a given rotation.
complex_t debyeWallerFactor(const R3 &q_i) const
IReParticle * m_basis
Definition: ReMesocrystal.h:60
ReParticle * m_outer_shape
The outer shape of this mesocrystal.
Definition: ReMesocrystal.h:61
double volume() const override
Returns the total volume of the particle of this form factor's shape.
ReMesocrystal(const Lattice3D &lattice, const IReParticle &basis, const ReParticle &outer_shape, double position_variance=0.0)
~ReMesocrystal() override
A reprocessed simple particle, with shape m_ff.
Definition: ReParticle.h:33
double radialExtension() const override
Returns the (approximate in some cases) radial size of the particle of this form factor's shape....
Definition: ReParticle.cpp:85
double topZ(const IRotation *rotation) const override
Returns the z-coordinate of the lowest point in this shape after a given rotation.
Definition: ReParticle.cpp:146
double bottomZ(const IRotation *rotation) const override
Returns the z-coordinate of the lowest point in this shape after a given rotation.
Definition: ReParticle.cpp:134
double volume() const override
Returns the total volume of the particle of this form factor's shape.
Definition: ReParticle.cpp:80
complex_t theFF(const WavevectorInfo &wavevectors) const override
Returns scattering amplitude for complex wavevectors ki, kf.
Definition: ReParticle.cpp:100
Holds all wavevector information relevant for calculating form factors.
double vacuumLambda() const
C3 getQ() const