@@ -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