Skip to content

Commit

Permalink
pybamm-team#1788 try to fix diff of U
Browse files Browse the repository at this point in the history
  • Loading branch information
brosaplanella committed Mar 29, 2023
1 parent 53d3078 commit 2463a0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pybamm/models/submodels/thermal/base_thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ def _get_standard_coupled_variables(self, variables):
D_p = variables["Positive particle effective diffusivity [m2.s-1]"]
Ueq_n = variables["Negative electrode open-circuit potential [V]"]
Ueq_p = variables["Positive electrode open-circuit potential [V]"]
dUeq_n = Ueq_n.diff(c_n)
dUeq_p = Ueq_p.diff(c_p)
# Drop the blow-up term as it has spatial operators and diff doesn't work
dUeq_n = Ueq_n.children[0].diff(c_n)
dUeq_p = Ueq_p.children[0].diff(c_p)
integrand_r_n = D_n * dc_n_dr**2 * dUeq_n
integrand_r_p = D_p * dc_p_dr**2 * dUeq_p
integration_variable_r_n = [pybamm.SpatialVariable("r", integrand_r_n)]
Expand Down
10 changes: 6 additions & 4 deletions pybamm/parameters/lithium_ion_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,14 @@ def U(self, sto, T, lithiation=None):
u_ref = pybamm.FunctionParameter(
f"{self.phase_prefactor}{Domain} electrode {lithiation}OCP [V]", inputs
)

dudt_func = self.dUdT(sto)
u_ref = u_ref + (T - self.main_param.T_ref) * dudt_func

# add a term to ensure that the OCP goes to infinity at 0 and -infinity at 1
# this will not affect the OCP for most values of sto
# see #1435
u_ref = u_ref + 1e-6 * (1 / sto + 1 / (sto - 1))
dudt_func = self.dUdT(sto)
out = u_ref + (T - self.main_param.T_ref) * dudt_func
# see #1435
out = u_ref + 1e-6 * (1 / sto + 1 / (sto - 1))

if self.domain == "negative":
out.print_name = r"U_\mathrm{n}(c^\mathrm{surf}_\mathrm{s,n}, T)"
Expand Down

0 comments on commit 2463a0b

Please sign in to comment.