-
-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,281 additions
and
535 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Equivalent Circuit Model with Split OCV (SplitOCVR) | ||
===================================================== | ||
|
||
.. autoclass:: pybamm.lithium_ion.SplitOCVR | ||
:members: | ||
|
||
.. footbibliography:: |
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 |
---|---|---|
|
@@ -12,3 +12,4 @@ Lithium-ion Models | |
msmr | ||
yang2017 | ||
electrode_soh | ||
ecm_split_ocv |
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,57 @@ | ||
import pybamm | ||
import time | ||
import numpy as np | ||
|
||
|
||
# This script provides an example for massively vectorised | ||
# model solves using the JAX BDF solver. First, | ||
# we set up the model and process parameters | ||
model = pybamm.lithium_ion.SPM() | ||
model.convert_to_format = "jax" | ||
model.events = [] # remove events (not supported in jax) | ||
geometry = model.default_geometry | ||
param = pybamm.ParameterValues("Chen2020") | ||
param.update({"Current function [A]": "[input]"}) | ||
param.process_geometry(geometry) | ||
param.process_model(model) | ||
|
||
# Discretise and setup solver | ||
mesh = pybamm.Mesh(geometry, model.default_submesh_types, model.default_var_pts) | ||
disc = pybamm.Discretisation(mesh, model.default_spatial_methods) | ||
disc.process_model(model) | ||
t_eval = np.linspace(0, 3600, 100) | ||
solver = pybamm.JaxSolver(atol=1e-6, rtol=1e-6, method="BDF") | ||
|
||
# Set number of vectorised solves | ||
values = np.linspace(0.01, 1.0, 1000) | ||
inputs = [{"Current function [A]": value} for value in values] | ||
|
||
# Run solve for all inputs, with a just-in-time compilation | ||
# occurring on the first solve. All sequential solves will | ||
# use the compiled code, with a large performance improvement. | ||
start_time = time.time() | ||
sol = solver.solve(model, t_eval, inputs=inputs) | ||
print(f"Time taken: {time.time() - start_time}") # 1.3s | ||
|
||
# Rerun the vectorised solve, showing performance improvement | ||
start_time = time.time() | ||
compiled_sol = solver.solve(model, t_eval, inputs=inputs) | ||
print(f"Compiled time taken: {time.time() - start_time}") # 0.42s | ||
|
||
# Plot one of the solves | ||
plot = pybamm.QuickPlot( | ||
sol[5], | ||
[ | ||
"Negative particle concentration [mol.m-3]", | ||
"Electrolyte concentration [mol.m-3]", | ||
"Positive particle concentration [mol.m-3]", | ||
"Current [A]", | ||
"Negative electrode potential [V]", | ||
"Electrolyte potential [V]", | ||
"Positive electrode potential [V]", | ||
"Voltage [V]", | ||
], | ||
time_unit="seconds", | ||
spatial_unit="um", | ||
) | ||
plot.dynamic_plot() |
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
100 changes: 100 additions & 0 deletions
100
src/pybamm/models/full_battery_models/lithium_ion/basic_splitOCVR.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,100 @@ | ||
# | ||
# Equivalent Circuit Model with split OCV | ||
# | ||
import pybamm | ||
|
||
|
||
class SplitOCVR(pybamm.BaseModel): | ||
"""Basic Equivalent Circuit Model that uses two OCV functions | ||
for each electrode. This model is easily parameterizable with minimal parameters. | ||
This class differs from the :class: pybamm.equivalent_circuit.Thevenin() due | ||
to dual OCV functions to make up the voltage from each electrode. | ||
Parameters | ||
---------- | ||
name: str, optional | ||
The name of the model. | ||
""" | ||
|
||
def __init__(self, name="ECM with split OCV"): | ||
super().__init__(name) | ||
|
||
###################### | ||
# Variables | ||
###################### | ||
# All variables are only time-dependent | ||
# No domain definition needed | ||
|
||
theta_n = pybamm.Variable("Negative particle stoichiometry") | ||
theta_p = pybamm.Variable("Positive particle stoichiometry") | ||
Q = pybamm.Variable("Discharge capacity [A.h]") | ||
V = pybamm.Variable("Voltage [V]") | ||
|
||
# model is isothermal | ||
I = pybamm.FunctionParameter("Current function [A]", {"Time [s]": pybamm.t}) | ||
|
||
# Capacity equation | ||
self.rhs[Q] = I / 3600 | ||
self.initial_conditions[Q] = pybamm.Scalar(0) | ||
|
||
# Capacity in each electrode | ||
Q_n = pybamm.Parameter("Negative electrode capacity [A.h]") | ||
Q_p = pybamm.Parameter("Positive electrode capacity [A.h]") | ||
|
||
# State of charge electrode equations | ||
theta_n_0 = pybamm.Parameter("Negative electrode initial stoichiometry") | ||
theta_p_0 = pybamm.Parameter("Positive electrode initial stoichiometry") | ||
self.rhs[theta_n] = -I / Q_n / 3600 | ||
self.rhs[theta_p] = I / Q_p / 3600 | ||
self.initial_conditions[theta_n] = theta_n_0 | ||
self.initial_conditions[theta_p] = theta_p_0 | ||
|
||
# Resistance for IR expression | ||
R = pybamm.Parameter("Ohmic resistance [Ohm]") | ||
|
||
# Open-circuit potential for each electrode | ||
Un = pybamm.FunctionParameter( | ||
"Negative electrode OCP [V]", {"Negative particle stoichiometry": theta_n} | ||
) | ||
Up = pybamm.FunctionParameter( | ||
"Positive electrode OCP [V]", {"Positive particle stoichiometry": theta_p} | ||
) | ||
|
||
# Voltage expression | ||
V = Up - Un - I * R | ||
|
||
# Parameters for Voltage cutoff | ||
voltage_high_cut = pybamm.Parameter("Upper voltage cut-off [V]") | ||
voltage_low_cut = pybamm.Parameter("Lower voltage cut-off [V]") | ||
|
||
self.variables = { | ||
"Negative particle stoichiometry": theta_n, | ||
"Positive particle stoichiometry": theta_p, | ||
"Current [A]": I, | ||
"Discharge capacity [A.h]": Q, | ||
"Voltage [V]": V, | ||
"Times [s]": pybamm.t, | ||
"Positive electrode OCP [V]": Up, | ||
"Negative electrode OCP [V]": Un, | ||
"Current function [A]": I, | ||
} | ||
|
||
# Events specify points at which a solution should terminate | ||
self.events += [ | ||
pybamm.Event("Minimum voltage [V]", V - voltage_low_cut), | ||
pybamm.Event("Maximum voltage [V]", voltage_high_cut - V), | ||
pybamm.Event("Maximum Negative Electrode stoichiometry", 0.999 - theta_n), | ||
pybamm.Event("Maximum Positive Electrode stoichiometry", 0.999 - theta_p), | ||
pybamm.Event("Minimum Negative Electrode stoichiometry", theta_n - 0.0001), | ||
pybamm.Event("Minimum Positive Electrode stoichiometry", theta_p - 0.0001), | ||
] | ||
|
||
@property | ||
def default_quick_plot_variables(self): | ||
return [ | ||
"Voltage [V]", | ||
["Negative particle stoichiometry", "Positive particle stoichiometry"], | ||
"Negative electrode OCP [V]", | ||
"Positive electrode OCP [V]", | ||
"Current [A]", | ||
] |
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
Oops, something went wrong.