Skip to content

Commit 35de180

Browse files
author
davidcorteso
committed
Added test for Zeeman energy
1 parent b3e7aec commit 35de180

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test_micromagnetic_zeeman.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,36 @@ def test_zeeman():
5050
assert field[7] == 2.3 * 0.5
5151

5252

53+
def test_zeeman_energy():
54+
55+
mu0 = 4 * np.pi * 1e-7
56+
# A system of 8 cells ( not using nm units)
57+
mesh = CuboidMesh(dx=2, dy=2, dz=2,
58+
nx=2, ny=2, nz=2
59+
)
60+
61+
sim = Sim(mesh)
62+
Ms = 1e5
63+
sim.set_Ms(Ms)
64+
65+
sim.set_m((0, 0, 1))
66+
67+
H = 0.1 / mu0
68+
zeeman = Zeeman((0, 0, H))
69+
sim.add(zeeman)
70+
71+
field = zeeman.compute_field()
72+
zf = sim.get_interaction('Zeeman')
73+
74+
# -> ->
75+
# Expected energy: Int ( -mu0 M * H ) dV
76+
# Since we have 8 cells with the same M, we just sum their contrib
77+
exp_energy = 8 * (-mu0 * H * Ms * mesh.dx * mesh.dy * mesh.dz)
78+
79+
assert np.abs(zf.compute_energy() - exp_energy) < 1e-10
80+
81+
5382
if __name__ == "__main__":
5483
test_zeeman()
5584
test_H0_is_indexable_or_callable()
85+
test_zeeman_energy()

0 commit comments

Comments
 (0)