Skip to content

Commit

Permalink
Merge pull request #98 from computationalmodelling/cvode_bug
Browse files Browse the repository at this point in the history
Cvode bug
  • Loading branch information
rpep authored Aug 10, 2017
2 parents a0df365 + b16094d commit 87fbe8e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fidimag/common/sundials/cvode.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cdef extern from "sundials/sundials_nvector.h":

ctypedef _generic_N_Vector *N_Vector
N_Vector N_VNew_Serial(long int vec_length)
N_Vector N_VNew_OpenMP(long int vec_length)
N_Vector N_VNew_OpenMP(long int vec_length, int num_threads)
void N_VDestroy_Serial(N_Vector v)
void N_VDestroy_OpenMP(N_Vector v)
void N_VPrint_Serial(N_Vector v)
Expand Down
11 changes: 9 additions & 2 deletions fidimag/common/sundials/cvode.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ cimport numpy as np # import special compile-time information about numpy
cimport openmp
np.import_array() # don't remove or you'll segfault
from libc.string cimport memcpy
import sys

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

self.cvode_already_initialised = 0

self.u_y = N_VMake_Serial(self.y.size, <realtype *> self.y.data)

self.set_initial_value(spins, self.t)
self.set_options(rtol, atol)

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

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

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

self.cvode_already_initialised = 0

self.u_y = N_VMake_OpenMP(self.y.size, <realtype *> self.y.data, self.num_threads)

self.set_initial_value(spins, self.t)
self.set_options(rtol, atol)

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

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

if self.cvode_already_initialised:
flag = CVodeReInit(self.cvode_mem, t, self.u_y)
Expand Down
1 change: 0 additions & 1 deletion fidimag/common/vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def __init__(self, mesh, header="", directory=".", filename="unnamed"):
# for keyword argument dimensions: if the mesh is made up of
# nx * ny * nz cells, it has (nx + 1) * (ny + 1) * (nz + 1)
# vertices.
print(mesh.grid)
structure = pyvtk.RectilinearGrid(* mesh.grid)
else:
raise NotImplementedError(
Expand Down

0 comments on commit 87fbe8e

Please sign in to comment.