Skip to content

Commit

Permalink
#2418 fixing tests, unit tests should finish now
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Nov 26, 2022
1 parent 95fe21e commit ce4a6b3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
7 changes: 7 additions & 0 deletions pybamm/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,13 @@ def process_parameters_and_discretise(self, symbol, parameter_values, disc):
# Set y slices
if disc.y_slices == {}:
variables = list(self.rhs.keys()) + list(self.algebraic.keys())
for variable in variables:
variable.bounds = tuple(
[
parameter_values.process_symbol(bound)
for bound in variable.bounds
]
)
disc.set_variable_slices(variables)

# Set boundary conditions (also requires setting parameter values)
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/test_models/standard_output_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ def test_all(self):
self.compare("X-averaged open circuit voltage [V]")
# Currents
self.compare(
"X-averaged negative electrode volumetric interfacial current density [A.m-3]"
"X-averaged negative electrode volumetric "
"interfacial current density [A.m-3]"
)
self.compare(
"X-averaged positive electrode volumetric interfacial current density [A.m-3]"
"X-averaged positive electrode volumetric "
"interfacial current density [A.m-3]"
)
# Concentration
self.compare("X-averaged electrolyte concentration [mol.m-3]")
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_solvers/test_idaklu.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_set_tol_by_variable(self):
t_eval = np.linspace(0, 3600, 100)
solver = pybamm.IDAKLUSolver()

variable_tols = {"Porosity times concentration": 1e-3}
variable_tols = {"Porosity times concentration [mol.m-3]": 1e-3}
solver.set_atol_by_variable(variable_tols, model)

solver.solve(model, t_eval)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_solvers/test_idaklu_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def test_set_atol(self):
disc.process_model(model)
solver = pybamm.IDAKLUSolver()

variable_tols = {"Porosity times concentration": 1e-3}
variable_tols = {"Porosity times concentration [mol.m-3]": 1e-3}
solver.set_atol_by_variable(variable_tols, model)

model = pybamm.BaseModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ def test_linear_extrapolate_left_right(self):

# check linear variable extrapolates correctly
linear_y = macro_submesh.nodes
self.assertEqual(extrap_left_disc.evaluate(None, linear_y), 0)
np.testing.assert_array_almost_equal(
extrap_left_disc.evaluate(None, linear_y), 0
)
np.testing.assert_array_almost_equal(
extrap_right_disc.evaluate(None, linear_y), 3
)
Expand All @@ -280,12 +282,12 @@ def test_linear_extrapolate_left_right(self):
extrap_flux_right_disc = disc.process_symbol(extrap_flux_right)

# check constant extrapolates to constant
self.assertEqual(extrap_flux_left_disc.evaluate(None, constant_y), 0)
self.assertEqual(extrap_flux_right_disc.evaluate(None, constant_y), 0)
np.testing.assert_allclose(extrap_flux_left_disc.evaluate(y=constant_y), 0)
np.testing.assert_allclose(extrap_flux_right_disc.evaluate(y=constant_y), 0)

# check linear variable extrapolates correctly
self.assertEqual(extrap_flux_left_disc.evaluate(None, linear_y), 2)
self.assertEqual(extrap_flux_right_disc.evaluate(None, linear_y), -1)
np.testing.assert_allclose(extrap_flux_left_disc.evaluate(y=linear_y), 2)
np.testing.assert_allclose(extrap_flux_right_disc.evaluate(y=linear_y), -1)

# Microscale
# create variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ def test_jacobian(self):
grad_matrix = spatial_method.gradient_matrix(
whole_cell, {"primary": whole_cell}
).entries
np.testing.assert_array_equal(jacobian.toarray()[1:-1], grad_matrix.toarray())
np.testing.assert_array_equal(
np.testing.assert_allclose(jacobian.toarray()[1:-1], grad_matrix.toarray())
np.testing.assert_allclose(
jacobian.toarray()[0, 0], grad_matrix.toarray()[0][0] * -2
)
np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
jacobian.toarray()[-1, -1], grad_matrix.toarray()[-1][-1] * -2
)

Expand Down Expand Up @@ -360,7 +360,7 @@ def test_delta_function(self):
var_disc = disc.process_symbol(var)
x = pybamm.standard_spatial_vars.x_n
delta_fn_int_disc = disc.process_symbol(pybamm.Integral(delta_fn_left, x))
np.testing.assert_array_equal(
np.testing.assert_allclose(
var_disc.evaluate(y=y) * mesh["negative electrode"].edges[-1],
np.sum(delta_fn_int_disc.evaluate(y=y)),
)
Expand Down

0 comments on commit ce4a6b3

Please sign in to comment.