Skip to content

Commit

Permalink
pybamm-team#1082 codacy and codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Jul 23, 2020
1 parent b14b7cf commit 9b438ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 2 additions & 5 deletions pybamm/solvers/casadi_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,8 @@ def event_fun(t):

# assign temporary solve time
current_step_sol.solve_time = np.nan
if solution is None:
solution = current_step_sol
else:
# append solution from the current step to solution
solution.append(current_step_sol)
# append solution from the current step to solution
solution.append(current_step_sol)
solution.termination = "event"
solution.t_event = t_event
solution.y_event = y_event
Expand Down
14 changes: 12 additions & 2 deletions tests/unit/test_solvers/test_casadi_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,16 @@ def test_model_solver_with_inputs(self):
self.assertLess(len(solution.t), len(t_eval))
np.testing.assert_allclose(solution.y[0], np.exp(-0.1 * solution.t), rtol=1e-04)

# Without grid
solver = pybamm.CasadiSolver(mode="safe without grid", rtol=1e-8, atol=1e-8)
t_eval = np.linspace(0, 10, 100)
solution = solver.solve(model, t_eval, inputs={"rate": 0.1})
self.assertLess(len(solution.t), len(t_eval))
np.testing.assert_allclose(solution.y[0], np.exp(-0.1 * solution.t), rtol=1e-04)
solution = solver.solve(model, t_eval, inputs={"rate": 1.1})
self.assertLess(len(solution.t), len(t_eval))
np.testing.assert_allclose(solution.y[0], np.exp(-1.1 * solution.t), rtol=1e-04)

def test_model_solver_dae_inputs_in_initial_conditions(self):
# Create model
model = pybamm.BaseModel()
Expand Down Expand Up @@ -547,10 +557,10 @@ def test_solve_with_symbolic_input_1D_vector_input(self):
)

sens = solution["var"].sensitivity({"param": p}).full()
for idx in range(len(t_eval)):
for idx, t in enumerate(t_eval):
np.testing.assert_array_almost_equal(
sens[40 * idx : 40 * (idx + 1), :],
-2 * t_eval[idx] * np.exp(-p * t_eval[idx]) * np.eye(40),
-2 * t * np.exp(-p * t) * np.eye(40),
decimal=4,
)

Expand Down

0 comments on commit 9b438ee

Please sign in to comment.