Skip to content

Commit

Permalink
Merge pull request #1234 from pybamm-team/issue-1233-quickplot-inputs
Browse files Browse the repository at this point in the history
make quickplot use scaling from solutions
  • Loading branch information
TomTranter authored Nov 9, 2020
2 parents d3b1cca + 1483504 commit 0785ec6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@

## Bug fixes

- Quickplot now works when timescale or lengthscale is a function of an input parameter ([#1234](https://github.com/pybamm-team/PyBaMM/pull/1234))
- Fix bug that was slowing down creation of the EC reaction SEI submodel ([#1227](https://github.com/pybamm-team/PyBaMM/pull/1227))
- Add missing separator thermal parameters for the Ecker parameter set ([#1226](https://github.com/pybamm-team/PyBaMM/pull/1226))
- Make sure simulation solves when evaluated timescale is a function of an input parameter ([#1218](https://github.com/pybamm-team/PyBaMM/pull/1218))
- Raise error if saving to MATLAB with variable names that MATLAB can't read, and give option of providing alternative variable names ([#1206](https://github.com/pybamm-team/PyBaMM/pull/1206))
- Raise error if the boundary condition at the origin in a spherical domain is other than no-flux ([#1175](https://github.com/pybamm-team/PyBaMM/pull/1175))
- Fix boundary conditions at r = 0 for Creating Models notebooks ([#1173](https://github.com/pybamm-team/PyBaMM/pull/1173))
- Make sure simulation solves when evaluated timescale is a function of an input parameter ([#1218](https://github.com/pybamm-team/PyBaMM/pull/1218))

## Breaking changes

Expand Down
9 changes: 1 addition & 8 deletions pybamm/plotting/quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,9 @@ def __init__(
else:
raise ValueError("spatial unit '{}' not recognized".format(spatial_unit))

# Set length scales
self.length_scales = {
domain: scale.evaluate() * self.spatial_factor
for domain, scale in models[0].length_scales.items()
}

# Time parameters
model_timescale_in_seconds = models[0].timescale_eval
self.ts_seconds = [
solution.t * model_timescale_in_seconds for solution in solutions
solution.t * solution.timescale_eval for solution in solutions
]
min_t = np.min([t[0] for t in self.ts_seconds])
max_t = np.max([t[-1] for t in self.ts_seconds])
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,36 @@ def test_failure(self):
with self.assertRaisesRegex(TypeError, "solutions must be"):
pybamm.QuickPlot(1)

def test_model_with_inputs(self):
chemistry = pybamm.parameter_sets.Chen2020
parameter_values = pybamm.ParameterValues(chemistry=chemistry)
model = pybamm.lithium_ion.SPMe()
parameter_values.update({"Electrode height [m]": "[input]"})
solver = pybamm.CasadiSolver(mode='safe')
sim1 = pybamm.Simulation(model, parameter_values=parameter_values,
solver=solver)
inputs1 = {"Electrode height [m]": 1.00}
sol1 = sim1.solve(t_eval=np.linspace(0, 1000, 101), inputs=inputs1)
sim2 = pybamm.Simulation(model, parameter_values=parameter_values,
solver=solver)
inputs2 = {"Electrode height [m]": 2.00}
sol2 = sim2.solve(t_eval=np.linspace(0, 1000, 101), inputs=inputs2)
output_variables = [
"Terminal voltage [V]",
"Current [A]",
"Negative electrode potential [V]",
"Positive electrode potential [V]",
"Electrolyte potential [V]",
"Electrolyte concentration",
"Negative particle surface concentration",
"Positive particle surface concentration",
]
quick_plot = pybamm.QuickPlot(solutions=[sol1, sol2],
output_variables=output_variables)
quick_plot.dynamic_plot(testing=True)
quick_plot.slider_update(1)
pybamm.close_plots()


if __name__ == "__main__":
print("Add -v for more debug output")
Expand Down

0 comments on commit 0785ec6

Please sign in to comment.