Skip to content

Commit

Permalink
#2304 add test for cccv simulation with idaklu and casadi solvers
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Nov 21, 2022
1 parent f3f26c1 commit be19129
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(
self.submesh_types = submesh_types or self.model.default_submesh_types
self.var_pts = var_pts or self.model.default_var_pts
self.spatial_methods = spatial_methods or self.model.default_spatial_methods
self.solver = solver or self.model.default_solver
self._solver = solver or self.model.default_solver
self.output_variables = output_variables

# Initialize empty built states
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/test_experiments/test_simulation_with_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,38 @@ def test_run_experiment_cccv_ode(self):
)
self.assertEqual(solutions[1].termination, "final time")

@unittest.skipIf(not pybamm.have_idaklu(), "idaklu solver is not installed")
def test_run_experiment_cccv_solvers(self):
experiment_2step = pybamm.Experiment(
[
(
"Discharge at C/20 for 1 hour",
"Charge at 1 A until 4.1 V",
"Hold at 4.1 V until C/2",
"Discharge at 2 W for 1 hour",
),
],
)

solutions = []
for solver in [pybamm.CasadiSolver(), pybamm.IDAKLUSolver()]:
model = pybamm.lithium_ion.SPM()
sim = pybamm.Simulation(model, experiment=experiment_2step, solver=solver)
solution = sim.solve()
solutions.append(solution)

np.testing.assert_array_almost_equal(
solutions[0]["Terminal voltage [V]"].data,
solutions[1]["Terminal voltage [V]"].data,
decimal=1,
)
np.testing.assert_array_almost_equal(
solutions[0]["Current [A]"].data,
solutions[1]["Current [A]"].data,
decimal=0,
)
self.assertEqual(solutions[1].termination, "final time")

def test_run_experiment_drive_cycle(self):
drive_cycle = np.array([np.arange(10), np.arange(10)]).T
experiment = pybamm.Experiment(
Expand Down

0 comments on commit be19129

Please sign in to comment.