Skip to content

Commit f140fb6

Browse files
author
davidcorteso
committed
Added update_field function to the atomistic Zeeman field class, using the micromagnetic one. Documented Zeeman field objects. Changed H0 to B0 in the atomistic Zeeman field since it uses Tesla rather than A / m as in the micromagnetic model.
1 parent ded962e commit f140fb6

File tree

2 files changed

+96
-7
lines changed

2 files changed

+96
-7
lines changed

fidimag/atomistic/zeeman.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,50 @@
55
class Zeeman(object):
66

77
"""
8-
The time independent external field, can vary with space
8+
9+
A time independent external magnetic field that can be space dependent.
10+
The field energy is computed as:
11+
12+
__ -> ->
13+
E = - \ \mu_i \cdot B_i
14+
/__
15+
i
16+
17+
where mu_i = g \mu_B S_i is the magnetic moment vector at the i-th lattice
18+
site, g is the Lande factor, \mu_B the Bohr magneton, S_i the average total
19+
spin vector at the i-th site and B_i the bias field vector at the i-th
20+
site, given in Tesla units.
21+
22+
If the field is homogeneous, it can be specified in a simulation object
23+
*Sim* as
24+
25+
Sim.add(Zeeman((B_x, B_y, B_z)))
26+
27+
Otherwise, it can be specified as any Fidimag field, passing a function or
28+
an array. For example, a space dependent field function that changes
29+
linearly in the x-direction, and only has a x-component, can be defined as:
30+
31+
def my_Zeeman_field(pos):
32+
B = 0.01 # T
33+
return (B * pos[0], 0, 0)
34+
35+
# Add field to Simulation object
36+
Sim.add(Zeeman(my_Zeeman_field))
37+
38+
39+
For a hysteresis loop, the field can be updated using the *update_field*
40+
function. For an already defined simulation object *Sim*, it is updated as
41+
42+
Sim.get_interaction('Zeeman').update_field(new_field)
43+
44+
where new_field is a 3-tuple, and array or a function, as shown before.
45+
It is recommended to reset the integrator with *Sim.reset_integrator()*
46+
to start a new relaxation after updating the field.
47+
948
"""
1049

11-
def __init__(self, H0, name='Zeeman'):
12-
self.H0 = H0
50+
def __init__(self, B0, name='Zeeman'):
51+
self.B0 = B0
1352
self.name = name
1453
self.jac = False
1554

@@ -28,7 +67,11 @@ def setup(self, mesh, spin, mu_s):
2867
self.mu_s_long.shape = (-1,)
2968

3069
self.field = np.zeros(3 * self.n)
31-
self.field[:] = helper.init_vector(self.H0, self.mesh)
70+
self.field[:] = helper.init_vector(self.B0, self.mesh)
71+
72+
def update_field(self, B0):
73+
self.B0 = B0
74+
self.field[:] = helper.init_vector(self.B0, self.mesh)
3275

3376
def compute_field(self, t=0):
3477
return self.field
@@ -56,8 +99,8 @@ class TimeZeeman(Zeeman):
5699
The time dependent external field, also can vary with space
57100
"""
58101

59-
def __init__(self, H0, time_fun, name='TimeZeeman'):
60-
self.H0 = H0
102+
def __init__(self, B0, time_fun, name='TimeZeeman'):
103+
self.B0 = B0
61104
self.time_fun = time_fun
62105
self.name = name
63106
self.jac = False

fidimag/micro/zeeman.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,50 @@
77
class Zeeman(object):
88

99
"""
10-
The time independent external field, can vary with space
10+
A time independent external magnetic field that can be space dependent.
11+
The field energy in the micromagnetic theory reads:
12+
_
13+
/ -> ->
14+
E = - \mu_0 / M \cdot H dV
15+
_ /
16+
17+
with H as the bias field in A / m, \mu_0 the vacuum permeability and M the
18+
magnetisation vector. Using finite differences, this quantity is computed
19+
through the summation
20+
21+
__ -> ->
22+
E = - \mu_0 * dV \ M_i \cdot H_i
23+
/__
24+
i
25+
26+
where M_i is the magnetisation at the i-th position of the mesh
27+
discretisation and dV = dx * dy * dz is the volume of a mesh unit cell.
28+
29+
If the field is homogeneous, it can be specified in a simulation object
30+
*Sim* as
31+
32+
Sim.add(Zeeman((H_x, H_y, H_z)))
33+
34+
Otherwise, it can be specified as any Fidimag field, passing a function or
35+
an array. For example, a space dependent field function that changes
36+
linearly in the x-direction, and only has a x-component, can be defined as:
37+
38+
def my_Zeeman_field(pos):
39+
H = 0.01 / (4 * np.pi * 1e-7) # A / m
40+
return (H * pos[0], 0, 0)
41+
42+
# Add field to Simulation object
43+
Sim.add(Zeeman(my_Zeeman_field))
44+
45+
For a hysteresis loop, the field can be updated using the *update_field*
46+
function. For an already defined simulation object *Sim*, it is updated as
47+
48+
Sim.get_interaction('Zeeman').update_field(new_field)
49+
50+
where new_field is a 3-tuple, and array or a function, as shown before.
51+
It is recommended to reset the integrator with *Sim.reset_integrator()*
52+
to start a new relaxation after updating the field.
53+
1154
"""
1255

1356
def __init__(self, H0, name='Zeeman'):
@@ -29,6 +72,9 @@ def setup(self, mesh, spin, Ms):
2972
self.Ms = Ms
3073
self.Ms_long = np.zeros(3 * mesh.n)
3174

75+
# TODO: Check if it is necessary to define a 3D matrix for
76+
# the Ms vectors. Maybe there is a way that uses less memory
77+
# (see the calculation in the *compute_energy* function)
3278
self.Ms_long.shape = (3, -1)
3379
for i in range(mesh.n):
3480
self.Ms_long[:, i] = Ms[i]

0 commit comments

Comments
 (0)