AutoPas  3.0.0
Loading...
Searching...
No Matches
GridGenerator.h
1
7#pragma once
8
12
13namespace autopasTools::generators {
17namespace GridGenerator {
30template <class ParticleCell>
32 std::vector<ParticleCell> &cells, const std::array<size_t, 3> &cellsPerDimension,
33 const std::array<size_t, 3> &particlesPerDim,
34 const typename ParticleCell::ParticleType &defaultParticle = typename ParticleCell::ParticleType(),
35 const std::array<double, 3> &spacing = std::array<double, 3>{1, 1, 1},
36 const std::array<double, 3> &offset = std::array<double, 3>{.5, .5, .5},
37 const std::array<double, 3> &cellSize = {1., 1., 1.});
38
49template <class Container>
50void fillWithParticles(Container &container, const std::array<size_t, 3> &particlesPerDim,
51 const typename autopas::utils::ParticleTypeTrait<Container>::value &defaultParticle =
53 const std::array<double, 3> &spacing = std::array<double, 3>{1., 1., 1.},
54 const std::array<double, 3> &offset = std::array<double, 3>{.5, .5, .5});
55}; // namespace GridGenerator
56
57template <class ParticleCell>
58void GridGenerator::fillWithParticles(std::vector<ParticleCell> &cells, const std::array<size_t, 3> &cellsPerDimension,
59 const std::array<size_t, 3> &particlesPerDim,
60 const typename ParticleCell::ParticleType &defaultParticle,
61 const std::array<double, 3> &spacing, const std::array<double, 3> &offset,
62 const std::array<double, 3> &cellSize) {
63 size_t id = defaultParticle.getID();
64 for (unsigned long z = 0; z < particlesPerDim[2]; ++z) {
65 for (unsigned long y = 0; y < particlesPerDim[1]; ++y) {
66 for (unsigned long x = 0; x < particlesPerDim[0]; ++x) {
67 auto p = defaultParticle;
68 std::array<double, 3> pos{static_cast<double>(x) * spacing[0] + offset[0],
69 static_cast<double>(y) * spacing[1] + offset[1],
70 static_cast<double>(z) * spacing[2] + offset[2]};
71 std::array<unsigned long, 3> cellIndex3D{static_cast<unsigned long>(pos[0] / cellSize[0]),
72 static_cast<unsigned long>(pos[1] / cellSize[1]),
73 static_cast<unsigned long>(pos[2] / cellSize[2])};
74 p.setR(pos);
75 p.setID(id++);
76 const auto cellIndex = autopas::utils::ThreeDimensionalMapping::threeToOneD(cellIndex3D, cellsPerDimension);
77
78 if (cells[cellIndex].getPossibleParticleOwnerships() == autopas::OwnershipState::halo) {
79 p.setOwnershipState(autopas::OwnershipState::halo);
80 }
81 if (cells[cellIndex].getPossibleParticleOwnerships() == autopas::OwnershipState::dummy) {
82 p.setOwnershipState(autopas::OwnershipState::dummy);
83 }
84 cells[cellIndex].addParticle(p);
85 }
86 }
87 }
88}
89
90template <class Container>
92 Container &container, const std::array<size_t, 3> &particlesPerDim,
93 const typename autopas::utils::ParticleTypeTrait<Container>::value &defaultParticle,
94 const std::array<double, 3> &spacing, const std::array<double, 3> &offset) {
95 size_t id = defaultParticle.getID();
96 for (unsigned int z = 0; z < particlesPerDim[2]; ++z) {
97 for (unsigned int y = 0; y < particlesPerDim[1]; ++y) {
98 for (unsigned int x = 0; x < particlesPerDim[0]; ++x) {
99 auto p = defaultParticle;
100 p.setR({x * spacing[0] + offset[0], y * spacing[1] + offset[1], z * spacing[2] + offset[2]});
101 p.setID(id++);
102 container.addParticle(p);
103 }
104 }
105 }
106}
107} // namespace autopasTools::generators
void fillWithParticles(std::vector< ParticleCell > &cells, const std::array< size_t, 3 > &cellsPerDimension, const std::array< size_t, 3 > &particlesPerDim, const typename ParticleCell::ParticleType &defaultParticle=typename ParticleCell::ParticleType(), const std::array< double, 3 > &spacing=std::array< double, 3 >{1, 1, 1}, const std::array< double, 3 > &offset=std::array< double, 3 >{.5,.5,.5}, const std::array< double, 3 > &cellSize={1., 1., 1.})
Fills a cell vector with a cuboid mesh of particles.
Definition: GridGenerator.h:58
constexpr T threeToOneD(T x, T y, T z, const std::array< T, 3 > &dims)
Convert a 3d index to a 1d index.
Definition: ThreeDimensionalMapping.h:29
@ dummy
Dummy or deleted state, a particle with this state is not an actual particle!
@ halo
Halo state, a particle with this state is an actual particle, but not owned by the current AutoPas ob...
typename Container::ParticleType value
The Particle Type.
Definition: ParticleTypeTrait.h:24