Skip to content

Commit

Permalink
#933 fix tests except public functions
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Apr 9, 2020
1 parent 23c6e2a commit 4fdf3d8
Show file tree
Hide file tree
Showing 20 changed files with 193 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ Negative electrode morphological parameter,0.6,srinivasan2003mathematical,
Negative electrode capacity [C.m-3],3473000000,,
,,,
# Interfacial reactions,,,
Negative electrode cation signed stoichiometry,-1,,
Negative electrode cation signed stoichiometry,1,,
Negative electrode electrons in reaction,2,,
Negative electrode reference exchange-current density [A.m-2],0.06,srinivasan2003mathematical,
Signed stoichiometry of cations (oxygen reaction),-4,,
Signed stoichiometry of water (oxygen reaction),1,,
Signed stoichiometry of oxygen (oxygen reaction),-1,,
Signed stoichiometry of cations (oxygen reaction),4,,
Signed stoichiometry of water (oxygen reaction),-1,,
Signed stoichiometry of oxygen (oxygen reaction),1,,
Electrons in oxygen reaction,4,,
Negative electrode reference exchange-current density (oxygen) [A.m-2],2.5E-32,srinivasan2003mathematical,
Reference oxygen molecule concentration [mol.m-3],1000,srinivasan2003mathematical,
Oxygen reference OCP vs SHE [V],1.229,srinivasan2003mathematical,
Signed stoichiometry of cations (hydrogen reaction),-2,,
Signed stoichiometry of hydrogen (hydrogen reaction),1,,
Signed stoichiometry of cations (hydrogen reaction),2,,
Signed stoichiometry of hydrogen (hydrogen reaction),-1,,
Electrons in hydrogen reaction,2,,
Negative electrode reference exchange-current density (hydrogen) [A.m-2],1.56E-11,srinivasan2003mathematical,
Hydrogen reference OCP vs SHE [V],0,srinivasan2003mathematical,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ Positive electrode morphological parameter,0.6,srinivasan2003mathematical,
Positive electrode capacity [C.m-3],2745000000,,
,,,
# Interfacial reactions,,,
Positive electrode cation signed stoichiometry,-3,,
Positive electrode cation signed stoichiometry,3,,
Positive electrode electrons in reaction,2,,
Positive electrode reference exchange-current density [A.m-2],0.004,srinivasan2003mathematical,
Signed stoichiometry of cations (oxygen reaction),-4,,
Signed stoichiometry of water (oxygen reaction),1,,
Signed stoichiometry of oxygen (oxygen reaction),-1,,
Signed stoichiometry of cations (oxygen reaction),4,,
Signed stoichiometry of water (oxygen reaction),-1,,
Signed stoichiometry of oxygen (oxygen reaction),1,,
Electrons in oxygen reaction,4,,
Positive electrode reference exchange-current density (oxygen) [A.m-2],2.5E-23,srinivasan2003mathematical,
Reference oxygen molecule concentration [mol.m-3],1000,srinivasan2003mathematical,
Oxygen reference OCP vs SHE [V],1.229,srinivasan2003mathematical,
Signed stoichiometry of cations (hydrogen reaction),-2,,
Signed stoichiometry of hydrogen (hydrogen reaction),1,,
Signed stoichiometry of cations (hydrogen reaction),2,,
Signed stoichiometry of hydrogen (hydrogen reaction),-1,,
Electrons in hydrogen reaction,2,,
Positive electrode reference exchange-current density (hydrogen) [A.m-2],0,srinivasan2003mathematical,
Hydrogen reference OCP vs SHE [V],0,srinivasan2003mathematical,
Expand Down
24 changes: 21 additions & 3 deletions pybamm/models/full_battery_models/base_battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,24 @@ def set_standard_output_variables(self):
{"y": var.y, "y [m]": var.y * L_y, "z": var.z, "z [m]": var.z * L_z}
)

# Initialize "total reaction" variables
self.variables.update(
{
"Sum of electrolyte reaction source terms": 0,
"Sum of negative electrode electrolyte reaction source terms": 0,
"Sum of positive electrode electrolyte reaction source terms": 0,
"Sum of x-averaged negative electrode "
"electrolyte reaction source terms": 0,
"Sum of x-averaged positive electrode "
"electrolyte reaction source terms": 0,
"Sum of interfacial current densities": 0,
"Sum of negative electrode interfacial current densities": 0,
"Sum of positive electrode interfacial current densities": 0,
"Sum of x-averaged negative electrode interfacial current densities": 0,
"Sum of x-averaged positive electrode interfacial current densities": 0,
}
)

def build_fundamental_and_external(self):
# Get the fundamental variables
for submodel_name, submodel in self.submodels.items():
Expand Down Expand Up @@ -350,11 +368,11 @@ def build_coupled_variables(self):
if len(submodels) == 1 or count == 100:
# no more submodels to try
raise pybamm.ModelError(
"""Submodel "{}" requires the variable {}, but it cannot be found.
Check the selected submodels provide all of the required
variables.""".format(
"Submodel '{}' requires the variable {}, ".format(
submodel_name, key
)
+ "but it cannot be found. Check the selected "
"submodels provide all of the required variables."
)
else:
# try setting coupled variables on next loop through
Expand Down
18 changes: 18 additions & 0 deletions pybamm/models/full_battery_models/lead_acid/higher_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ def set_leading_order_model(self):
leading_order_model.variables["X-averaged electrolyte concentration"]
]

# Reset sums
self.variables.update(
{
"Sum of electrolyte reaction source terms": 0,
"Sum of negative electrode electrolyte reaction source terms": 0,
"Sum of positive electrode electrolyte reaction source terms": 0,
"Sum of x-averaged negative electrode "
"electrolyte reaction source terms": 0,
"Sum of x-averaged positive electrode "
"electrolyte reaction source terms": 0,
"Sum of interfacial current densities": 0,
"Sum of negative electrode interfacial current densities": 0,
"Sum of positive electrode interfacial current densities": 0,
"Sum of x-averaged negative electrode interfacial current densities": 0,
"Sum of x-averaged positive electrode interfacial current densities": 0,
}
)

def set_average_interfacial_submodel(self):
self.submodels[
"x-averaged negative interface"
Expand Down
9 changes: 4 additions & 5 deletions pybamm/models/submodels/electrode/ohm/full_ohm.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ def set_algebraic(self, variables):
phi_s = variables[self.domain + " electrode potential"]
i_s = variables[self.domain + " electrode current density"]

# All possible reactions. Some of these could be zero
j = variables[self.domain + " electrode interfacial current density"]
j_ox = variables[self.domain + " electrode oxygen interfacial current density"]

sum_j = j + j_ox
# Variable summing all of the interfacial current densities
sum_j = variables[
"Sum of " + self.domain.lower() + " electrode interfacial current densities"
]

self.algebraic[phi_s] = pybamm.div(i_s) + sum_j

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ def set_algebraic(self, variables):
phi_e = variables["Electrolyte potential"]
i_e = variables["Electrolyte current density"]

# All possible reactions. Some of these could be zero
j = variables["Interfacial current density"]
j_ox = variables["Oxygen interfacial current density"]

sum_j = j + j_ox
# Variable summing all of the interfacial current densities
sum_j = variables["Sum of interfacial current densities"]

self.algebraic = {phi_e: pybamm.div(i_e) - sum_j}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ def set_algebraic(self, variables):
delta_phi = variables[self.domain + " electrode surface potential difference"]
i_e = variables[self.domain + " electrolyte current density"]

# All possible reactions. Some of these could be zero
j = variables[self.domain + " electrode interfacial current density"]
j_ox = variables[self.domain + " electrode oxygen interfacial current density"]
# Variable summing all of the interfacial current densities
sum_j = variables[
"Sum of " + self.domain.lower() + " electrode interfacial current densities"
]

sum_j = j + j_ox
self.algebraic[delta_phi] = pybamm.div(i_e) - sum_j


Expand Down Expand Up @@ -270,10 +270,9 @@ def set_rhs(self, variables):
delta_phi = variables[self.domain + " electrode surface potential difference"]
i_e = variables[self.domain + " electrolyte current density"]

# All possible reactions. Some of these could be zero
j = variables[self.domain + " electrode interfacial current density"]
j_ox = variables[self.domain + " electrode oxygen interfacial current density"]

sum_j = j + j_ox
# Variable summing all of the interfacial current densities
sum_j = variables[
"Sum of " + self.domain.lower() + " electrode interfacial current densities"
]

self.rhs[delta_phi] = 1 / C_dl * (pybamm.div(i_e) - sum_j)
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,11 @@ def set_rhs(self, variables):

param = self.param

# All possible reactions. Some of these could be zero
j = variables[
"X-averaged "
sum_j = variables[
"Sum of x-averaged "
+ self.domain.lower()
+ " electrode interfacial current density"
+ " electrode interfacial current densities"
]
j_ox = variables[
"X-averaged "
+ self.domain.lower()
+ " electrode oxygen interfacial current density"
]

sum_j = j + j_ox

sum_j_av = variables[
"X-averaged "
Expand Down Expand Up @@ -157,19 +149,11 @@ def set_algebraic(self, variables):
if self.domain == "Separator":
return

# All possible reactions. Some of these could be zero
j = variables[
"X-averaged "
sum_j = variables[
"Sum of x-averaged "
+ self.domain.lower()
+ " electrode interfacial current density"
+ " electrode interfacial current densities"
]
j_ox = variables[
"X-averaged "
+ self.domain.lower()
+ " electrode oxygen interfacial current density"
]

sum_j = j + j_ox

sum_j_av = variables[
"X-averaged "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,52 +64,26 @@ def set_rhs(self, variables):
c_e = variables["Electrolyte concentration"]
N_e = variables["Electrolyte flux"]
if self.extended is False:
source_terms_0 = self._get_source_terms_leading_order(variables)
sum_s_j = variables[
"Leading-order sum of electrolyte reaction source terms"
]
elif self.extended == "distributed":
source_terms_0 = self._get_source_terms_first_order(variables)
sum_s_j = variables["Sum of electrolyte reaction source terms"]
elif self.extended == "average":
source_terms_0 = self._get_source_terms_first_order_average(variables)
sum_s_j_0 = variables[
"Leading-order sum of electrolyte reaction source terms"
]
sum_s_j_1 = variables[
"Sum of first-order electrolyte reaction source terms"
]
sum_s_j = sum_s_j_0 + param.C_e * sum_s_j_1
source_terms_0 = sum_s_j / self.param.gamma_e

self.rhs = {
c_e: (1 / eps_0)
* (-pybamm.div(N_e) / param.C_e + source_terms_0 - c_e * deps_0_dt)
}

def _get_source_terms_leading_order(self, variables):
param = self.param

# All possible reactions. Some of these could be zero
j = variables["Leading-order interfacial current density"]
j_ox = variables["Leading-order oxygen interfacial current density"]

return (-param.s_plus_S * j - param.s_plus_Ox * j_ox) / self.param.gamma_e

def _get_source_terms_first_order(self, variables):
param = self.param

# All possible reactions. Some of these could be zero
j = variables["Interfacial current density"]
j_ox = variables["Oxygen interfacial current density"]

return (-param.s_plus_S * j - param.s_plus_Ox * j_ox) / self.param.gamma_e

def _get_source_terms_first_order_average(self, variables):
param = self.param
# All possible reactions. Some of these could be zero
j_av = variables["First-order x-averaged interfacial current density"]
j_ox_av = variables["First-order x-averaged oxygen interfacial current density"]

first_order_average = (
-param.s_plus_S * j_av - param.s_plus_Ox * j_ox_av
) / param.gamma_e

return self._get_source_terms_leading_order(
variables
) + self.param.C_e * pybamm.PrimaryBroadcast(
first_order_average,
["negative electrode", "separator", "positive electrode"],
)

def set_initial_conditions(self, variables):

c_e = variables["Electrolyte concentration"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,39 +56,30 @@ def get_coupled_variables(self, variables):
d_epsc_p_0_dt = c_e_0 * deps_p_0_dt + eps_p_0 * dc_e_0_dt

# Right-hand sides
# All possible reactions. Some of these could be zero
j_n_0 = variables[
"Leading-order x-averaged negative electrode interfacial current density"
sum_j_n_0 = variables[
"Leading-order sum of x-averaged "
"negative electrode interfacial current densities"
]
j_p_0 = variables[
"Leading-order x-averaged positive electrode interfacial current density"
sum_j_p_0 = variables[
"Leading-order sum of x-averaged "
"positive electrode interfacial current densities"
]
j_ox_n_0 = variables[
"Leading-order x-averaged negative electrode "
"oxygen interfacial current density"
sum_s_j_n_0 = variables[
"Leading-order sum of x-averaged "
"negative electrode electrolyte reaction source terms"
]
j_ox_p_0 = variables[
"Leading-order x-averaged positive electrode "
"oxygen interfacial current density"
sum_s_j_p_0 = variables[
"Leading-order sum of x-averaged "
"positive electrode electrolyte reaction source terms"
]
rhs_n = (
d_epsc_n_0_dt
- (
-param.s_plus_n_S * j_n_0
- param.s_plus_Ox * j_ox_n_0
- param.t_plus(c_e_0) * (j_n_0 + j_ox_n_0)
)
/ param.gamma_e
- (sum_s_j_n_0 - param.t_plus(c_e_0) * sum_j_n_0) / param.gamma_e
)
rhs_s = d_epsc_s_0_dt
rhs_p = (
d_epsc_p_0_dt
- (
-param.s_plus_p_S * j_p_0
- param.s_plus_Ox * j_ox_p_0
- param.t_plus(c_e_0) * (j_p_0 + j_ox_p_0)
)
/ param.gamma_e
- (sum_s_j_p_0 - param.t_plus(c_e_0) * sum_j_p_0) / param.gamma_e
)

# Diffusivities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,8 @@ def set_rhs(self, variables):
N_e = variables["Electrolyte flux"]
div_Vbox = variables["Transverse volume-averaged acceleration"]

# All possible reactions. Some of these could be zero
j = variables["Interfacial current density"]
j_ox = variables["Oxygen interfacial current density"]

source_terms = (
-param.s_plus_S * j - param.s_plus_Ox * j_ox
) / self.param.gamma_e
sum_s_j = variables["Sum of electrolyte reaction source terms"]
source_terms = sum_s_j / self.param.gamma_e

self.rhs = {
c_e: (1 / eps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,21 @@ def set_rhs(self, variables):
"X-averaged separator transverse volume-averaged acceleration"
]

# All possible reactions. Some of these could be zero
j_n_0 = variables["X-averaged negative electrode interfacial current density"]
j_p_0 = variables["X-averaged positive electrode interfacial current density"]
j_ox_n_0 = variables[
"X-averaged negative electrode oxygen interfacial current density"
sum_j_n_0 = variables[
"Sum of x-averaged negative electrode interfacial current densities"
]
j_ox_p_0 = variables[
"X-averaged positive electrode oxygen interfacial current density"
sum_j_p_0 = variables[
"Sum of x-averaged positive electrode interfacial current densities"
]
sum_s_j_n_0 = variables[
"Sum of x-averaged negative electrode electrolyte reaction source terms"
]
sum_s_j_p_0 = variables[
"Sum of x-averaged positive electrode electrolyte reaction source terms"
]

source_terms = (
param.l_n
* (
-param.s_plus_n_S * j_n_0
- param.s_plus_Ox * j_ox_n_0
- param.t_plus(c_e_av) * (j_n_0 + j_ox_n_0)
)
+ param.l_p
* (
-param.s_plus_p_S * j_p_0
- param.s_plus_Ox * j_ox_p_0
- param.t_plus(c_e_av) * (j_p_0 + j_ox_p_0)
)
param.l_n * (sum_s_j_n_0 - param.t_plus(c_e_av) * sum_j_n_0)
+ param.l_p * (sum_s_j_p_0 - param.t_plus(c_e_av) * sum_j_p_0)
) / param.gamma_e

self.rhs = {
Expand Down
Loading

0 comments on commit 4fdf3d8

Please sign in to comment.