Skip to content

Commit 1132cfb

Browse files
committed
revert back to old TimeZeeman but add arbitrary arguments parameters
1 parent 6b9309a commit 1132cfb

File tree

3 files changed

+8
-76
lines changed

3 files changed

+8
-76
lines changed

fidimag/micro/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .demag import Demag
33
from .exchange import UniformExchange
44
from .exchange_rkky import ExchangeRKKY
5-
from .zeeman import Zeeman, TimeZeeman, TimeZeemanSimple, TimeZeemanFast
5+
from .zeeman import Zeeman, TimeZeeman
66
from .anisotropy import UniaxialAnisotropy
77
from .dmi import DMI
88
from .baryakhtar import LLBar, LLBarFull

fidimag/micro/zeeman.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ def __init__(self, H0, time_fun, extra_args=[], name='TimeZeeman'):
122122
self.time_fun = time_fun
123123
self.name = name
124124
self.jac = True
125+
self.extra_args = extra_args
125126

126127
def setup(self, mesh, spin, Ms):
127128
super(TimeZeeman, self).setup(mesh, spin, Ms)
128129
self.H_init = self.field.copy()
129130

130131
def compute_field(self, t=0, spin=None):
131-
self.field[:] = self.H_init[:] * self.time_fun(t, *extra_args)
132-
return self.field
132+
self.field[:] = self.H_init[:] * self.time_fun(t, *self.extra_args)
133+
return self.field

tests/test_time_zeeman.py

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import numpy as np
22
from fidimag.common import CuboidMesh
3-
from fidimag.micro import TimeZeeman, TimeZeemanSimple, TimeZeemanFast
4-
from fidimag.user.example import TimeZeemanFast_test_time_fun
3+
from fidimag.micro import TimeZeeman
4+
from fidimag.user.example2 import TimeZeemanFast_test_time_fun
55

66

7-
def time_fun_spatial(pos, t, frequency):
8-
return (0.0, 0.0, 10*np.cos(frequency*t))
9-
107
def time_fun(t, frequency):
11-
return (0.0, 0.0, 10*np.cos(frequency*t))
12-
13-
8+
return 10*np.cos(frequency*t)
149

1510
def fixture_setup(nx, ny, nz):
1611
"""
@@ -23,79 +18,15 @@ def fixture_setup(nx, ny, nz):
2318
frequency = 10e9
2419
return mesh, frequency, spin, Ms
2520

26-
2721
def test_TimeZeeman():
2822
mesh, frequency, spin, Ms = fixture_setup(10, 10, 10)
29-
zee = TimeZeeman(time_fun_spatial, extra_args=[frequency])
23+
zee = TimeZeeman(np.array([0.0, 0.0, 1.0]), time_fun, extra_args=[frequency])
3024
zee.setup(mesh, spin, Ms)
3125
field1 = zee.compute_field(t=0)
3226
assert field1[0] == 0
3327
assert field1[1] == 0
3428
assert field1[2] == 10
35-
36-
field2 = zee.compute_field(t=1)
37-
assert field2[0] == 0
38-
assert field2[1] == 0
39-
assert field2[2] == 10*np.cos(frequency)
40-
41-
def test_TimeZeemanSimple():
42-
mesh, frequency, spin, Ms = fixture_setup(10, 10, 10)
43-
zee = TimeZeemanSimple(time_fun, extra_args=[frequency])
44-
zee.setup(mesh, spin, Ms)
45-
field1 = zee.compute_field(t=0)
46-
assert field1[0] == 0
47-
assert field1[1] == 0
48-
assert field1[2] == 10
49-
5029
field2 = zee.compute_field(t=1)
5130
assert field2[0] == 0
5231
assert field2[1] == 0
5332
assert field2[2] == 10*np.cos(frequency)
54-
55-
def test_TimeZeemanFast():
56-
mesh, frequency, spin, Ms = fixture_setup(10, 10, 10)
57-
zee = TimeZeemanFast(TimeZeemanFast_test_time_fun, extra_args=[frequency])
58-
zee.setup(mesh, spin, Ms)
59-
field1 = zee.compute_field(t=0)
60-
assert field1[0] == 0
61-
assert field1[1] == 0
62-
assert field1[2] == 10
63-
64-
field2 = zee.compute_field(t=1)
65-
assert field2[0] == 0
66-
assert field2[1] == 0
67-
assert field2[2] == 10*np.cos(frequency)
68-
69-
if __name__ == "__main__":
70-
import time
71-
# Run the speed tests...
72-
for i in range(1, 5):
73-
nx = 10**i
74-
ny = nz = 10
75-
print('\nN = {} * {} * {} = '.format(nx, ny, nz, nx*ny*nz))
76-
mesh, frequency, spin, Ms = setup(nx, ny, nz)
77-
78-
zee = TimeZeeman(time_fun_spatial, extra_args=[frequency])
79-
zee.setup(mesh, spin, Ms)
80-
t1 = time.time()
81-
field1 = zee.compute_field(t=0)
82-
field2 = zee.compute_field(t=1)
83-
t2 = time.time()
84-
print(' Timing results for TimeZeeman = {}'.format(t2 - t1))
85-
86-
zee = TimeZeemanSimple(time_fun, extra_args=[frequency])
87-
zee.setup(mesh, spin, Ms)
88-
t3 = time.time()
89-
field1 = zee.compute_field(t=0)
90-
field2 = zee.compute_field(t=1)
91-
t4 = time.time()
92-
print(' Timing results for TimeZeemanSimple = {}'.format(t4 - t3))
93-
94-
zee = TimeZeemanFast(TimeZeemanFast_test_time_fun, extra_args=[frequency])
95-
zee.setup(mesh, spin, Ms)
96-
t5 = time.time()
97-
field1 = zee.compute_field(t=0)
98-
field2 = zee.compute_field(t=1)
99-
t6 = time.time()
100-
print(' Timing results for TimeZeemanFast = {}'.format(t6 - t5))
101-
print('\n Normalised: TimeZeeman = 1, TimeZeemanSimple = {}, TimeZeemanFast = {}'.format((t4-t3)/(t2-t1), (t6-t5)/(t2-t1)))

0 commit comments

Comments
 (0)