PyBaMM
PyBaMM copied to clipboard
Observe custom variables after solving + faster simulation build time
Description
Adds a few features:
- All values in the
model.variablesdict are now lazily evaluated as a post-processing step, which reduces build time by ~2.25x. The total time to solve the first simulation is now ~1.5x faster. - Adds the ability to lazily observe custom pybamm expressions after solving the simulation. E.g.,
import pybamm
model = pybamm.lithium_ion.SPM()
sim = pybamm.Simulation(model)
sol = sim.solve([0, 1000])
soc = model.variables["Discharge capacity [A.h]"] / model.variables["Nominal cell capacity [A.h]"]
sol.observe(soc)
# <pybamm.solvers.processed_variable.ProcessedVariable0D at 0x104606c90>
which supports all variables. This requires that the solver does not haveoutput_variables.
Type of change
Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #)
Important checks:
Please confirm the following before marking the PR as ready for review:
- No style issues:
nox -s pre-commit - All tests pass:
nox -s tests - The documentation builds:
nox -s doctests - Code is commented for hard-to-understand areas
- Tests added that prove fix is effective or that feature works