Skip to content

Commit

Permalink
Split the models into separate classes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTranter committed Oct 15, 2023
1 parent c79113e commit ee27daf
Show file tree
Hide file tree
Showing 23 changed files with 602 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@















import pybamm
import numpy as np


sols = []
te_opts = pybamm.BatteryModelOptions({}).possible_options["transport efficiency"]
parameter_values = pybamm.ParameterValues("Marquis2019")
print(te_opts)


parameter_values.search("porosity")


parameter_values.search("Bruggeman")





parameter_values.update({'Negative electrode tortuosity factor (electrolyte)': 0.3**(-0.5),
'Positive electrode tortuosity factor (electrolyte)': 0.3**(-0.5),
'Negative electrode tortuosity factor (electrode)': 0.7**(-0.5),
'Positive electrode tortuosity factor (electrode)': 0.7**(-0.5),
'Separator tortuosity factor (electrolyte)': 1.0}, check_already_exists=False)





for t_label in te_opts:
model = pybamm.lithium_ion.DFN(options={'transport efficiency': t_label}) # Doyle-Fuller-Newman model
sim = pybamm.Simulation(model, parameter_values=parameter_values)
sols.append(sim.solve([0, 3600])) # solve for 1 hour


pybamm.dynamic_plot(sols,labels=te_opts)





np.allclose(sols[0]["Terminal voltage [V]"].data, sols[4]["Terminal voltage [V]"].data)





parameter_values.update({'Negative electrode tortuosity factor (electrolyte)': 4.0,
'Positive electrode tortuosity factor (electrolyte)': 4.0,
'Negative electrode tortuosity factor (electrode)': 3.0,
'Positive electrode tortuosity factor (electrode)': 3.0,
'Separator tortuosity factor (electrolyte)': 1.5}, check_already_exists=False)


model = pybamm.lithium_ion.DFN(options={'transport efficiency': "tortuosity factor"}) # Doyle-Fuller-Newman model
sim = pybamm.Simulation(model, parameter_values=parameter_values)
sols.append(sim.solve([0, 3600]))


pybamm.dynamic_plot(sols,labels=te_opts+["higher tortuosity factor"])





pybamm.print_citations()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bruggeman Transport Efficiency Model
====================================

.. autoclass:: pybamm.transport_efficiency.Bruggeman
:members:
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Cation-Exchange Membrane Transport Efficiency Model
===================================================

.. autoclass:: pybamm.transport_efficiency.CationExchangeMembrane
:members:

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Heterogeneous Catalyst Transport Efficiency Model
=================================================

.. autoclass:: pybamm.transport_efficiency.HeterogeneousCatalyst
:members:
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Hyperbola of Revolution Transport Efficiency Model
==================================================

.. autoclass:: pybamm.transport_efficiency.HyperbolaOfRevolution
:members:
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ transport_efficiency
:maxdepth: 1

base_transport_efficiency
general_transport_efficiency
bruggeman
cation_exchange_membrane
heterogeneous_catalyst
hyperbola_of_revolution
ordered_packing
overlapping_spheres
random_overlapping_cylinders
tortuosity_factor
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Ordered Packing Transport Efficiency Model
==========================================

.. autoclass:: pybamm.transport_efficiency.OrderedPacking
:members:
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Overlapping Spheres Transport Efficiency Model
==============================================

.. autoclass:: pybamm.transport_efficiency.OverlappingSpheres
:members:
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Random Overlapping Cylinders Transport Efficiency Model
=======================================================

.. autoclass:: pybamm.transport_efficiency.RandomOverlappingCylinders
:members:
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Tortuosity Factor Transport Efficiency Model
============================================

.. autoclass:: pybamm.transport_efficiency.TortuosityFactor
:members:
10 changes: 5 additions & 5 deletions docs/source/examples/notebooks/models/tortuosity_models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "240db810f1e0430696821ee44192b2b1",
"model_id": "93cb2f124bd348a0bf99249423a14717",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -180,7 +180,7 @@
{
"data": {
"text/plain": [
"<pybamm.plotting.quick_plot.QuickPlot at 0x1cdea7f35b0>"
"<pybamm.plotting.quick_plot.QuickPlot at 0x1b7f3ebec50>"
]
},
"execution_count": 7,
Expand Down Expand Up @@ -258,7 +258,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "cbdb93c1b74f434880b57dc8f8a0f3f6",
"model_id": "abd08396d3434395833472560a7114d1",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -272,7 +272,7 @@
{
"data": {
"text/plain": [
"<pybamm.plotting.quick_plot.QuickPlot at 0x1cdf8c86950>"
"<pybamm.plotting.quick_plot.QuickPlot at 0x1b7f8659b10>"
]
},
"execution_count": 11,
Expand Down Expand Up @@ -338,7 +338,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
98 changes: 88 additions & 10 deletions pybamm/models/full_battery_models/base_battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,16 +1153,94 @@ def set_external_circuit_submodel(self):
self.submodels["external circuit"] = model

def set_transport_efficiency_submodels(self):
self.submodels[
"electrolyte transport efficiency"
] = pybamm.transport_efficiency.GeneralTransportEfficiency(
self.param, "Electrolyte", self.options
)
self.submodels[
"electrode transport efficiency"
] = pybamm.transport_efficiency.GeneralTransportEfficiency(
self.param, "Electrode", self.options
)
if self.options["transport efficiency"] == "Bruggeman":
self.submodels[
"electrolyte transport efficiency"
] = pybamm.transport_efficiency.Bruggeman(
self.param, "Electrolyte", self.options
)
self.submodels[
"electrode transport efficiency"
] = pybamm.transport_efficiency.Bruggeman(
self.param, "Electrode", self.options
)
elif self.options["transport efficiency"] == "tortuosity factor":
self.submodels[
"electrolyte transport efficiency"
] = pybamm.transport_efficiency.TortuosityFactor(
self.param, "Electrolyte", self.options
)
self.submodels[
"electrode transport efficiency"
] = pybamm.transport_efficiency.TortuosityFactor(
self.param, "Electrode", self.options
)
elif self.options["transport efficiency"] == "ordered packing":
self.submodels[
"electrolyte transport efficiency"
] = pybamm.transport_efficiency.OrderedPacking(
self.param, "Electrolyte", self.options
)
self.submodels[
"electrode transport efficiency"
] = pybamm.transport_efficiency.OrderedPacking(
self.param, "Electrode", self.options
)
elif self.options["transport efficiency"] == "hyperbola of revolution":
self.submodels[
"electrolyte transport efficiency"
] = pybamm.transport_efficiency.HyperbolaOfRevolution(
self.param, "Electrolyte", self.options
)
self.submodels[
"electrode transport efficiency"
] = pybamm.transport_efficiency.HyperbolaOfRevolution(
self.param, "Electrode", self.options
)
elif self.options["transport efficiency"] == "overlapping spheres":
self.submodels[
"electrolyte transport efficiency"
] = pybamm.transport_efficiency.OverlappingSpheres(
self.param, "Electrolyte", self.options
)
self.submodels[
"electrode transport efficiency"
] = pybamm.transport_efficiency.OverlappingSpheres(
self.param, "Electrode", self.options
)
elif self.options["transport efficiency"] == "random overlapping cylinders":
self.submodels[
"electrolyte transport efficiency"
] = pybamm.transport_efficiency.RandomOverlappingCylinders(
self.param, "Electrolyte", self.options
)
self.submodels[
"electrode transport efficiency"
] = pybamm.transport_efficiency.RandomOverlappingCylinders(
self.param, "Electrode", self.options
)
elif self.options["transport efficiency"] == "heterogeneous catalyst":
self.submodels[
"electrolyte transport efficiency"
] = pybamm.transport_efficiency.HeterogeneousCatalyst(
self.param, "Electrolyte", self.options
)
self.submodels[
"electrode transport efficiency"
] = pybamm.transport_efficiency.HeterogeneousCatalyst(
self.param, "Electrode", self.options
)
elif self.options["transport efficiency"] == "cation-exchange membrane":
self.submodels[
"electrolyte transport efficiency"
] = pybamm.transport_efficiency.CationExchangeMembrane(
self.param, "Electrolyte", self.options
)
self.submodels[
"electrode transport efficiency"
] = pybamm.transport_efficiency.CationExchangeMembrane(
self.param, "Electrode", self.options
)

def set_thermal_submodel(self):
if self.options["thermal"] == "isothermal":
Expand Down
9 changes: 8 additions & 1 deletion pybamm/models/submodels/transport_efficiency/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
from .base_transport_efficiency import BaseModel
from .general_transport_efficiency import GeneralTransportEfficiency
from .bruggeman import Bruggeman
from .cation_exchange_membrane import CationExchangeMembrane
from .heterogeneous_catalyst import HeterogeneousCatalyst
from .hyperbola_of_revolution import HyperbolaOfRevolution
from .ordered_packing import OrderedPacking
from .overlapping_spheres import OverlappingSpheres
from .random_overlapping_cylinders import RandomOverlappingCylinders
from .tortuosity_factor import TortuosityFactor
50 changes: 50 additions & 0 deletions pybamm/models/submodels/transport_efficiency/bruggeman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Class for Bruggeman transport_efficiency
#
import pybamm
from .base_transport_efficiency import BaseModel


class Bruggeman(BaseModel):
"""Submodel for transport_efficiency
Parameters
----------
param : parameter class
The parameters to use for this submodel
component : str
The material for the model ('electrolyte' or 'electrode').
options : dict, optional
A dictionary of options to be passed to the model.
"""

def __init__(self, param, component, options=None):
super().__init__(param, component, options=options)

def get_coupled_variables(self, variables):
if self.component == "Electrolyte":
tor_dict = {}
for domain in self.options.whole_cell_domains:
Domain = domain.capitalize()
eps_k = variables[f"{Domain} porosity"]
pybamm.citations.register("bruggeman1935berechnung")
b_k = self.param.domain_params[domain.split()[0]].b_e
tor_k = eps_k**b_k
tor_dict[domain] = tor_k
elif self.component == "Electrode":
tor_dict = {}
for domain in self.options.whole_cell_domains:
if domain == "separator":
tor_k = pybamm.FullBroadcast(0, "separator", "current collector")
else:
Domain = domain.capitalize()
phi_k = (1 - variables[f"{Domain} porosity"])
pybamm.citations.register("bruggeman1935berechnung")
b_k = self.param.domain_params[domain.split()[0]].b_s
tor_k = phi_k**b_k
tor_dict[domain] = tor_k
variables.update(self._get_standard_transport_efficiency_variables(tor_dict))

return variables


Loading

0 comments on commit ee27daf

Please sign in to comment.