Skip to content

Commit

Permalink
debugging scale
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Nov 3, 2022
1 parent ffac2c4 commit 302f305
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
18 changes: 11 additions & 7 deletions pybamm/discretisations/discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,6 @@ def process_dict(self, var_eqn_dict):
# Calculate scale if the key has a scale
scale = getattr(eqn_key, "scale", 1)
new_var_eqn_dict[eqn_key] = processed_eqn / scale

return new_var_eqn_dict

def process_symbol(self, symbol):
Expand Down Expand Up @@ -940,9 +939,14 @@ def _process_symbol(self, symbol):
return symbol._function_new_copy(disc_children)

elif isinstance(symbol, pybamm.VariableDot):
return pybamm.StateVectorDot(
*self.y_slices[symbol.get_variable()],
domains=symbol.domains,
# Multiply the output by the symbol's scale so that the state vector
# is of order 1
return (
pybamm.StateVectorDot(
*self.y_slices[symbol.get_variable()],
domains=symbol.domains,
)
# * symbol.scale
)

elif isinstance(symbol, pybamm.Variable):
Expand Down Expand Up @@ -989,9 +993,9 @@ def _process_symbol(self, symbol):
)
# Multiply the output by the symbol's scale so that the state vector
# is of order 1
return (
pybamm.StateVector(*y_slices, domains=symbol.domains) * symbol.scale
)
return pybamm.StateVector(
*y_slices, domains=symbol.domains
) # * symbol.scale

elif isinstance(symbol, pybamm.SpatialVariable):
return spatial_method.spatial_variable(symbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,19 @@ def __init__(self, name="Doyle-Fuller-Newman model"):
"Negative particle concentration",
domain="negative particle",
auxiliary_domains={"secondary": "negative electrode"},
scale=param.n.prim.c_max,
scale=1 + 0 * param.n.prim.c_max,
)
c_s_p = pybamm.Variable(
"Positive particle concentration",
domain="positive particle",
auxiliary_domains={"secondary": "positive electrode"},
scale=param.p.prim.c_max,
)
c_s_p_nondim = c_s_p
c_s_p_dim = c_s_p * param.p.prim.c_max
c_scale = param.p.prim.c_max
# c_s_p_dim = c_s_p
# c_s_p_nondim = c_s_p / param.p.prim.c_max

# Constant temperature
T = param.T_init_dim
Expand Down Expand Up @@ -148,13 +153,10 @@ def __init__(self, name="Doyle-Fuller-Newman model"):
Feta_RT_n = param.F * eta_n / (param.R * T)
j_n = 2 * j0_n * pybamm.sinh(param.n.prim.ne / 2 * Feta_RT_n)
# j_n = pybamm.PrimaryBroadcast(i_cell / (a_n * param.n.L), "negative electrode")
c_s_surf_p = pybamm.surf(c_s_p)
j0_p = param.p.prim.j0_dimensional(c_e_p, c_s_surf_p, T)
eta_p = (
phi_s_p
- phi_e_p
- param.p.prim.U_dimensional(c_s_surf_p / param.p.prim.c_max, T)
)
c_s_surf_p_dim = pybamm.surf(c_s_p_dim)
c_s_surf_p_nondim = pybamm.surf(c_s_p_nondim)
j0_p = param.p.prim.j0_dimensional(c_e_p, c_s_surf_p_dim, T)
eta_p = phi_s_p - phi_e_p - param.p.prim.U_dimensional(c_s_surf_p_nondim, T)
Feta_RT_p = param.F * eta_p / (param.R * T)
j_s = pybamm.PrimaryBroadcast(0, "separator")
j_p = 2 * j0_p * pybamm.sinh(param.p.prim.ne / 2 * Feta_RT_p)
Expand Down Expand Up @@ -182,7 +184,7 @@ def __init__(self, name="Doyle-Fuller-Newman model"):
# The div and grad operators will be converted to the appropriate matrix
# multiplication at the discretisation stage
N_s_n = -param.n.prim.D_dimensional(c_s_n, T) * pybamm.grad(c_s_n)
N_s_p = -param.p.prim.D_dimensional(c_s_p, T) * pybamm.grad(c_s_p)
N_s_p = -param.p.prim.D_dimensional(c_s_p_dim, T) * pybamm.grad(c_s_p) * c_scale
self.rhs[c_s_n] = -pybamm.div(N_s_n)
self.rhs[c_s_p] = -pybamm.div(N_s_p)
# Boundary conditions must be provided for equations with spatial derivatives
Expand All @@ -196,7 +198,7 @@ def __init__(self, name="Doyle-Fuller-Newman model"):
self.boundary_conditions[c_s_p] = {
"left": (pybamm.Scalar(0), "Neumann"),
"right": (
-j_p / (param.F * param.p.prim.D_dimensional(c_s_surf_p, T)),
-j_p / (param.F * param.p.prim.D_dimensional(c_s_surf_p_dim, T)),
"Neumann",
),
}
Expand Down Expand Up @@ -264,8 +266,8 @@ def __init__(self, name="Doyle-Fuller-Newman model"):
"Negative particle surface concentration [mol.m-3]": c_s_surf_n,
"Negative particle surface concentration": c_s_surf_n / param.n.prim.c_max,
"Electrolyte concentration [mol.m-3]": c_e,
"Positive particle surface concentration [mol.m-3]": c_s_surf_p,
"Positive particle surface concentration": c_s_surf_p / param.p.prim.c_max,
"Positive particle surface concentration [mol.m-3]": c_s_surf_p_dim,
"Positive particle surface concentration": c_s_surf_p_nondim,
"Current [A]": I,
"Negative electrode potential [V]": phi_s_n,
"Electrolyte potential [V]": phi_e,
Expand Down

0 comments on commit 302f305

Please sign in to comment.