Skip to content

Commit 27ef6c8

Browse files
Merge pull request #1387 from Iximiel/merging/210-fix-atdist-sc-aprox
2 parents a686bbe + bf45fd0 commit 27ef6c8

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/tools/AtomDistribution.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,16 @@ void tiledSimpleCubic::frame(std::vector<Vector>& posToUpdate,
180180
//Tiling the space in this way will not tests 100% the pbc, but
181181
//I do not think that write a spacefilling curve, like Hilbert, Peano or Morton
182182
//could be a good idea, in this case
183-
const unsigned rmax = std::ceil(std::cbrt(static_cast<double>(posToUpdate.size())));
183+
184+
// the lambda is here because in some case a perfect cube is not well represented
185+
// by double and will get uncorrectly ceiled up (for example 24389 will result in a 30 and not in 29)
186+
const unsigned rmax = [&] {
187+
const size_t x = std::ceil(std::cbrt(static_cast<double>(posToUpdate.size())))-1;
188+
if ( x*x*x >= posToUpdate.size()) {
189+
return x;
190+
}
191+
return x+1;
192+
}();
184193

185194
auto s=posToUpdate.begin();
186195
auto e=posToUpdate.end();

0 commit comments

Comments
 (0)