Skip to content

Commit

Permalink
#923 fix interface tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Mar 28, 2020
1 parent 1a09b86 commit aae9402
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 90 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

## Optimizations

- Sped up model building
- Changed default solver for lead-acid to `CasadiSolver`
- Sped up model building ([#927](https://github.com/pybamm-team/PyBaMM/pull/927))
- Changed default solver for lead-acid to `CasadiSolver` ([#927](https://github.com/pybamm-team/PyBaMM/pull/927))

## Bug fixes

- Reformatted electrolyte submodels
- Reformatted electrolyte submodels ([#927](https://github.com/pybamm-team/PyBaMM/pull/927))
- Fixed bug raised if function returns a scalar ([#919](https://github.com/pybamm-team/PyBaMM/pull/919))
- Fixed event handling in `ScipySolver` ([#905](https://github.com/pybamm-team/PyBaMM/pull/905))
- Made input handling clearer in solvers ([#905](https://github.com/pybamm-team/PyBaMM/pull/905))
Expand Down
4 changes: 2 additions & 2 deletions pybamm/models/submodels/interface/kinetics/tafel.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class BackwardTafel(BaseKinetics):
**Extends:** :class:`pybamm.interface.kinetics.BaseKinetics`
"""

def __init__(self, param, domain):
super().__init__(param, domain)
def __init__(self, param, domain, reaction):
super().__init__(param, domain, reaction)

def _get_kinetics(self, j0, ne, eta_r, T):
return -j0 * pybamm.exp(-(ne / (2 * (1 + self.param.Theta * T))) * eta_r)
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Test diffusion limited submodel
#

import pybamm
import tests
import unittest


class TestBaseModel(unittest.TestCase):
def test_public_function(self):
param = pybamm.standard_parameters_lead_acid

a_n = pybamm.PrimaryBroadcast(pybamm.Scalar(0), ["negative electrode"])
a_s = pybamm.PrimaryBroadcast(pybamm.Scalar(0), ["separator"])
a = pybamm.Scalar(0)
variables = {
"Current collector current density": a,
"Negative electrode potential": a_n,
"Negative electrolyte potential": a_n,
"Negative electrolyte concentration": a_n,
"X-averaged positive electrode oxygen interfacial current density": a,
"Separator tortuosity": a_s,
"Separator oxygen concentration": a_s,
}
submodel = pybamm.interface.DiffusionLimited(
param, "Negative", "lead-acid oxygen", "leading"
)
std_tests = tests.StandardSubModelTests(submodel, variables)
std_tests.test_all()

submodel = pybamm.interface.DiffusionLimited(
param, "Negative", "lead-acid oxygen", "full"
)
std_tests = tests.StandardSubModelTests(submodel, variables)
std_tests.test_all()


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

if "-v" in sys.argv:
debug = True
pybamm.settings.debug_mode = True
unittest.main()

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,31 @@ def test_public_functions(self):
param = pybamm.standard_parameters_lithium_ion

a = pybamm.Scalar(0)
variables = {"Negative electrode open circuit potential": a}
variables = {
"Negative electrode open circuit potential": a,
"Negative particle surface concentration": a,
"Negative electrode temperature": a,
"Negative electrolyte concentration": a,
"Current collector current density": a,
}
submodel = pybamm.interface.inverse_kinetics.InverseButlerVolmer(
param, "Negative"
param, "Negative", "lithium-ion main"
)
std_tests = tests.StandardSubModelTests(submodel, variables)

with self.assertRaises(NotImplementedError):
std_tests.test_all()

variables = {"Positive electrode open circuit potential": a}
std_tests.test_all()

variables = {
"Positive electrode open circuit potential": a,
"Positive particle surface concentration": a,
"Positive electrode temperature": a,
"Positive electrolyte concentration": a,
"Current collector current density": a,
}
submodel = pybamm.interface.inverse_kinetics.InverseButlerVolmer(
param, "Positive"
param, "Positive", "lithium-ion main"
)
std_tests = tests.StandardSubModelTests(submodel, variables)
with self.assertRaises(NotImplementedError):
std_tests.test_all()
std_tests.test_all()


if __name__ == "__main__":
Expand Down
Empty file.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,41 @@
import unittest


class TestBaseModel(unittest.TestCase):
class TestButlerVolmer(unittest.TestCase):
def test_public_functions(self):
param = pybamm.standard_parameters_lithium_ion

a_n = pybamm.PrimaryBroadcast(pybamm.Scalar(0), ["negative electrode"])
a_p = pybamm.PrimaryBroadcast(pybamm.Scalar(0), ["positive electrode"])
a = pybamm.Scalar(0)
variables = {
"Current collector current density": a,
"Negative electrode potential": a,
"Negative electrolyte potential": a,
"Negative electrode open circuit potential": a,
"Negative electrolyte concentration": a,
"Negative particle surface concentration": a,
"Negative electrode temperature": a,
}
submodel = pybamm.interface.kinetics.BaseModel(param, "Negative")
submodel = pybamm.interface.ButlerVolmer(param, "Negative", "lithium-ion main")
std_tests = tests.StandardSubModelTests(submodel, variables)

with self.assertRaises(NotImplementedError):
std_tests.test_all()
std_tests.test_all()

variables = {
"Current collector current density": a,
"Positive electrode potential": a,
"Positive electrolyte potential": a,
"Positive electrode open circuit potential": a,
"Positive electrode potential": a_p,
"Positive electrolyte potential": a_p,
"Positive electrode open circuit potential": a_p,
"Positive electrolyte concentration": a_p,
"Positive particle surface concentration": a_p,
"Negative electrode interfacial current density": a_n,
"Negative electrode exchange current density": a_n,
"Positive electrode temperature": a_p,
}
submodel = pybamm.interface.kinetics.BaseModel(param, "Positive")
submodel = pybamm.interface.ButlerVolmer(param, "Positive", "lithium-ion main")
std_tests = tests.StandardSubModelTests(submodel, variables)
with self.assertRaises(NotImplementedError):
std_tests.test_all()
std_tests.test_all()


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
#
# Test base butler volmer submodel
# Test base Tafel submodel
#

import pybamm
import tests
import unittest


class TestTafel(unittest.TestCase):
def test_forward_tafel(self):
submodel = pybamm.interface.kinetics.ForwardTafel(None, None)
j = submodel._get_kinetics(pybamm.Scalar(1), pybamm.Scalar(1), pybamm.Scalar(1))
self.assertIsInstance(j, pybamm.Symbol)

def test_backward_tafel(self):
submodel = pybamm.interface.kinetics.BackwardTafel(None, None)
j = submodel._get_kinetics(pybamm.Scalar(1), pybamm.Scalar(1), pybamm.Scalar(1))
self.assertIsInstance(j, pybamm.Symbol)
def test_public_function(self):
param = pybamm.standard_parameters_lithium_ion

a_n = pybamm.PrimaryBroadcast(pybamm.Scalar(0), ["negative electrode"])
a_p = pybamm.PrimaryBroadcast(pybamm.Scalar(0), ["positive electrode"])
a = pybamm.Scalar(0)
variables = {
"Current collector current density": a,
"Negative electrode potential": a_n,
"Negative electrolyte potential": a_n,
"Negative electrode open circuit potential": a_n,
"Negative electrolyte concentration": a_n,
"Negative particle surface concentration": a_n,
"Negative electrode temperature": a_n,
}
submodel = pybamm.interface.ForwardTafel(param, "Negative", "lithium-ion main")
std_tests = tests.StandardSubModelTests(submodel, variables)

std_tests.test_all()

variables = {
"Current collector current density": a,
"Positive electrode potential": a_p,
"Positive electrolyte potential": a_p,
"Positive electrode open circuit potential": a_p,
"Positive electrolyte concentration": a_p,
"Positive particle surface concentration": a_p,
"Negative electrode interfacial current density": a_n,
"Negative electrode exchange current density": a_n,
"Positive electrode temperature": a_p,
}
submodel = pybamm.interface.BackwardTafel(param, "Positive", "lithium-ion main")
std_tests = tests.StandardSubModelTests(submodel, variables)
std_tests.test_all()


if __name__ == "__main__":
Expand Down

0 comments on commit aae9402

Please sign in to comment.