Skip to content

Commit 80e1870

Browse files
Bugfix: inputs for initial_conditions_from scale evaluation (pybamm-team#5285)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 86fec31 commit 80e1870

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/pybamm/models/base_model.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,12 @@ def _build_model(self):
906906
self.build_model_equations()
907907

908908
def set_initial_conditions_from(
909-
self, solution, inplace=True, return_type="model", mesh=None
909+
self,
910+
solution,
911+
inputs=None,
912+
inplace=True,
913+
return_type="model",
914+
mesh=None,
910915
):
911916
"""
912917
Update initial conditions with the final states from a Solution object or from
@@ -918,6 +923,8 @@ def set_initial_conditions_from(
918923
----------
919924
solution : :class:`pybamm.Solution`, or dict
920925
The solution to use to initialize the model
926+
inputs : dict
927+
The dictionary of model input parameters.
921928
inplace : bool, optional
922929
Whether to modify the model inplace or create a new model (default True)
923930
return_type : str, optional
@@ -1081,7 +1088,7 @@ def get_variable_state(var):
10811088
scale, reference = pybamm.Scalar(1), pybamm.Scalar(0)
10821089
initial_conditions[var] = (
10831090
pybamm.Vector(final_state_eval) - reference
1084-
) / scale.evaluate()
1091+
) / scale.evaluate(inputs=inputs)
10851092

10861093
# Also update the concatenated initial conditions if the model is already
10871094
# discretised

src/pybamm/models/full_battery_models/lithium_ion/electrode_soh.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,14 +561,14 @@ def _set_up_solve(self, inputs, direction):
561561
def _solve_full(self, inputs, ics, direction):
562562
sim = self._get_electrode_soh_sims_full(direction)
563563
sim.build()
564-
sim.built_model.set_initial_conditions_from(ics)
564+
sim.built_model.set_initial_conditions_from(ics, inputs=inputs)
565565
sol = sim.solve([0], inputs=inputs)
566566
return sol
567567

568568
def _solve_split(self, inputs, ics, direction):
569569
x100_sim, x0_sim = self._get_electrode_soh_sims_split(direction)
570570
x100_sim.build()
571-
x100_sim.built_model.set_initial_conditions_from(ics)
571+
x100_sim.built_model.set_initial_conditions_from(ics, inputs=inputs)
572572
x100_sol = x100_sim.solve([0], inputs=inputs)
573573
if self.options["open-circuit potential"] == "MSMR":
574574
inputs["Un(x_100)"] = x100_sol["Un(x_100)"].data[0]
@@ -577,7 +577,7 @@ def _solve_split(self, inputs, ics, direction):
577577
inputs["x_100"] = x100_sol["x_100"].data[0]
578578
inputs["y_100"] = x100_sol["y_100"].data[0]
579579
x0_sim.build()
580-
x0_sim.built_model.set_initial_conditions_from(ics)
580+
x0_sim.built_model.set_initial_conditions_from(ics, inputs=inputs)
581581
x0_sol = x0_sim.solve([0], inputs=inputs)
582582

583583
return x0_sol

src/pybamm/solvers/base_solver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,9 @@ def step(
13811381

13821382
else:
13831383
_, concatenated_initial_conditions = model.set_initial_conditions_from(
1384-
old_solution, return_type="ics"
1384+
old_solution,
1385+
inputs=model_inputs,
1386+
return_type="ics",
13851387
)
13861388
model.y0 = concatenated_initial_conditions.evaluate(0, inputs=model_inputs)
13871389
if using_sensitivities:

0 commit comments

Comments
 (0)