Skip to content

Commit

Permalink
#633 fixed nnz issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Scottmar93 committed Oct 8, 2019
1 parent 9c3039a commit 6f4c94e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
7 changes: 5 additions & 2 deletions pybamm/solvers/klu_sparse_solver.py
Expand Up @@ -70,7 +70,8 @@ def eqsres(t, y, ydot, return_residuals):
if sparse.issparse(jac_y0_t0):

def jacfn(t, y, cj):
return jacobian(t, y) - cj * mass_matrix
j = jacobian(t, y) - cj * mass_matrix
return j

else:

Expand All @@ -83,7 +84,8 @@ class SundialsJacobian:
def __init__(self):
self.J = None

J = jacfn(0, y0, 0.1)
random = np.random.random(size=y0.size)
J = jacfn(10, random, 20)
self.nnz = J.nnz # hoping nnz remains constant...

def jac_res(self, t, y, cj):
Expand All @@ -93,6 +95,7 @@ def jac_res(self, t, y, cj):
self.J = jacfn(t, y, cj)

def get_jac_data(self):
# print("nnz: ", self.J.nnz)
return self.J.data

def get_jac_row_vals(self):
Expand Down
14 changes: 7 additions & 7 deletions results/2plus1D/dfn_2plus1D.py
Expand Up @@ -31,13 +31,13 @@
# set mesh
var = pybamm.standard_spatial_vars
var_pts = {
var.x_n: 5,
var.x_s: 5,
var.x_p: 5,
var.r_n: 5,
var.r_p: 5,
var.y: 5,
var.z: 5,
var.x_n: 15,
var.x_s: 15,
var.x_p: 15,
var.r_n: 15,
var.r_p: 15,
var.y: 15,
var.z: 15,
}
# depnding on number of points in y-z plane may need to increase recursion depth...
sys.setrecursionlimit(10000)
Expand Down
2 changes: 1 addition & 1 deletion results/2plus1D/spm_2plus1D.py
Expand Up @@ -51,7 +51,7 @@
tau = param.process_symbol(pybamm.standard_parameters_lithium_ion.tau_discharge)
t_end = 3600 / tau.evaluate(0)
t_eval = np.linspace(0, t_end, 120)
solution = model.default_solver.solve(model, t_eval)
solution = pybamm.KLU(1e-8).solve(model, t_eval)

# TO DO: 2+1D automated plotting
phi_s_cn = pybamm.ProcessedVariable(
Expand Down
2 changes: 1 addition & 1 deletion results/2plus1D/spme_2plus1D.py
Expand Up @@ -51,7 +51,7 @@
tau = param.process_symbol(pybamm.standard_parameters_lithium_ion.tau_discharge)
t_end = 3600 / tau.evaluate(0)
t_eval = np.linspace(0, t_end, 120)
solution = pybamm.KLU().solve(model, t_eval)
solution = pybamm.KLU(1e-8).solve(model, t_eval)

# TO DO: 2+1D automated plotting
phi_s_cn = pybamm.ProcessedVariable(
Expand Down

0 comments on commit 6f4c94e

Please sign in to comment.