forked from pybamm-team/PyBaMM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds additional tests for Casadi modes (pybamm-team#4028)
* Add casadi solver mode tests * add experiment definition to test * tests: relocate to integration, update for pytest. --------- Co-authored-by: Martin Robinson <[email protected]>
- Loading branch information
1 parent
4d391fa
commit 7537784
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |