Skip to content

Commit

Permalink
pybamm-team#1117 added total concentration in electrolyte
Browse files Browse the repository at this point in the history
  • Loading branch information
brosaplanella committed Jul 30, 2020
1 parent 0c15c50 commit 689091f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,13 @@ def _get_standard_concentration_variables(self, c_e_n, c_e_s, c_e_p):
"""

c_e_typ = self.param.c_e_typ
L_x = self.param.L_x

c_e = pybamm.Concatenation(c_e_n, c_e_s, c_e_p)
c_e_av = pybamm.x_average(c_e)
c_e_n_av = pybamm.x_average(c_e_n)
c_e_s_av = pybamm.x_average(c_e_s)
c_e_p_av = pybamm.x_average(c_e_p)

# if "epsilon_n" in vars(self.param).values():
# eps_n = self.param.epsilon_n
# eps_s = self.param.epsilon_s
# eps_p = self.param.epsilon_p
# eps = pybamm.Concatenation(eps_n, eps_s, eps_p)

# c_e_total = pybamm.x_average(eps * c_e)

# raise NotImplementedError("I entered the if statement!!!!")
# else:
# c_e_total = pybamm.x_average(c_e)
c_e_total = c_e

variables = {
"Electrolyte concentration": c_e,
"Electrolyte concentration [mol.m-3]": c_e_typ * c_e,
Expand All @@ -88,9 +74,6 @@ def _get_standard_concentration_variables(self, c_e_n, c_e_s, c_e_p):
"X-averaged positive electrolyte concentration": c_e_p_av,
"X-averaged positive electrolyte concentration [mol.m-3]": c_e_typ
* c_e_p_av,
"Total lithium concentration in electrolyte [mol.m-2]": c_e_typ
* L_x
* c_e_total,
}

return variables
Expand Down Expand Up @@ -122,6 +105,37 @@ def _get_standard_flux_variables(self, N_e):

return variables

def _get_total_concentration_electrolyte(self, c_e, epsilon):
"""
A private function to obtain the total ion concentration in the electrolyte.
Parameters
----------
c_e : :class:`pybamm.Symbol`
The electrolyte concentration
epsilon : :class:`pybamm.Symbol`
The porosity
Returns
-------
variables : dict
The variables which can be derived from the flux in the
electrolyte.
"""

c_e_typ = self.param.c_e_typ
L_x = self.param.L_x

c_e_total = pybamm.x_average(c_e)

variables = {
"Total concentration in electrolyte [mol.m-2]": c_e_typ
* L_x
* c_e_total,
}

return variables

def set_events(self, variables):
c_e = variables["Electrolyte concentration"]
self.events.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def get_fundamental_variables(self):
def get_coupled_variables(self, variables):

tor_0 = variables["Leading-order electrolyte tortuosity"]
eps = variables["Leading-order porosity"]
c_e_0_av = variables["Leading-order x-averaged electrolyte concentration"]
c_e = variables["Electrolyte concentration"]
i_e = variables["Electrolyte current density"]
Expand All @@ -51,6 +52,7 @@ def get_coupled_variables(self, variables):
N_e = N_e_diffusion + N_e_migration + N_e_convection

variables.update(self._get_standard_flux_variables(N_e))
variables.update(self._get_total_concentration_electrolyte(c_e, eps))

return variables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@ def get_fundamental_variables(self):

variables.update(self._get_standard_flux_variables(N_e))

eps = pybamm.standard_variables.eps
c_e = pybamm.Concatenation(c_e_n, c_e_s, c_e_p)

variables.update(self._get_total_concentration_electrolyte(c_e, eps))

return variables

Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,8 @@ def get_coupled_variables(self, variables):
)
variables.update(self._get_standard_flux_variables(N_e))

c_e = pybamm.Concatenation(c_e_n, c_e_s, c_e_p)
eps = pybamm.Concatenation(eps_n_0, eps_s_0, eps_p_0)
variables.update(self._get_total_concentration_electrolyte(c_e, eps))

return variables
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def get_fundamental_variables(self):
def get_coupled_variables(self, variables):

tor = variables["Electrolyte tortuosity"]
eps = variables["Porosity"]
c_e = variables["Electrolyte concentration"]
i_e = variables["Electrolyte current density"]
v_box = variables["Volume-averaged velocity"]
Expand All @@ -48,6 +49,7 @@ def get_coupled_variables(self, variables):
N_e = N_e_diffusion + N_e_migration + N_e_convection

variables.update(self._get_standard_flux_variables(N_e))
variables.update(self._get_total_concentration_electrolyte(c_e, eps))

return variables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def get_coupled_variables(self, variables):

variables.update(self._get_standard_flux_variables(N_e))

eps = pybamm.standard_variables.eps
c_e = pybamm.standard_variables.c_e
variables.update(self._get_total_concentration_electrolyte(c_e, eps))

return variables

def set_rhs(self, variables):
Expand Down

0 comments on commit 689091f

Please sign in to comment.