Skip to content

Commit 09af800

Browse files
author
Weiwei Wang
committed
add next-neighbour interaction for cuboid mesh in monte carlo method
1 parent db55ac0 commit 09af800

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

fidimag/atomistic/lib/clib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ void llg_rhs_dw_c(double *m, double *h, double *dm, double *T, double *alpha,
9090
double *mu_s_inv, int *pins, double *eta, int n, double gamma, double dt);
9191

9292
//======================================================================
93-
void run_step_mc(mt19937_state *state, double *spin, double *new_spin, int *ngbs, double J, double D, double *h, double Kc, int n, double T, int hexagnoal_mesh);
93+
94+
void run_step_mc(mt19937_state *state, double *spin, double *new_spin, int *ngbs, int *nngbs, double J, double J1, double D, double D1, double *h, double Kc, int n, double T, int hexagnoal_mesh);
9495

9596

9697
#endif

fidimag/atomistic/lib/clib.pyx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ cdef extern from "time.h":
1919
time_t time(time_t *timer)
2020

2121
cdef extern from "clib.h":
22-
void run_step_mc(mt19937_state *state, double *spin, double *new_spin, int *ngbs, double J, double D, double *h, double Kc, int n, double T, int hexagnoal_mesh)
23-
22+
void run_step_mc(mt19937_state *state, double *spin, double *new_spin, int *ngbs, int *nngbs,
23+
double J, double J1, double D, double D1, double *h, double Kc, int n, double T, int hexagnoal_mesh)
2424
double skyrmion_number(double *spin, double *charge,
2525
int nx, int ny, int nz, int *ngbs)
2626

@@ -340,8 +340,9 @@ cdef class monte_carlo(object):
340340
def run_step(self,np.ndarray[double, ndim=1, mode="c"] spin,
341341
np.ndarray[double, ndim=1, mode="c"] new_spin,
342342
np.ndarray[int, ndim=2, mode="c"] ngbs,
343-
J, D, np.ndarray[double, ndim=1, mode="c"] h,
343+
np.ndarray[int, ndim=2, mode="c"] nngbs,
344+
J, J1, D, D1, np.ndarray[double, ndim=1, mode="c"] h,
344345
Kc, n, T, hexagnoal_mesh):
345346

346-
run_step_mc(self._c_state, &spin[0], &new_spin[0], &ngbs[0,0], J, D, &h[0], Kc, n, T, hexagnoal_mesh)
347+
run_step_mc(self._c_state, &spin[0], &new_spin[0], &ngbs[0,0], &nngbs[0,0], J, J1, D, D1, &h[0], Kc, n, T, hexagnoal_mesh)
347348

fidimag/atomistic/lib/mc.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,37 @@ double compute_deltaE_exchange_DMI_hexagnoal(double *spin, double *new_spin, int
9797

9898
}
9999

100-
double compute_deltaE_exchange_DMI(double *spin, double *new_spin, int *ngbs, double J, double D, int i){
100+
double compute_deltaE_exchange_DMI(double *spin, double *new_spin, int *ngbs, int *nngbs, double J, double J1, double D, double D1, int i){
101101

102102
int id_nn = 6 * i;
103103
double energy1=0, energy2=0;
104104

105105
for (int j = 0; j < 6; j++) {
106106
int k = ngbs[id_nn + j];
107107
if (k >= 0) {
108-
energy1 -= J*dot(&spin[3*i], &spin[3*k]);//exchange energy
108+
energy1 -= J*dot(&spin[3*i], &spin[3*k]) ;//exchange energy
109109
energy1 += D*dmi_energy_site(&spin[3*i], &spin[3*k], j); //DMI energy
110110

111111
energy2 -= J*dot(&new_spin[3*i], &spin[3*k]);
112112
energy2 += D*dmi_energy_site(&new_spin[3*i], &spin[3*k], j);
113+
}
114+
k = nngbs[id_nn + j];
115+
if (k >= 0) {
116+
energy1 -= J1*dot(&spin[3*i], &spin[3*k]) ;//exchange energy
117+
energy1 += D1*dmi_energy_site(&spin[3*i], &spin[3*k], j); //DMI energy
113118

119+
energy2 -= J1*dot(&new_spin[3*i], &spin[3*k]);
120+
energy2 += D1*dmi_energy_site(&new_spin[3*i], &spin[3*k], j);
114121
}
122+
115123
}
116124

117125
return energy2-energy1;
118126

119127
}
120128

121129

122-
void run_step_mc(mt19937_state *state, double *spin, double *new_spin, int *ngbs, double J, double D, double *h, double Kc, int n, double T, int hexagnoal_mesh){
130+
void run_step_mc(mt19937_state *state, double *spin, double *new_spin, int *ngbs, int *nngbs, double J, double J1, double D, double D1, double *h, double Kc, int n, double T, int hexagnoal_mesh){
123131

124132
double delta_E, r;
125133
int update=0;
@@ -136,7 +144,7 @@ void run_step_mc(mt19937_state *state, double *spin, double *new_spin, int *ngbs
136144
if(hexagnoal_mesh){
137145
delta_E += compute_deltaE_exchange_DMI_hexagnoal(&spin[0], &new_spin[0], &ngbs[0], J, D, index);
138146
}else{
139-
delta_E += compute_deltaE_exchange_DMI(&spin[0], &new_spin[0], &ngbs[0], J, D, index);
147+
delta_E += compute_deltaE_exchange_DMI(&spin[0], &new_spin[0], &ngbs[0], &nngbs[0], J, J1, D, D1, index);
140148
}
141149

142150

fidimag/atomistic/monte_carlo.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,27 @@ def __init__(self, mesh, name='unnamed'):
3434
self.hexagnoal_mesh = False
3535
if mesh.mesh_type == 'hexagonal':
3636
self.hexagnoal_mesh = True
37+
#FIX ME !!!!
38+
self.nngbs = np.copy(mesh.neighbours)
39+
else:
40+
self.nngbs = mesh.next_neighbours
3741

3842
self.step = 0
3943
self.skx_num = 0
4044
self.mc = clib.monte_carlo()
4145
self.set_options()
4246

43-
def set_options(self, J=50.0, D=0, Kc=0, H=None, seed=100, T=10.0, S=1):
47+
def set_options(self, J=50.0, J1=0, D=0, D1=0, Kc=0, H=None, seed=100, T=10.0, S=1):
4448
"""
4549
J, D and Kc in units of k_B
4650
H in units of Tesla.
4751
S is the spin length
4852
"""
4953
self.mc.set_seed(seed)
5054
self.J = J
55+
self.J1 = J1
5156
self.D = D
57+
self.D1 = D1
5258
self.T = T
5359
self.Kc = Kc
5460
self.mu_s = 1.0
@@ -145,8 +151,8 @@ def run(self, steps=1000, save_m_steps=100, save_vtk_steps=100, save_data_steps=
145151

146152
for step in range(1, steps + 1):
147153
self.step = step
148-
self.mc.run_step(self.spin, self.random_spin, self.ngbs,
149-
self.J, self.D, self._H, self.Kc, self.n, self.T, self.hexagnoal_mesh)
154+
self.mc.run_step(self.spin, self.random_spin, self.ngbs, self.nngbs,
155+
self.J, self.J1, self.D, self.D1, self._H, self.Kc, self.n, self.T, self.hexagnoal_mesh)
150156
if save_data_steps is not None:
151157
if step % save_data_steps == 0:
152158
self.saver.save()

0 commit comments

Comments
 (0)