|
| 1 | +import numpy as np |
| 2 | +import pytest |
| 3 | + |
| 4 | +from rocketpy.mathutils.function import Function |
| 5 | + |
| 6 | + |
| 7 | +def test_from_grid_unsupported_extrapolation_raises(): |
| 8 | + """from_grid should reject unsupported extrapolation names with ValueError.""" |
| 9 | + mach = np.array([0.0, 1.0]) |
| 10 | + reynolds = np.array([1e5, 2e5]) |
| 11 | + grid = np.zeros((mach.size, reynolds.size)) |
| 12 | + |
| 13 | + with pytest.raises(ValueError): |
| 14 | + Function.from_grid(grid, [mach, reynolds], extrapolation="unsupported_mode") |
| 15 | + |
| 16 | + |
| 17 | +def test_from_grid_is_multidimensional_property(): |
| 18 | + """Ensure `is_multidimensional` is True for ND grid Functions and False for 1D.""" |
| 19 | + mach = np.array([0.0, 0.5, 1.0]) |
| 20 | + reynolds = np.array([1e5, 2e5, 3e5]) |
| 21 | + alpha = np.array([0.0, 2.0]) |
| 22 | + |
| 23 | + M, R, A = np.meshgrid(mach, reynolds, alpha, indexing="ij") |
| 24 | + cd_data = 0.1 + 0.2 * M + 1e-7 * R + 0.01 * A |
| 25 | + |
| 26 | + func_nd = Function.from_grid( |
| 27 | + cd_data, [mach, reynolds, alpha], inputs=["Mach", "Reynolds", "Alpha"], outputs="Cd" |
| 28 | + ) |
| 29 | + |
| 30 | + assert hasattr(func_nd, "is_multidimensional") |
| 31 | + assert func_nd.is_multidimensional is True |
| 32 | + |
| 33 | + # 1D Function constructed from a two-column array should not be multidimensional |
| 34 | + src = np.column_stack((mach, 0.5 + 0.1 * mach)) |
| 35 | + func_1d = Function(src, inputs=["Mach"], outputs="Cd") |
| 36 | + assert hasattr(func_1d, "is_multidimensional") |
| 37 | + assert func_1d.is_multidimensional is False |
0 commit comments