Fix rounding error bug in calculation of number of top-level cells
Because a value of 0.99
was used to force rounding down (see changelog), trying to use a top-level cells count of ~100 could lead to rounding to +/-1 from expected value. This more adaptive approach should avoid this issue for arbitrarily large numbers of top-level cells (at least until Ncells^2 approaches the floating point limit).
There is a potential issue if trying to use one top-level cell. I think it might make sense to enforce a minimum value for the tol
that I've introduced (could be the previously-used 0.99
, for instance, just needs to be less than 1). Thought I'd ask here before adding more logic, though.
Merge request reports
Activity
added bug label
I don't think that this will affect runs where a re-grid occurs, if I understand the code. The calculation simplifies to (pseudo-code-ish):
if h_max * kernel_gamma * space_stretch > s->cell_min: cdim = floor(s->dim / (h_max * kernel_gamma * space_stretch)) else: cdim = floor(max_top_level_cells / tol)
I think that a re-grid would only be triggered by h_max becoming large enough? In that case it always goes to the first branch of the
if
statement and never touchestol
.Thinking about this further, I should put a lower bound on
tol
, because for small number of cells you'd get things likecdim = floor(max_top_level_cells/0.5)
, which is just glitchy rounding in the other direction!