def test_inject_time_shift(shape, coords, result, npoints=19): """Test generic point injection testing the x-coordinate of an abitrary set of points going across the grid. This test verifies the optional time shifting for SparseTimeFunctions """ a = unit_box_time(shape=shape) a.data[:] = 0. p = time_points(a.grid, ranges=coords, npoints=npoints) expr = p.inject(a, FLOAT(1.), u_t=a.indices[0] + 1) Operator(expr)(a=a, time=1) indices = [slice(1, 1, 1)] + [slice(4, 6, 1) for _ in coords] indices[1] = slice(1, -1, 1) assert np.allclose(a.data[indices], result, rtol=1.e-5) a.data[:] = 0. expr = p.inject(a, FLOAT(1.), p_t=p.indices[0] + 1) Operator(expr)(a=a, time=1) indices = [slice(0, 0, 1)] + [slice(4, 6, 1) for _ in coords] indices[1] = slice(1, -1, 1) assert np.allclose(a.data[indices], result, rtol=1.e-5) a.data[:] = 0. expr = p.inject(a, FLOAT(1.), u_t=a.indices[0] + 1, p_t=p.indices[0] + 1) Operator(expr)(a=a, time=1) indices = [slice(1, 1, 1)] + [slice(4, 6, 1) for _ in coords] indices[1] = slice(1, -1, 1) assert np.allclose(a.data[indices], result, rtol=1.e-5)
def coordinate_bases(self): """Symbol for the base coordinates of the reference grid point""" indices = self.grid.dimensions return tuple([FLOAT(c - idx * i.spacing) for c, idx, i in zip(self.coordinate_symbols, self.coordinate_indices, indices[:self.grid.dim])])
def test_inject(shape, coords, result, npoints=19): """Test point injection with a set of points forming a line through the middle of the grid. """ a = unit_box(shape=shape) a.data[:] = 0. p = points(a.grid, ranges=coords, npoints=npoints) expr = p.inject(a, FLOAT(1.)) Operator(expr)(a=a) indices = [slice(4, 6, 1) for _ in coords] indices[0] = slice(1, -1, 1) assert np.allclose(a.data[indices], result, rtol=1.e-5)