4
4
import fidimag .common .helper as helper
5
5
import inspect
6
6
7
+
7
8
class Zeeman (object ):
8
9
9
10
"""
@@ -153,10 +154,10 @@ def setup(self, mesh, spin, Ms):
153
154
self .field = np .zeros (3 * self .n )
154
155
155
156
def compute_field (self , t = 0 , spin = None ):
156
- self .field [:] = helper .init_vector (self .time_fun ,
157
- self .mesh ,
158
- False ,
159
- t )
157
+ self .field [:] = helper .init_vector_func_fast (self .time_fun ,
158
+ self .mesh ,
159
+ False ,
160
+ t )
160
161
return self .field
161
162
162
163
@@ -182,6 +183,7 @@ def __init__(self, time_fun, name='TimeZeeman'):
182
183
self .time_fun = time_fun
183
184
self .name = name
184
185
self .jac = True
186
+ self ._v = np .zeros (3 )
185
187
186
188
def setup (self , mesh , spin , Ms ):
187
189
self .mesh = mesh
@@ -206,4 +208,58 @@ def compute_field(self, t=0, spin=None):
206
208
self .field [0 ::3 ] = v [0 ]
207
209
self .field [1 ::3 ] = v [1 ]
208
210
self .field [2 ::3 ] = v [2 ]
209
- return self .field
211
+ #self.field[::3] = v
212
+ return self .field
213
+
214
+
215
+ class TimeZeemanFast (Zeeman ):
216
+
217
+ """
218
+ The time dependent external field, also can vary with space
219
+
220
+ The function time_fun must be a function which takes two arguments:
221
+
222
+ def time_fun(mesh, t):
223
+ x, y, z = pos
224
+ # compute Bx, By, Bz as a function of x y, z and t.
225
+ Bx = ...
226
+ By = ...
227
+ Bz = ...
228
+ return (Bx, By, Bz)
229
+
230
+ Add the function to the user modules and recompile.
231
+
232
+
233
+ """
234
+
235
+ def __init__ (self , time_fun , extra_args , name = 'TimeZeeman' ):
236
+ self .time_fun = time_fun
237
+ self .name = name
238
+ self .jac = True
239
+ self .extra_args = extra_args
240
+
241
+ def setup (self , mesh , spin , Ms ):
242
+ self .mesh = mesh
243
+ self .spin = spin
244
+ self .n = mesh .n
245
+
246
+ self .Ms = Ms
247
+ self .Ms_long = np .zeros (3 * mesh .n )
248
+
249
+ # TODO: Check if it is necessary to define a 3D matrix for
250
+ # the Ms vectors. Maybe there is a way that uses less memory
251
+ # (see the calculation in the *compute_energy* function)
252
+ self .Ms_long .shape = (3 , - 1 )
253
+ for i in range (mesh .n ):
254
+ self .Ms_long [:, i ] = Ms [i ]
255
+
256
+ self .Ms_long .shape = (- 1 ,)
257
+ self .field = np .zeros (3 * self .n )
258
+
259
+ def compute_field (self , t = 0 , spin = None ):
260
+ helper .init_vector_func_fast (self .time_fun ,
261
+ self .mesh ,
262
+ self .field ,
263
+ False ,
264
+ t , * self .extra_args )
265
+ return self .field
0 commit comments