def test_interpolation_singular(): """ test interpolation on singular dimensions """ grid = UnitGrid([1]) field = ScalarField(grid, data=3) # test constant boundary conditions bc = [{"type": "value", "value": 1}, {"type": "value", "value": 5}] x = np.linspace(0, 1, 7).reshape((7, 1)) y = field.interpolate(x, method="numba", bc=bc) np.testing.assert_allclose(y, 1 + 4 * x.ravel()) # test derivative boundary conditions bc = [{ "type": "derivative", "value": -2 }, { "type": "derivative", "value": 2 }] x = np.linspace(0, 1, 7).reshape((7, 1)) y = field.interpolate(x, method="numba", bc=bc) np.testing.assert_allclose(y, 2 + 2 * x.ravel()) # test boundary interpolation for upper in [True, False]: val = field.get_boundary_values(axis=0, upper=upper, bc=[{"value": 1}]) assert val == pytest.approx(1)
def test_boundary_interpolation_1d(): """test boundary interpolation for 1d fields""" grid = UnitGrid([5]) field = ScalarField(grid, np.arange(grid.shape[0])) # test boundary interpolation bndry_val = 0.25 for bndry in grid._iter_boundaries(): val = field.get_boundary_values(*bndry, bc={"value": bndry_val}) np.testing.assert_allclose(val, bndry_val)
def test_interpolation_singular(): """test interpolation on singular dimensions""" grid = UnitGrid([1]) field = ScalarField(grid, data=3) # test constant boundary conditions x = np.linspace(0, 1, 7).reshape((7, 1)) y = field.interpolate(x, backend="numba") np.testing.assert_allclose(y, 3) # # test boundary interpolation for upper in [True, False]: val = field.get_boundary_values(axis=0, upper=upper, bc=[{"value": 1}]) assert val == pytest.approx(1)
def test_boundary_interpolation_1d(): """test boundary interpolation for 1d fields""" grid = UnitGrid([5]) field = ScalarField(grid, np.arange(grid.shape[0])) # test boundary interpolation bndry_val = 0.25 for bndry in grid._iter_boundaries(): val = field.get_boundary_values(*bndry, bc={"value": bndry_val}) np.testing.assert_allclose(val, bndry_val) # boundary conditions have already been enforced ev = field.make_get_boundary_values(*bndry) out = ev() np.testing.assert_allclose(out, bndry_val) ev(data_full=field._data_full, out=out) np.testing.assert_allclose(out, bndry_val)