Skip to content

Commit

Permalink
Adds additional tests for Casadi modes (#4028)
Browse files Browse the repository at this point in the history
* Add casadi solver mode tests

* add experiment definition to test

* tests: relocate to integration, update for pytest.

---------

Co-authored-by: Martin Robinson <martinjrobins@gmail.com>
  • Loading branch information
BradyPlanden and martinjrobins committed Aug 26, 2024
1 parent 4d391fa commit 7537784
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/integration/test_solvers/test_casadi_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# Tests for the Casadi Solver Modes
#

import pybamm
import numpy as np


class TestCasadiModes:
def test_casadi_solver_mode(self):
solvers = [
pybamm.CasadiSolver(mode="safe", atol=1e-6, rtol=1e-6),
pybamm.CasadiSolver(mode="fast", atol=1e-6, rtol=1e-6),
pybamm.CasadiSolver(mode="fast with events", atol=1e-6, rtol=1e-6),
]

# define experiment
experiment = pybamm.Experiment(
[
("Discharge at 1C until 3.0 V (10 seconds period)",),
]
)

solutions = []
for solver in solvers:
# define model
model = pybamm.lithium_ion.SPM()

# solve simulation
sim = pybamm.Simulation(
model,
experiment=experiment,
solver=solver,
)

# append to solutions
solutions.append(sim.solve())

# define variables to compare
output_vars = [
"Terminal voltage [V]",
"Positive particle surface concentration [mol.m-3]",
"Electrolyte concentration [mol.m-3]",
]

# assert solutions
for var in output_vars:
np.testing.assert_allclose(
solutions[0][var].data, solutions[1][var].data, rtol=1e-6, atol=1e-6
)
np.testing.assert_allclose(
solutions[0][var].data, solutions[2][var].data, rtol=1e-6, atol=1e-6
)
np.testing.assert_allclose(
solutions[1][var].data, solutions[2][var].data, rtol=1e-6, atol=1e-6
)

0 comments on commit 7537784

Please sign in to comment.