@@ -76,31 +76,21 @@ def test_micro_dmi_array_bulk():
76
76
77
77
"""
78
78
D = 1
79
- # The DMI norms for the NNs: -x +x -y +y -z +z
80
- DMInorms = np .array ([0 , 0 , 0 , 0 , D , D ])
81
- # This norm is the same for every lattice site
82
- DMInorms = np .repeat (DMInorms [np .newaxis , :], 4 , axis = 0 ).flatten ()
83
79
84
- mesh = CuboidMesh (nx = 2 , ny = 1 , nz = 2 , dx = 1 , dy = 1 , dz = 1 )
80
+ mesh = CuboidMesh (nx = 3 , ny = 1 , nz = 1 , dx = 1 , dy = 1 , dz = 1 )
85
81
sim = microSim (mesh )
86
82
sim .Ms = 1
87
- sim .set_m (np .array ([1 , 0 , 0 ,
88
- - 1 , 0 , 0 ,
89
- 0 , 1 , 0 ,
90
- 0 , 1 , 0 ]))
83
+ sim .set_m (np .array ([0 , 0 , 1 ]))
84
+
91
85
92
- sim .add (microDMI (DMInorms , dmi_type = 'bulk' ))
86
+ sim .add (microDMI (D , dmi_type = 'bulk' ))
93
87
sim .compute_effective_field (0 )
88
+ D_field = C .mu_0 * sim .field .reshape (- 1 , 3 )
89
+ print (D_field )
94
90
95
- # The field is computed as: - (1 / mu_0 Ms) D ( r_ij X M )
96
- # Thus the field at the 0th site should be: -D ( z X (0, 1, 0) )
97
- # which is (1, 0, 0), since Ms=1 and D is defined only for the
98
- # neighbours as +- z
99
- D_field = sim .field .reshape (- 1 , 3 )
100
- hx , hy , hz = C .mu_0 * D_field [0 ]
101
- assert np .abs (hx - 1 ) < 1e-10
102
- assert np .abs (hy ) < 1e-10
103
- assert np .abs (hz ) < 1e-10
91
+ np .testing .assert_allclose (np .array ([[ 0. , 1. , 0. ],
92
+ [ 0. , 0. , 0. ],
93
+ [ 0. , - 1. , 0. ]]), D_field , rtol = 1e-14 )
104
94
105
95
106
96
def test_micro_dmi_array_interfacial ():
@@ -124,36 +114,28 @@ def test_micro_dmi_array_interfacial():
124
114
125
115
"""
126
116
D = 1
127
- # The DMI norms for the NNs: -x +x -y +y -z +z
128
- DMInorms = np .array ([0 , D , 0 , D , 0 , 0 ])
129
- # This norm is the same for every lattice site
130
- DMInorms = np .repeat (DMInorms [np .newaxis , :], 3 , axis = 0 ).flatten ()
117
+
131
118
132
119
mesh = CuboidMesh (nx = 3 , ny = 1 , nz = 1 , dx = 1 , dy = 1 , dz = 1 )
133
120
sim = microSim (mesh )
134
121
sim .Ms = 1
135
- sim .set_m (np .array ([1 , 0 , 0 ,
136
- 0 , 1 , 0 ,
137
- 0 , 0 , - 1 ]))
122
+ sim .set_m (np .array ([0 , 0 , 1 ]))
138
123
139
- sim .add (microDMI (DMInorms , dmi_type = 'interfacial' ))
124
+
125
+ sim .add (microDMI (D , dmi_type = 'interfacial' ))
140
126
sim .compute_effective_field (0 )
141
127
142
128
# The field is computed as: - (1 / mu_0 Ms) D ( (r_ij X z) X M )
143
129
# Thus the field at the middle site should be: -D ( (-y) X (0, 0, -1) )
144
130
# which is (1, 0, 0), since Ms=1 and D is defined only for the
145
131
# neighbours as +- z
146
132
D_field = sim .field .reshape (- 1 , 3 )
147
- hx , hy , hz = C .mu_0 * D_field [1 ]
148
- assert np .abs (hx - 1 ) < 1e-10
149
- assert np .abs (hy ) < 1e-10
150
- assert np .abs (hz ) < 1e-10
151
-
152
- # At the first site the field is zero
153
- hx , hy , hz = C .mu_0 * D_field [0 ]
154
- assert np .abs (hx ) < 1e-10
155
- assert np .abs (hy ) < 1e-10
156
- assert np .abs (hz ) < 1e-10
133
+ D_field = C .mu_0 * sim .field .reshape (- 1 , 3 )
134
+ print (D_field )
135
+ np .testing .assert_allclose (np .array ([[ - 1. , 0. , 0. ],
136
+ [ 0. , 0. , 0. ],
137
+ [ 1. , 0. , 0. ]]), D_field , rtol = 1e-14 )
138
+
157
139
158
140
if __name__ == '__main__' :
159
141
# test_atom_dmi_1d()
0 commit comments