AutoPas  3.0.0
Loading...
Searching...
No Matches
ClosestPackingGenerator.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <cmath>
10#include <vector>
11
14
29template <class Container>
30void fillWithParticles(Container &container, const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax,
31 const typename autopas::utils::ParticleTypeTrait<Container>::value &defaultParticle =
33 const double spacing = 1.) {
34 // Spacing in y direction when only moving 60° on the unit circle. Or the height in an equilateral triangle.
35 const double spacingRow = spacing * sqrt(3. / 4.);
36 // Spacing in z direction. Height in an equilateral tetraeder.
37 const double spacingLayer = spacing * sqrt(2. / 3.);
38 // Shorter part of the bisectrix when split at the intersection of all bisectrices.
39 const double xOffset = spacing * 1. / 2.;
40 // Shorter part of the bisectrix when split at the intersection of all bisectrices.
41 const double yOffset = spacing * sqrt(1. / 12.);
42
43 // The packing alternates between odd and even layers and rows
44 bool evenLayer = true;
45
46 size_t id = defaultParticle.getID();
47 for (double z = boxMin[2]; z < boxMax[2]; z += spacingLayer) {
48 double starty = evenLayer ? boxMin[1] : boxMin[1] + yOffset;
49 bool evenRow = evenLayer; // To ensure layers are alternating as for hexagonal close packed.
50 for (double y = starty; y < boxMax[1]; y += spacingRow) {
51 double startx = evenRow ? boxMin[0] : boxMin[0] + xOffset;
52 for (double x = startx; x < boxMax[0]; x += spacing) {
53 auto p = defaultParticle;
54 p.setR({x, y, z});
55 p.setID(id++);
56 container.addParticle(p);
57 }
58 evenRow = not evenRow;
59 }
60 evenLayer = not evenLayer;
61 }
62};
63}; // namespace autopasTools::generators::ClosestPackingGenerator
Generator for grids of particles.
Definition: ClosestPackingGenerator.h:18
void fillWithParticles(Container &container, const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, const typename autopas::utils::ParticleTypeTrait< Container >::value &defaultParticle=typename autopas::utils::ParticleTypeTrait< Container >::value(), const double spacing=1.)
Fills any container (also AutoPas object) with a hexagonally closest packed particles.
Definition: ClosestPackingGenerator.h:30
typename Container::ParticleType value
The Particle Type.
Definition: ParticleTypeTrait.h:24