4
4
# FIDIMAG:
5
5
from fidimag .micro import Sim
6
6
from fidimag .common import CuboidMesh
7
- from fidimag .micro import UniformExchange , UniaxialAnisotropy , Demag
7
+ from fidimag .micro import UniformExchange , UniaxialAnisotropy
8
8
from fidimag .common .neb_cartesian import NEB_Sundials
9
+ from fidimag .common .neb_spherical import NEB_Sundials as NEB_Sundials_spherical
9
10
import numpy as np
10
11
11
12
# Material Parameters
25
26
26
27
def two_part (pos ):
27
28
28
- x , y = pos [0 ], pos [ 1 ]
29
+ x = pos [0 ]
29
30
30
31
if x > 6 or x < 3 :
31
32
return Ms
@@ -34,15 +35,16 @@ def two_part(pos):
34
35
35
36
# Finite differences mesh
36
37
mesh = CuboidMesh (nx = 3 ,
37
- ny = 1 ,
38
- nz = 1 ,
39
- dx = 3 , dy = 3 , dz = 3 ,
40
- unit_length = 1e-9
41
- )
38
+ ny = 1 ,
39
+ nz = 1 ,
40
+ dx = 3 , dy = 3 , dz = 3 ,
41
+ unit_length = 1e-9
42
+ )
42
43
43
44
44
45
# Simulation Function
45
- def relax_neb (k , maxst , simname , init_im , interp , save_every = 10000 ):
46
+ def relax_neb (k , maxst , simname , init_im , interp , save_every = 10000 ,
47
+ coordinates = 'Cartesian' ):
46
48
"""
47
49
Execute a simulation with the NEB function of the FIDIMAG code, for an
48
50
elongated particle (long cylinder)
@@ -78,28 +80,36 @@ def relax_neb(k, maxst, simname, init_im, interp, save_every=10000):
78
80
# equal to 'the number of initial states specified', minus one.
79
81
interpolations = interp
80
82
81
- neb = NEB_Sundials (sim ,
82
- init_images ,
83
- interpolations = interpolations ,
84
- spring = k ,
85
- name = simname )
83
+ if coordinates == 'Cartesian' :
84
+ neb = NEB_Sundials (sim ,
85
+ init_images ,
86
+ interpolations = interpolations ,
87
+ spring = k ,
88
+ name = simname )
89
+ elif coordinates == 'Spherical' :
90
+ neb = NEB_Sundials_spherical (sim ,
91
+ init_images ,
92
+ interpolations = interpolations ,
93
+ spring = k ,
94
+ name = simname )
86
95
87
96
neb .relax (max_steps = maxst ,
88
97
save_vtk_steps = save_every ,
89
98
save_npy_steps = save_every ,
90
99
stopping_dmdt = 1e-2 )
91
100
92
101
102
+ def mid_m (pos ):
103
+ if pos [0 ] > 4 :
104
+ return (0.5 , 0 , 0.2 )
105
+ else :
106
+ return (- 0.5 , 0 , 0.2 )
107
+
108
+
93
109
# this test runs for over a minute
94
110
@pytest .mark .slow
95
111
def test_energy_barrier_2particles ():
96
112
# Initial images: we set here a rotation interpolating
97
- def mid_m (pos ):
98
- if pos [0 ] > 4 :
99
- return (0.5 , 0 , 0.2 )
100
- else :
101
- return (- 0.5 , 0 , 0.2 )
102
-
103
113
init_im = [(- 1 , 0 , 0 ), mid_m , (1 , 0 , 0 )]
104
114
interp = [6 , 6 ]
105
115
@@ -114,12 +124,27 @@ def mid_m(pos):
114
124
interp ,
115
125
save_every = 5000 )
116
126
127
+ # Relax the same system using spherical coordinates
128
+ relax_neb (float (k ), 2000 ,
129
+ 'neb_2particles_k{}_10-10int_spherical' .format (k ),
130
+ init_im ,
131
+ interp ,
132
+ save_every = 5000 ,
133
+ coordinates = 'Spherical'
134
+ )
135
+
117
136
# Get the energies from the last state
118
137
data = np .loadtxt ('neb_2particles_k1e8_10-10int_energy.ndt' )[- 1 ][1 :]
138
+ data_spherical = np .loadtxt (
139
+ 'neb_2particles_k1e8_10-10int_spherical_energy.ndt' )[- 1 ][1 :]
119
140
120
141
ebarrier = np .abs (np .max (data ) - np .min (data )) / (1.602e-19 )
121
142
print (ebarrier )
122
143
144
+ ebarrier_spherical = np .abs (np .max (data_spherical ) -
145
+ np .min (data_spherical )) / (1.602e-19 )
146
+ print (ebarrier_spherical )
147
+
123
148
# Analitically, the energy when a single particle rotates is:
124
149
# K V cos^2 theta
125
150
# where theta is the angle of the direction of one particle with respect
@@ -133,6 +158,9 @@ def mid_m(pos):
133
158
assert ebarrier < 0.017
134
159
assert ebarrier > 0.005
135
160
161
+ assert ebarrier_spherical < 0.017
162
+ assert ebarrier_spherical > 0.005
163
+
136
164
137
- if __name__ == '__main__' :
138
- test_energy_barrier_2particles ()
165
+ if __name__ == '__main__' :
166
+ test_energy_barrier_2particles ()
0 commit comments