You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UniformGrid weight="Fourier2" integrates everything to about zero #349
UniformGrid(..., weight="Fourier2") gives weights that are antisymmetric along each axis, so they add up to roughly zero and any integral comes out near 0.
Small example: a Gaussian centred in a cube that is large enough for it to vanish on the boundary (exact value pi**1.5 = 5.5683):
The weights come from the rectangle rule for sine series with interior points x_i = (2i - 1) / (2M) on [0, 1] (Boyd):
w_i = 2 sin((i - 1/2) pi) sin^2(M pi / 2) / (M^2 pi) + 4 / (M pi) * sum_{p=1}^{M-1} sin(p pi x_i) sin^2(p pi / 2) / p
In _fourier2 the sine argument is built as (2i - 1) / M * p * pi, i.e. x_i is missing the factor 1/2, which is what makes the weights antisymmetric. The weights are also scaled by the "alternative" volume (M - 1) h per axis, but the points x_i above sit half a spacing in from each end of an interval of length M h, so the scale should be the plain grid volume. With only the first change the integral still converges like ((M - 1) / M)**3; with both it converges spectrally:
The existing test_fourier2_weights_are_correct re-implements the same formula with the same missing factor, so it does not catch this. I have a fix (two lines in cubic.py, plus the docstring) and a test that checks the Gaussian integral above. Happy to open a PR if that's fine.
Activity