Skip to content

Commit 2ca23c7

Browse files
committed
additional tests
1 parent 1c3e8c0 commit 2ca23c7

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

tests/test_basics.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import magpylib as magpy
33
from magpylib_force import getFT
4+
from scipy.spatial.transform import Rotation as R
45

56

67
def test_rotation1():
@@ -54,3 +55,20 @@ def test_rotation2():
5455
FT = getFT(s1, [c1, c2], anchor=(0,0,0))
5556

5657
np.testing.assert_allclose(FT[0], FT[1])
58+
59+
60+
def test_orientation():
61+
"""
62+
test if dipole with orientation gives same result as rotated magnetic moment
63+
"""
64+
mm, md = np.array((0.976, 4.304, 2.055)), np.array((0.878, -1.527, 2.918))
65+
pm, pd = np.array((-1.248, 7.835, 9.273)), np.array((-2.331, 5.835, 0.578))
66+
67+
magnet = magpy.magnet.Cuboid(position=pm, dimension=(1,2,3), polarization=mm)
68+
r = R.from_euler('xyz', (25, 65, 150), degrees=True)
69+
dipole1 = magpy.misc.Dipole(position=pd, moment=md, orientation=r)
70+
dipole2 = magpy.misc.Dipole(position=pd, moment=r.apply(md))
71+
72+
F = getFT(magnet, [dipole1, dipole2], anchor=(0,0,0))
73+
74+
np.testing.assert_allclose(F[0], F[1])

tests/test_physics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,4 @@ def test_physics_force_between_two_dipoles():
266266
5*r_unit*(np.dot(np.cross(r_unit, m1), np.cross(r_unit, m2)))
267267
)
268268

269-
np.testing.assert_allclose(F_num, F_ana)
269+
np.testing.assert_allclose(F_num, F_ana, rtol=1e-8, atol=1e-8)

tests/test_self_consistency.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,26 @@ def test_consistency_polyline_circle():
267267
F2,T2 = getFT(src, loop2, anchor=(0,0,0))
268268
assert abs(np.linalg.norm(F1-F2)/np.linalg.norm(F1+F2)) < 1e-7
269269
assert abs(np.linalg.norm(T1-T2)/np.linalg.norm(T1+T2)) < 1e-7
270+
271+
272+
def test_consistency_sphere_dipole():
273+
"""
274+
force on sphere and dipole should be the same in nearly homogeneous field
275+
"""
276+
277+
src = magpy.current.Circle(diameter=10, current=123)
278+
pos = (0,0,0)
279+
diameter = 0.5
280+
magnetization_sphere = np.array((1e6,2e6,3e6))
281+
moment_dipole = magnetization_sphere*diameter**3/6*np.pi
282+
283+
sphere = magpy.magnet.Sphere(diameter=diameter, magnetization=magnetization_sphere, position=pos)
284+
sphere.meshing = 100
285+
286+
dipole = magpy.misc.Dipole(position=pos, moment=moment_dipole)
287+
288+
FT_sphere = getFT(src, sphere, anchor=(0,0,0))
289+
FT_dipole = getFT(src, dipole, anchor=(0,0,0))
290+
291+
np.testing.assert_allclose(FT_sphere, FT_dipole, rtol=1e-6, atol=1e-6)
292+

0 commit comments

Comments
 (0)