@@ -4,21 +4,6 @@ import ctypes
4
4
cimport numpy as np
5
5
np.import_array()
6
6
7
-
8
-
9
-
10
-
11
- cdef pointer_to_numpy_array_float64(void * ptr, np.npy_intp size):
12
- ''' Convert c pointer to numpy array.
13
- The memory will be freed as soon as the ndarray is deallocated.
14
- '''
15
- cdef extern from " numpy/arrayobject.h" :
16
- void PyArray_ENABLEFLAGS(np.ndarray arr, int flags)
17
- cdef np.ndarray[np.float64_t, ndim= 1 ] arr = \
18
- np.PyArray_SimpleNewFromData(1 , & size, np.NPY_FLOAT64, ptr)
19
- PyArray_ENABLEFLAGS(arr, np.NPY_OWNDATA)
20
- return arr
21
-
22
7
cdef extern from " dipolar.h" :
23
8
24
9
# used for demag
@@ -33,6 +18,18 @@ cdef extern from "dipolar.h":
33
18
double * tensor_yy
34
19
double * tensor_yz
35
20
double * tensor_zz
21
+ complex * Nxx
22
+ complex * Nxy
23
+ complex * Nxz
24
+ complex * Nyy
25
+ complex * Nyz
26
+ complex * Nzz
27
+ complex * Hx
28
+ complex * Hy
29
+ complex * Hz
30
+ complex * Mx
31
+ complex * My
32
+ complex * Mz
36
33
37
34
fft_demag_plan * create_plan()
38
35
void finalize_plan(fft_demag_plan * plan)
@@ -51,8 +48,11 @@ cdef class FFTDemag(object):
51
48
cdef int total_length
52
49
cdef np.float64_t[:] tensor_xx_p, tensor_xy_p, tensor_xz_p, tensor_yy_p, \
53
50
tensor_yz_p, tensor_zz_p
51
+ cdef np.complex128_t[:] Nxx_p, Nxy_p, Nxz_p, Nyy_p, Nyz_p, Nzz_p, Hx_p, \
52
+ Hy_p, Hz_p, Mx_p, My_p, Mz_p
54
53
cdef public np.ndarray tensor_xx, tensor_xy, tensor_xz, tensor_yy, \
55
- tensor_yz, tensor_zz
54
+ tensor_yz, tensor_zz, Nxx, Nxy, Nxz, Nyy, Nyz, Nzz, \
55
+ Mx, My, Mz, Hx, Hy, Hz
56
56
# tensor_type could be 'dipolar', 'demag' or '2d_pbc'
57
57
def __cinit__ (self , dx , dy , dz , nx , ny , nz , tensor_type = ' dipolar' ):
58
58
self ._c_plan = create_plan()
@@ -75,6 +75,35 @@ cdef class FFTDemag(object):
75
75
self .total_length = int (self ._c_plan.total_length)
76
76
self .tensor_xx_p = < np.float64_t[:self .total_length]> self ._c_plan.tensor_xx
77
77
self .tensor_xx = np.asarray(self .tensor_xx_p)
78
+
79
+ self .Nxx_p = < np.complex128_t[:self .total_length]> self ._c_plan.Nxx
80
+ self .Nxx = np.asarray(self .Nxx_p)
81
+ self .Nxy_p = < np.complex128_t[:self .total_length]> self ._c_plan.Nxy
82
+ self .Nxy = np.asarray(self .Nxy_p)
83
+ self .Nxz_p = < np.complex128_t[:self .total_length]> self ._c_plan.Nxz
84
+ self .Nxz = np.asarray(self .Nxz_p)
85
+ self .Nyy_p = < np.complex128_t[:self .total_length]> self ._c_plan.Nyy
86
+ self .Nyy = np.asarray(self .Nyy_p)
87
+ self .Nyz_p = < np.complex128_t[:self .total_length]> self ._c_plan.Nyz
88
+ self .Nyz = np.asarray(self .Nyz_p)
89
+ self .Nzz_p = < np.complex128_t[:self .total_length]> self ._c_plan.Nzz
90
+ self .Nzz = np.asarray(self .Nzz_p)
91
+
92
+ self .Mx_p = < np.complex128_t[:self .total_length]> self ._c_plan.Mx
93
+ self .Mx = np.asarray(self .Mx_p)
94
+ self .My_p = < np.complex128_t[:self .total_length]> self ._c_plan.My
95
+ self .My = np.asarray(self .My_p)
96
+ self .Mz_p = < np.complex128_t[:self .total_length]> self ._c_plan.Mz
97
+ self .Mz = np.asarray(self .Mz_p)
98
+
99
+ self .Hx_p = < np.complex128_t[:self .total_length]> self ._c_plan.Hx
100
+ self .Hx = np.asarray(self .Hx_p)
101
+ self .Hy_p = < np.complex128_t[:self .total_length]> self ._c_plan.Hy
102
+ self .Hy = np.asarray(self .Hy_p)
103
+ self .Hz_p = < np.complex128_t[:self .total_length]> self ._c_plan.Hz
104
+ self .Hz = np.asarray(self .Hz_p)
105
+
106
+
78
107
self .tensor_xy_p = < np.float64_t[:self .total_length]> self ._c_plan.tensor_xy
79
108
self .tensor_xy = np.asarray(self .tensor_xy_p)
80
109
self .tensor_xz_p = < np.float64_t[:self .total_length]> self ._c_plan.tensor_xz
@@ -86,6 +115,7 @@ cdef class FFTDemag(object):
86
115
self .tensor_zz_p = < np.float64_t[:self .total_length]> self ._c_plan.tensor_zz
87
116
self .tensor_zz = np.asarray(self .tensor_zz_p)
88
117
118
+
89
119
def print_tensor (self ):
90
120
for k in range (self ._c_plan.lenz):
91
121
for j in range (self ._c_plan.leny):
0 commit comments