@@ -131,6 +131,11 @@ def _integrate(self, model, t_eval, inputs_dict=None):
131
131
inputs_dict : dict, optional
132
132
Any external variables or input parameters to pass to the model when solving
133
133
"""
134
+
135
+
136
+ # are we solving explicit forward equations?
137
+ explicit_sensitivities = self .sensitivity == 'explicit forward'
138
+
134
139
# Record whether there are any symbolic inputs
135
140
inputs_dict = inputs_dict or {}
136
141
@@ -158,14 +163,15 @@ def _integrate(self, model, t_eval, inputs_dict=None):
158
163
# Create integrator without grid to avoid having to create several times
159
164
self .create_integrator (model , inputs )
160
165
solution = self ._run_integrator (
161
- model , model .y0 , inputs_dict , inputs , t_eval , use_grid = False
166
+ model , model .y0 , inputs_dict , inputs , t_eval , use_grid = False ,
162
167
)
163
168
if self .sensitivity == "casadi" and inputs_dict != {}:
164
169
# If the solution has already been created, we can reuse it
165
170
if model in self .y_sols :
166
171
y_sol = self .y_sols [model ]
167
172
solution = pybamm .Solution (
168
- t_eval , y_sol , model = model , inputs = inputs_dict
173
+ t_eval , y_sol , model = model , inputs = inputs_dict ,
174
+ sensitivities = explicit_sensitivities
169
175
)
170
176
else :
171
177
# Create integrator without grid, which will be called repeatedly
@@ -212,7 +218,10 @@ def _integrate(self, model, t_eval, inputs_dict=None):
212
218
# to avoid having to create several times
213
219
self .create_integrator (model , inputs_dict )
214
220
# Initialize solution
215
- solution = pybamm .Solution (np .array ([t ]), y0 , model , inputs_dict )
221
+ solution = pybamm .Solution (
222
+ np .array ([t ]), y0 , model , inputs_dict ,
223
+ sensitivities = explicit_sensitivities
224
+ )
216
225
solution .solve_time = 0
217
226
solution .integration_time = 0
218
227
use_grid = False
@@ -455,6 +464,7 @@ def integer_bisect():
455
464
np .array ([t_event ]),
456
465
y_event [:, np .newaxis ],
457
466
"event" ,
467
+ sensitivities = explicit_sensitivities
458
468
)
459
469
solution .integration_time = (
460
470
coarse_solution .integration_time + dense_step_sol .integration_time
@@ -613,6 +623,10 @@ def create_integrator(self, model, inputs, t_eval=None, use_event_switch=False):
613
623
614
624
def _run_integrator (self , model , y0 , inputs_dict , inputs , t_eval , use_grid = True ):
615
625
pybamm .logger .debug ("Running CasADi integrator" )
626
+
627
+ # are we solving explicit forward equations?
628
+ explicit_sensitivities = self .sensitivity == 'explicit forward'
629
+
616
630
if use_grid is True :
617
631
t_eval_shifted = t_eval - t_eval [0 ]
618
632
t_eval_shifted_rounded = np .round (t_eval_shifted , decimals = 12 ).tobytes ()
@@ -649,7 +663,10 @@ def _run_integrator(self, model, y0, inputs_dict, inputs, t_eval, use_grid=True)
649
663
)
650
664
integration_time = timer .time ()
651
665
y_sol = casadi .vertcat (casadi_sol ["xf" ], casadi_sol ["zf" ])
652
- sol = pybamm .Solution (t_eval , y_sol , model , inputs_dict )
666
+ sol = pybamm .Solution (
667
+ t_eval , y_sol , model , inputs_dict ,
668
+ sensitivities = explicit_sensitivities
669
+ )
653
670
sol .integration_time = integration_time
654
671
return sol
655
672
else :
@@ -682,7 +699,10 @@ def _run_integrator(self, model, y0, inputs_dict, inputs, t_eval, use_grid=True)
682
699
# Save the solution, can just reuse and change the inputs
683
700
self .y_sols [model ] = y_sol
684
701
685
- sol = pybamm .Solution (t_eval , y_sol , model , inputs_dict )
702
+ sol = pybamm .Solution (
703
+ t_eval , y_sol , model , inputs_dict ,
704
+ sensitivities = explicit_sensitivities
705
+ )
686
706
sol .integration_time = integration_time
687
707
return sol
688
708
except RuntimeError as e :
0 commit comments