Skip to content

Commit

Permalink
Add VolumetricEnergyDensity example (#191)
Browse files Browse the repository at this point in the history
* Add VolumetricEnergyDensity example

* Update CHANGELOG.md

* Update test_cost.py

* Update example to pass coverage tests

* Split cost classes by type

* Add DesignCost to init

* Update error checking
  • Loading branch information
NicolaCourtier authored Feb 9, 2024
1 parent 27c49f0 commit 7d09c5d
Show file tree
Hide file tree
Showing 13 changed files with 655 additions and 449 deletions.
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)
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

0 comments on commit 7d09c5d

Please sign in to comment.