Skip to content

Commit

Permalink
#247 add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Nov 26, 2019
1 parent f9d57e7 commit 50980b5
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ def test_compare_averages_asymptotics(self):
comparison = StandardOutputComparison(models, discs, solutions)
comparison.test_averages()

def test_compare_outputs_capacitance(self):
def test_compare_outputs_surface_form(self):
"""
Check that the leading-order model solution converges linearly in C_e to the
full model solution
Check that the models agree with the different surface forms
"""
# load models
options = [
{"surface form": cap} for cap in [False, "differential", "algebraic"]
]
model_combos = [
([pybamm.lead_acid.LOQS(opt) for opt in options]),
([pybamm.lead_acid.Composite(opt) for opt in options]),
([pybamm.lead_acid.Full(opt) for opt in options]),
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#
# Tests for the surface formulation
#
import pybamm
import numpy as np
import unittest
from tests import StandardOutputComparison


class TestCompareOutputs(unittest.TestCase):
def test_compare_outputs_surface_form(self):
# load models
options = [
{"surface form": cap} for cap in [False, "differential", "algebraic"]
]
model_combos = [
# ([pybamm.lithium_ion.SPM(opt) for opt in options]),
([pybamm.lithium_ion.DFN(opt) for opt in options])
]

for models in model_combos:
# load parameter values (same for all models)
param = models[0].default_parameter_values
param.update({"Typical current [A]": 1})
for model in models:
param.process_model(model)

# set mesh
var = pybamm.standard_spatial_vars
var_pts = {var.x_n: 5, var.x_s: 5, var.x_p: 5, var.r_n: 5, var.r_p: 5}

# discretise models
discs = {}
for model in models:
geometry = model.default_geometry
param.process_geometry(geometry)
mesh = pybamm.Mesh(geometry, model.default_submesh_types, var_pts)
disc = pybamm.Discretisation(mesh, model.default_spatial_methods)
disc.process_model(model)
discs[model] = disc

# solve model
solutions = {}
t_eval = np.linspace(0, 0.2, 100)
for i, model in enumerate(models):
solution = model.default_solver.solve(model, t_eval)
solutions[model] = solution

# compare outputs
comparison = StandardOutputComparison(models, discs, solutions)
comparison.test_all(skip_first_timestep=True)


if __name__ == "__main__":
print("Add -v for more debug output")
import sys

if "-v" in sys.argv:
debug = True
pybamm.set_logging_level("DEBUG")
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ def test_particle_fast_diffusion(self):
modeltest = tests.StandardModelTest(model)
modeltest.test_all()

def test_surface_form_differential(self):
options = {"surface form": "differential"}
model = pybamm.lithium_ion.DFN(options)
modeltest = tests.StandardModelTest(model)
modeltest.test_all()

def test_surface_form_algebraic(self):
options = {"surface form": "algebraic"}
model = pybamm.lithium_ion.DFN(options)
modeltest = tests.StandardModelTest(model)
modeltest.test_all()


if __name__ == "__main__":
print("Add -v for more debug output")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ def test_particle_fast_diffusion(self):
modeltest = tests.StandardModelTest(model)
modeltest.test_all()

def test_surface_form_differential(self):
options = {"surface form": "differential"}
model = pybamm.lithium_ion.SPM(options)
modeltest = tests.StandardModelTest(model)
modeltest.test_all()

def test_surface_form_algebraic(self):
options = {"surface form": "algebraic"}
model = pybamm.lithium_ion.SPM(options)
modeltest = tests.StandardModelTest(model)
modeltest.test_all()


if __name__ == "__main__":
print("Add -v for more debug output")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ def test_particle_fast_diffusion(self):
modeltest = tests.StandardModelTest(model)
modeltest.test_all()

def test_surface_form_differential(self):
options = {"surface form": "differential"}
model = pybamm.lithium_ion.SPMe(options)
modeltest = tests.StandardModelTest(model)
modeltest.test_all()

def test_surface_form_algebraic(self):
options = {"surface form": "algebraic"}
model = pybamm.lithium_ion.SPMe(options)
modeltest = tests.StandardModelTest(model)
modeltest.test_all()


if __name__ == "__main__":
print("Add -v for more debug output")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ def test_well_posed(self):


class TestLeadAcidCompositeWithSideReactions(unittest.TestCase):
def test_well_posed_differential(self):
options = {"surface form": "differential", "side reactions": ["oxygen"]}
model = pybamm.lead_acid.Composite(options)
model.check_well_posedness()

def test_well_posed_algebraic(self):
options = {"surface form": "algebraic", "side reactions": ["oxygen"]}
model = pybamm.lead_acid.Composite(options)
Expand All @@ -69,10 +64,6 @@ def test_well_posed_algebraic(self):


class TestLeadAcidCompositeExtended(unittest.TestCase):
def test_well_posed(self):
model = pybamm.lead_acid.CompositeExtended()
model.check_well_posedness()

def test_well_posed_differential_side_reactions(self):
options = {"surface form": "differential", "side reactions": ["oxygen"]}
model = pybamm.lead_acid.CompositeExtended(options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ def test_particle_fast_diffusion(self):
model = pybamm.lithium_ion.DFN(options)
model.check_well_posedness()

def test_surface_form_differential(self):
options = {"surface form": "differential"}
model = pybamm.lithium_ion.DFN(options)
model.check_well_posedness()

def test_surface_form_algebraic(self):
options = {"surface form": "algebraic"}
model = pybamm.lithium_ion.DFN(options)
model.check_well_posedness()


if __name__ == "__main__":
print("Add -v for more debug output")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ def test_particle_fast_diffusion(self):
model = pybamm.lithium_ion.SPM(options)
model.check_well_posedness()

def test_surface_form_differential(self):
options = {"surface form": "differential"}
model = pybamm.lithium_ion.SPM(options)
model.check_well_posedness()

def test_surface_form_algebraic(self):
options = {"surface form": "algebraic"}
model = pybamm.lithium_ion.SPM(options)
model.check_well_posedness()


if __name__ == "__main__":
print("Add -v for more debug output")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ def test_particle_fast_diffusion(self):
model = pybamm.lithium_ion.SPMe(options)
model.check_well_posedness()

def test_surface_form_differential(self):
options = {"surface form": "differential"}
model = pybamm.lithium_ion.SPMe(options)
model.check_well_posedness()

def test_surface_form_algebraic(self):
options = {"surface form": "algebraic"}
model = pybamm.lithium_ion.SPMe(options)
model.check_well_posedness()


if __name__ == "__main__":
print("Add -v for more debug output")
Expand Down

0 comments on commit 50980b5

Please sign in to comment.