From 0cc6f72654277a8728b02088880954bce6a6f49b Mon Sep 17 00:00:00 2001 From: Robert Timms <43040151+rtimms@users.noreply.github.com> Date: Sun, 8 Sep 2024 18:35:05 -0700 Subject: [PATCH] allow tol and inputs to be passes to get_initial_ocps (#4426) --- .../lithium_ion/electrode_soh.py | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/pybamm/models/full_battery_models/lithium_ion/electrode_soh.py b/src/pybamm/models/full_battery_models/lithium_ion/electrode_soh.py index a5710dc986..c5b6a9b911 100644 --- a/src/pybamm/models/full_battery_models/lithium_ion/electrode_soh.py +++ b/src/pybamm/models/full_battery_models/lithium_ion/electrode_soh.py @@ -657,6 +657,8 @@ def get_initial_stoichiometries(self, initial_value, tol=1e-6, inputs=None): The tolerance for the solver used to compute the initial stoichiometries. A lower value results in higher precision but may increase computation time. Default is 1e-6. + inputs : dict, optional + A dictionary of input parameters passed to the model. Returns ------- @@ -727,6 +729,11 @@ def get_min_max_stoichiometries(self, inputs=None): Calculate min/max stoichiometries given voltage limits, open-circuit potentials, etc defined by parameter_values + Parameters + ---------- + inputs : dict, optional + A dictionary of input parameters passed to the model. + Returns ------- x_0, x_100, y_100, y_0 @@ -751,7 +758,7 @@ def get_min_max_stoichiometries(self, inputs=None): sol = self.solve(all_inputs) return [sol["x_0"], sol["x_100"], sol["y_100"], sol["y_0"]] - def get_initial_ocps(self, initial_value, tol=1e-6): + def get_initial_ocps(self, initial_value, tol=1e-6, inputs=None): """ Calculate initial open-circuit potentials to start off the simulation at a particular state of charge, given voltage limits, open-circuit potentials, etc @@ -760,9 +767,14 @@ def get_initial_ocps(self, initial_value, tol=1e-6): Parameters ---------- initial_value : float - Target SOC, must be between 0 and 1. + Target initial value. + If integer, interpreted as SOC, must be between 0 and 1. + If string e.g. "4 V", interpreted as voltage, + must be between V_min and V_max. tol: float, optional Tolerance for the solver used in calculating initial stoichiometries. + inputs : dict, optional + A dictionary of input parameters passed to the model. Returns ------- @@ -771,7 +783,7 @@ def get_initial_ocps(self, initial_value, tol=1e-6): """ parameter_values = self.parameter_values param = self.param - x, y = self.get_initial_stoichiometries(initial_value, tol) + x, y = self.get_initial_stoichiometries(initial_value, tol, inputs=inputs) if self.options["open-circuit potential"] == "MSMR": msmr_pot_model = _get_msmr_potential_model( self.parameter_values, self.param @@ -783,8 +795,8 @@ def get_initial_ocps(self, initial_value, tol=1e-6): Up = sol["Up"].data[0] else: T_ref = parameter_values["Reference temperature [K]"] - Un = parameter_values.evaluate(param.n.prim.U(x, T_ref)) - Up = parameter_values.evaluate(param.p.prim.U(y, T_ref)) + Un = parameter_values.evaluate(param.n.prim.U(x, T_ref), inputs=inputs) + Up = parameter_values.evaluate(param.p.prim.U(y, T_ref), inputs=inputs) return Un, Up def get_min_max_ocps(self): @@ -871,6 +883,8 @@ def get_initial_stoichiometries( The tolerance for the solver used to compute the initial stoichiometries. A lower value results in higher precision but may increase computation time. Default is 1e-6. + inputs : dict, optional + A dictionary of input parameters passed to the model. Returns ------- @@ -918,6 +932,8 @@ def get_initial_ocps( param=None, known_value="cyclable lithium capacity", options=None, + tol=1e-6, + inputs=None, ): """ Calculate initial open-circuit potentials to start off the simulation at a @@ -942,6 +958,10 @@ def get_initial_ocps( options : dict-like, optional A dictionary of options to be passed to the model, see :class:`pybamm.BatteryModelOptions`. + tol: float, optional + Tolerance for the solver used in calculating initial open-circuit potentials. + inputs : dict, optional + A dictionary of input parameters passed to the model. Returns ------- @@ -949,7 +969,7 @@ def get_initial_ocps( The initial electrode OCPs that give the desired initial state of charge """ esoh_solver = ElectrodeSOHSolver(parameter_values, param, known_value, options) - return esoh_solver.get_initial_ocps(initial_value) + return esoh_solver.get_initial_ocps(initial_value, tol, inputs=inputs) def get_min_max_ocps(