BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
Finite2DLatticePositionBuilder Class Reference

Description

Definition at line 102 of file IPositionBuilder.h.

Inheritance diagram for Finite2DLatticePositionBuilder:
[legend]
Collaboration diagram for Finite2DLatticePositionBuilder:
[legend]

Public Member Functions

 Finite2DLatticePositionBuilder (const InterferenceFinite2DLattice *p_iff)
 
 ~Finite2DLatticePositionBuilder () override
 
std::vector< std::vector< double > > generatePositions (double layer_size, double density=0.0) const
 

Private Member Functions

std::vector< std::vector< double > > generatePositionsImpl (double layer_size, double density=0.0) const override
 
double positionVariance () const override
 

Private Attributes

std::unique_ptr< InterferenceFinite2DLattice > m_iff
 

Constructor & Destructor Documentation

◆ Finite2DLatticePositionBuilder()

Finite2DLatticePositionBuilder::Finite2DLatticePositionBuilder ( const InterferenceFinite2DLattice *  p_iff)

Definition at line 176 of file IPositionBuilder.cpp.

178  : m_iff(p_iff->clone())
179 {
180 }
std::unique_ptr< InterferenceFinite2DLattice > m_iff

◆ ~Finite2DLatticePositionBuilder()

Finite2DLatticePositionBuilder::~Finite2DLatticePositionBuilder ( )
overridedefault

Member Function Documentation

◆ generatePositions()

std::vector< std::vector< double > > IPositionBuilder::generatePositions ( double  layer_size,
double  density = 0.0 
) const
inherited

Definition at line 29 of file IPositionBuilder.cpp.

31 {
32  std::vector<std::vector<double>> positions = generatePositionsImpl(layer_size, density);
33  double pos_var = positionVariance();
34  if (pos_var > 0.0) {
35  // random generator and distribution
36  std::random_device rd; // Will be used to obtain a seed for the random number engine
37  std::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd()
38  std::normal_distribution<double> dis(0.0, std::sqrt(pos_var));
39  for (auto& position : positions) {
40  for (auto& coordinate : position)
41  coordinate += dis(gen);
42  }
43  }
44  return positions;
45 }
virtual std::vector< std::vector< double > > generatePositionsImpl(double layer_size, double density=0.0) const =0
virtual double positionVariance() const =0

References IPositionBuilder::generatePositionsImpl(), and IPositionBuilder::positionVariance().

Here is the call graph for this function:

◆ generatePositionsImpl()

std::vector< std::vector< double > > Finite2DLatticePositionBuilder::generatePositionsImpl ( double  layer_size,
double  density = 0.0 
) const
overrideprivatevirtual

Implements IPositionBuilder.

Definition at line 185 of file IPositionBuilder.cpp.

186 {
187  const auto& lattice = m_iff->lattice();
188  double l1 = lattice.length1();
189  double l2 = lattice.length2();
190  double alpha = lattice.latticeAngle();
191  double xi = lattice.rotationAngle();
192 
193  unsigned n1, n2;
194  double sina = std::abs(std::sin(alpha));
195  if (sina <= 1e-4) {
196  n1 = l1 == 0.0 ? 2 : static_cast<unsigned>(2.0 * layer_size * std::sqrt(2.0) / l1);
197  n2 = l2 == 0.0 ? 2 : static_cast<unsigned>(2.0 * layer_size * std::sqrt(2.0) / l2);
198  } else {
199  n1 = l1 == 0.0 ? 2 : static_cast<unsigned>(2.0 * layer_size * std::sqrt(2.0) / l1 / sina);
200  n2 = l2 == 0.0 ? 2 : static_cast<unsigned>(2.0 * layer_size * std::sqrt(2.0) / l2 / sina);
201  }
202  n1 = std::min(n1, m_iff->numberUnitCells1());
203  n2 = std::min(n2, m_iff->numberUnitCells2());
204 
205  return Generate2DLatticePoints(l1, l2, alpha, xi, n1, n2);
206 }

References m_iff.

◆ positionVariance()

double Finite2DLatticePositionBuilder::positionVariance ( ) const
overrideprivatevirtual

Implements IPositionBuilder.

Definition at line 208 of file IPositionBuilder.cpp.

209 {
210  return m_iff->positionVariance();
211 }

References m_iff.

Member Data Documentation

◆ m_iff

std::unique_ptr<InterferenceFinite2DLattice> Finite2DLatticePositionBuilder::m_iff
private

Definition at line 111 of file IPositionBuilder.h.

Referenced by generatePositionsImpl(), and positionVariance().


The documentation for this class was generated from the following files: