Skip to content

Commit

Permalink
pybamm-team#1594 add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brosaplanella committed Aug 12, 2021
1 parent 9cb237a commit 042172d
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from pybamm import Scalar


def aluminium_heat_capacity_CRC(T):
"""
Aluminium specific heat capacity as a function of the temperature from [1].
Expand All @@ -20,4 +23,4 @@ def aluminium_heat_capacity_CRC(T):

cp = 4.503e-6 * T ** 3 - 6.256e-3 * T ** 2 + 3.281 * T + 355.7

return cp
return Scalar(cp)
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from pybamm import Scalar


def copper_heat_capacity_CRC(T):
"""
Copper specific heat capacity as a function of the temperature from [1].
Expand All @@ -20,4 +23,4 @@ def copper_heat_capacity_CRC(T):

cp = 1.445e-6 * T ** 3 - 1.946e-3 * T ** 2 + 0.9633 * T + 236

return cp
return Scalar(cp)
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from pybamm import Scalar


def copper_thermal_conductivity_CRC(T):
"""
Copper thermal conductivity as a function of the temperature from [1].
Expand All @@ -20,4 +23,4 @@ def copper_thermal_conductivity_CRC(T):

lambda_th = -5.409e-7 * T ** 3 + 7.054e-4 * T ** 2 - 0.3727 * T + 463.6

return lambda_th
return Scalar(lambda_th)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def graphite_LGM50_entropic_change_ORegan2021(sto):
"""

a0 = -0.1112
a1 = -0.09002 * 0 # fixed fit (see discussion O'Regan et al 2021)
a1 = -0.09002 * 0 # fixed fit (see discussion O'Regan et al 2021)
a2 = 0.3561
b1 = 0.4955
b2 = 0.08309
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from pybamm import Scalar


def graphite_LGM50_thermal_conductivity_ORegan2021(T):
"""
Wet negative electrode thermal conductivity as a function of the temperature from
Expand All @@ -23,4 +26,4 @@ def graphite_LGM50_thermal_conductivity_ORegan2021(T):

lambda_wet = -2.61e-4 * T ** 2 + 0.1726 * T - 24.49

return lambda_wet
return Scalar(lambda_wet)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def nmc_LGM50_electrolyte_exchange_current_density_ORegan2021(c_e, c_s_surf, T):
Kendrick. "Thermal-electrochemical parametrisation of a lithium-ion battery:
mapping Li concentration and temperature dependencies." Journal of the
Electrochemical Society, submitted (2021).
Parameters
----------
c_e : :class:`pybamm.Symbol`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from pybamm import Scalar


def nmc_LGM50_thermal_conductivity_ORegan2021(T):
"""
Wet positive electrode thermal conductivity as a function of the temperature from
Expand All @@ -23,4 +26,4 @@ def nmc_LGM50_thermal_conductivity_ORegan2021(T):

lambda_wet = 2.063e-5 * T ** 2 - 0.01127 * T + 2.331

return lambda_wet
return Scalar(lambda_wet)
8 changes: 6 additions & 2 deletions tests/unit/test_citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_sulzer_2019(self):
pybamm.lead_acid.Full(build=False)
self.assertIn("Sulzer2019physical", citations._papers_to_cite)

def test_timms_2020(self):
def test_timms_2021(self):
# Test that calling relevant bits of code adds the right paper to citations
citations = pybamm.citations

Expand Down Expand Up @@ -131,7 +131,7 @@ def test_subramanian_2005(self):
pybamm.particle.PolynomialManyParticles(None, "Negative", "quadratic profile")
self.assertIn("Subramanian2005", citations._papers_to_cite)

def test_brosaplanella_2020(self):
def test_brosaplanella_2021(self):
# Test that calling relevant bits of code adds the right paper to citations
citations = pybamm.citations

Expand Down Expand Up @@ -206,6 +206,10 @@ def test_parameter_citations(self):
self.assertIn("Ecker2015ii", citations._papers_to_cite)
self.assertIn("Richardson2020", citations._papers_to_cite)

citations._reset()
pybamm.ParameterValues(chemistry=pybamm.parameter_sets.ORegan2021)
self.assertIn("ORegan2021", citations._papers_to_cite)

def test_solver_citations(self):
# Test that solving each solver adds the right citations
citations = pybamm.citations
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#
# Tests for LG M50 parameter set loads
#
import pybamm
import unittest
import os


class TestORegan2021(unittest.TestCase):
def test_load_params(self):
negative_electrode = pybamm.ParameterValues({}).read_parameters_csv(
pybamm.get_parameters_filepath(
"input/parameters/lithium_ion/negative_electrodes/graphite_ORegan2021/"
"parameters.csv"
)
)
self.assertEqual(
negative_electrode["Negative electrode diffusivity [m2.s-1]"],
"[function]graphite_LGM50_diffusivity_ORegan2021",
)

positive_electrode = pybamm.ParameterValues({}).read_parameters_csv(
pybamm.get_parameters_filepath(
"input/parameters/lithium_ion/positive_electrodes/nmc_ORegan2021/"
"parameters.csv"
)
)
self.assertEqual(
positive_electrode["Positive electrode conductivity [S.m-1]"],
"[function]nmc_LGM50_electronic_conductivity_ORegan2021",
)

electrolyte = pybamm.ParameterValues({}).read_parameters_csv(
pybamm.get_parameters_filepath(
"input/parameters/lithium_ion/electrolytes/lipf6_EC_EMC_3_7_"
"Landesfeind2019/parameters.csv"
)
)
self.assertEqual(
electrolyte["Typical electrolyte concentration [mol.m-3]"], "1000"
)

cell = pybamm.ParameterValues({}).read_parameters_csv(
pybamm.get_parameters_filepath(
"input/parameters/lithium_ion/cells/LGM50_ORegan2021/parameters.csv"
)
)
self.assertEqual(
cell["Negative current collector thermal conductivity [W.m-1.K-1]"],
"[function]copper_thermal_conductivity_CRC",
)

def test_functions(self):
root = pybamm.root_dir()
param = pybamm.ParameterValues(chemistry=pybamm.parameter_sets.ORegan2021)

# Positive electrode
p = "pybamm/input/parameters/lithium_ion/positive_electrodes/nmc_ORegan2021/"
k_path = os.path.join(root, p)

fun_test = {
"nmc_LGM50_entropic_change_ORegan2021.py": ([0.5], -9.7940e-07),
"nmc_LGM50_heat_capacity_ORegan2021.py": ([298.15], 902.6502),
"nmc_LGM50_diffusivity_ORegan2021.py": ([0.5, 298.15], 7.2627e-15),
"nmc_LGM50_electrolyte_exchange_current_density_ORegan2021.py": (
[1e3, 1e4, 298.15],
2.1939,
),
"nmc_LGM50_ocp_Chen2020.py": ([0.5], 3.9720),
"nmc_LGM50_electronic_conductivity_ORegan2021.py": ([298.15], 0.8473),
"nmc_LGM50_thermal_conductivity_ORegan2021.py": ([298.15], 0.8047),
}

for name, value in fun_test.items():
fun = pybamm.load_function(os.path.join(k_path, name))
self.assertAlmostEqual(param.evaluate(fun(*value[0])), value[1], places=4)

# Negative electrode
p = (
"pybamm/input/parameters/lithium_ion/negative_electrodes/"
"graphite_ORegan2021/"
)
k_path = os.path.join(root, p)

fun_test = {
"graphite_LGM50_entropic_change_ORegan2021.py": ([0.5], -2.6460e-07),
"graphite_LGM50_heat_capacity_ORegan2021.py": ([298.15], 847.7155),
"graphite_LGM50_diffusivity_ORegan2021.py": ([0.5, 298.15], 2.8655e-16),
"graphite_LGM50_electrolyte_exchange_current_density_ORegan2021.py": (
[1e3, 1e4, 298.15],
1.0372,
),
"graphite_LGM50_ocp_Chen2020.py": ([0.5], 0.1331),
"graphite_LGM50_thermal_conductivity_ORegan2021.py": ([298.15], 3.7695),
}

for name, value in fun_test.items():
fun = pybamm.load_function(os.path.join(k_path, name))
self.assertAlmostEqual(param.evaluate(fun(*value[0])), value[1], places=4)

# Cells
p = "pybamm/input/parameters/lithium_ion/cells/LGM50_ORegan2021/"
k_path = os.path.join(root, p)

fun_test = {
"aluminium_heat_capacity_CRC.py": ([298.15], 897.1585),
"copper_heat_capacity_CRC.py": ([298.15], 388.5190),
"copper_thermal_conductivity_CRC.py": ([298.15], 400.8491),
}

for name, value in fun_test.items():
fun = pybamm.load_function(os.path.join(k_path, name))
self.assertAlmostEqual(param.evaluate(fun(*value[0])), value[1], places=4)

# Separator
p = "pybamm/input/parameters/lithium_ion/separators/separator_ORegan2021/"
k_path = os.path.join(root, p)

fun_test = {
"separator_LGM50_heat_capacity_ORegan2021.py": ([298.15], 1130.9656),
}

for name, value in fun_test.items():
fun = pybamm.load_function(os.path.join(k_path, name))
self.assertAlmostEqual(param.evaluate(fun(*value[0])), value[1], places=4)

def test_standard_lithium_parameters(self):

chemistry = pybamm.parameter_sets.ORegan2021
parameter_values = pybamm.ParameterValues(chemistry=chemistry)

model = pybamm.lithium_ion.DFN()
sim = pybamm.Simulation(model, parameter_values=parameter_values)
sim.set_parameters()
sim.build()


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 042172d

Please sign in to comment.