Skip to content

Commit

Permalink
#1477 make fix better
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Aug 2, 2021
1 parent 5726251 commit f9daa06
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pybamm/solvers/base_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,9 @@ def jacp(*args, **kwargs):

# if we have changed the equations to include the explicit sensitivity
# equations, then we also need to update the mass matrix
n_state_without_sens = model.len_rhs_and_alg
if calculate_sensitivities_explicit:
n_inputs = model.len_rhs_sens // model.len_rhs
if model.mass_matrix.shape[0] == n_state_without_sens:
if model.mass_matrix.shape[0] == model.len_rhs_and_alg:
model.mass_matrix_inv = pybamm.Matrix(
block_diag(
[model.mass_matrix_inv.entries] * (n_inputs + 1),
Expand All @@ -625,14 +624,14 @@ def jacp(*args, **kwargs):
)
else:
# take care if calculate_sensitivites used then not used
if model.mass_matrix.shape[0] > n_state_without_sens:
if model.mass_matrix.shape[0] > model.len_rhs_and_alg:
model.mass_matrix_inv = pybamm.Matrix(
model.mass_matrix_inv.entries[:n_state_without_sens,
:n_state_without_sens]
model.mass_matrix_inv.entries[:model.len_rhs_and_alg,
:model.len_rhs_and_alg]
)
model.mass_matrix = pybamm.Matrix(
model.mass_matrix.entries[:n_state_without_sens,
:n_state_without_sens]
model.mass_matrix.entries[:model.len_rhs_and_alg,
:model.len_rhs_and_alg]
)

# Save CasADi functions for the CasADi solver
Expand Down

0 comments on commit f9daa06

Please sign in to comment.