Skip to content

Commit

Permalink
#923 merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Apr 1, 2020
2 parents a733286 + 4cc26b1 commit 942b713
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 31 deletions.
25 changes: 15 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
# [Unreleased](https://github.com/pybamm-team/PyBaMM)
# [Unreleased](https://github.com/pybamm-team/PyBaMM/)

## Optimizations

- Sped up model building ([#927](https://github.com/pybamm-team/PyBaMM/pull/927))
- Changed default solver for lead-acid to `CasadiSolver` ([#927](https://github.com/pybamm-team/PyBaMM/pull/927))

## Bug fixes

- Reformatted electrolyte submodels ([#927](https://github.com/pybamm-team/PyBaMM/pull/927))

# [v0.2.1](https://github.com/pybamm-team/PyBaMM/tree/v0.2.1) - 2020-03-31

New expression tree node types, models, parameter sets and solvers, as well as general bug fixes and new examples.

## Features

Expand All @@ -9,9 +22,6 @@
- Added functionality to broadcast to edges ([#891](https://github.com/pybamm-team/PyBaMM/pull/891))
- Reformatted and cleaned up `QuickPlot` ([#886](https://github.com/pybamm-team/PyBaMM/pull/886))
- Added thermal effects to lead-acid models ([#885](https://github.com/pybamm-team/PyBaMM/pull/885))
- Add new symbols `VariableDot`, representing the derivative of a variable wrt time,
and `StateVectorDot`, representing the derivative of a state vector wrt time
([#858](https://github.com/pybamm-team/PyBaMM/issues/858))
- Added a helper function for info on function parameters ([#881](https://github.com/pybamm-team/PyBaMM/pull/881))
- Added additional notebooks showing how to create and compare models ([#877](https://github.com/pybamm-team/PyBaMM/pull/877))
- Added `Minimum`, `Maximum` and `Sign` operators
Expand All @@ -24,14 +34,9 @@
and `StateVectorDot`, representing the derivative of a state vector wrt time
([#858](https://github.com/pybamm-team/PyBaMM/issues/858))

## Optimizations

- Sped up model building ([#927](https://github.com/pybamm-team/PyBaMM/pull/927))
- Changed default solver for lead-acid to `CasadiSolver` ([#927](https://github.com/pybamm-team/PyBaMM/pull/927))

## Bug fixes

- Reformatted electrolyte submodels ([#927](https://github.com/pybamm-team/PyBaMM/pull/927))
- Fixed tight layout for QuickPlot in jupyter notebooks ([#930](https://github.com/pybamm-team/PyBaMM/pull/930))
- Fixed bug raised if function returns a scalar ([#919](https://github.com/pybamm-team/PyBaMM/pull/919))
- Fixed event handling in `ScipySolver` ([#905](https://github.com/pybamm-team/PyBaMM/pull/905))
- Made input handling clearer in solvers ([#905](https://github.com/pybamm-team/PyBaMM/pull/905))
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# The short X.Y version
version = "0.2"
# The full version, including alpha/beta/rc tags
release = "0.2.0"
release = "0.2.1"


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pybamm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def version(formatted=False):
# other
#
from .processed_variable import ProcessedVariable
from .quick_plot import QuickPlot, ax_min, ax_max
from .quick_plot import QuickPlot, dynamic_plot, ax_min, ax_max

from .simulation import Simulation, load_sim, is_notebook

Expand Down
29 changes: 22 additions & 7 deletions pybamm/quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#
import numpy as np
import pybamm
import warnings
from collections import defaultdict


Expand Down Expand Up @@ -45,6 +44,24 @@ def split_long_string(title, max_words=4):
return first_line + "\n" + second_line


def dynamic_plot(*args, **kwargs):
"""
Creates a :class:`pybamm.QuickPlot` object (with arguments 'args' and keyword
arguments 'kwargs') and then calls :meth:`pybamm.QuickPlot.dynamic_plot`.
The key-word argument 'testing' is passed to the 'dynamic_plot' method, not the
`QuickPlot' class.
Returns
-------
plot : :class:`pybamm.QuickPlot`
The 'QuickPlot' object that was created
"""
kwargs_for_class = {k: v for k, v in kwargs.items() if k != "testing"}
plot = pybamm.QuickPlot(*args, **kwargs_for_class)
plot.dynamic_plot(kwargs.get("testing", False))
return plot


class QuickPlot(object):
"""
Generates a quick plot of a subset of key outputs of the model so that the model
Expand Down Expand Up @@ -615,6 +632,10 @@ def plot(self, t):
if len(solution_handles) > 0:
self.fig.legend(solution_handles, self.labels, loc="lower right")

# Fix layout
bottom = 0.05 + 0.03 * max((len(self.labels) - 2), 0)
self.gridspec.tight_layout(self.fig, rect=[0, bottom, 1, 1])

def dynamic_plot(self, testing=False, step=None):
"""
Generate a dynamic plot with a slider to control the time.
Expand Down Expand Up @@ -651,12 +672,6 @@ def dynamic_plot(self, testing=False, step=None):
)
self.slider.on_changed(self.slider_update)

# ignore the warning about tight layout
warnings.simplefilter("ignore")
bottom = 0.05 + 0.03 * max((len(self.labels) - 2), 0)
self.gridspec.tight_layout(self.fig, rect=[0, bottom, 1, 1])
warnings.simplefilter("always")

if not testing: # pragma: no cover
plt.show()

Expand Down
13 changes: 6 additions & 7 deletions pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ class Simulation:
----------
model : :class:`pybamm.BaseModel`
The model to be simulated
experiment : : class:`pybamm.Experiment` (optional)
experiment : :class:`pybamm.Experiment` (optional)
The experimental conditions under which to solve the model
geometry: :class:`pybamm.Geometry` (optional)
The geometry upon which to solve the model
parameter_values: dict (optional)
A dictionary of parameters and their corresponding numerical
values
parameter_values: :class:`pybamm.ParameterValues` (optional)
Parameters and their corresponding numerical values.
submesh_types: dict (optional)
A dictionary of the types of submesh to use on each subdomain
var_pts: dict (optional)
Expand Down Expand Up @@ -533,9 +532,9 @@ def plot(self, quick_plot_vars=None, testing=False):
if quick_plot_vars is None:
quick_plot_vars = self.quick_plot_vars

plot = pybamm.QuickPlot(self._solution, output_variables=quick_plot_vars)

plot.dynamic_plot(testing=testing)
self.quick_plot = pybamm.dynamic_plot(
self._solution, output_variables=quick_plot_vars, testing=testing
)

@property
def model(self):
Expand Down
6 changes: 3 additions & 3 deletions pybamm/solvers/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ def save_data(self, filename, variables=None, to_format="pickle"):
savemat(filename, data)
elif to_format == "csv":
for name, var in data.items():
if var.ndim == 2:
if var.ndim >= 2:
raise ValueError(
"only 1D variables can be saved to csv, but '{}' is 2D".format(
name
"only 0D variables can be saved to csv, but '{}' is {}D".format(
name, var.ndim - 1
)
)
df = pd.DataFrame(data)
Expand Down
2 changes: 1 addition & 1 deletion pybamm/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0, 2, 0
0, 2, 1
2 changes: 1 addition & 1 deletion tests/unit/test_solvers/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_save(self):

# to csv
with self.assertRaisesRegex(
ValueError, "only 1D variables can be saved to csv"
ValueError, "only 0D variables can be saved to csv"
):
solution.save_data("test.csv", to_format="csv")
# only save "c" and "2c"
Expand Down

0 comments on commit 942b713

Please sign in to comment.