diff --git a/conftest.py b/conftest.py index ba258c541a..c2909df5d0 100644 --- a/conftest.py +++ b/conftest.py @@ -2,6 +2,7 @@ import pytest import pybamm +from tests.shared import get_mesh_for_testing def pytest_addoption(parser): @@ -50,3 +51,12 @@ def set_debug_value(): @pytest.fixture(autouse=True) def disable_telemetry(): pybamm.telemetry.disable() + + +@pytest.fixture +def p2d_mesh(): + """ + Default P2D mesh for unit tests. + """ + geometry = pybamm.battery_geometry() + return get_mesh_for_testing(xpts=None, rpts=10, geometry=geometry) diff --git a/tests/__init__.py b/tests/__init__.py index 56f64e381e..14641a8eed 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -29,7 +29,6 @@ get_unit_3d_mesh_for_testing, get_mesh_for_testing_symbolic, get_mesh_for_testing_symbolic_concatenation, - get_p2d_mesh_for_testing, get_size_distribution_mesh_for_testing, get_1p1d_mesh_for_testing, get_2p1d_mesh_for_testing, diff --git a/tests/unit/test_spatial_methods/test_finite_volume/test_extrapolation.py b/tests/unit/test_spatial_methods/test_finite_volume/test_extrapolation.py index 0f8a810519..0f73c772fc 100644 --- a/tests/unit/test_spatial_methods/test_finite_volume/test_extrapolation.py +++ b/tests/unit/test_spatial_methods/test_finite_volume/test_extrapolation.py @@ -10,7 +10,6 @@ get_1p1d_mesh_for_testing, get_mesh_for_testing, get_mesh_for_testing_symbolic, - get_p2d_mesh_for_testing, ) @@ -733,9 +732,9 @@ def test_extrapolate_on_nonuniform_grid(self): surf_eqn_disc.evaluate(None, linear_y), y_surf, rtol=1e-7, atol=1e-6 ) - def test_extrapolate_2d_models(self): + def test_extrapolate_2d_models(self, p2d_mesh): # create discretisation - mesh = get_p2d_mesh_for_testing() + mesh = p2d_mesh method_options = { "extrapolation": { "order": {"gradient": "linear", "value": "linear"}, diff --git a/tests/unit/test_spatial_methods/test_finite_volume/test_finite_volume.py b/tests/unit/test_spatial_methods/test_finite_volume/test_finite_volume.py index 8fe3a10d42..4c2d47a17c 100644 --- a/tests/unit/test_spatial_methods/test_finite_volume/test_finite_volume.py +++ b/tests/unit/test_spatial_methods/test_finite_volume/test_finite_volume.py @@ -11,7 +11,6 @@ get_1p1d_mesh_for_testing, get_mesh_for_testing, get_mesh_for_testing_symbolic, - get_p2d_mesh_for_testing, ) @@ -254,7 +253,7 @@ def test_mass_matrix_shape(self): mass = np.eye(submesh.npts) np.testing.assert_array_equal(mass, model.mass_matrix.entries.toarray()) - def test_p2d_mass_matrix_shape(self): + def test_p2d_mass_matrix_shape(self, p2d_mesh): # Create model c = pybamm.Variable( "c", @@ -271,7 +270,7 @@ def test_p2d_mass_matrix_shape(self): model.variables = {"c": c, "N": N} # Create discretisation - mesh = get_p2d_mesh_for_testing() + mesh = p2d_mesh spatial_methods = {"negative particle": pybamm.FiniteVolume()} disc = pybamm.Discretisation(mesh, spatial_methods) disc.process_model(model) @@ -355,8 +354,8 @@ def test_jacobian(self): eqn_jac = eqn_disc.jac(y) eqn_jac.evaluate(y=y_test) - def test_boundary_value_domain(self): - mesh = get_p2d_mesh_for_testing() + def test_boundary_value_domain(self, p2d_mesh): + mesh = p2d_mesh spatial_methods = { "macroscale": pybamm.FiniteVolume(), "negative particle": pybamm.FiniteVolume(), @@ -645,8 +644,8 @@ def test_full_broadcast_domains(self): disc = pybamm.Discretisation(mesh, spatial_methods) disc.process_model(model) - def test_evaluate_at(self): - mesh = get_p2d_mesh_for_testing() + def test_evaluate_at(self, p2d_mesh): + mesh = p2d_mesh spatial_methods = { "macroscale": pybamm.FiniteVolume(), "negative particle": pybamm.FiniteVolume(), diff --git a/tests/unit/test_spatial_methods/test_finite_volume/test_ghost_nodes_and_neumann.py b/tests/unit/test_spatial_methods/test_finite_volume/test_ghost_nodes_and_neumann.py index f219dafbe6..b891d7dfb3 100644 --- a/tests/unit/test_spatial_methods/test_finite_volume/test_ghost_nodes_and_neumann.py +++ b/tests/unit/test_spatial_methods/test_finite_volume/test_ghost_nodes_and_neumann.py @@ -6,7 +6,7 @@ import pytest import pybamm -from tests import get_mesh_for_testing, get_p2d_mesh_for_testing +from tests import get_mesh_for_testing class TestGhostNodes: @@ -102,9 +102,9 @@ def test_add_ghost_nodes_concatenation(self): + symbol_plus_ghost_both.evaluate(None, y_test)[-1] ) / 2 == 3 - def test_p2d_add_ghost_nodes(self): + def test_p2d_add_ghost_nodes(self, p2d_mesh): # create discretisation - mesh = get_p2d_mesh_for_testing() + mesh = p2d_mesh spatial_methods = { "macroscale": pybamm.FiniteVolume(), "negative particle": pybamm.FiniteVolume(), diff --git a/tests/unit/test_spatial_methods/test_finite_volume/test_grad_div_shapes.py b/tests/unit/test_spatial_methods/test_finite_volume/test_grad_div_shapes.py index 92cfb4d341..ad72ef77b3 100644 --- a/tests/unit/test_spatial_methods/test_finite_volume/test_grad_div_shapes.py +++ b/tests/unit/test_spatial_methods/test_finite_volume/test_grad_div_shapes.py @@ -12,7 +12,6 @@ get_mesh_for_testing, get_mesh_for_testing_symbolic, get_mesh_for_testing_symbolic_concatenation, - get_p2d_mesh_for_testing, get_spherical_mesh_for_testing_symbolic, ) @@ -137,7 +136,7 @@ def test_cylindrical_grad_div_shapes_Dirichlet_bcs(self): div_eval[1:-1], 4 * np.ones((npts - 2, 1)), rtol=1e-7, atol=1e-6 ) - def test_spherical_grad_div_shapes_Dirichlet_bcs(self): + def test_spherical_grad_div_shapes_Dirichlet_bcs(self, p2d_mesh): """ Test grad and div with Dirichlet boundary conditions in spherical polar coordinates @@ -212,13 +211,13 @@ def test_spherical_grad_div_shapes_Dirichlet_bcs(self): div_eval[:, :-1], 6 * np.ones([sec_npts, npts - 1]), rtol=1e-7, atol=1e-6 ) - def test_p2d_spherical_grad_div_shapes_Dirichlet_bcs(self): + def test_p2d_spherical_grad_div_shapes_Dirichlet_bcs(self, p2d_mesh): """ Test grad and div with Dirichlet boundary conditions in the pseudo 2-dimensional case """ # Create discretisation - mesh = get_p2d_mesh_for_testing() + mesh = p2d_mesh spatial_methods = {"negative particle": pybamm.FiniteVolume()} disc = pybamm.Discretisation(mesh, spatial_methods) prim_pts = mesh["negative particle"].npts @@ -633,13 +632,13 @@ def test_spherical_grad_div_shapes_Neumann_bcs_symbolic(self): atol=1e-6, ) - def test_p2d_spherical_grad_div_shapes_Neumann_bcs(self): + def test_p2d_spherical_grad_div_shapes_Neumann_bcs(self, p2d_mesh): """ Test grad and div with Neumann boundary conditions in the pseudo 2-dimensional case """ # Create discretisation - mesh = get_p2d_mesh_for_testing() + mesh = p2d_mesh spatial_methods = {"negative particle": pybamm.FiniteVolume()} disc = pybamm.Discretisation(mesh, spatial_methods) prim_pts = mesh["negative particle"].npts