Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with atol in KLU #710

Closed
valentinsulzer opened this issue Nov 6, 2019 · 1 comment · Fixed by #721
Closed

Bug with atol in KLU #710

valentinsulzer opened this issue Nov 6, 2019 · 1 comment · Fixed by #721
Assignees
Labels
bug Something isn't working

Comments

@valentinsulzer
Copy link
Member

Describe the bug
Cannot do convergence study with IDAKLUSolver due to error with atol

To Reproduce
Run the following code:

import pybamm
import numpy as np


model = pybamm.lithium_ion.SPM()
solver = pybamm.IDAKLUSolver()

# load parameter values and geometry
geometry = model.default_geometry
param = model.default_parameter_values

# Process parameters
param.process_model(model)
param.process_geometry(geometry)

# Calculate time for each solver and each number of grid points
var = pybamm.standard_spatial_vars
t_eval = np.linspace(0, 0.17, 100)
for npts in [100, 200]:
    # discretise
    var_pts = {
        spatial_var: npts
        for spatial_var in [var.x_n, var.x_s, var.x_p, var.r_n, var.r_p]
    }
    mesh = pybamm.Mesh(geometry, model.default_submesh_types, var_pts)
    disc = pybamm.Discretisation(mesh, model.default_spatial_methods)
    model_disc = disc.process_model(model, inplace=False)

    # solve
    solution = solver.solve(model_disc, t_eval)

Expected behaviour
No output

Actual behaviour
It goes through the first solve fine, but fails on the second solve

Traceback (most recent call last):
  File "/mnt/c/Users/vsulzer/Documents/Energy_Storage/PyBaMM/bug.py", line 30, in <module>
    solution = solver.solve(model_disc, t_eval)
  File "/mnt/c/Users/vsulzer/Documents/Energy_Storage/PyBaMM/pybamm/solvers/base_solver.py", line 84, in solve
    solution, solve_time, termination = self.compute_solution(model, t_eval)
  File "/mnt/c/Users/vsulzer/Documents/Energy_Storage/PyBaMM/pybamm/solvers/dae_solver.py", line 90, in compute_solution
    jacobian=self.jacobian,
  File "/mnt/c/Users/vsulzer/Documents/Energy_Storage/PyBaMM/pybamm/solvers/idaklu_solver.py", line 158, in integrate
    self._check_atol_type(y0.size)
  File "/mnt/c/Users/vsulzer/Documents/Energy_Storage/PyBaMM/pybamm/solvers/idaklu_solver.py", line 124, in _check_atol_type
    of the same shape at y0"""
pybamm.expression_tree.exceptions.SolverError: Absolute tolerances must be either a scalar or a numpy arrray
                of the same shape at y0
@valentinsulzer valentinsulzer added the bug Something isn't working label Nov 6, 2019
@valentinsulzer
Copy link
Member Author

Note this is fixed by making _check_atol_type return atol directly (instead of setting self._atol and then reading atol=self._atol, but you might want to do it differently?

@Scottmar93 Scottmar93 mentioned this issue Nov 11, 2019
8 tasks
Scottmar93 added a commit that referenced this issue Nov 12, 2019
Scottmar93 added a commit that referenced this issue Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants