Skip to content

Commit fc997b6

Browse files
committed
Add test for parameter setting of init_vector
1 parent 60a215b commit fc997b6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/test_init_vector.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import fidimag
2+
from fidimag.common import init_vector
3+
import numpy as np
4+
import unittest
5+
6+
def m_init(pos, t):
7+
x, y, z = pos
8+
return (np.sin(t), np.cos(t), 0.0)
9+
10+
def test_init_scalar_function():
11+
import fidimag
12+
import numpy as np
13+
# Create simulation
14+
nx = ny = nz = 2
15+
mesh = fidimag.common.CuboidMesh(nx=nx, ny=ny, nz=nz,
16+
dx=1, dy=1, dz=1)
17+
18+
test_vec = np.zeros(3 * nx * ny * nz)
19+
test_vec[:] = init_vector(m_init, mesh, False, 0)
20+
assert test_vec[0] < 1e-15
21+
assert test_vec[1] - 1.0 < 1e-15
22+
test_vec[:] = init_vector(m_init, mesh, False, np.pi/2.0)
23+
assert test_vec[0] - 1.0 < 1e-15
24+
assert test_vec[1] < 1e-15

0 commit comments

Comments
 (0)