Skip to content

Commit

Permalink
dont add eqns for discharge and throughput capacity in experiment ste…
Browse files Browse the repository at this point in the history
…p set up
  • Loading branch information
rtimms committed May 1, 2024
1 parent a3c5e5d commit 75f2a6d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 27 deletions.
14 changes: 10 additions & 4 deletions pybamm/experiment/step/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def get_parameter_values(self, variables):

def get_submodel(self, model):
return pybamm.external_circuit.VoltageFunctionControl(
model.param, model.options
model.param, model.options, add_discharge_capacity=False
)


Expand Down Expand Up @@ -211,7 +211,9 @@ def get_parameter_values(self, variables):
return {"Power function [W]": self.value}

def get_submodel(self, model):
return pybamm.external_circuit.PowerFunctionControl(model.param, model.options)
return pybamm.external_circuit.PowerFunctionControl(
model.param, model.options, add_discharge_capacity=False
)


def power(value, **kwargs):
Expand Down Expand Up @@ -243,7 +245,7 @@ def get_parameter_values(self, variables):

def get_submodel(self, model):
return pybamm.external_circuit.ResistanceFunctionControl(
model.param, model.options
model.param, model.options, add_discharge_capacity=False
)


Expand Down Expand Up @@ -410,7 +412,11 @@ def __init__(self, current_rhs_function, control="algebraic", **kwargs):

def get_submodel(self, model):
return pybamm.external_circuit.FunctionControl(
model.param, self.current_rhs_function, model.options, control=self.control
model.param,
self.current_rhs_function,
model.options,
control=self.control,
add_discharge_capacity=False,
)

def copy(self):
Expand Down
25 changes: 14 additions & 11 deletions pybamm/models/submodels/external_circuit/base_external_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
class BaseModel(pybamm.BaseSubModel):
"""Model to represent the behaviour of the external circuit."""

def __init__(self, param, options):
def __init__(self, param, options, add_discharge_capacity=True):
super().__init__(param, options=options)
self.add_discharge_capacity = add_discharge_capacity

def get_fundamental_variables(self):
Q_Ah = pybamm.Variable("Discharge capacity [A.h]")
Expand Down Expand Up @@ -41,23 +42,25 @@ def get_fundamental_variables(self):
return variables

def set_initial_conditions(self, variables):
Q_Ah = variables["Discharge capacity [A.h]"]
Qt_Ah = variables["Throughput capacity [A.h]"]
self.initial_conditions[Q_Ah] = pybamm.Scalar(0)
self.initial_conditions[Qt_Ah] = pybamm.Scalar(0)
if self.add_discharge_capacity:
Q_Ah = variables["Discharge capacity [A.h]"]
Qt_Ah = variables["Throughput capacity [A.h]"]
self.initial_conditions[Q_Ah] = pybamm.Scalar(0)
self.initial_conditions[Qt_Ah] = pybamm.Scalar(0)
if self.options["calculate discharge energy"] == "true":
Q_Wh = variables["Discharge energy [W.h]"]
Qt_Wh = variables["Throughput energy [W.h]"]
self.initial_conditions[Q_Wh] = pybamm.Scalar(0)
self.initial_conditions[Qt_Wh] = pybamm.Scalar(0)

def set_rhs(self, variables):
# ODEs for discharge capacity and throughput capacity
Q_Ah = variables["Discharge capacity [A.h]"]
Qt_Ah = variables["Throughput capacity [A.h]"]
I = variables["Current [A]"]
self.rhs[Q_Ah] = I / 3600 # Returns to zero after a complete cycle
self.rhs[Qt_Ah] = abs(I) / 3600 # Increases with each cycle
if self.add_discharge_capacity:
# ODEs for discharge capacity and throughput capacity
Q_Ah = variables["Discharge capacity [A.h]"]
Qt_Ah = variables["Throughput capacity [A.h]"]
I = variables["Current [A]"]
self.rhs[Q_Ah] = I / 3600 # Returns to zero after a complete cycle
self.rhs[Qt_Ah] = abs(I) / 3600 # Increases with each cycle
if self.options["calculate discharge energy"] == "true":
Q_Wh = variables["Discharge energy [W.h]"]
Qt_Wh = variables["Throughput energy [W.h]"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def get_fundamental_variables(self):
}

# Add discharge capacity variable
variables.update(super().get_fundamental_variables())
if self.add_discharge_capacity:
variables.update(super().get_fundamental_variables())

return variables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ class FunctionControl(BaseModel):
or 'differential'.
"""

def __init__(self, param, external_circuit_function, options, control="algebraic"):
super().__init__(param, options)
def __init__(
self,
param,
external_circuit_function,
options,
control="algebraic",
add_discharge_capacity=True,
):
super().__init__(param, options, add_discharge_capacity=add_discharge_capacity)
self.external_circuit_function = external_circuit_function
self.control = control

Expand All @@ -51,7 +58,8 @@ def get_fundamental_variables(self):
}

# Add discharge capacity variable
variables.update(super().get_fundamental_variables())
if self.add_discharge_capacity:
variables.update(super().get_fundamental_variables())

return variables

Expand Down Expand Up @@ -84,8 +92,14 @@ class VoltageFunctionControl(FunctionControl):
External circuit with voltage control, implemented as an extra algebraic equation.
"""

def __init__(self, param, options):
super().__init__(param, self.constant_voltage, options, control="algebraic")
def __init__(self, param, options, add_discharge_capacity=True):
super().__init__(
param,
self.constant_voltage,
options,
control="algebraic",
add_discharge_capacity=add_discharge_capacity,
)

def constant_voltage(self, variables):
V = variables["Voltage [V]"]
Expand All @@ -97,8 +111,16 @@ def constant_voltage(self, variables):
class PowerFunctionControl(FunctionControl):
"""External circuit with power control."""

def __init__(self, param, options, control="algebraic"):
super().__init__(param, self.constant_power, options, control=control)
def __init__(
self, param, options, control="algebraic", add_discharge_capacity=True
):
super().__init__(
param,
self.constant_power,
options,
control=control,
add_discharge_capacity=add_discharge_capacity,
)

def constant_power(self, variables):
I = variables["Current [A]"]
Expand All @@ -118,8 +140,16 @@ def constant_power(self, variables):
class ResistanceFunctionControl(FunctionControl):
"""External circuit with resistance control."""

def __init__(self, param, options, control="algebraic"):
super().__init__(param, self.constant_resistance, options, control=control)
def __init__(
self, param, options, control="algebraic", add_discharge_capacity=True
):
super().__init__(
param,
self.constant_resistance,
options,
control=control,
add_discharge_capacity=add_discharge_capacity,
)

def constant_resistance(self, variables):
I = variables["Current [A]"]
Expand All @@ -145,8 +175,14 @@ class CCCVFunctionControl(FunctionControl):
"""

def __init__(self, param, options):
super().__init__(param, self.cccv, options, control="differential with max")
def __init__(self, param, options, add_discharge_capacity=True):
super().__init__(
param,
self.cccv,
options,
control="differential with max",
add_discharge_capacity=add_discharge_capacity,
)
pybamm.citations.register("Mohtat2021")

def cccv(self, variables):
Expand Down

0 comments on commit 75f2a6d

Please sign in to comment.