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

make quickplot use scaling from solutions #1234

Merged
merged 4 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -27,6 +27,7 @@
- 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))
TomTranter marked this conversation as resolved.
Show resolved Hide resolved
- Quickplot now works when timescale or lengthscale is a function of an input parameter ([#1234](https://github.com/pybamm-team/PyBaMM/pull/1234))

## Breaking changes

Expand Down
18 changes: 11 additions & 7 deletions pybamm/plotting/quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,20 @@ 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()
}
try:
# Set length scales
self.length_scales = {
domain: scale.evaluate() * self.spatial_factor
for domain, scale in models[0].length_scales.items()
}
except KeyError:
# Length scales are probably function of input
# Use the evaluated length scales from the first solution
self.length_scales = solutions[0].length_scales_eval

# 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