Skip to content

Commit 313c9c3

Browse files
committed
#1477 fix bug in solution
1 parent d18cf81 commit 313c9c3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pybamm/solvers/solution.py

+18
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,25 @@ def __init__(
135135
pybamm.citations.register("Andersson2019")
136136

137137
def extract_explicit_sensitivities(self):
138+
# if we got here, we havn't set y yet
139+
self.set_y()
140+
141+
# extract sensitivities from full y solution
138142
self._y, self._sensitivities = \
139143
self._extract_explicit_sensitivities(
140144
self.all_models[0], self.y, self.t, self.all_inputs[0]
141145
)
142146

147+
# make sure we remove all sensitivities from all_ys
148+
for index, (model, ys, ts, inputs) in enumerate(
149+
zip(self.all_models, self.all_ys, self.all_ts,
150+
self.all_inputs)
151+
):
152+
self._all_ys[index], _ = \
153+
self._extract_explicit_sensitivities(
154+
model, ys, ts, inputs
155+
)
156+
143157
def _extract_explicit_sensitivities(self, model, y, t_eval, inputs):
144158
"""
145159
given a model and a solution y, extracts the sensitivities
@@ -411,6 +425,10 @@ def set_summary_variables(self, all_summary_variables):
411425

412426
def update(self, variables):
413427
"""Add ProcessedVariables to the dictionary of variables in the solution"""
428+
# make sure that sensitivities are extracted if required
429+
if isinstance(self._sensitivities, bool) and self._sensitivities:
430+
self.extract_explicit_sensitivities()
431+
414432
# Convert single entry to list
415433
if isinstance(variables, str):
416434
variables = [variables]

0 commit comments

Comments
 (0)