Skip to content
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

Add VolumetricEnergyDensity example #191

Merged
merged 8 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [#118](https://github.com/pybop-team/PyBOP/issues/118) - Adds example jupyter notebooks.
- [#151](https://github.com/pybop-team/PyBOP/issues/151) - Adds a standalone version of the Problem class.
- [#12](https://github.com/pybop-team/PyBOP/issues/12) - Adds initial implementation of an Observer class and an unscented Kalman filter.
- [#190](https://github.com/pybop-team/PyBOP/issues/190) - Adds a second example design cost, namely the VolumetricEnergyDensity.

## Bug Fixes

Expand Down
3 changes: 2 additions & 1 deletion examples/notebooks/spm_electrode_design.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13340,7 +13340,8 @@
}
],
"source": [
"cost.problem._model.approximate_capacity(x)\n",
"if cost.update_capacity:\n",
" cost.problem._model.approximate_capacity(x)\n",
"pybop.quick_plot(x, cost, title=\"Optimised Comparison\");"
]
},
Expand Down
13 changes: 9 additions & 4 deletions examples/scripts/spme_max_energy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pybop

## NOTE: This is a brittle example, the classes and methods below will be
## integrated into pybop in a future release.

# A design optimisation example loosely based on work by L.D. Couto
# available at https://doi.org/10.1016/j.energy.2022.125966.
Expand All @@ -12,6 +10,12 @@
# electrode widths, particle radii, volume fractions and
# separator width.

# NOTE: This script can be easily adjusted to consider the volumetric
# (instead of gravimetric) energy density by changing the line which
# defines the cost and changing the output to:
# print(f"Initial volumetric energy density: {-cost(cost.x0):.2f} Wh.m-3")
# print(f"Optimised volumetric energy density: {-final_cost:.2f} Wh.m-3")

# Define parameter set and model
parameter_set = pybop.ParameterSet.pybamm("Chen2020")
model = pybop.lithium_ion.SPMe(parameter_set=parameter_set)
Expand Down Expand Up @@ -42,7 +46,7 @@
model, parameters, experiment, signal=signal, init_soc=init_soc
)

# Generate cost function and optimisation class
# Generate cost function and optimisation class:
cost = pybop.GravimetricEnergyDensity(problem)
optim = pybop.Optimisation(
cost, optimiser=pybop.PSO, verbose=True, allow_infeasible_solutions=False
Expand All @@ -56,7 +60,8 @@
print(f"Optimised gravimetric energy density: {-final_cost:.2f} Wh.kg-1")

# Plot the timeseries output
# model.approximate_capacity(x)
if cost.update_capacity:
cost.problem._model.approximate_capacity(x)

Check warning on line 64 in examples/scripts/spme_max_energy.py

View check run for this annotation

Codecov / codecov/patch

examples/scripts/spme_max_energy.py#L64

Added line #L64 was not covered by tests
pybop.quick_plot(x, cost, title="Optimised Comparison")

# Plot the cost landscape with optimisation path
Expand Down
8 changes: 6 additions & 2 deletions pybop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@
#
# Cost function class
#
from ._costs import (
BaseCost,
from .costs.base_cost import BaseCost
from .costs.fitting_costs import (
RootMeanSquaredError,
SumSquaredError,
ObserverCost,
)
from .costs.design_costs import (
DesignCost,
GravimetricEnergyDensity,
VolumetricEnergyDensity,
)

#
Expand Down
Loading
Loading