Skip to content

Commit 1ee249b

Browse files
committed
Add a test to check that adding and removing an interaction both works and writes zeros to the data table
1 parent 95ecef7 commit 1ee249b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/test_add_remove_interaction.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from fidimag.common import CuboidMesh, constant
2+
from fidimag.micro import UniformExchange, Sim, Zeeman
3+
import numpy as np
4+
5+
def test_add_remove_interaction_simple():
6+
mesh = CuboidMesh(nx=10, ny=10, nz=10, unit_length=1e-9)
7+
name = 'test_add_remove_intn_simple'
8+
sim = Sim(mesh, name=name)
9+
sim.set_m(lambda pos: (0, 0, 1))
10+
sim.set_Ms(5.8e5)
11+
exch = UniformExchange(A=1e-11, name='Exchange')
12+
zee = Zeeman((0, 0, 0.05 / constant.mu_0), name='Zeeman')
13+
sim.add(exch)
14+
sim.add(zee)
15+
sim.driver.run_until(1e-9)
16+
sim.remove('Zeeman')
17+
sim.driver.run_until(2e-9)
18+
f = open(name + '.txt')
19+
lines = f.read().split('\n')
20+
headers = lines[0].split()
21+
first_data = lines[2].split()
22+
last_data = lines[2].split()
23+
# Find the position in the data table
24+
position = headers.index('E_Zeeman')
25+
assert np.abs(float(last_data[position])) < 1e-15

0 commit comments

Comments
 (0)