Skip to content

Commit

Permalink
#1477 fix bug in solution
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Aug 3, 2021
1 parent d18cf81 commit 313c9c3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pybamm/solvers/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,25 @@ def __init__(
pybamm.citations.register("Andersson2019")

def extract_explicit_sensitivities(self):
# if we got here, we havn't set y yet
self.set_y()

# extract sensitivities from full y solution
self._y, self._sensitivities = \
self._extract_explicit_sensitivities(
self.all_models[0], self.y, self.t, self.all_inputs[0]
)

# make sure we remove all sensitivities from all_ys
for index, (model, ys, ts, inputs) in enumerate(
zip(self.all_models, self.all_ys, self.all_ts,
self.all_inputs)
):
self._all_ys[index], _ = \
self._extract_explicit_sensitivities(
model, ys, ts, inputs
)

def _extract_explicit_sensitivities(self, model, y, t_eval, inputs):
"""
given a model and a solution y, extracts the sensitivities
Expand Down Expand Up @@ -411,6 +425,10 @@ def set_summary_variables(self, all_summary_variables):

def update(self, variables):
"""Add ProcessedVariables to the dictionary of variables in the solution"""
# make sure that sensitivities are extracted if required
if isinstance(self._sensitivities, bool) and self._sensitivities:
self.extract_explicit_sensitivities()

# Convert single entry to list
if isinstance(variables, str):
variables = [variables]
Expand Down

0 comments on commit 313c9c3

Please sign in to comment.