Skip to content

Commit bcdd0b5

Browse files
authored
allow tol in initial voltage for setting stoichiometries (#4586)
1 parent 4223be8 commit bcdd0b5

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/pybamm/models/full_battery_models/lithium_ion/electrode_soh.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ def get_initial_stoichiometries(self, initial_value, tol=1e-6, inputs=None):
673673
V_min = parameter_values.evaluate(self.param.ocp_soc_0)
674674
V_max = parameter_values.evaluate(self.param.ocp_soc_100)
675675

676-
if not V_min <= V_init <= V_max:
676+
if not V_min - tol <= V_init <= V_max + tol:
677677
raise ValueError(
678678
f"Initial voltage {V_init}V is outside the voltage limits "
679679
f"({V_min}, {V_max})"
@@ -881,7 +881,6 @@ def get_initial_stoichiometries(
881881
:class:`pybamm.BatteryModelOptions`.
882882
tol : float, optional
883883
The tolerance for the solver used to compute the initial stoichiometries.
884-
A lower value results in higher precision but may increase computation time.
885884
Default is 1e-6.
886885
inputs : dict, optional
887886
A dictionary of input parameters passed to the model.

src/pybamm/models/full_battery_models/lithium_ion/electrode_soh_half_cell.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def get_initial_stoichiometry_half_cell(
6363
parameter_values,
6464
param=None,
6565
options=None,
66+
tol=1e-6,
6667
inputs=None,
6768
**kwargs,
6869
):
@@ -80,7 +81,14 @@ def get_initial_stoichiometry_half_cell(
8081
must be between V_min and V_max.
8182
parameter_values : pybamm.ParameterValues
8283
The parameter values to use in the calculation
83-
84+
param : :class:`pybamm.LithiumIonParameters`, optional
85+
The symbolic parameter set to use for the simulation.
86+
If not provided, the default parameter set will be used.
87+
tol : float, optional
88+
The tolerance for the solver used to compute the initial stoichiometries.
89+
Default is 1e-6.
90+
inputs : dict, optional
91+
A dictionary of input parameters passed to the model.
8492
Returns
8593
-------
8694
x
@@ -94,7 +102,7 @@ def get_initial_stoichiometry_half_cell(
94102
V_min = parameter_values.evaluate(param.voltage_low_cut)
95103
V_max = parameter_values.evaluate(param.voltage_high_cut)
96104

97-
if not V_min <= V_init <= V_max:
105+
if not V_min - tol <= V_init <= V_max + tol:
98106
raise ValueError(
99107
f"Initial voltage {V_init}V is outside the voltage limits "
100108
f"({V_min}, {V_max})"
@@ -113,7 +121,9 @@ def get_initial_stoichiometry_half_cell(
113121
soc_model.initial_conditions[soc] = (V_init - V_min) / (V_max - V_min)
114122
soc_model.variables["soc"] = soc
115123
parameter_values.process_model(soc_model)
116-
initial_soc = pybamm.AlgebraicSolver().solve(soc_model, [0])["soc"].data[0]
124+
initial_soc = (
125+
pybamm.AlgebraicSolver(tol=tol).solve(soc_model, [0])["soc"].data[0]
126+
)
117127
elif isinstance(initial_value, (int, float)):
118128
initial_soc = initial_value
119129
if not 0 <= initial_soc <= 1:

0 commit comments

Comments
 (0)