Skip to content

Commit dc69d8e

Browse files
#1100 merge develop
2 parents 94314fb + e2e837b commit dc69d8e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

pybamm/solvers/casadi_solver.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,8 @@ def event_fun(t):
299299

300300
# assign temporary solve time
301301
current_step_sol.solve_time = np.nan
302-
if solution is None:
303-
solution = current_step_sol
304-
else:
305-
# append solution from the current step to solution
306-
solution.append(current_step_sol)
302+
# append solution from the current step to solution
303+
solution.append(current_step_sol)
307304
solution.termination = "event"
308305
solution.t_event = t_event
309306
solution.y_event = y_event

tests/unit/test_solvers/test_casadi_solver.py

+10
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ def test_model_solver_with_inputs(self):
306306
self.assertLess(len(solution.t), len(t_eval))
307307
np.testing.assert_allclose(solution.y[0], np.exp(-0.1 * solution.t), rtol=1e-04)
308308

309+
# Without grid
310+
solver = pybamm.CasadiSolver(mode="safe without grid", rtol=1e-8, atol=1e-8)
311+
t_eval = np.linspace(0, 10, 100)
312+
solution = solver.solve(model, t_eval, inputs={"rate": 0.1})
313+
self.assertLess(len(solution.t), len(t_eval))
314+
np.testing.assert_allclose(solution.y[0], np.exp(-0.1 * solution.t), rtol=1e-04)
315+
solution = solver.solve(model, t_eval, inputs={"rate": 1.1})
316+
self.assertLess(len(solution.t), len(t_eval))
317+
np.testing.assert_allclose(solution.y[0], np.exp(-1.1 * solution.t), rtol=1e-04)
318+
309319
def test_model_solver_dae_inputs_in_initial_conditions(self):
310320
# Create model
311321
model = pybamm.BaseModel()

0 commit comments

Comments
 (0)