Skip to content

Commit

Permalink
#546 fix temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Jul 23, 2019
1 parent 131939e commit b85f455
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 39 deletions.
36 changes: 24 additions & 12 deletions examples/scripts/compare_lead_acid.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
#
# Compare lead-acid battery models
#
import argparse
import numpy as np
import pybamm
import sys

pybamm.set_logging_level("DEBUG")
parser = argparse.ArgumentParser()
parser.add_argument(
"--debug", action="store_true", help="Set logging level to 'DEBUG'."
)
args = parser.parse_args()
if args.debug:
pybamm.set_logging_level("DEBUG")
else:
pybamm.set_logging_level("INFO")

# load models
models = [
Expand All @@ -12,7 +24,7 @@
# ),
pybamm.lead_acid.LOQS(),
# pybamm.lead_acid.FOQS(),
pybamm.lead_acid.Composite(),
pybamm.lead_acid.CompositeExtended(),
# # pybamm.lead_acid.Composite({"surface form": "algebraic"}),
pybamm.lead_acid.NewmanTiedemann(),
]
Expand All @@ -21,7 +33,7 @@
param = models[0].default_parameter_values
param.update(
{
"Bruggeman coefficient": 0.001,
# "Bruggeman coefficient": 0.001,
"Typical current [A]": 20,
"Initial State of Charge": 1,
"Typical electrolyte concentration [mol.m-3]": 5600,
Expand Down Expand Up @@ -54,15 +66,15 @@

# plot
output_variables = [
# [
# "Average negative electrode interfacial current density [A.m-2]",
# "Average positive electrode interfacial current density [A.m-2]",
# ],
# "Average negative electrode surface potential difference [V]",
# "Average positive electrode surface potential difference [V]",
# "Electrolyte concentration",
# "Electrolyte flux",
"Terminal voltage [V]"
[
"Average negative electrode interfacial current density [A.m-2]",
"Average positive electrode interfacial current density [A.m-2]",
],
"Average negative electrode surface potential difference [V]",
"Average positive electrode surface potential difference [V]",
"Electrolyte concentration",
"Electrolyte flux",
"Terminal voltage [V]",
]
plot = pybamm.QuickPlot(models, mesh, solutions, output_variables)
plot.dynamic_plot()
17 changes: 0 additions & 17 deletions pybamm/expression_tree/broadcasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,7 @@ def check_and_set_domain_and_broadcast_type(
if broadcast_type == "secondary":
domain = child.domain

# Otherwise only some domains can be broadcast
else:
if child.domain not in [
[],
broadcast_domain,
["current collector"],
["negative particle"],
["positive particle"],
]:
raise pybamm.DomainError(
"""
Domain of a broadcasted child must be [], ['current collector'],
["negative particle"], ["positive particle"] or same as
'broadcast_domain' ('{}'), but is '{}'
""".format(
broadcast_domain, child.domain
)
)
domain = broadcast_domain

# Variables on the current collector can only be broadcast to 'primary'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ def get_fundamental_variables(self):
def get_coupled_variables(self, variables):

c_s = variables[self.domain + " particle concentration"]
T_k_av = variables["Average " + self.domain.lower() + " electrode temperature"]
T_k_av = pybamm.PrimaryBroadcast(
variables[self.domain + " electrode temperature"],
[self.domain.lower() + " particle"],
)

# TODO: fix average so can do X-average N_s
# TODO: add full temperature instead of just electrode average
N_s = self._flux_law(c_s, T_k_av)

variables.update(self._get_standard_flux_variables(N_s, N_s))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ def get_coupled_variables(self, variables):
[self.domain.lower() + " particle"],
)

import ipdb

ipdb.set_trace()
N_s_xav = self._flux_law(c_s_xav, T_k_av)
N_s = pybamm.SecondaryBroadcast(
pybamm.PrimaryBroadcast(N_s_xav, [self._domain.lower() + " electrode"]),
Expand Down
2 changes: 0 additions & 2 deletions pybamm/models/submodels/thermal/base_thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def __init__(self, param):
def _get_standard_fundamental_variables(self, T):
param = self.param
T_n, T_s, T_p = T.orphans
import ipdb

ipdb.set_trace()
T_av = pybamm.average(T)

q = self._flux_law(T)
Expand Down
12 changes: 9 additions & 3 deletions pybamm/models/submodels/thermal/isothermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ def __init__(self, param):

def get_fundamental_variables(self):

T_n = pybamm.FullBroadcast(0, "negative electrode", "current collector")
T_s = pybamm.FullBroadcast(0, "separator", "current collector")
T_p = pybamm.FullBroadcast(0, "positive electrode", "current collector")
T_n = pybamm.PrimaryBroadcast(
pybamm.PrimaryBroadcast(0, "current collector"), "negative electrode"
)
T_s = pybamm.PrimaryBroadcast(
pybamm.PrimaryBroadcast(0, "current collector"), "separator"
)
T_p = pybamm.PrimaryBroadcast(
pybamm.PrimaryBroadcast(0, "current collector"), "positive electrode"
)
T = pybamm.Concatenation(T_n, T_s, T_p)

variables = self._get_standard_fundamental_variables(T)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ def test_default_geometry(self):
self.assertIsInstance(model.default_geometry, pybamm.Geometry)
self.assertTrue("secondary" in model.default_geometry["negative particle"])

def test_thermal(self):
options = {"thermal": "lumped"}
model = pybamm.lithium_ion.DFN(options)
model.check_well_posedness()

options = {"thermal": "full"}
model = pybamm.lithium_ion.DFN(options)
model.check_well_posedness()

@unittest.skipIf(pybamm.have_scikits_odes(), "scikits.odes not installed")
def test_default_solver(self):
options = {"thermal": None}
Expand Down

0 comments on commit b85f455

Please sign in to comment.