19namespace autopasTools::generators::TwoCellsInteractionHitrateGenerator {
57template <
class Container_T,
class Particle_T>
58void fillWithParticles(Container_T &cell1, Container_T &cell2,
const std::array<double, 3> &boxMin1,
59 const std::array<double, 3> &boxMax1,
const std::array<double, 3> &boxMin2,
60 const std::array<double, 3> &boxMax2, std::size_t n,
double hitrate,
double cutoff,
61 const Particle_T &defaultParticle = Particle_T{},
unsigned int seed = 42) {
62 if (std::abs(boxMax1[0] - boxMin2[0]) > 1e-10) {
64 "TwoCellsInteractionHitrateGenerator: cells must share an x-boundary "
65 "(boxMax1[0]={} != boxMin2[0]={})",
66 boxMax1[0], boxMin2[0]);
68 if ((boxMax1[0] - boxMin1[0]) <= 1.2 * cutoff) {
70 "TwoCellsInteractionHitrateGenerator: cell1 x-extent ({}) must be > 1.2 * cutoff ({})", boxMax1[0] - boxMin1[0],
73 if ((boxMax2[0] - boxMin2[0]) <= 1.2 * cutoff) {
75 "TwoCellsInteractionHitrateGenerator: cell2 x-extent ({}) must be > 1.2 * cutoff ({})", boxMax2[0] - boxMin2[0],
78 if (hitrate < 0.0 || hitrate > 1.0) {
83 const double boundary = boxMax1[0];
84 const auto k =
static_cast<std::size_t
>(std::round(
static_cast<double>(n) * hitrate));
85 const std::size_t farCount = n - k;
86 const auto idBase =
static_cast<std::size_t
>(defaultParticle.getID());
88 std::mt19937 rng(seed);
91 const double eps = cutoff * 1e-6;
92 std::uniform_real_distribution<double> dxDist(eps, cutoff / 2.0 - eps);
94 auto uniform = [&](
double lo,
double hi) {
return std::uniform_real_distribution<double>(lo, hi)(rng); };
96 std::vector<Particle_T> particles1, particles2;
97 particles1.reserve(n);
98 particles2.reserve(n);
101 for (std::size_t i = 0; i < k; ++i) {
102 const double dx = dxDist(rng);
103 const double y = uniform(boxMin1[1], boxMax1[1]);
104 const double z = uniform(boxMin1[2], boxMax1[2]);
106 Particle_T p1(defaultParticle);
107 p1.setR({boundary - dx, y, z});
108 p1.setID(idBase + i);
110 particles1.push_back(p1);
112 Particle_T p2(defaultParticle);
113 p2.setR({boundary + dx, y, z});
114 p2.setID(idBase + n + i);
116 particles2.push_back(p2);
120 for (std::size_t i = 0; i < farCount; ++i) {
121 Particle_T p(defaultParticle);
122 p.setR({uniform(boxMin1[0], boundary - cutoff), uniform(boxMin1[1], boxMax1[1]), uniform(boxMin1[2], boxMax1[2])});
123 p.setID(idBase + k + i);
125 particles1.push_back(p);
129 for (std::size_t i = 0; i < farCount; ++i) {
130 Particle_T p(defaultParticle);
131 p.setR({uniform(boundary + cutoff, boxMax2[0]), uniform(boxMin2[1], boxMax2[1]), uniform(boxMin2[2], boxMax2[2])});
132 p.setID(idBase + n + k + i);
134 particles2.push_back(p);
137 std::shuffle(particles1.begin(), particles1.end(), rng);
138 std::shuffle(particles2.begin(), particles2.end(), rng);
140 for (
auto &p : particles1) {
141 cell1.addParticle(p);
143 for (
auto &p : particles2) {
144 cell2.addParticle(p);
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:64
@ owned
Owned state, a particle with this state is an actual particle and owned by the current AutoPas object...