-
Notifications
You must be signed in to change notification settings - Fork 57
Implement GITT example #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BradyPlanden
merged 36 commits into
pybop-team:develop
from
brosaplanella:issue-223-GITT
May 16, 2024
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
c8069ba
#223 refactor problems into problem folder
brosaplanella f380ea4
add Weppner & Huggins model, with some hacks to make it work
brosaplanella e83d6b3
add GITT FittingProblem
brosaplanella 575c27e
add GITT example
brosaplanella ab34b4d
Merge branch 'develop' into issue-223-GITT
brosaplanella 7b53b75
style: pre-commit fixes
pre-commit-ci[bot] 659c98e
#223 fix typo
brosaplanella d98349a
#223 rename example
brosaplanella 4cbac89
#223 add unit test GITT
brosaplanella feae75b
Merge remote-tracking branch 'upstream/develop' into issue-223-GITT
brosaplanella b586aac
style: pre-commit fixes
pre-commit-ci[bot] d583f1d
#223 import pybop
brosaplanella cef8cc2
style: pre-commit fixes
pre-commit-ci[bot] 6ab1378
#223 comment out failing test to check coverage
brosaplanella d17b1f7
Merge branch 'issue-223-GITT' of github.com:brosaplanella/PyBOP into …
brosaplanella b85dbcb
#223 fix ruff
brosaplanella d447d66
#223 fix failing example
brosaplanella da4ff8b
Apply suggestions from code review
brosaplanella d4bf431
#223 fix typo
brosaplanella edb5e18
remove duplicated parameters
brosaplanella c4e88d4
#223 add citation
brosaplanella 1e49571
Merge remote-tracking branch 'upstream/develop' into issue-223-GITT
brosaplanella 8ae2f19
style: pre-commit fixes
pre-commit-ci[bot] 74972bc
ruff
brosaplanella a9d57c5
#223 fix failing tests
brosaplanella 2f6a0e7
style: pre-commit fixes
pre-commit-ci[bot] c505c41
Merge branch 'develop' into issue-223-GITT
brosaplanella c126ee2
Merge remote-tracking branch 'upstream/develop' into issue-223-GITT
brosaplanella 3e1b601
#223 get surface area to volume ratio from PyBaMM
brosaplanella 6a5ee3d
#223 reverted change as surface area per unit volume is a variable
brosaplanella d38b38f
#223 remove GITT class and move to example
brosaplanella 0a646f8
#223 update CHANGELOG
brosaplanella 20d3612
#223 remove references to GITT class
brosaplanella fdbc803
#223 add credit to pbparam team
brosaplanella 1ab30d4
#223 add tests for WeppnerHuggins
brosaplanella d91c1e5
style: pre-commit fixes
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,70 @@ | ||
| import numpy as np | ||
|
|
||
| import pybop | ||
|
|
||
| # Define model | ||
| parameter_set = pybop.ParameterSet.pybamm("Xu2019") | ||
| model = pybop.lithium_ion.SPM( | ||
| parameter_set=parameter_set, options={"working electrode": "positive"} | ||
| ) | ||
|
|
||
| # Generate data | ||
| sigma = 0.005 | ||
| t_eval = np.arange(0, 150, 2) | ||
| values = model.predict(t_eval=t_eval) | ||
| corrupt_values = values["Voltage [V]"].data + np.random.normal(0, sigma, len(t_eval)) | ||
|
|
||
| # Form dataset | ||
| dataset = pybop.Dataset( | ||
| { | ||
| "Time [s]": t_eval, | ||
| "Current function [A]": values["Current [A]"].data, | ||
| "Voltage [V]": corrupt_values, | ||
| } | ||
| ) | ||
|
|
||
| # Define parameter set | ||
| parameter_set.update( | ||
| { | ||
| "Reference OCP [V]": 4.1821, | ||
| "Derivative of the OCP wrt stoichiometry [V]": -1.38636, | ||
| }, | ||
| check_already_exists=False, | ||
| ) | ||
|
|
||
| # Define the cost to optimise | ||
| model = pybop.lithium_ion.WeppnerHuggins(parameter_set=parameter_set) | ||
|
|
||
| parameters = [ | ||
| pybop.Parameter( | ||
| "Positive electrode diffusivity [m2.s-1]", | ||
| prior=pybop.Gaussian(5e-14, 1e-13), | ||
| bounds=[1e-16, 1e-11], | ||
| true_value=parameter_set["Positive electrode diffusivity [m2.s-1]"], | ||
| ), | ||
| ] | ||
|
|
||
| problem = pybop.FittingProblem( | ||
| model, | ||
| parameters, | ||
| dataset, | ||
| signal=["Voltage [V]"], | ||
| ) | ||
|
|
||
| cost = pybop.RootMeanSquaredError(problem) | ||
|
|
||
| # Build the optimisation problem | ||
| optim = pybop.Optimisation(cost=cost, optimiser=pybop.PSO, verbose=True) | ||
|
|
||
| # Run the optimisation problem | ||
| x, final_cost = optim.run() | ||
| print("Estimated parameters:", x) | ||
|
|
||
| # Plot the timeseries output | ||
| pybop.quick_plot(problem, parameter_values=x, title="Optimised Comparison") | ||
|
|
||
| # Plot convergence | ||
| pybop.plot_convergence(optim) | ||
|
|
||
| # Plot the parameter traces | ||
| pybop.plot_parameters(optim) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,113 @@ | ||
| # | ||
| # Weppner Huggins Model | ||
| # | ||
| import numpy as np | ||
| import pybamm | ||
|
|
||
|
|
||
| class BaseWeppnerHuggins(pybamm.lithium_ion.BaseModel): | ||
| """WeppnerHuggins Model for GITT. Credit: pybamm-param team. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| name : str, optional | ||
| The name of the model. | ||
| """ | ||
|
|
||
| def __init__(self, name="Weppner & Huggins model"): | ||
| super().__init__({}, name) | ||
|
|
||
| pybamm.citations.register(""" | ||
| @article{Weppner1977, | ||
| title={{Determination of the kinetic parameters | ||
| of mixed-conducting electrodes and application to the system Li3Sb}}, | ||
| author={Weppner, W and Huggins, R A}, | ||
| journal={Journal of The Electrochemical Society}, | ||
| volume={124}, | ||
| number={10}, | ||
| pages={1569}, | ||
| year={1977}, | ||
| publisher={IOP Publishing} | ||
| } | ||
| """) | ||
|
|
||
| # `self.param` is a class containing all the relevant parameters and functions for | ||
| # this model. These are purely symbolic at this stage, and will be set by the | ||
| # `ParameterValues` class when the model is processed. | ||
| self.options["working electrode"] = "positive" | ||
| self._summary_variables = [] | ||
|
|
||
| t = pybamm.t | ||
| ###################### | ||
| # Parameters | ||
| ###################### | ||
|
|
||
| d_s = pybamm.Parameter("Positive electrode diffusivity [m2.s-1]") | ||
|
|
||
| c_s_max = pybamm.Parameter( | ||
| "Maximum concentration in positive electrode [mol.m-3]" | ||
| ) | ||
|
|
||
| i_app = self.param.current_density_with_time | ||
|
|
||
| U = pybamm.Parameter("Reference OCP [V]") | ||
|
|
||
| U_prime = pybamm.Parameter("Derivative of the OCP wrt stoichiometry [V]") | ||
|
|
||
| epsilon = pybamm.Parameter("Positive electrode active material volume fraction") | ||
|
|
||
| r_particle = pybamm.Parameter("Positive particle radius [m]") | ||
|
|
||
| a = 3 * (epsilon / r_particle) | ||
|
BradyPlanden marked this conversation as resolved.
|
||
|
|
||
| l_w = self.param.p.L | ||
|
|
||
| ###################### | ||
| # Governing equations | ||
| ###################### | ||
| u_surf = ( | ||
| (2 / (np.pi**0.5)) | ||
| * (i_app / ((d_s**0.5) * a * self.param.F * l_w)) | ||
| * (t**0.5) | ||
| ) | ||
| # Linearised voltage | ||
| V = U + (U_prime * u_surf) / c_s_max | ||
| ###################### | ||
| # (Some) variables | ||
| ###################### | ||
| self.variables = { | ||
| "Voltage [V]": V, | ||
| "Time [s]": t, | ||
| } | ||
|
|
||
| @property | ||
| def default_geometry(self): | ||
| return {} | ||
|
|
||
| @property | ||
| def default_parameter_values(self): | ||
| parameter_values = pybamm.ParameterValues("Xu2019") | ||
| parameter_values.update( | ||
| { | ||
| "Reference OCP [V]": 4.1821, | ||
| "Derivative of the OCP wrt stoichiometry [V]": -1.38636, | ||
| }, | ||
| check_already_exists=False, | ||
| ) | ||
| return parameter_values | ||
|
|
||
| @property | ||
| def default_submesh_types(self): | ||
| return {} | ||
|
|
||
| @property | ||
| def default_var_pts(self): | ||
| return {} | ||
|
|
||
| @property | ||
| def default_spatial_methods(self): | ||
| return {} | ||
|
|
||
| @property | ||
| def default_solver(self): | ||
| return pybamm.DummySolver() | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.