From 75f2a6dce60dede77a212c27059fe60ae030c4fa Mon Sep 17 00:00:00 2001 From: Robert Timms Date: Wed, 1 May 2024 12:23:57 +0100 Subject: [PATCH] dont add eqns for discharge and throughput capacity in experiment step set up --- pybamm/experiment/step/steps.py | 14 +++-- .../external_circuit/base_external_circuit.py | 25 ++++---- .../explicit_control_external_circuit.py | 3 +- .../function_control_external_circuit.py | 58 +++++++++++++++---- 4 files changed, 73 insertions(+), 27 deletions(-) diff --git a/pybamm/experiment/step/steps.py b/pybamm/experiment/step/steps.py index 66b3ff5645..03596971e2 100644 --- a/pybamm/experiment/step/steps.py +++ b/pybamm/experiment/step/steps.py @@ -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 ) @@ -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): @@ -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 ) @@ -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): diff --git a/pybamm/models/submodels/external_circuit/base_external_circuit.py b/pybamm/models/submodels/external_circuit/base_external_circuit.py index 713616c063..40a9f72db0 100644 --- a/pybamm/models/submodels/external_circuit/base_external_circuit.py +++ b/pybamm/models/submodels/external_circuit/base_external_circuit.py @@ -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]") @@ -41,10 +42,11 @@ 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]"] @@ -52,12 +54,13 @@ def set_initial_conditions(self, variables): 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]"] diff --git a/pybamm/models/submodels/external_circuit/explicit_control_external_circuit.py b/pybamm/models/submodels/external_circuit/explicit_control_external_circuit.py index 5c72da2db1..e560c50607 100644 --- a/pybamm/models/submodels/external_circuit/explicit_control_external_circuit.py +++ b/pybamm/models/submodels/external_circuit/explicit_control_external_circuit.py @@ -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 diff --git a/pybamm/models/submodels/external_circuit/function_control_external_circuit.py b/pybamm/models/submodels/external_circuit/function_control_external_circuit.py index c49c1f8c7e..fa55f6c665 100644 --- a/pybamm/models/submodels/external_circuit/function_control_external_circuit.py +++ b/pybamm/models/submodels/external_circuit/function_control_external_circuit.py @@ -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 @@ -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 @@ -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]"] @@ -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]"] @@ -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]"] @@ -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):