devito icon indicating copy to clipboard operation
devito copied to clipboard

default time_M value in presence of saved TimeFunction is wrong

Open FabioLuporini opened this issue 8 months ago • 0 comments

Reproducer

import numpy as np
from devito import Eq, Grid, TimeFunction, Operator

grid = Grid(shape=(4, 4))

u = TimeFunction(name='u', grid=grid)
usave = TimeFunction(name='usave', grid=grid, save=5)

eqns = [Eq(u.forward, u + 1),
        Eq(usave, u)]

op = Operator(eqns)

assert op.arguments()['time_M'] == 4

op.apply()

assert all(np.all(usave.data[i] == i) for i in range(5))

The issue stems from the fact that op._dspace sets [0,1] as the time dimension's data space bounds, and that "1" will cause the default value to become 3. Which is clearly wrong, since 4 is perfectly fine here.

This violates the principle of least surprise.

FabioLuporini avatar Oct 13 '23 10:10 FabioLuporini