Skip to content

Commit 049960d

Browse files
#492 get potentiostatic working for 1D lithium-ion
1 parent ee030ee commit 049960d

File tree

7 files changed

+40
-39
lines changed

7 files changed

+40
-39
lines changed

examples/scripts/compare_lead_acid.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,23 @@
1616
pybamm.set_logging_level("INFO")
1717

1818
# load models
19+
options = {"operating mode": "voltage"}
1920
models = [
20-
pybamm.lead_acid.LOQS(),
21-
pybamm.lead_acid.FOQS(),
22-
pybamm.lead_acid.Composite(),
23-
pybamm.lead_acid.Full(),
21+
pybamm.lead_acid.LOQS(options),
22+
# pybamm.lead_acid.FOQS(options),
23+
# pybamm.lead_acid.Composite(options),
24+
pybamm.lead_acid.Full(options),
2425
]
2526

2627
# load parameter values and process models and geometry
2728
param = models[0].default_parameter_values
28-
param.update({"Typical current [A]": 10, "Initial State of Charge": 1})
29+
param.update(
30+
{
31+
"Typical current [A]": 10,
32+
"Initial State of Charge": 1,
33+
"Voltage function": 14 / 6,
34+
}
35+
)
2936
for model in models:
3037
param.process_model(model)
3138

examples/scripts/compare_lithium_ion.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@
1818
# load models
1919
options = {"thermal": "isothermal", "operating mode": "voltage"}
2020
models = [
21-
# pybamm.lithium_ion.SPM(options),
22-
# pybamm.lithium_ion.SPMe(options),
23-
# pybamm.lithium_ion.DFN(),
24-
pybamm.lithium_ion.DFN(options)
21+
pybamm.lithium_ion.SPM(options),
22+
pybamm.lithium_ion.SPMe(options),
23+
pybamm.lithium_ion.DFN(options),
2524
]
2625

2726

2827
# load parameter values and process models and geometry
2928
param = models[0].default_parameter_values
3029
param["Typical current [A]"] = 1.0
31-
param["Voltage function"] = 4
30+
param["Voltage function"] = 4 # voltage
3231
for model in models:
3332
param.process_model(model)
3433

pybamm/models/base_model.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ def check_well_determined(self, post_discretisation):
338338
vars_in_rhs_keys = set()
339339
vars_in_algebraic_keys = set()
340340
vars_in_eqns = set()
341-
# Get all variables ids from rhs and algebraic keys and equations
341+
# Get all variables ids from rhs and algebraic keys and equations, and
342+
# from boundary conditions
342343
# For equations we look through the whole expression tree.
343344
# "Variables" can be Concatenations so we also have to look in the whole
344345
# expression tree
@@ -356,11 +357,16 @@ def check_well_determined(self, post_discretisation):
356357
vars_in_eqns.update(
357358
[x.id for x in eqn.pre_order() if isinstance(x, pybamm.Variable)]
358359
)
360+
for var, side_eqn in self.boundary_conditions.items():
361+
for side, (eqn, typ) in side_eqn.items():
362+
vars_in_eqns.update(
363+
[x.id for x in eqn.pre_order() if isinstance(x, pybamm.Variable)]
364+
)
359365
# If any keys are repeated between rhs and algebraic then the model is
360366
# overdetermined
361367
if not set(vars_in_rhs_keys).isdisjoint(vars_in_algebraic_keys):
362368
raise pybamm.ModelError("model is overdetermined (repeated keys)")
363-
# If any algebraic keys don't appear in the eqns then the model is
369+
# If any algebraic keys don't appear in the eqns (or bcs) then the model is
364370
# overdetermined (but rhs keys can be absent from the eqns, e.g. dcdt = -1 is
365371
# fine)
366372
# Skip this step after discretisation, as any variables in the equations will

pybamm/models/full_battery_models/base_battery_model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,10 @@ def build_model(self):
466466
)
467467
self.update(submodel)
468468

469-
pybamm.logger.debug("Setting voltage variables")
469+
pybamm.logger.debug("Setting voltage variables ({})".format(self.name))
470470
self.set_voltage_variables()
471471

472-
pybamm.logger.debug("Setting SoC variables")
472+
pybamm.logger.debug("Setting SoC variables ({})".format(self.name))
473473
self.set_soc_variables()
474474

475475
# Massive hack for consistent delta_phi = phi_s - phi_e with SPMe

pybamm/models/full_battery_models/lithium_ion/dfn.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ def set_particle_submodel(self):
8585
def set_solid_submodel(self):
8686

8787
self.submodels["negative electrode"] = pybamm.electrode.ohm.Full(
88-
self.param, "Negative", self.reactions, self.options["operating mode"]
88+
self.param, "Negative", self.reactions
8989
)
9090
self.submodels["positive electrode"] = pybamm.electrode.ohm.Full(
91-
self.param, "Positive", self.reactions, self.options["operating mode"]
91+
self.param, "Positive", self.reactions
9292
)
9393

9494
def set_electrolyte_submodel(self):

pybamm/models/submodels/electrode/ohm/full_ohm.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ class Full(BaseModel):
1919
**Extends:** :class:`pybamm.electrode.ohm.BaseModel`
2020
"""
2121

22-
def __init__(self, param, domain, reactions, operating_mode):
22+
def __init__(self, param, domain, reactions):
2323
super().__init__(param, domain, reactions)
24-
self.operating_mode = operating_mode
2524

2625
def get_fundamental_variables(self):
2726

@@ -80,14 +79,11 @@ def set_boundary_conditions(self, variables):
8079

8180
elif self.domain == "Positive":
8281
lbc = (pybamm.Scalar(0), "Neumann")
83-
if self.operating_mode == "current":
84-
sigma_eff = self.param.sigma_p * tor
85-
rbc = (
86-
i_boundary_cc / pybamm.boundary_value(-sigma_eff, "right"),
87-
"Neumann",
88-
)
89-
elif self.operating_mode == "voltage":
90-
rbc = (self.param.voltage_with_time, "Dirichlet")
82+
sigma_eff = self.param.sigma_p * tor
83+
rbc = (
84+
i_boundary_cc / pybamm.boundary_value(-sigma_eff, "right"),
85+
"Neumann",
86+
)
9187

9288
self.boundary_conditions[phi_s] = {"left": lbc, "right": rbc}
9389

pybamm/models/submodels/external_circuit/voltage_control_external_circuit.py

+6-13
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,10 @@ def set_initial_conditions(self, variables):
3232
self.initial_conditions[i_cell] = self.param.current_with_time
3333

3434
def set_algebraic(self, variables):
35-
# Read off the current from the solid current density
36-
# TODO: investigate whether defining the current differently gives better
37-
# results (e.g. based on electrolyte current density in the separator)
38-
# This also needs to be defined in a model-inpedendent way (currently assumes
39-
# Ohm's law)
35+
# External circuit submodels are always equations on the current
36+
# Fix voltage to be equal to terminal voltage
4037
i_cell = variables["Total current density"]
41-
phi_s_p = variables["Positive electrode potential"]
42-
tor_p = variables["Positive electrode tortuosity"]
43-
sigma_eff = self.param.sigma_p * tor_p
44-
i_s_p_right = -pybamm.boundary_value(
45-
sigma_eff, "right"
46-
) * pybamm.BoundaryGradient(phi_s_p, "right")
47-
48-
self.algebraic[i_cell] = i_cell - i_s_p_right
38+
# TODO: change this to terminal voltage
39+
V = variables["Local current collector potential difference"]
40+
# TODO: find a way to get rid of 0 * i_cell
41+
self.algebraic[i_cell] = V - self.param.voltage_with_time + 0 * i_cell

0 commit comments

Comments
 (0)