Skip to content

Commit cd946f5

Browse files
Moved DAMPING functions and variable to the DriverBase class. Moved common variables to DriverBase. Now we pass one less variable from sim to the driver. To initialise alpha in the BaseDriver it is necessary to define the number of spins from sim.mesh.n first
1 parent 232fb4f commit cd946f5

File tree

17 files changed

+96
-88
lines changed

17 files changed

+96
-88
lines changed

fidimag/atomistic/atomistic_driver.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class AtomisticDriver(DriverBase):
1919
2020
Variables that are proper of the driver class:
2121
22+
* alpha (damping)
2223
* mu_s_const
2324
* t
2425
* spin_last
@@ -33,9 +34,11 @@ class AtomisticDriver(DriverBase):
3334
during the LLG equation integration. See the
3435
fidimag/atomistic/lib/llg.c file for more details)
3536
37+
From DriverBase: t, spin_last, dm_dt, integrator_tolerances_set, step
38+
3639
"""
3740

38-
def __init__(self, mesh, spin, mu_s, mu_s_inv, field, alpha, pins,
41+
def __init__(self, mesh, spin, mu_s, mu_s_inv, field, pins,
3942
interactions,
4043
name,
4144
data_saver,
@@ -56,33 +59,29 @@ def __init__(self, mesh, spin, mu_s, mu_s_inv, field, alpha, pins,
5659
self.mu_s_const = 0
5760

5861
self.field = field
59-
self._alpha = alpha
6062
self._pins = pins
6163
self.interactions = interactions
6264
# Strings are not referenced, this is a copy:
6365
self.name = name
6466

65-
# The following are proper of the driver class: -----------------------
67+
# The following are proper of the driver class: (see DriverBase) ------
6668
# See also the set_default_options() function
6769

68-
self.t = 0
69-
self.step = 0
70-
self.spin_last = np.ones(3 * self.mesh.n, dtype=np.float)
71-
self.dm_dt = np.zeros(3 * self.mesh.n, dtype=np.float)
72-
self.integrator_tolerances_set = False
73-
7470
self.n = self.mesh.n
7571
self.n_nonzero = self.mesh.n # number of spins that are not zero
7672
# We check this in the set_Ms function
7773

74+
self.initiate_variables(self.n)
75+
self.set_default_options()
76+
77+
# Integrator options --------------------------------------------------
78+
7879
if use_jac is not True:
7980
self.integrator = cvode.CvodeSolver(self.spin, self.sundials_rhs)
8081
else:
8182
self.integrator = cvode.CvodeSolver(
8283
self.spin, self.sundials_rhs, self.sundials_jtn)
8384

84-
self.set_default_options()
85-
8685
self.set_tols()
8786

8887
# When initialising the integrator in the self.integrator call, the

fidimag/atomistic/llg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class LLG(AtomisticDriver):
2727
2828
"""
2929

30-
def __init__(self, mesh, spin, mu_s, mu_s_inv, field, alpha, pins,
30+
def __init__(self, mesh, spin, mu_s, mu_s_inv, field, pins,
3131
interactions,
3232
name,
3333
data_saver,
@@ -36,7 +36,7 @@ def __init__(self, mesh, spin, mu_s, mu_s_inv, field, alpha, pins,
3636

3737
# Inherit from the driver class
3838
super(LLG, self).__init__(mesh, spin, mu_s, mu_s_inv, field,
39-
alpha, pins, interactions, name,
39+
pins, interactions, name,
4040
data_saver,
4141
use_jac
4242
)

fidimag/atomistic/llg_stt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LLG_STT(AtomisticDriver):
3030
3131
"""
3232

33-
def __init__(self, mesh, spin, mu_s, mu_s_inv, field, alpha, pins,
33+
def __init__(self, mesh, spin, mu_s, mu_s_inv, field, pins,
3434
interactions,
3535
name,
3636
data_saver,
@@ -39,7 +39,7 @@ def __init__(self, mesh, spin, mu_s, mu_s_inv, field, alpha, pins,
3939

4040
# Inherit from the driver class
4141
super(LLG_STT, self).__init__(mesh, spin, mu_s, mu_s_inv, field,
42-
alpha, pins, interactions, name,
42+
pins, interactions, name,
4343
data_saver,
4444
use_jac
4545
)

fidimag/atomistic/llg_stt_cpp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LLG_STT_CPP(AtomisticDriver):
3030
3131
"""
3232

33-
def __init__(self, mesh, spin, mu_s, mu_s_inv, field, alpha, pins,
33+
def __init__(self, mesh, spin, mu_s, mu_s_inv, field, pins,
3434
interactions,
3535
name,
3636
data_saver,
@@ -39,7 +39,7 @@ def __init__(self, mesh, spin, mu_s, mu_s_inv, field, alpha, pins,
3939

4040
# Inherit from the driver class
4141
super(LLG_STT_CPP, self).__init__(mesh, spin, mu_s, mu_s_inv, field,
42-
alpha, pins, interactions, name,
42+
pins, interactions, name,
4343
data_saver,
4444
use_jac
4545
)

fidimag/atomistic/sim.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def __init__(self, mesh, name='unnamed', driver='llg',
7979
self._mu_s,
8080
self._mu_s_inv,
8181
self.field,
82-
self._alpha,
8382
self._pins,
8483
self.interactions,
8584
self.name,

fidimag/atomistic/sllg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class SLLG(AtomisticDriver):
2626
2727
"""
2828

29-
def __init__(self, mesh, spin, mu_s, mu_s_inv, field, alpha, pins,
29+
def __init__(self, mesh, spin, mu_s, mu_s_inv, field, pins,
3030
interactions,
3131
name,
3232
data_saver,
@@ -35,7 +35,7 @@ def __init__(self, mesh, spin, mu_s, mu_s_inv, field, alpha, pins,
3535

3636
# Inherit from the driver class
3737
super(SLLG, self).__init__(mesh, spin, mu_s, mu_s_inv, field,
38-
alpha, pins, interactions, name,
38+
pins, interactions, name,
3939
data_saver,
4040
use_jac=False
4141
)

fidimag/common/driver_base.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import os
55
import numpy as np
6+
import fidimag.common.helper as helper
67

78

89
class DriverBase(object):
@@ -15,6 +16,61 @@ def __init__(self):
1516

1617
# -------------------------------------------------------------------------
1718

19+
def initiate_variables(self, n_spins):
20+
"""
21+
Common variables for both micro and atomistic drivers
22+
"""
23+
self._alpha = np.zeros(n_spins, dtype=np.float)
24+
25+
self.t = 0
26+
self.spin_last = np.ones(3 * n_spins, dtype=np.float)
27+
self.dm_dt = np.zeros(3 * n_spins, dtype=np.float)
28+
self.integrator_tolerances_set = False
29+
self.step = 0
30+
31+
def get_alpha(self):
32+
"""
33+
Returns the array with the spatially dependent Gilbert damping
34+
per mesh/lattice site
35+
"""
36+
return self._alpha
37+
38+
def set_alpha(self, value):
39+
"""
40+
41+
Set the Gilbert damping of the system as a uniform or spatially
42+
dependent scalar field
43+
44+
ARGUMENTS:
45+
46+
value :: * For a uniform damping across the whole sample, just
47+
specify a float ranging from 0 to 1
48+
49+
* In addition, you can specify a function that returns
50+
values ranging from 0 to 1, which depends on the spatial
51+
coordinates. For example, a damping that increases
52+
linearly in the x direction:
53+
54+
def alpha_profile(r):
55+
for r[0] <= 10:
56+
return r[0] / 10.
57+
else:
58+
return 0
59+
60+
* You can also manually specify an array with n values
61+
ranging from 0 to 1 with the damping values, in the same
62+
order than the mesh coordinates array.
63+
64+
* Alternatively, if you previously saved the damping
65+
field array to a numpy file, you can load it using
66+
numpy.load(my_array)
67+
"""
68+
self._alpha[:] = helper.init_scalar(value, self.mesh)
69+
70+
alpha = property(get_alpha, set_alpha)
71+
72+
# ------------------------------------------------------------------------
73+
1874
def stat(self):
1975
return self.integrator.stat()
2076

fidimag/common/sim_base.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def __init__(self, mesh, name):
2020
self.unit_length = mesh.unit_length
2121

2222
self._magnetisation = np.zeros(self.n, dtype=np.float)
23-
self._alpha = np.zeros(self.n, dtype=np.float)
2423
self.spin = np.ones(3 * self.n, dtype=np.float)
2524
self._pins = np.zeros(self.n, dtype=np.int32)
2625
self.field = np.zeros(3 * self.n, dtype=np.float)
@@ -149,47 +148,6 @@ def pin_profile(r):
149148

150149
pins = property(get_pins, set_pins)
151150

152-
def get_alpha(self):
153-
"""
154-
Returns the array with the spatially dependent Gilbert damping
155-
per mesh/lattice site
156-
"""
157-
return self._alpha
158-
159-
def set_alpha(self, value):
160-
"""
161-
162-
Set the Gilbert damping of the system as a uniform or spatially
163-
dependent scalar field
164-
165-
ARGUMENTS:
166-
167-
value :: * For a uniform damping across the whole sample, just
168-
specify a float ranging from 0 to 1
169-
170-
* In addition, you can specify a function that returns
171-
values ranging from 0 to 1, which depends on the spatial
172-
coordinates. For example, a damping that increases
173-
linearly in the x direction:
174-
175-
def alpha_profile(r):
176-
for r[0] <= 10:
177-
return r[0] / 10.
178-
else:
179-
return 0
180-
181-
* You can also manually specify an array with n values
182-
ranging from 0 to 1 with the damping values, in the same
183-
order than the mesh coordinates array.
184-
185-
* Alternatively, if you previously saved the damping
186-
field array to a numpy file, you can load it using
187-
numpy.load(my_array)
188-
"""
189-
self._alpha[:] = helper.init_scalar(value, self.mesh)
190-
191-
alpha = property(get_alpha, set_alpha)
192-
193151
def add(self, interaction, save_field=False):
194152
"""
195153

fidimag/micro/llg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class LLG(MicroDriver):
2828
2929
"""
3030

31-
def __init__(self, mesh, spin, Ms, field, alpha, pins,
31+
def __init__(self, mesh, spin, Ms, field, pins,
3232
interactions,
3333
name,
3434
data_saver,
@@ -38,7 +38,7 @@ def __init__(self, mesh, spin, Ms, field, alpha, pins,
3838

3939
# Inherit from the driver class
4040
super(LLG, self).__init__(mesh, spin, Ms, field,
41-
alpha, pins, interactions, name,
41+
pins, interactions, name,
4242
data_saver,
4343
integrator='sundials',
4444
use_jac=False

fidimag/micro/llg_stt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LLG_STT(MicroDriver):
2929
3030
"""
3131

32-
def __init__(self, mesh, spin, Ms, field, alpha, pins,
32+
def __init__(self, mesh, spin, Ms, field, pins,
3333
interactions,
3434
name,
3535
data_saver,
@@ -39,7 +39,7 @@ def __init__(self, mesh, spin, Ms, field, alpha, pins,
3939

4040
# Inherit from the driver class
4141
super(LLG_STT, self).__init__(mesh, spin, Ms, field,
42-
alpha, pins, interactions, name,
42+
pins, interactions, name,
4343
data_saver,
4444
integrator='sundials',
4545
use_jac=False

0 commit comments

Comments
 (0)