Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest

import pybamm
from tests.shared import get_mesh_for_testing


def pytest_addoption(parser):
Expand Down Expand Up @@ -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)
1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
get_1p1d_mesh_for_testing,
get_mesh_for_testing,
get_mesh_for_testing_symbolic,
get_p2d_mesh_for_testing,
)


Expand Down Expand Up @@ -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"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
get_1p1d_mesh_for_testing,
get_mesh_for_testing,
get_mesh_for_testing_symbolic,
get_p2d_mesh_for_testing,
)


Expand Down Expand Up @@ -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",
Expand All @@ -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)
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading