AutoPas  3.0.0
Loading...
Searching...
No Matches
UniformGenerator.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <array>
10#include <random>
11
13#include "autopas/utils/inBox.h"
14
15namespace autopasTools::generators {
19namespace UniformGenerator {
27std::array<double, 3> randomPosition(std::mt19937 &generator, const std::array<double, 3> &boxMin,
28 const std::array<double, 3> &boxMax);
29
42template <class Container, class Particle>
43void fillWithParticles(Container &container, const Particle &defaultParticle, const std::array<double, 3> &boxMin,
44 const std::array<double, 3> &boxMax, unsigned long numParticles = 100ul, unsigned int seed = 42);
45
59template <class Container, class Particle, class HaloAddFunction>
60void fillWithHaloParticles(Container &container, const Particle &defaultParticle, double haloWidth,
61 unsigned long numParticles, const HaloAddFunction &haloAddFunction, unsigned int seed = 42);
62
74template <class Container, class Particle>
75void fillWithHaloParticles(Container &container, const Particle &defaultParticle, double haloWidth,
76 unsigned long numParticles, unsigned int seed = 42) {
78 container, defaultParticle, haloWidth, numParticles,
79 [](Container &c, Particle &p) {
80 p.setOwnershipState(autopas::OwnershipState::halo);
81 c.addHaloParticle(p);
82 },
83 seed);
84}
85}; // namespace UniformGenerator
86
87template <class Container, class Particle>
88void UniformGenerator::fillWithParticles(Container &container, const Particle &defaultParticle,
89 const std::array<double, 3> &boxMin, const std::array<double, 3> &boxMax,
90 unsigned long numParticles, unsigned int seed) {
91 std::mt19937 generator(seed);
92
93 for (unsigned long i = defaultParticle.getID(); i < defaultParticle.getID() + numParticles; ++i) {
94 Particle particle(defaultParticle);
95 particle.setR(randomPosition(generator, boxMin, boxMax));
96 particle.setID(i);
97 particle.setOwnershipState(autopas::OwnershipState::owned);
98 container.addParticle(particle);
99 }
100}
101
102template <class Container, class Particle, class HaloAddFunction>
103void UniformGenerator::fillWithHaloParticles(Container &container, const Particle &defaultParticle, double haloWidth,
104 unsigned long numParticles, const HaloAddFunction &haloAddFunction,
105 unsigned int seed) {
106 std::mt19937 generator(seed);
107
108 auto haloBoxMin = container.getBoxMin();
109 auto haloBoxMax = container.getBoxMax();
110
111 // increase the box size not exactly by the width to make it exclusive
112 for (unsigned int i = 0; i < 3; ++i) {
113 haloBoxMin[i] -= haloWidth * .99;
114 haloBoxMax[i] += haloWidth * .99;
115 }
116
117 for (unsigned long i = defaultParticle.getID(); i < defaultParticle.getID() + numParticles; ++i) {
118 auto pos = randomPosition(generator, haloBoxMin, haloBoxMax);
119 // we only want to add particles not in the actual box
120 while (autopas::utils::inBox(pos, container.getBoxMin(), container.getBoxMax())) {
121 pos = randomPosition(generator, haloBoxMin, haloBoxMax);
122 }
123 Particle particle(defaultParticle);
124 particle.setR(pos);
125 particle.setID(i);
126 haloAddFunction(container, particle);
127 }
128}
129} // namespace autopasTools::generators
std::array< double, 3 > randomPosition(std::mt19937 &generator, const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax)
Generate a random position within a given box.
Definition: UniformGenerator.cpp:13
void fillWithParticles(Container &container, const Particle &defaultParticle, const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, unsigned long numParticles=100ul, unsigned int seed=42)
Fills any container (also AutoPas object) with randomly uniformly distributed particles.
Definition: UniformGenerator.h:88
void fillWithHaloParticles(Container &container, const Particle &defaultParticle, double haloWidth, unsigned long numParticles, const HaloAddFunction &haloAddFunction, unsigned int seed=42)
Fills the halo of a container (also AutoPas object) with randomly uniformly distributed particles.
Definition: UniformGenerator.h:103
bool inBox(const std::array< T, 3 > &position, const std::array< T, 3 > &low, const std::array< T, 3 > &high)
Checks if position is inside of a box defined by low and high.
Definition: inBox.h:26
@ halo
Halo state, a particle with this state is an actual particle, but not owned by the current AutoPas ob...
@ owned
Owned state, a particle with this state is an actual particle and owned by the current AutoPas object...