Skip to content

Commit 040e3ad

Browse files
committed
Add single valued DMI test
1 parent 8debacc commit 040e3ad

File tree

1 file changed

+19
-37
lines changed

1 file changed

+19
-37
lines changed

tests/test_dmi.py

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,21 @@ def test_micro_dmi_array_bulk():
7676
7777
"""
7878
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()
8379

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)
8581
sim = microSim(mesh)
8682
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+
9185

92-
sim.add(microDMI(DMInorms, dmi_type='bulk'))
86+
sim.add(microDMI(D, dmi_type='bulk'))
9387
sim.compute_effective_field(0)
88+
D_field = C.mu_0 * sim.field.reshape(-1, 3)
89+
print(D_field)
9490

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)
10494

10595

10696
def test_micro_dmi_array_interfacial():
@@ -124,36 +114,28 @@ def test_micro_dmi_array_interfacial():
124114
125115
"""
126116
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+
131118

132119
mesh = CuboidMesh(nx=3, ny=1, nz=1, dx=1, dy=1, dz=1)
133120
sim = microSim(mesh)
134121
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]))
138123

139-
sim.add(microDMI(DMInorms, dmi_type='interfacial'))
124+
125+
sim.add(microDMI(D, dmi_type='interfacial'))
140126
sim.compute_effective_field(0)
141127

142128
# The field is computed as: - (1 / mu_0 Ms) D ( (r_ij X z) X M )
143129
# Thus the field at the middle site should be: -D ( (-y) X (0, 0, -1) )
144130
# which is (1, 0, 0), since Ms=1 and D is defined only for the
145131
# neighbours as +- z
146132
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+
157139

158140
if __name__ == '__main__':
159141
# test_atom_dmi_1d()

0 commit comments

Comments
 (0)