Skip to content

Commit 87fbe8e

Browse files
authored
Merge pull request #98 from computationalmodelling/cvode_bug
Cvode bug
2 parents a0df365 + b16094d commit 87fbe8e

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

fidimag/common/sundials/cvode.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cdef extern from "sundials/sundials_nvector.h":
99

1010
ctypedef _generic_N_Vector *N_Vector
1111
N_Vector N_VNew_Serial(long int vec_length)
12-
N_Vector N_VNew_OpenMP(long int vec_length)
12+
N_Vector N_VNew_OpenMP(long int vec_length, int num_threads)
1313
void N_VDestroy_Serial(N_Vector v)
1414
void N_VDestroy_OpenMP(N_Vector v)
1515
void N_VPrint_Serial(N_Vector v)

fidimag/common/sundials/cvode.pyx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ cimport numpy as np # import special compile-time information about numpy
44
cimport openmp
55
np.import_array() # don't remove or you'll segfault
66
from libc.string cimport memcpy
7+
import sys
78

89
cdef extern from "../../atomistic/lib/clib.h":
910
void normalise(double * m, int nxyz)
@@ -179,6 +180,9 @@ cdef class CvodeSolver(object):
179180
self.check_flag(flag, "CVodeSetUserData")
180181

181182
self.cvode_already_initialised = 0
183+
184+
self.u_y = N_VMake_Serial(self.y.size, <realtype *> self.y.data)
185+
182186
self.set_initial_value(spins, self.t)
183187
self.set_options(rtol, atol)
184188

@@ -191,7 +195,7 @@ cdef class CvodeSolver(object):
191195
self.y[:] = spin[:]
192196

193197
cdef np.ndarray[double, ndim = 1, mode = "c"] y = self.y
194-
self.u_y = N_VMake_Serial(y.size, & y[0])
198+
copy_arr2nv(self.y, self.u_y)
195199

196200
if self.cvode_already_initialised:
197201
flag = CVodeReInit(self.cvode_mem, t, self.u_y)
@@ -363,6 +367,9 @@ cdef class CvodeSolver_OpenMP(object):
363367
self.check_flag(flag, "CVodeSetUserData")
364368

365369
self.cvode_already_initialised = 0
370+
371+
self.u_y = N_VMake_OpenMP(self.y.size, <realtype *> self.y.data, self.num_threads)
372+
366373
self.set_initial_value(spins, self.t)
367374
self.set_options(rtol, atol)
368375

@@ -375,7 +382,7 @@ cdef class CvodeSolver_OpenMP(object):
375382
self.y[:] = spin[:]
376383

377384
cdef np.ndarray[double, ndim = 1, mode = "c"] y = self.y
378-
self.u_y = N_VMake_OpenMP(y.size, &y[0], self.num_threads)
385+
copy_arr2nv_openmp(self.y, self.u_y)
379386

380387
if self.cvode_already_initialised:
381388
flag = CVodeReInit(self.cvode_mem, t, self.u_y)

fidimag/common/vtk.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def __init__(self, mesh, header="", directory=".", filename="unnamed"):
2121
# for keyword argument dimensions: if the mesh is made up of
2222
# nx * ny * nz cells, it has (nx + 1) * (ny + 1) * (nz + 1)
2323
# vertices.
24-
print(mesh.grid)
2524
structure = pyvtk.RectilinearGrid(* mesh.grid)
2625
else:
2726
raise NotImplementedError(

0 commit comments

Comments
 (0)