44# FIDIMAG:
55from fidimag .micro import Sim
66from fidimag .common import CuboidMesh
7- from fidimag .micro import UniformExchange , UniaxialAnisotropy , Demag
7+ from fidimag .micro import UniformExchange , UniaxialAnisotropy
88from fidimag .common .neb_cartesian import NEB_Sundials
9+ from fidimag .common .neb_spherical import NEB_Sundials as NEB_Sundials_spherical
910import numpy as np
1011
1112# Material Parameters
2526
2627def two_part (pos ):
2728
28- x , y = pos [0 ], pos [ 1 ]
29+ x = pos [0 ]
2930
3031 if x > 6 or x < 3 :
3132 return Ms
@@ -34,15 +35,16 @@ def two_part(pos):
3435
3536# Finite differences mesh
3637mesh = 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+ )
4243
4344
4445# 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' ):
4648 """
4749 Execute a simulation with the NEB function of the FIDIMAG code, for an
4850 elongated particle (long cylinder)
@@ -78,28 +80,36 @@ def relax_neb(k, maxst, simname, init_im, interp, save_every=10000):
7880 # equal to 'the number of initial states specified', minus one.
7981 interpolations = interp
8082
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 )
8695
8796 neb .relax (max_steps = maxst ,
8897 save_vtk_steps = save_every ,
8998 save_npy_steps = save_every ,
9099 stopping_dmdt = 1e-2 )
91100
92101
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+
93109# this test runs for over a minute
94110@pytest .mark .slow
95111def test_energy_barrier_2particles ():
96112 # 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-
103113 init_im = [(- 1 , 0 , 0 ), mid_m , (1 , 0 , 0 )]
104114 interp = [6 , 6 ]
105115
@@ -114,12 +124,27 @@ def mid_m(pos):
114124 interp ,
115125 save_every = 5000 )
116126
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+
117136 # Get the energies from the last state
118137 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 :]
119140
120141 ebarrier = np .abs (np .max (data ) - np .min (data )) / (1.602e-19 )
121142 print (ebarrier )
122143
144+ ebarrier_spherical = np .abs (np .max (data_spherical ) -
145+ np .min (data_spherical )) / (1.602e-19 )
146+ print (ebarrier_spherical )
147+
123148 # Analitically, the energy when a single particle rotates is:
124149 # K V cos^2 theta
125150 # where theta is the angle of the direction of one particle with respect
@@ -133,6 +158,9 @@ def mid_m(pos):
133158 assert ebarrier < 0.017
134159 assert ebarrier > 0.005
135160
161+ assert ebarrier_spherical < 0.017
162+ assert ebarrier_spherical > 0.005
163+
136164
137- if __name__ == '__main__' :
138- test_energy_barrier_2particles ()
165+ if __name__ == '__main__' :
166+ test_energy_barrier_2particles ()
0 commit comments