1
1
import numpy as np
2
2
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
5
5
6
6
7
- def time_fun_spatial (pos , t , frequency ):
8
- return (0.0 , 0.0 , 10 * np .cos (frequency * t ))
9
-
10
7
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 )
14
9
15
10
def fixture_setup (nx , ny , nz ):
16
11
"""
@@ -23,79 +18,15 @@ def fixture_setup(nx, ny, nz):
23
18
frequency = 10e9
24
19
return mesh , frequency , spin , Ms
25
20
26
-
27
21
def test_TimeZeeman ():
28
22
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 ])
30
24
zee .setup (mesh , spin , Ms )
31
25
field1 = zee .compute_field (t = 0 )
32
26
assert field1 [0 ] == 0
33
27
assert field1 [1 ] == 0
34
28
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
-
50
29
field2 = zee .compute_field (t = 1 )
51
30
assert field2 [0 ] == 0
52
31
assert field2 [1 ] == 0
53
32
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 ('\n N = {} * {} * {} = ' .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