Adds a lot of stuff for discretisation

This commit is contained in:
2022-01-02 20:20:58 -06:00
parent 0adca4bcd7
commit 93e0cdb623
8 changed files with 138 additions and 15 deletions

View File

@@ -2,13 +2,13 @@ from pdme.model.fixed_z_plane_model import FixedZPlaneModel, FixedZPlaneDiscreti
import numpy
def test_fixed_z_plane_model_cost_and_jac_single():
def test_fixed_z_plane_model_discretization():
model = FixedZPlaneModel(4, -10, 10, -10, 10, 1)
discretisation = FixedZPlaneDiscretisation(model, 2, 5)
discretisation = FixedZPlaneDiscretisation(model, 2, 5, 15)
# x: (-10, 0) and (0, 10)
# y: (-10, -6, -2, 2, 6, 10)
assert discretisation.cell_count == 10
assert discretisation.x_step == 10
assert discretisation.y_step == 4
numpy.testing.assert_allclose(discretisation.bounds((0, 0)), ((-numpy.inf, -10, -10, -numpy.inf), (numpy.inf, 0, -6, numpy.inf)))
numpy.testing.assert_allclose(discretisation.bounds((0, 0)), ((-15, -10, -10, -numpy.inf), (15, 0, -6, numpy.inf)))
numpy.testing.assert_allclose(list(discretisation.all_indices()), list(numpy.ndindex((2, 5))))

View File

@@ -13,7 +13,7 @@ def test_unrestricted_model_solve_basic():
))
dots = dipoles.get_dot_measurements(dot_inputs)
model = UnrestrictedModel(1)
model = UnrestrictedModel(1, -1, 1, -1, 1, -1, 1)
# from the dipole, these are the unspecified variables in ((0, 0, 2), (1, 2, 4), 1)
expected_solution = [0.2, 0, 2, 1, 2, 4, 1]

View File

@@ -0,0 +1,15 @@
from pdme.model.unrestricted_model import UnrestrictedModel, UnrestrictedDiscretisation
import numpy
def test_unrestricted_model_discretization():
model = UnrestrictedModel(-10, 10, -10, 10, -10, 10, 1)
discretisation = UnrestrictedDiscretisation(model, 2, 5, 1, 15)
# x: (-10, 0) and (0, 10)
# y: (-10, -6, -2, 2, 6, 10)
assert discretisation.cell_count == 10
assert discretisation.x_step == 10
assert discretisation.y_step == 4
assert discretisation.z_step == 20
numpy.testing.assert_allclose(discretisation.bounds((0, 0, 0)), ((-15, -15, -15, -10, -10, -10, -numpy.inf), (15, 15, 15, 0, -6, 10, numpy.inf)))
numpy.testing.assert_allclose(list(discretisation.all_indices()), list(numpy.ndindex((2, 5, 1))))

View File

@@ -5,12 +5,12 @@ import numpy
def test_unrestricted_plane_model_repr():
model = UnrestrictedModel(6)
assert repr(model) == "UnrestrictedModel(6)"
model = UnrestrictedModel(1, 2, 3, 4, 5, 6, 6)
assert repr(model) == "UnrestrictedModel(1, 2, 3, 4, 5, 6, 6)"
def test_unrestricted_model_cost_and_jac_single():
model = UnrestrictedModel(1)
model = UnrestrictedModel(1, -1, 1, -1, 1, -1, 1)
measured_v = 0.000191292 # from dipole with p=(0, 0, 2) at (1, 2, 4) with w = 1
dot = DotMeasurement(measured_v, (1, 2, 0), 5)
pt = numpy.array([0, 0, 2, 2, 2, 4, 2])