Skip to content

Commit

Permalink
#492 add docs and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Nov 19, 2019
1 parent 8561598 commit e968272
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Current control external circuit
================================

.. autoclass:: pybamm.external_circuit.CurrentControl
:members:

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Function control external circuit
=================================

.. autoclass:: pybamm.external_circuit.FunctionControl
:members:
14 changes: 14 additions & 0 deletions docs/source/models/submodels/external_circuit/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
External circuit
================

Models to enforce different boundary conditions (as imposed by an imaginary external
circuit) such as constant current, constant voltage, constant power, or any other
relationship between the current and voltage

.. toctree::
:maxdepth: 1

current_control_external_circuit
function_control_external_circuit
power_control_external_circuit
voltage_control_external_circuit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Power control external circuit
==============================

.. autoclass:: pybamm.external_circuit.PowerControl
:members:

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Voltage control external circuit
================================

.. autoclass:: pybamm.external_circuit.VoltageControl
:members:

1 change: 1 addition & 0 deletions docs/source/models/submodels/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Submodels
convection/index
electrode/index
electrolyte/index
external_circuit/index
interface/index
oxygen_diffusion/index
particle/index
Expand Down
6 changes: 3 additions & 3 deletions examples/scripts/charging_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Compare some charging strategies for lithium-ion batteries
#
# 1. CC-CV: Charge at 1A to 4.2V then 4.2V hold
# 2. CV: Charge at 4.2V
# 2. CV: Charge at 4.1V
# 3. Constant Power-CV: Charge at 4W to 4.2V then 4.2V hold
#
import argparse
Expand Down Expand Up @@ -43,8 +43,8 @@ def cccv(I, V):
params[0]["CCCV switch"] = 1 # start with CC
params[0]["External circuit function"] = cccv

# 2. CV: Charge at 4.2V
params[1]["Voltage function"] = 4.2
# 2. CV: Charge at 4.1V
params[1]["Voltage function"] = 4.1
for model, param in zip(models, params):
param.process_model(model)

Expand Down
2 changes: 1 addition & 1 deletion pybamm/models/full_battery_models/base_battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def options(self, extra_options):
"current",
"voltage",
"power",
"arbitrary",
"custom",
]:
raise pybamm.OptionError(
"operating mode '{}' not recognised".format(options["operating mode"])
Expand Down
3 changes: 2 additions & 1 deletion pybamm/models/submodels/base_submodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BaseSubModel:
symbols.
"""

def __init__(self, param, domain=None, reactions=None):
def __init__(self, param, domain=None, reactions=None, name="Unnamed submodel"):
super().__init__()
self.param = param
# Initialise empty variables (to avoid overwriting with 'None')
Expand All @@ -61,6 +61,7 @@ def __init__(self, param, domain=None, reactions=None):
self.domain = domain
self.set_domain_for_broadcast()
self.reactions = reactions
self.name = name

@property
def domain(self):
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Test current control submodel
#

import pybamm
import tests
import unittest


class TestCurrentControl(unittest.TestCase):
def test_public_functions(self):
param = pybamm.standard_parameters_lithium_ion
submodel = pybamm.external_circuit.CurrentControl(param)
std_tests = tests.StandardSubModelTests(submodel)
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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Test function control submodel
#
import numpy as np
import pybamm
import tests
import unittest


class TestFunctionControl(unittest.TestCase):
def test_public_functions(self):
param = pybamm.standard_parameters_lithium_ion
submodel = pybamm.external_circuit.FunctionControl(param)
variables = {"Terminal voltage [V]": pybamm.Scalar(0)}
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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Test power control submodel
#

import pybamm
import tests
import unittest


class TestPowerControl(unittest.TestCase):
def test_public_functions(self):
param = pybamm.standard_parameters_lithium_ion
submodel = pybamm.external_circuit.PowerControl(param)
variables = {"Terminal voltage [V]": pybamm.Scalar(0)}
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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Test voltage control submodel
#

import pybamm
import tests
import unittest


class TestVoltageControl(unittest.TestCase):
def test_public_functions(self):
param = pybamm.standard_parameters_lithium_ion
submodel = pybamm.external_circuit.VoltageControl(param)
variables = {"Terminal voltage [V]": pybamm.Scalar(0)}
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()

0 comments on commit e968272

Please sign in to comment.