Skip to content

Commit 74cbb14

Browse files
author
davidcorteso
committed
Merge branch 'master' of github.com:computationalmodelling/fidimag
2 parents 18f3c45 + e272f41 commit 74cbb14

File tree

13 files changed

+332
-40
lines changed

13 files changed

+332
-40
lines changed

doc/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
contain the root `toctree` directive.
55
66
Welcome to fidimag's documentation!
7-
================================
7+
===================================
88

99
The official webpage is
1010
http://computationalmodelling.github.io/fidimag/, the github
@@ -17,6 +17,7 @@ Contents:
1717
:maxdepth: 2
1818

1919
install
20+
ipynb/tutorial-docker-container
2021
core_eqs
2122
extended_eqs
2223
monte_carlo

doc/ipynb/tutorial-docker-container.ipynb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
"source": [
2929
"## Setup fidimag docker container with Jupyter Notebook\n",
3030
"\n",
31-
"Pull the `fidimag notebook` container:\n",
31+
"Pull the fidimag notebook container:\n",
3232
"\n",
3333
"```\n",
34-
"docker pull fidimag\n",
34+
"docker pull fidimag/notebook\n",
3535
" ```"
3636
]
3737
},
@@ -60,9 +60,9 @@
6060
"```\n",
6161
"docker-machine ip\n",
6262
"```\n",
63-
"For example, if `docker-machine ip` returns `192.168.99.100`, then the right URL to paste into the browser on the host system is `http://192.168.99.100/30000`.\n",
63+
"For example, if `docker-machine ip` returns `192.168.99.100`, then the right URL to paste into the browser on the host system is `http://192.168.99.100:30000`.\n",
6464
"\n",
65-
"[How does this work on Windows? Pull requests welcome.]"
65+
"[*How does this work on Windows? Pull requests welcome.*]"
6666
]
6767
},
6868
{
@@ -84,10 +84,13 @@
8484
"## Show active Docker containers\n",
8585
"```docker ps``` lists all running containers.\n",
8686
"\n",
87-
"To only show the `id`s, we can use ```docker ps -q```\n",
87+
"To only show the `id`s, we can use \n",
88+
"\n",
89+
" docker ps -q\n",
8890
"\n",
8991
"To only show the containers that was last started, we can use the `-l` flag:\n",
90-
"``` docker ps -l```"
92+
"\n",
93+
" docker ps -l"
9194
]
9295
},
9396
{
@@ -163,7 +166,7 @@
163166
"We can use the container like this to achieve that:\n",
164167
"\n",
165168
"```\n",
166-
"docker run -v `pwd`:/io -ti fidimag/notebook python hello.py```\n",
169+
"docker run -v `pwd`:/io -ti fidimag/notebook python run.py```\n",
167170
"\n",
168171
"The ```-v `pwd`:/io``` tells the docker container to take the current working directory on the host (``` `pwd` ```) and mount it to the path `/io` on the container. The container is set up so that the default working directory is `/io`."
169172
]

fidimag/atomistic/lib/clib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ void llg_s_rhs(double * dm_dt, double * spin, double * h, double *alpha,
6060
double *chi, double gamma, int n);
6161

6262

63-
void compute_stt_field_c(double *spin, double *field, double *jx, double *jy,
64-
double dx, double dy, int *ngbs, int n);
63+
void compute_stt_field_c(double *spin, double *field, double *jx, double *jy, double *jz,
64+
double dx, double dy, double dz, int *ngbs, int n);
6565

6666
void llg_stt_rhs(double *dm_dt, double *m, double *h,
6767
double *h_stt, double *alpha,

fidimag/atomistic/lib/clib.pyx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ cdef extern from "clib.h":
7878
void normalise(double *m, int *pins, int n)
7979

8080
void compute_stt_field_c(double *spin, double *field,
81-
double *jx, double *jy,
82-
double dx, double dy, int *ngbs, int n)
81+
double *jx, double *jy, double *jz,
82+
double dx, double dy, double dz, int *ngbs, int n)
8383

8484
void llg_stt_rhs(double *dm_dt, double *m, double *h, double *h_stt,
8585
double *alpha,double beta, double u0, double gamma, int n)
@@ -241,12 +241,13 @@ def compute_stt_field(np.ndarray[double, ndim=1, mode="c"] spin,
241241
np.ndarray[double, ndim=1, mode="c"] field,
242242
np.ndarray[double, ndim=1, mode="c"] jx,
243243
np.ndarray[double, ndim=1, mode="c"] jy,
244-
dx, dy,
244+
np.ndarray[double, ndim=1, mode="c"] jz,
245+
dx, dy, dz,
245246
np.ndarray[int, ndim=2, mode="c"] ngbs,
246247
n
247248
):
248-
compute_stt_field_c(&spin[0], &field[0], &jx[0], &jy[0],
249-
dx, dy, &ngbs[0, 0], n)
249+
compute_stt_field_c(&spin[0], &field[0], &jx[0], &jy[0],&jz[0],
250+
dx, dy, dz, &ngbs[0, 0], n)
250251

251252
def compute_llg_stt_rhs(np.ndarray[double, ndim=1, mode="c"] dm_dt,
252253
np.ndarray[double, ndim=1, mode="c"] spin,

fidimag/atomistic/lib/stt.c

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* is
55
* ( \vec{j}_s \cdot \nabla ) \vec{m}
66
*
7-
* where j_s is the current vector in 2D
7+
* where j_s is the current vector in 3D
88
* For this computation we use the neighbours matrix to make easier the
99
* derivative calculation at the boundaries.
1010
* ** For now this only works with the CUBOID mesh
@@ -17,6 +17,7 @@
1717
* the derivatives are simply:
1818
* f(x + 1, y, z) - f(x - 1, y, z) / 2 dx
1919
* f(x, y + 1, z) - f(x, y - 1, z) / 2 dy
20+
* f(x, y, z + 1) - f(x, y, z - 1) / 2 dz
2021
*
2122
* where x+-1 is the neighbour to the left or right.
2223
*
@@ -31,7 +32,7 @@
3132
* i-th site and nn_x2 for the NN to the right. These variables are simply
3233
* the i-th index (in the corresponding cases) when there is a single NN
3334
*
34-
* Similar for y
35+
* Similar for y and z
3536
*
3637
* n is the number of spins or lattice sites in the system
3738
*
@@ -50,25 +51,24 @@
5051
* Neighbouring sites where there is no material, has index -1
5152
*
5253
*/
53-
void compute_stt_field_c(double *spin, double *field, double *jx, double *jy,
54-
double dx, double dy, int *ngbs, int n) {
54+
void compute_stt_field_c(double *spin, double *field, double *jx, double *jy, double *jz,
55+
double dx, double dy, double dz, int *ngbs, int n) {
5556

56-
int i, j;
57-
float factor_x, factor_y;
58-
int nn_i;
59-
int nn_x1, nn_x2, nn_y1, nn_y2;
60-
61-
for (i = 0; i < 3 * n; i++) {
57+
//#pragma omp parallel for
58+
for (int i = 0; i < 3 * n; i++) {
6259
field[i] = 0;
6360
}
64-
61+
62+
#pragma omp parallel for
6563
/* Iterate through every lattice site */
66-
for (i = 0; i < n; i++){
64+
for (int i = 0; i < n; i++){
6765

6866
/* Starting index for the NNs of the i-th site
6967
* i+0, i+1, i+2, i+3 ... --> -x, +x, -y, +y ...
7068
*/
71-
nn_i = 6 * i;
69+
int nn_i = 6 * i;
70+
double factor_x, factor_y, factor_z;
71+
int nn_x1, nn_x2, nn_y1, nn_y2, nn_z1, nn_z2;
7272

7373
/* Here we distinguish if there are 2 NNs, no NN in the
7474
* -x direction, or no NN in the +x direction,
@@ -100,7 +100,7 @@ void compute_stt_field_c(double *spin, double *field, double *jx, double *jy,
100100
* This calculation is: jx[i] * d m[i] / dx
101101
* */
102102
if (factor_x){
103-
for(j = 0; j < 3; j++){
103+
for(int j = 0; j < 3; j++){
104104
field[3 * i + j] += jx[i] * (spin[3 * nn_x2 + j]
105105
- spin[3 * nn_x1 + j]) / (factor_x * dx);
106106
}
@@ -124,11 +124,37 @@ void compute_stt_field_c(double *spin, double *field, double *jx, double *jy,
124124
}
125125

126126
if (factor_y){
127-
for(j = 0; j < 3; j++){
127+
for(int j = 0; j < 3; j++){
128128
field[3 * i + j] += jy[i] * (spin[3 * nn_y2 + j]
129129
- spin[3 * nn_y1 + j]) / (factor_y * dy);
130130
}
131131
}
132+
133+
134+
// We do the same along the z direction
135+
if(ngbs[nn_i + 4] >= 0 && ngbs[nn_i + 5] >= 0) {
136+
factor_z = 2;
137+
nn_z1 = ngbs[nn_i + 4];
138+
nn_z2 = ngbs[nn_i + 5];
139+
} else if(ngbs[nn_i + 4] >= 0 && ngbs[nn_i + 5] < 0){
140+
factor_z = 1;
141+
nn_z1 = ngbs[nn_i + 4];
142+
nn_z2 = i;
143+
} else if(ngbs[nn_i + 4] < 0 && ngbs[nn_i + 5] >= 0 ){
144+
factor_z = 1;
145+
nn_z1 = i;
146+
nn_z2 = ngbs[nn_i + 5];
147+
} else {
148+
factor_z = 0;
149+
}
150+
151+
if (factor_z){
152+
for(int j = 0; j < 3; j++){
153+
field[3 * i + j] += jz[i] * (spin[3 * nn_z2 + j]
154+
- spin[3 * nn_z1 + j]) / (factor_z * dz);
155+
}
156+
}
157+
132158
}
133159
}
134160

fidimag/atomistic/llg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def set_default_options(self, gamma=1, mu_s=1, alpha=0.1):
8686
self.default_c = -1
8787
self._alpha[:] = alpha
8888
self._mu_s[:] = mu_s
89+
self.mu_s_const = mu_s
8990
self.gamma = gamma
9091
self.do_precession = True
9192

@@ -156,6 +157,8 @@ def set_mu_s(self, value):
156157
# Set the neighbour index to -1 for sites with mu_s = 0
157158
self.mesh.neighbours[self.mesh.neighbours == i] = -1
158159

160+
self.mu_s_const = np.max(self._mu_s)
161+
159162
mu_s = property(get_mu_s, set_mu_s)
160163

161164
def add(self, interaction, save_field=False):

fidimag/atomistic/llg_stt.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
from __future__ import division
2+
3+
import fidimag.extensions.clib as clib
4+
import numpy as np
5+
6+
from .llg import LLG
7+
import fidimag.common.helper as helper
8+
import fidimag.common.constant as const
9+
10+
11+
class LLG_STT(LLG):
12+
13+
def __init__(self, mesh, name='unnamed'):
14+
"""Simulation object.
15+
16+
*Arguments*
17+
18+
name : the Simulation name (used for writing data files, for examples)
19+
20+
"""
21+
super(LLG_STT, self).__init__(mesh, name=name)
22+
23+
self.field_stt = np.zeros(3 * self.n)
24+
25+
self._jx = np.zeros(self.n, dtype=np.float)
26+
self._jy = np.zeros(self.n, dtype=np.float)
27+
self._jz = np.zeros(self.n, dtype=np.float)
28+
29+
self.p = 0.5
30+
self.beta = 0
31+
self.update_j_fun = None
32+
33+
# FIXME: change the u0 to spatial
34+
v = self.mesh.dx* self.mesh.dy * self.mesh.dz * (self.mesh.unit_length**3)
35+
self.u0 = const.g_e * const.mu_B / (2 * const.c_e) * v
36+
37+
def get_jx(self):
38+
return self._jx
39+
40+
def set_jx(self, value):
41+
self._jx[:] = helper.init_scalar(value, self.mesh)
42+
43+
jx = property(get_jx, set_jx)
44+
45+
def get_jy(self):
46+
return self._jy
47+
48+
def set_jy(self, value):
49+
self._jy[:] = helper.init_scalar(value, self.mesh)
50+
51+
jy = property(get_jy, set_jy)
52+
53+
def get_jz(self):
54+
return self._jz
55+
56+
def set_jz(self, value):
57+
self._jz[:] = helper.init_scalar(value, self.mesh)
58+
59+
jz = property(get_jz, set_jz)
60+
61+
def sundials_rhs(self, t, y, ydot):
62+
63+
self.t = t
64+
65+
# already synchronized when call this funciton
66+
# self.spin[:]=y[:]
67+
68+
self.compute_effective_field(t)
69+
70+
if self.update_j_fun is not None:
71+
clib.compute_stt_field(self.spin,
72+
self.field_stt,
73+
self._jx * self.update_j_fun(t),
74+
self._jy * self.update_j_fun(t),
75+
self._jz * self.update_j_fun(t),
76+
self.mesh.dx * self.mesh.unit_length,
77+
self.mesh.dy * self.mesh.unit_length,
78+
self.mesh.dz * self.mesh.unit_length,
79+
self.mesh.neighbours,
80+
self.n
81+
)
82+
else:
83+
clib.compute_stt_field(self.spin,
84+
self.field_stt,
85+
self._jx,
86+
self._jy,
87+
self._jz,
88+
self.mesh.dx * self.mesh.unit_length,
89+
self.mesh.dy * self.mesh.unit_length,
90+
self.mesh.dz * self.mesh.unit_length,
91+
self.mesh.neighbours,
92+
self.n
93+
)
94+
95+
clib.compute_llg_stt_rhs(ydot,
96+
self.spin,
97+
self.field,
98+
self.field_stt,
99+
self.alpha,
100+
self.beta,
101+
self.u0 * self.p / self.mu_s_const,
102+
self.gamma,
103+
self.n)

fidimag/atomistic/llg_stt_slonczewski_type.py renamed to fidimag/atomistic/llg_stt_cpp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import fidimag.common.helper as helper
1010

1111

12-
class LLG_STT_Slonczewski(LLG):
12+
class LLG_STT_CPP(LLG):
1313

1414
def __init__(self, mesh, name='unnamed'):
1515
"""Simulation object.
@@ -19,7 +19,7 @@ def __init__(self, mesh, name='unnamed'):
1919
name : the Simulation name (used for writing data files, for examples)
2020
2121
"""
22-
super(LLG_STT_Slonczewski, self).__init__(mesh, name=name)
22+
super(LLG_STT_CPP, self).__init__(mesh, name=name)
2323

2424
self._p = np.zeros(3 * self.n, dtype=np.float)
2525
self._a_J = np.zeros(self.n, dtype=np.float)

fidimag/atomistic/sim.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from .llg import LLG
22
from .sllg import SLLG
3-
from .llg_stt_slonczewski_type import LLG_STT_Slonczewski
3+
from .llg_stt import LLG_STT
4+
from .llg_stt_cpp import LLG_STT_CPP
45

56

67
KNOWN_DRIVERS = {'llg': LLG,
78
'sllg': SLLG,
8-
'slonczewski': LLG_STT_Slonczewski
9+
'llg_stt': LLG_STT,
10+
'llg_stt_cpp': LLG_STT_CPP
911
}
1012

1113

0 commit comments

Comments
 (0)