@@ -4,8 +4,8 @@ np.import_array()
44
55
66cdef extern from " clib.h" :
7-
8- void gauss_random_vec_with_init (double * x, int n)
7+ void initial_random( int seed)
8+ void gauss_random_vec (double * x, int n)
99
1010 double skyrmion_number(double * spin, double * charge,
1111 int nx, int ny, int nz, int * ngbs)
@@ -70,32 +70,7 @@ cdef extern from "clib.h":
7070 double * alpha, int * pins, double * a_J, double beta, double gamma, int n)
7171
7272 # used for sllg
73- ctypedef struct ode_solver:
74- pass
75-
76- ode_solver * create_ode_plan()
77-
78- void init_solver(ode_solver * s, double k_B, double theta,
79- int n, double dt, double gamma)
80-
81- void finalize_ode_plan(ode_solver * plan)
82-
83- void run_step1(ode_solver * s, double * m, double * h,
84- double * m_pred, double * T, double * alpha,
85- double * mu_s_inv, int * pins)
86-
87- void run_step2(ode_solver * s, double * m_pred,
88- double * h, double * m, double * T,
89- double * alpha, double * mu_s_inv, int * pins)
90-
91- def random_number (np.ndarray[double , ndim = 1 , mode = " c" ] v):
92- cdef int n = len (v)
93-
94-
95- print n
96-
97- gauss_random_vec_with_init(& v[0 ], n)
98-
73+ void llg_rhs_dw_c(double * m, double * h, double * dm, double * T, double * alpha, double * mu_s_inv, int * pins, double * eta, int n, double gamma, double dt)
9974
10075
10176def compute_skyrmion_number (np.ndarray[double , ndim = 1 , mode = " c" ] spin,
@@ -273,87 +248,22 @@ def normalise_spin(np.ndarray[double, ndim=1, mode="c"] spin, n):
273248 normalise(& spin[0 ], n)
274249
275250
251+ def init_random (seed ):
252+ initial_random(seed);
276253
277- cdef class RK2S(object ):
278- cdef ode_solver * _c_plan
279- cdef double dt
280- cdef update_fun
281- cdef np.ndarray pred_m
282- cdef np.ndarray field
283- cdef np.ndarray mu_s_inv
284- cdef np.ndarray T
285- cdef np.ndarray alpha
286- cdef np.ndarray pins
254+ def random_number_array (np.ndarray[double , ndim = 1 , mode = " c" ] v):
255+
256+ cdef int n = len (v)
287257
288- cdef public double t
289- cdef public int step
290- cdef public np.ndarray y
258+ gauss_random_vec(& v[0 ], n)
291259
292- def __cinit__ (self ,dt ,n ,gamma ,k_B ,theta ,
293- np.ndarray[double , ndim = 1 , mode = " c" ] mu_s_inv,
294- np.ndarray[double , ndim = 1 , mode = " c" ] alpha,
295- np.ndarray[double , ndim = 1 , mode = " c" ] spin,
296- np.ndarray[double , ndim = 1 , mode = " c" ] field,
297- np.ndarray[double , ndim = 1 , mode = " c" ] T,
298- np.ndarray[int , ndim = 1 , mode = " c" ] pins,
299- update_fun ):
300-
301- self .t = 0
302- self .step = 0
303- self .dt = dt
304-
305- self .update_fun = update_fun
306- self .mu_s_inv = mu_s_inv
307- self .field = field
308- self .T = T
309- self .alpha = alpha
310- self .pins = pins
311- self .pred_m = numpy.zeros(3 * n,dtype = numpy.float)
312- self .y = numpy.zeros(3 * n,dtype = numpy.float)
313-
314-
315- self ._c_plan = create_ode_plan()
316- if self ._c_plan is NULL :
317- raise MemoryError ()
318-
319- init_solver(self ._c_plan,k_B,theta,n,dt,gamma)
320-
321- def __dealloc__ (self ):
322- if self ._c_plan is not NULL :
323- finalize_ode_plan(self ._c_plan)
324- self ._c_plan = NULL
325-
326- def set_initial_value (self ,np.ndarray[double , ndim = 1 , mode = " c" ] spin, t ):
327- self .t = t
328- self .y[:] = spin[:]
329-
330- def successful (self ):
331- # print self.spin
332- return True
333-
334- def run_step (self ):
335- cdef np.ndarray[double , ndim= 1 , mode= " c" ] y= self .y
336- cdef np.ndarray[double , ndim= 1 , mode= " c" ] field= self .field
337- cdef np.ndarray[double , ndim= 1 , mode= " c" ] pred_m= self .pred_m
338- cdef np.ndarray[double , ndim= 1 , mode= " c" ] T= self .T
339- cdef np.ndarray[double , ndim= 1 , mode= " c" ] alpha= self .alpha
340- cdef np.ndarray[double , ndim= 1 , mode= " c" ] mu_s_inv= self .mu_s_inv
341- cdef np.ndarray[int , ndim= 1 , mode= " c" ] pins = self .pins
342-
343- # print "from cython1", self.spin,self.field,self.pred_m
344- self .update_fun(self .y, self .t)
345- run_step1(self ._c_plan, & y[0 ], & field[0 ], & pred_m[0 ],
346- & T[0 ], & alpha[0 ], & mu_s_inv[0 ], & pins[0 ])
347-
348- self .step += 1
349- self .t = self .step * self .dt
350-
351- self .update_fun(self .pred_m, self .t)
352- run_step2(self ._c_plan, & pred_m[0 ], & field[0 ],
353- & y[0 ], & T[0 ], & alpha[0 ], & mu_s_inv[0 ], & pins[0 ])
354-
355-
356- def run_until (self , t ):
357- while (self .t< t):
358- self .run_step()
359- return 0
260+
261+ def compute_llg_rhs_dw (np.ndarray[double , ndim = 1 , mode = " c" ] dm,
262+ np.ndarray[double , ndim = 1 , mode = " c" ] spin,
263+ np.ndarray[double , ndim = 1 , mode = " c" ] field,
264+ np.ndarray[double , ndim = 1 , mode = " c" ] T,
265+ np.ndarray[double , ndim = 1 , mode = " c" ] alpha,
266+ np.ndarray[double , ndim = 1 , mode = " c" ] mu_s_inv,
267+ np.ndarray[double , ndim = 1 , mode = " c" ] eta,
268+ np.ndarray[int , ndim = 1 , mode = " c" ] pin, n , gamma , dt ):
269+ llg_rhs_dw_c(& spin[0 ], & field[0 ], & dm[0 ], & T[0 ], & alpha[0 ], & mu_s_inv[0 ], & pin[0 ], & eta[0 ], n, gamma, dt)
0 commit comments