diff --git a/tests/integration/test_experiments.py b/tests/integration/test_experiments.py index 595e5af2bb..e31f098184 100644 --- a/tests/integration/test_experiments.py +++ b/tests/integration/test_experiments.py @@ -20,14 +20,18 @@ def test_discharge_rest_charge(self): model, experiment=experiment, solver=pybamm.CasadiSolver() ) sim.solve() - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( sim._solution["Time [h]"].entries, np.array([0, 0.5, 1, 1 + 1e-9, 1.5, 2, 2 + 1e-9, 2.5, 3]), + rtol=1e-7, + atol=1e-6, ) cap = model.default_parameter_values["Nominal cell capacity [A.h]"] - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( sim._solution["Current [A]"].entries, [cap / 2] * 3 + [0] * 3 + [-cap / 2] * 3, + rtol=1e-7, + atol=1e-6, ) def test_rest_discharge_rest(self): @@ -45,8 +49,10 @@ def test_rest_discharge_rest(self): solver=pybamm.CasadiSolver(), ) sol = sim.solve() - np.testing.assert_array_almost_equal(sol["Current [A]"].data[:5], 0) - np.testing.assert_array_almost_equal(sol["Current [A]"].data[-29:], 0) + np.testing.assert_allclose(sol["Current [A]"].data[:5], 0, rtol=1e-7, atol=1e-6) + np.testing.assert_allclose( + sol["Current [A]"].data[-29:], 0, rtol=1e-7, atol=1e-6 + ) def test_gitt(self): experiment = pybamm.Experiment( @@ -58,9 +64,11 @@ def test_gitt(self): ) sim.solve() cap = model.default_parameter_values["Nominal cell capacity [A.h]"] - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( sim._solution["Current [A]"].entries, [cap / 20] * 11 + [0] * 11 + ([cap / 20] * 11 + [0] * 11) * 9, + rtol=1e-7, + atol=1e-6, ) def test_infeasible(self): diff --git a/tests/integration/test_models/standard_model_tests.py b/tests/integration/test_models/standard_model_tests.py index a962894c44..ae423c6af0 100644 --- a/tests/integration/test_models/standard_model_tests.py +++ b/tests/integration/test_models/standard_model_tests.py @@ -167,8 +167,6 @@ def test_serialisation(self, solver=None, t_eval=None): new_solver.rtol = 1e-8 new_solver.atol = 1e-8 - accuracy = 5 - Crate = abs( self.parameter_values["Current function [A]"] / self.parameter_values["Nominal cell capacity [A.h]"] @@ -182,8 +180,11 @@ def test_serialisation(self, solver=None, t_eval=None): new_solution = new_solver.solve(new_model, t_eval) for x, _ in enumerate(self.solution.all_ys): - np.testing.assert_array_almost_equal( - new_solution.all_ys[x], self.solution.all_ys[x], decimal=accuracy + np.testing.assert_allclose( + new_solution.all_ys[x], + self.solution.all_ys[x], + rtol=1e-6, + atol=1e-6, ) temp.close() diff --git a/tests/integration/test_models/standard_output_tests.py b/tests/integration/test_models/standard_output_tests.py index a2006a4bca..3dc61219d6 100644 --- a/tests/integration/test_models/standard_output_tests.py +++ b/tests/integration/test_models/standard_output_tests.py @@ -163,8 +163,8 @@ def test_each_reaction_overpotential(self): np.testing.assert_array_less(self.eta_r_n(t, x_n), tol) np.testing.assert_array_less(-self.eta_r_p(t, x_p), tol) elif self.operating_condition == "off": - np.testing.assert_array_almost_equal(self.eta_r_n(t, x_n), 0) - np.testing.assert_array_almost_equal(-self.eta_r_p(t, x_p), 0) + np.testing.assert_allclose(self.eta_r_n(t, x_n), 0, rtol=1e-7, atol=1e-6) + np.testing.assert_allclose(-self.eta_r_p(t, x_p), 0, rtol=1e-7, atol=1e-6) def test_overpotentials(self): """Testing that all are: @@ -183,8 +183,8 @@ def test_overpotentials(self): np.testing.assert_array_less(-self.delta_phi_s_av(self.t), tol) elif self.operating_condition == "off": - np.testing.assert_array_almost_equal(self.eta_r_av(self.t), 0) - np.testing.assert_array_almost_equal(self.eta_e_av(self.t), 0, decimal=11) + np.testing.assert_allclose(self.eta_r_av(self.t), 0, rtol=1e-7, atol=1e-6) + np.testing.assert_allclose(self.eta_e_av(self.t), 0, rtol=1e-12, atol=1e-11) np.testing.assert_allclose( self.delta_phi_s_av(self.t), 0, atol=2e-14, rtol=1e-16 ) @@ -204,8 +204,8 @@ def test_ocps(self): np.testing.assert_array_less(neg_end_vs_start, 0) np.testing.assert_array_less(-pos_end_vs_start, 0) elif self.operating_condition == "off": - np.testing.assert_array_almost_equal(neg_end_vs_start, 0) - np.testing.assert_array_almost_equal(pos_end_vs_start, 0) + np.testing.assert_allclose(neg_end_vs_start, 0, rtol=1e-7, atol=1e-6) + np.testing.assert_allclose(pos_end_vs_start, 0, rtol=1e-7, atol=1e-6) def test_ocv(self): """Testing that: @@ -221,7 +221,7 @@ def test_ocv(self): elif self.operating_condition == "charge": np.testing.assert_array_less(-end_vs_start, 0) elif self.operating_condition == "off": - np.testing.assert_array_almost_equal(end_vs_start, 0) + np.testing.assert_allclose(end_vs_start, 0, rtol=1e-7, atol=1e-6) def test_voltage(self): """Testing that: @@ -236,24 +236,32 @@ def test_voltage(self): elif self.operating_condition == "charge": np.testing.assert_array_less(-end_vs_start, 0) elif self.operating_condition == "off": - np.testing.assert_array_almost_equal(end_vs_start, 0) + np.testing.assert_allclose(end_vs_start, 0, rtol=1e-7, atol=1e-6) def test_consistent(self): """Test voltage components are consistent with one another by ensuring they sum correctly""" - np.testing.assert_array_almost_equal( - self.ocv(self.t), self.ocp_p(self.t) - self.ocp_n(self.t) + np.testing.assert_allclose( + self.ocv(self.t), + self.ocp_p(self.t) - self.ocp_n(self.t), + rtol=1e-7, + atol=1e-6, ) - np.testing.assert_array_almost_equal( - self.eta_r_av(self.t), self.eta_r_p_av(self.t) - self.eta_r_n_av(self.t) + np.testing.assert_allclose( + self.eta_r_av(self.t), + self.eta_r_p_av(self.t) - self.eta_r_n_av(self.t), + rtol=1e-7, + atol=1e-6, ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( self.eta_particle(self.t), self.eta_particle_p(self.t) - self.eta_particle_n(self.t), + rtol=1e-7, + atol=1e-6, ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( self.voltage(self.t), self.ocv(self.t) + self.eta_particle(self.t) @@ -261,7 +269,8 @@ def test_consistent(self): + self.eta_e_av(self.t) + self.delta_phi_s_av(self.t) + self.eta_sei_av(self.t), - decimal=5, + rtol=1e-6, + atol=1e-5, ) def test_all(self): @@ -385,8 +394,8 @@ def test_concentration_increase_decrease(self): np.testing.assert_array_less(0, neg_end_vs_start) np.testing.assert_array_less(pos_end_vs_start, 0) elif self.operating_condition == "off": - np.testing.assert_array_almost_equal(neg_diff, 0) - np.testing.assert_array_almost_equal(pos_diff, 0) + np.testing.assert_allclose(neg_diff, 0, rtol=1e-7, atol=1e-6) + np.testing.assert_allclose(pos_diff, 0, rtol=1e-7, atol=1e-6) np.testing.assert_allclose(neg_end_vs_start, 0, rtol=1e-16, atol=1e-5) np.testing.assert_allclose(pos_end_vs_start, 0, rtol=1e-16, atol=1e-5) @@ -455,7 +464,8 @@ def test_conservation(self): decimal = 9 else: decimal = 14 - np.testing.assert_array_almost_equal(diff, 0, decimal=decimal) + atol = 10 ** (-decimal + 1) + np.testing.assert_allclose(diff, 0, rtol=1e-7, atol=atol) def test_concentration_profile(self): """Test that the concentration in the centre of the negative particles is @@ -479,8 +489,8 @@ def test_fluxes(self): ) if self.model.options["particle"] == "uniform profile": # Fluxes are zero everywhere since the concentration is uniform - np.testing.assert_array_almost_equal(self.N_s_n(t, x_n, r_n), 0) - np.testing.assert_array_almost_equal(self.N_s_p(t, x_p, r_p), 0) + np.testing.assert_allclose(self.N_s_n(t, x_n, r_n), 0, rtol=1e-7, atol=1e-6) + np.testing.assert_allclose(self.N_s_p(t, x_p, r_p), 0, rtol=1e-7, atol=1e-6) else: if self.operating_condition == "discharge": if self.model.options["particle"] == "quartic profile": @@ -498,11 +508,15 @@ def test_fluxes(self): np.testing.assert_array_less(self.N_s_n(t[1:], x_n, r_n[1:]), 1e-16) np.testing.assert_array_less(-1e-16, self.N_s_p(t[1:], x_p, r_p[1:])) if self.operating_condition == "off": - np.testing.assert_array_almost_equal(self.N_s_n(t, x_n, r_n), 0) - np.testing.assert_array_almost_equal(self.N_s_p(t, x_p, r_p), 0) + np.testing.assert_allclose( + self.N_s_n(t, x_n, r_n), 0, rtol=1e-7, atol=1e-6 + ) + np.testing.assert_allclose( + self.N_s_p(t, x_p, r_p), 0, rtol=1e-7, atol=1e-6 + ) - np.testing.assert_array_almost_equal(0, self.N_s_n(t, x_n, r_n[0]), decimal=4) - np.testing.assert_array_almost_equal(0, self.N_s_p(t, x_p, r_p[0]), decimal=4) + np.testing.assert_allclose(0, self.N_s_n(t, x_n, r_n[0]), rtol=1e-5, atol=1e-4) + np.testing.assert_allclose(0, self.N_s_p(t, x_p, r_p[0]), rtol=1e-5, atol=1e-4) def test_all(self): self.test_concentration_increase_decrease() @@ -590,8 +604,8 @@ def test_fluxes(self): models (bug in implementation of boundary conditions?)""" t, x = self.t, self.x_edge - np.testing.assert_array_almost_equal(self.N_e_hat(t, x[0]), 0, decimal=3) - np.testing.assert_array_almost_equal(self.N_e_hat(t, x[-1]), 0, decimal=3) + np.testing.assert_allclose(self.N_e_hat(t, x[0]), 0, rtol=1e-4, atol=1e-3) + np.testing.assert_allclose(self.N_e_hat(t, x[-1]), 0, rtol=1e-4, atol=1e-3) def test_splitting(self): """Test that when splitting the concentrations and fluxes by negative electrode, @@ -604,7 +618,7 @@ def test_splitting(self): # Loose tolerance since the different way that c_e and c_e_n/s/p are calculated # introduces some numerical error - np.testing.assert_array_almost_equal(self.c_e(t, x), c_e_combined, decimal=12) + np.testing.assert_allclose(self.c_e(t, x), c_e_combined, rtol=1e-13, atol=1e-12) def test_all(self): self.test_concentration_limit() @@ -660,7 +674,7 @@ def __init__(self, model, param, disc, solution, operating_condition): def test_negative_electrode_potential_profile(self): """Test that negative electrode potential is zero on left boundary. Test average negative electrode potential is less than or equal to zero.""" - np.testing.assert_array_almost_equal(self.phi_s_n(self.t, x=0), 0, decimal=5) + np.testing.assert_allclose(self.phi_s_n(self.t, x=0), 0, rtol=1e-6, atol=1e-5) def test_positive_electrode_potential_profile(self): """Test average positive electrode potential is less than the positive electrode @@ -673,13 +687,17 @@ def test_potential_differences(self): potential and electrolyte potential""" t, x_n, x_p = self.t, self.x_n, self.x_p - np.testing.assert_array_almost_equal( - self.phi_s_n(t, x_n) - self.phi_e_n(t, x_n), self.delta_phi_n(t, x_n) + np.testing.assert_allclose( + self.phi_s_n(t, x_n) - self.phi_e_n(t, x_n), + self.delta_phi_n(t, x_n), + rtol=1e-7, + atol=1e-6, ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( self.phi_s_p(t, x_p) - self.phi_e_p(t, x_p), self.delta_phi_p(t, x_p), - decimal=5, + rtol=1e-6, + atol=1e-5, ) def test_average_potential_differences(self): @@ -687,11 +705,17 @@ def test_average_potential_differences(self): potential and electrolyte potential""" t = self.t - np.testing.assert_array_almost_equal( - self.phi_s_n_av(t) - self.phi_e_n_av(t), self.delta_phi_n_av(t), decimal=4 + np.testing.assert_allclose( + self.phi_s_n_av(t) - self.phi_e_n_av(t), + self.delta_phi_n_av(t), + rtol=1e-5, + atol=1e-4, ) - np.testing.assert_array_almost_equal( - self.phi_s_p_av(t) - self.phi_e_p_av(t), self.delta_phi_p_av(t), decimal=4 + np.testing.assert_allclose( + self.phi_s_p_av(t) - self.phi_e_p_av(t), + self.delta_phi_p_av(t), + rtol=1e-5, + atol=1e-4, ) def test_gradient_splitting(self): @@ -802,10 +826,10 @@ def test_current_density_boundaries(self): current_param = self.model.param.current_density_with_time i_cell = self.param.process_symbol(current_param).evaluate(t=t) - np.testing.assert_array_almost_equal(self.i_s_n(t, x_n[0]), i_cell, decimal=2) - np.testing.assert_array_almost_equal(self.i_s_n(t, x_n[-1]), 0, decimal=4) - np.testing.assert_array_almost_equal(self.i_s_p(t, x_p[-1]), i_cell, decimal=3) - np.testing.assert_array_almost_equal(self.i_s_p(t, x_p[0]), 0, decimal=4) + np.testing.assert_allclose(self.i_s_n(t, x_n[0]), i_cell, rtol=1e-3, atol=1e-2) + np.testing.assert_allclose(self.i_s_n(t, x_n[-1]), 0, rtol=1e-5, atol=1e-4) + np.testing.assert_allclose(self.i_s_p(t, x_p[-1]), i_cell, rtol=1e-4, atol=1e-3) + np.testing.assert_allclose(self.i_s_p(t, x_p[0]), 0, rtol=1e-5, atol=1e-4) def test_all(self): self.test_conservation() @@ -827,8 +851,8 @@ def __init__(self, model, param, disc, solution, operating_condition): def test_velocity_boundaries(self): """Test the boundary values of the current densities""" L_x = self.x_edge[-1] - np.testing.assert_array_almost_equal(self.v_box(self.t, 0), 0, decimal=4) - np.testing.assert_array_almost_equal(self.v_box(self.t, L_x), 0, decimal=4) + np.testing.assert_allclose(self.v_box(self.t, 0), 0, rtol=1e-5, atol=1e-4) + np.testing.assert_allclose(self.v_box(self.t, L_x), 0, rtol=1e-5, atol=1e-4) def test_vertical_velocity(self): """Test the boundary values of the current densities""" @@ -847,11 +871,11 @@ def test_velocity_vs_current(self): DeltaV_p = self.param.evaluate(DeltaV_p) F = pybamm.constants.F.value - np.testing.assert_array_almost_equal( - self.v_box(t, x_n), DeltaV_n * self.i_e(t, x_n) / F + np.testing.assert_allclose( + self.v_box(t, x_n), DeltaV_n * self.i_e(t, x_n) / F, rtol=1e-7, atol=1e-6 ) - np.testing.assert_array_almost_equal( - self.v_box(t, x_p), DeltaV_p * self.i_e(t, x_p) / F + np.testing.assert_allclose( + self.v_box(t, x_p), DeltaV_p * self.i_e(t, x_p) / F, rtol=1e-7, atol=1e-6 ) def test_all(self): @@ -889,12 +913,13 @@ def test_degradation_modes(self): def test_lithium_lost(self): """Test the two ways of measuring lithium lost give the same value""" - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( self.n_Li_lost(self.t), self.n_Li_lost_rxn(self.t) + self.n_Li_lost_LAM_n(self.t) + self.n_Li_lost_LAM_p(self.t), - decimal=5, + rtol=1e-6, + atol=1e-5, ) def test_all(self): diff --git a/tests/integration/test_models/test_full_battery_models/test_lead_acid/test_full.py b/tests/integration/test_models/test_full_battery_models/test_lead_acid/test_full.py index 1c5e93615d..a039bc127e 100644 --- a/tests/integration/test_models/test_full_battery_models/test_lead_acid/test_full.py +++ b/tests/integration/test_models/test_full_battery_models/test_lead_acid/test_full.py @@ -28,7 +28,7 @@ def test_optimisations(self): original = optimtest.evaluate_model() to_python = optimtest.evaluate_model(to_python=True) - np.testing.assert_array_almost_equal(original, to_python) + np.testing.assert_allclose(original, to_python, rtol=1e-7, atol=1e-6) def test_set_up(self): options = {"thermal": "isothermal"} diff --git a/tests/integration/test_models/test_full_battery_models/test_lead_acid/test_loqs.py b/tests/integration/test_models/test_full_battery_models/test_lead_acid/test_loqs.py index b9893224da..267e35792c 100644 --- a/tests/integration/test_models/test_full_battery_models/test_lead_acid/test_loqs.py +++ b/tests/integration/test_models/test_full_battery_models/test_lead_acid/test_loqs.py @@ -19,7 +19,7 @@ def test_optimisations(self): original = optimtest.evaluate_model() to_python = optimtest.evaluate_model(to_python=True) - np.testing.assert_array_almost_equal(original, to_python) + np.testing.assert_allclose(original, to_python, rtol=1e-7, atol=1e-6) def test_set_up(self): model = pybamm.lead_acid.LOQS() diff --git a/tests/integration/test_models/test_full_battery_models/test_lead_acid/test_loqs_surface_form.py b/tests/integration/test_models/test_full_battery_models/test_lead_acid/test_loqs_surface_form.py index a99e42d93e..b60321cd06 100644 --- a/tests/integration/test_models/test_full_battery_models/test_lead_acid/test_loqs_surface_form.py +++ b/tests/integration/test_models/test_full_battery_models/test_lead_acid/test_loqs_surface_form.py @@ -48,7 +48,7 @@ def test_optimisations(self): original = optimtest.evaluate_model() to_python = optimtest.evaluate_model(to_python=True) - np.testing.assert_array_almost_equal(original, to_python, decimal=5) + np.testing.assert_allclose(original, to_python, rtol=1e-6, atol=1e-5) def test_set_up(self): options = {"surface form": "differential"} diff --git a/tests/integration/test_models/test_full_battery_models/test_lithium_ion/base_lithium_ion_tests.py b/tests/integration/test_models/test_full_battery_models/test_lithium_ion/base_lithium_ion_tests.py index 8f58d0ad6b..8621d8a861 100644 --- a/tests/integration/test_models/test_full_battery_models/test_lithium_ion/base_lithium_ion_tests.py +++ b/tests/integration/test_models/test_full_battery_models/test_lithium_ion/base_lithium_ion_tests.py @@ -45,11 +45,11 @@ def test_optimisations(self): original = optimtest.evaluate_model() to_python = optimtest.evaluate_model(to_python=True) - np.testing.assert_array_almost_equal(original, to_python) + np.testing.assert_allclose(original, to_python, rtol=1e-7, atol=1e-7) if pybamm.has_jax(): to_jax = optimtest.evaluate_model(to_jax=True) - np.testing.assert_array_almost_equal(original, to_jax) + np.testing.assert_allclose(original, to_jax, rtol=1e-7, atol=1e-7) def test_set_up(self): model = self.model() diff --git a/tests/integration/test_models/test_full_battery_models/test_lithium_ion/test_dfn.py b/tests/integration/test_models/test_full_battery_models/test_lithium_ion/test_dfn.py index a147104f4f..36f45526b0 100644 --- a/tests/integration/test_models/test_full_battery_models/test_lithium_ion/test_dfn.py +++ b/tests/integration/test_models/test_full_battery_models/test_lithium_ion/test_dfn.py @@ -149,8 +149,8 @@ def test_conservation_each_electrode(self): pos_Li.append(pos) # compare - np.testing.assert_array_almost_equal(neg_Li[0], neg_Li[1], decimal=12) - np.testing.assert_array_almost_equal(pos_Li[0], pos_Li[1], decimal=12) + np.testing.assert_allclose(neg_Li[0], neg_Li[1], rtol=1e-13, atol=1e-12) + np.testing.assert_allclose(pos_Li[0], pos_Li[1], rtol=1e-13, atol=1e-12) def test_basic_processing_nonlinear_diffusion(self): options = { diff --git a/tests/integration/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py b/tests/integration/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py index dc5700eec3..1a093c68ed 100644 --- a/tests/integration/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py +++ b/tests/integration/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py @@ -23,11 +23,11 @@ def test_optimisations(self): original = optimtest.evaluate_model() to_python = optimtest.evaluate_model(to_python=True) - np.testing.assert_array_almost_equal(original, to_python) + np.testing.assert_allclose(original, to_python, rtol=1e-7, atol=1e-6) if pybamm.has_jax(): to_jax = optimtest.evaluate_model(to_jax=True) - np.testing.assert_array_almost_equal(original, to_jax) + np.testing.assert_allclose(original, to_jax, rtol=1e-7, atol=1e-6) def test_set_up(self): model = pybamm.lithium_ion.MPM() @@ -122,8 +122,8 @@ def test_conservation_each_electrode(self): pos_Li.append(pos) # compare - np.testing.assert_array_almost_equal(neg_Li[0], neg_Li[1], decimal=13) - np.testing.assert_array_almost_equal(pos_Li[0], pos_Li[1], decimal=13) + np.testing.assert_allclose(neg_Li[0], neg_Li[1], rtol=1e-13, atol=1e-13) + np.testing.assert_allclose(pos_Li[0], pos_Li[1], rtol=1e-13, atol=1e-13) def test_basic_processing_nonlinear_diffusion(self): model = pybamm.lithium_ion.MPM() diff --git a/tests/integration/test_models/test_submodels/test_external_circuit/test_function_control.py b/tests/integration/test_models/test_submodels/test_external_circuit/test_function_control.py index b2c46eed5b..62c8307d65 100644 --- a/tests/integration/test_models/test_submodels/test_external_circuit/test_function_control.py +++ b/tests/integration/test_models/test_submodels/test_external_circuit/test_function_control.py @@ -41,14 +41,17 @@ def constant_current(variables): for i, model in enumerate(models): solutions[i] = model.default_solver.solve(model, t_eval) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( solutions[0]["Discharge capacity [A.h]"].entries, solutions[0]["Current [A]"].entries * solutions[0]["Time [h]"].entries, + rtol=1e-7, + atol=1e-6, ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( solutions[0]["Voltage [V]"](solutions[0].t), solutions[1]["Voltage [V]"](solutions[0].t), - decimal=5, + rtol=1e-6, + atol=1e-5, ) def test_constant_voltage(self): @@ -87,11 +90,11 @@ def constant_voltage(variables): V0 = solutions[0]["Voltage [V]"].entries V1 = solutions[1]["Voltage [V]"].entries - np.testing.assert_array_almost_equal(V0, V1) + np.testing.assert_allclose(V0, V1, rtol=1e-7, atol=1e-6) I0 = solutions[0]["Current [A]"].entries I1 = solutions[1]["Current [A]"].entries - np.testing.assert_array_almost_equal(abs((I1 - I0) / I0), 0, decimal=1) + np.testing.assert_allclose(abs((I1 - I0) / I0), 0, rtol=1e-2, atol=1e-1) def test_constant_power(self): def constant_power(variables): @@ -126,8 +129,8 @@ def constant_power(variables): for var in ["Voltage [V]", "Current [A]"]: for sol in solutions[1:]: - np.testing.assert_array_almost_equal( - solutions[0][var].data, sol[var].data + np.testing.assert_allclose( + solutions[0][var].data, sol[var].data, rtol=1e-7, atol=1e-6 ) def test_constant_resistance(self): @@ -163,8 +166,8 @@ def constant_resistance(variables): for var in ["Voltage [V]", "Current [A]"]: for sol in solutions[1:]: - np.testing.assert_array_almost_equal( - solutions[0][var].data, sol[var].data + np.testing.assert_allclose( + solutions[0][var].data, sol[var].data, rtol=1e-7, atol=1e-6 ) def test_cccv(self): diff --git a/tests/integration/test_solvers/test_solution.py b/tests/integration/test_solvers/test_solution.py index d0b98e8eb9..b062b0cc63 100644 --- a/tests/integration/test_solvers/test_solution.py +++ b/tests/integration/test_solvers/test_solution.py @@ -42,8 +42,9 @@ def test_append(self): old_t = t # Check both give the same answer - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( solution["Voltage [V]"](solution.t[:-1]), step_solution["Voltage [V]"](solution.t[:-1]), - decimal=4, + rtol=1e-5, + atol=1e-4, ) diff --git a/tests/integration/test_spatial_methods/test_finite_volume.py b/tests/integration/test_spatial_methods/test_finite_volume.py index 45b30f959d..e07d5fb24c 100644 --- a/tests/integration/test_spatial_methods/test_finite_volume.py +++ b/tests/integration/test_spatial_methods/test_finite_volume.py @@ -320,20 +320,29 @@ def solve_laplace_equation(coord_sys="cartesian"): class TestFiniteVolumeLaplacian: def test_laplacian_cartesian(self): solution = solve_laplace_equation(coord_sys="cartesian") - np.testing.assert_array_almost_equal( - solution["u"].entries, solution["r"].entries - 1, decimal=10 + np.testing.assert_allclose( + solution["u"].entries, + solution["r"].entries - 1, + rtol=1e-11, + atol=1e-10, ) def test_laplacian_cylindrical(self): solution = solve_laplace_equation(coord_sys="cylindrical polar") - np.testing.assert_array_almost_equal( - solution["u"].entries, np.log(solution["r"].entries) / np.log(2), decimal=5 + np.testing.assert_allclose( + solution["u"].entries, + np.log(solution["r"].entries) / np.log(2), + rtol=1e-6, + atol=1e-5, ) def test_laplacian_spherical(self): solution = solve_laplace_equation(coord_sys="spherical polar") - np.testing.assert_array_almost_equal( - solution["u"].entries, 2 - 2 / solution["r"].entries, decimal=5 + np.testing.assert_allclose( + solution["u"].entries, + 2 - 2 / solution["r"].entries, + rtol=1e-6, + atol=1e-5, ) @@ -375,12 +384,18 @@ def solve_advection_equation(direction="upwind", source=1, bc=0): class TestUpwindDownwind: def test_upwind(self): solution = solve_advection_equation("upwind") - np.testing.assert_array_almost_equal( - solution["u"].entries, solution["analytical"].entries, decimal=2 + np.testing.assert_allclose( + solution["u"].entries, + solution["analytical"].entries, + rtol=1e-3, + atol=1e-1, ) def test_downwind(self): solution = solve_advection_equation("downwind") - np.testing.assert_array_almost_equal( - solution["u"].entries, solution["analytical"].entries, decimal=2 + np.testing.assert_allclose( + solution["u"].entries, + solution["analytical"].entries, + rtol=1e-3, + atol=1e-1, )