17 #include "Sample/Aggregate/Interferences.h"
23 std::vector<std::vector<double>> Generate2DLatticePoints(
double l1,
double l2,
double alpha,
24 double xi,
unsigned n1,
unsigned n2);
36 std::random_device rd;
37 std::mt19937 gen(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);
53 std::vector<double> origin = {0.0, 0.0};
69 std::vector<std::vector<double>> lattice_positions;
70 std::vector<double> position;
74 int num_particles =
static_cast<int>(density * (2 * layer_size) * (2 * layer_size));
77 std::random_device rd;
78 std::mt19937 gen(rd());
79 std::uniform_real_distribution<double> dis(0.0, 1.0);
81 for (
int i = 1; i <= num_particles; ++i) {
83 position.push_back(dis(gen) * 2 * layer_size - layer_size);
84 position.push_back(dis(gen) * 2 * layer_size - layer_size);
86 lattice_positions.push_back(position);
89 return lattice_positions;
98 : m_iff(p_iff->clone())
107 const double length =
m_iff->length();
108 const double xi =
m_iff->xi();
113 length == 0.0 ? 2 :
static_cast<unsigned>(2.0 * layer_size * std::sqrt(2.0) / length);
115 return Generate2DLatticePoints(length, 0.0, 0.0, xi, n1, 1u);
120 return m_iff->positionVariance();
124 : m_iff(p_iff->clone())
133 const auto& lattice =
m_iff->lattice();
134 double l1 = lattice.length1();
135 double l2 = lattice.length2();
136 double alpha = lattice.latticeAngle();
137 double xi = lattice.rotationAngle();
142 double sina = std::abs(std::sin(alpha));
144 n1 = l1 == 0.0 ? 2 :
static_cast<unsigned>(2.0 * layer_size * std::sqrt(2.0) / l1);
145 n2 = l2 == 0.0 ? 2 :
static_cast<unsigned>(2.0 * layer_size * std::sqrt(2.0) / l2);
147 n1 = l1 == 0.0 ? 2 :
static_cast<unsigned>(2.0 * layer_size * std::sqrt(2.0) / l1 / sina);
148 n2 = l2 == 0.0 ? 2 :
static_cast<unsigned>(2.0 * layer_size * std::sqrt(2.0) / l2 / sina);
150 return Generate2DLatticePoints(l1, l2, alpha, xi, n1, n2);
155 return m_iff->positionVariance();
159 : m_iff(p_iff->clone())
165 std::vector<std::vector<double>>
173 return m_iff->positionVariance();
177 const InterferenceFinite2DLattice* p_iff)
178 : m_iff(p_iff->clone())
184 std::vector<std::vector<double>>
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();
194 double sina = std::abs(std::sin(alpha));
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);
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);
202 n1 = std::min(n1,
m_iff->numberUnitCells1());
203 n2 = std::min(n2,
m_iff->numberUnitCells2());
205 return Generate2DLatticePoints(l1, l2, alpha, xi, n1, n2);
210 return m_iff->positionVariance();
214 const InterferenceRadialParaCrystal* p_iff)
215 : m_iff(p_iff->clone())
221 std::vector<std::vector<double>>
224 std::vector<std::vector<double>> lattice_positions;
226 double distance =
m_iff->peakDistance();
230 int n = distance <= 0.0 ? 1 :
static_cast<int>(layer_size * std::sqrt(2.0) / distance);
232 lattice_positions.resize(2 * n + 1);
233 for (
auto& it : lattice_positions)
236 lattice_positions[0][0] = 0.0;
237 lattice_positions[0][1] = 0.0;
239 for (
int i = 1; i <= n; ++i) {
241 unsigned i_left =
static_cast<unsigned>(std::max(0, 2 * i - 3));
243 double offset =
m_iff->randomSample();
244 lattice_positions[2 * i - 1][0] = lattice_positions[i_left][0] + distance + offset;
245 lattice_positions[2 * i - 1][1] = 0.0;
248 offset =
m_iff->randomSample();
249 lattice_positions[2 * i][0] = lattice_positions[2 * (i - 1)][0] - distance + offset;
250 lattice_positions[2 * i][1] = 0.0;
252 return lattice_positions;
257 return m_iff->positionVariance();
262 std::vector<std::vector<double>> Generate2DLatticePoints(
double l1,
double l2,
double alpha,
263 double xi,
unsigned n1,
unsigned n2)
265 std::vector<std::vector<double>> lattice_positions;
266 std::vector<double> position;
268 unsigned nn1 = std::max(1u, n1);
269 unsigned nn2 = std::max(1u, n2);
270 int n1m = -
static_cast<int>((nn1 - 1) / 2);
271 int n1M =
static_cast<int>(nn1 / 2);
272 int n2m = -
static_cast<int>((nn2 - 1) / 2);
273 int n2M =
static_cast<int>(nn2 / 2);
275 for (
int i = n1m; i <= n1M; ++i) {
276 for (
int j = n2m; j <= n2M; ++j) {
279 position.push_back(i * l1 * std::cos(xi)
280 + j * l2 * std::cos(alpha + xi));
281 position.push_back(i * l1 * std::sin(xi)
282 + j * l2 * std::sin(alpha + xi));
284 lattice_positions.push_back(position);
288 return lattice_positions;
Declares interface IPositionBuilder and subclasses.
Defines namespace GUI::RealSpace::Paracrystal2D.
std::vector< std::vector< double > > generatePositionsImpl(double layer_size, double density=0.0) const override
double positionVariance() const override
~DefaultPositionBuilder() override
std::unique_ptr< InterferenceFinite2DLattice > m_iff
std::vector< std::vector< double > > generatePositionsImpl(double layer_size, double density=0.0) const override
~Finite2DLatticePositionBuilder() override
Finite2DLatticePositionBuilder(const InterferenceFinite2DLattice *p_iff)
double positionVariance() const override
virtual ~IPositionBuilder()
virtual std::vector< std::vector< double > > generatePositionsImpl(double layer_size, double density=0.0) const =0
std::vector< std::vector< double > > generatePositions(double layer_size, double density=0.0) const
virtual double positionVariance() const =0
Lattice1DPositionBuilder(const Interference1DLattice *p_iff)
std::unique_ptr< Interference1DLattice > m_iff
~Lattice1DPositionBuilder() override
std::vector< std::vector< double > > generatePositionsImpl(double layer_size, double density=0.0) const override
double positionVariance() const override
~Lattice2DPositionBuilder() override
Lattice2DPositionBuilder(const Interference2DLattice *p_iff)
std::unique_ptr< Interference2DLattice > m_iff
std::vector< std::vector< double > > generatePositionsImpl(double layer_size, double density=0.0) const override
double positionVariance() const override
std::unique_ptr< Interference2DParaCrystal > m_iff
double positionVariance() const override
std::vector< std::vector< double > > generatePositionsImpl(double layer_size, double density=0.0) const override
ParaCrystal2DPositionBuilder(const Interference2DParaCrystal *p_iff)
~ParaCrystal2DPositionBuilder() override
std::unique_ptr< InterferenceRadialParaCrystal > m_iff
RadialParacrystalPositionBuilder(const InterferenceRadialParaCrystal *p_iff)
std::vector< std::vector< double > > generatePositionsImpl(double layer_size, double density=0.0) const override
double positionVariance() const override
~RadialParacrystalPositionBuilder() override
~RandomPositionBuilder() override
std::vector< std::vector< double > > generatePositionsImpl(double layer_size, double density=0.0) const override
double positionVariance() const override
std::vector< std::vector< double > > latticePositions(const Interference2DParaCrystal *, double layer_size)