-
-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1257 from pybamm-team/issue-1207-composite-surface
#1207 add composite surface form
- Loading branch information
Showing
7 changed files
with
295 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
pybamm/models/submodels/electrolyte_conductivity/surface_potential_form/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
...ls/electrolyte_conductivity/surface_potential_form/composite_surface_form_conductivity.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
# | ||
# Class for composite surface form electrolyte conductivity employing stefan-maxwell | ||
# | ||
import pybamm | ||
|
||
from ..composite_conductivity import Composite | ||
|
||
|
||
class BaseModel(Composite): | ||
""" | ||
Base class for composite conservation of charge in the electrolyte employing | ||
the Stefan-Maxwell constitutive equations employing the surface potential difference | ||
formulation. | ||
Parameters | ||
---------- | ||
param : parameter class | ||
The parameters to use for this submodel | ||
domain : str | ||
The domain in which the model holds | ||
reactions : dict | ||
Dictionary of reaction terms | ||
**Extends:** :class:`pybamm.electrolyte_conductivity.Composite` | ||
""" | ||
|
||
def __init__(self, param, domain): | ||
super().__init__(param, domain) | ||
|
||
def get_fundamental_variables(self): | ||
|
||
if self.domain == "Negative": | ||
delta_phi = pybamm.standard_variables.delta_phi_n_av | ||
elif self.domain == "Separator": | ||
return {} | ||
elif self.domain == "Positive": | ||
delta_phi = pybamm.standard_variables.delta_phi_p_av | ||
|
||
variables = self._get_standard_surface_potential_difference_variables(delta_phi) | ||
return variables | ||
|
||
def set_initial_conditions(self, variables): | ||
|
||
if self.domain == "Separator": | ||
return | ||
|
||
delta_phi = variables[ | ||
"X-averaged " | ||
+ self.domain.lower() | ||
+ " electrode surface potential difference" | ||
] | ||
if self.domain == "Negative": | ||
delta_phi_init = self.param.U_n(self.param.c_n_init(0), self.param.T_init) | ||
elif self.domain == "Positive": | ||
delta_phi_init = self.param.U_p(self.param.c_p_init(1), self.param.T_init) | ||
|
||
self.initial_conditions = {delta_phi: delta_phi_init} | ||
|
||
def set_boundary_conditions(self, variables): | ||
if self.domain == "Negative": | ||
phi_e = variables["Electrolyte potential"] | ||
self.boundary_conditions = { | ||
phi_e: { | ||
"left": (pybamm.Scalar(0), "Neumann"), | ||
"right": (pybamm.Scalar(0), "Neumann"), | ||
} | ||
} | ||
|
||
|
||
class CompositeDifferential(BaseModel): | ||
""" | ||
Composite model for conservation of charge in the electrolyte employing the | ||
Stefan-Maxwell constitutive equations employing the surface potential difference | ||
formulation and where capacitance is present. | ||
Parameters | ||
---------- | ||
param : parameter class | ||
The parameters to use for this submodel | ||
**Extends:** :class:`BaseModel` | ||
""" | ||
|
||
def __init__(self, param, domain): | ||
super().__init__(param, domain) | ||
|
||
def set_rhs(self, variables): | ||
if self.domain == "Separator": | ||
return | ||
|
||
param = self.param | ||
|
||
sum_j = variables[ | ||
"Sum of x-averaged " | ||
+ self.domain.lower() | ||
+ " electrode interfacial current densities" | ||
] | ||
|
||
sum_j_av = variables[ | ||
"X-averaged " | ||
+ self.domain.lower() | ||
+ " electrode total interfacial current density" | ||
] | ||
delta_phi = variables[ | ||
"X-averaged " | ||
+ self.domain.lower() | ||
+ " electrode surface potential difference" | ||
] | ||
|
||
if self.domain == "Negative": | ||
C_dl = param.C_dl_n | ||
elif self.domain == "Positive": | ||
C_dl = param.C_dl_p | ||
|
||
self.rhs[delta_phi] = 1 / C_dl * (sum_j_av - sum_j) | ||
|
||
|
||
class CompositeAlgebraic(BaseModel): | ||
""" | ||
Composite model for conservation of charge in the electrolyte employing the | ||
Stefan-Maxwell constitutive equations employing the surface potential difference | ||
formulation. | ||
Parameters | ||
---------- | ||
param : parameter class | ||
The parameters to use for this submodel | ||
**Extends:** :class:`BaseModel` | ||
""" | ||
|
||
def __init__(self, param, domain): | ||
super().__init__(param, domain) | ||
|
||
def set_algebraic(self, variables): | ||
if self.domain == "Separator": | ||
return | ||
|
||
sum_j = variables[ | ||
"Sum of x-averaged " | ||
+ self.domain.lower() | ||
+ " electrode interfacial current densities" | ||
] | ||
|
||
sum_j_av = variables[ | ||
"X-averaged " | ||
+ self.domain.lower() | ||
+ " electrode total interfacial current density" | ||
] | ||
delta_phi = variables[ | ||
"X-averaged " | ||
+ self.domain.lower() | ||
+ " electrode surface potential difference" | ||
] | ||
|
||
self.algebraic[delta_phi] = sum_j_av - sum_j |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...st_electrolyte_conductivity/test_surface_form/test_composite_surface_form_conductivity.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# | ||
# Test leading surface form stefan maxwell electrolyte conductivity submodel | ||
# | ||
|
||
import pybamm | ||
import tests | ||
import unittest | ||
|
||
|
||
class TestCompositeModel(unittest.TestCase): | ||
def test_public_functions(self): | ||
param = pybamm.LithiumIonParameters() | ||
a = pybamm.PrimaryBroadcast(0, "current collector") | ||
a_n = pybamm.FullBroadcast( | ||
pybamm.Scalar(0), ["negative electrode"], "current collector" | ||
) | ||
a_s = pybamm.FullBroadcast(pybamm.Scalar(0), ["separator"], "current collector") | ||
a_p = pybamm.FullBroadcast( | ||
pybamm.Scalar(0), ["positive electrode"], "current collector" | ||
) | ||
c_e_n = pybamm.standard_variables.c_e_n | ||
c_e_s = pybamm.standard_variables.c_e_s | ||
c_e_p = pybamm.standard_variables.c_e_p | ||
variables = { | ||
"Leading-order current collector current density": a, | ||
"Negative electrolyte concentration": c_e_n, | ||
"Separator electrolyte concentration": c_e_s, | ||
"Positive electrolyte concentration": c_e_p, | ||
"X-averaged electrolyte concentration": a, | ||
"X-averaged negative electrode potential": a, | ||
"X-averaged negative electrode surface potential difference": a, | ||
"Leading-order x-averaged negative electrode porosity": a, | ||
"Leading-order x-averaged separator porosity": a, | ||
"Leading-order x-averaged positive electrode porosity": a, | ||
"Leading-order x-averaged negative electrolyte tortuosity": a, | ||
"Leading-order x-averaged separator tortuosity": a, | ||
"Leading-order x-averaged positive electrolyte tortuosity": a, | ||
"X-averaged cell temperature": a, | ||
"Current collector current density": a, | ||
"Negative electrode porosity": a_n, | ||
"Sum of x-averaged negative electrode interfacial current densities": a, | ||
"X-averaged negative electrode total interfacial current density": a, | ||
"Current collector current density": a, | ||
"Negative electrolyte potential": a_n, | ||
"Negative electrolyte current density": a_n, | ||
"Separator electrolyte potential": a_s, | ||
"Separator electrolyte current density": a_s, | ||
"Positive electrode porosity": a_p, | ||
"Sum of x-averaged positive electrode interfacial current densities": a, | ||
"X-averaged positive electrode total interfacial current density": a, | ||
} | ||
|
||
spf = pybamm.electrolyte_conductivity.surface_potential_form | ||
submodel = spf.CompositeAlgebraic(param, "Negative") | ||
std_tests = tests.StandardSubModelTests(submodel, variables) | ||
std_tests.test_all() | ||
submodel = spf.CompositeDifferential(param, "Negative") | ||
std_tests = tests.StandardSubModelTests(submodel, variables) | ||
std_tests.test_all() | ||
|
||
submodel = spf.CompositeAlgebraic(param, "Positive") | ||
std_tests = tests.StandardSubModelTests(submodel, variables) | ||
std_tests.test_all() | ||
submodel = spf.CompositeDifferential(param, "Positive") | ||
std_tests = tests.StandardSubModelTests(submodel, variables) | ||
std_tests.test_all() | ||
|
||
|
||
if __name__ == "__main__": | ||
print("Add -v for more debug output") | ||
import sys | ||
|
||
if "-v" in sys.argv: | ||
debug = True | ||
pybamm.settings.debug_mode = True | ||
unittest.main() |