-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/magpylib/magpylib-material-…
- Loading branch information
Showing
11 changed files
with
1,900 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
__temp* | ||
|
||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,48 @@ | ||
import magpylib as magpy | ||
import numpy as np | ||
|
||
import magpylib_material_response | ||
from magpylib_material_response.demag import apply_demag | ||
from magpylib_material_response.meshing import mesh_Cuboid | ||
|
||
|
||
def test_version(): | ||
assert isinstance(magpylib_material_response.__version__, str) | ||
|
||
|
||
def test_susceptibility_inputs(): | ||
""" | ||
test if different xi inputs give the same result | ||
""" | ||
|
||
zone = magpy.magnet.Cuboid( | ||
dimension=(1, 1, 1), | ||
polarization=(0, 0, 1), | ||
) | ||
mesh = mesh_Cuboid(zone, (2, 2, 2)) | ||
|
||
dm1 = apply_demag(mesh, susceptibility=4) | ||
dm2 = apply_demag(mesh, susceptibility=(4, 4, 4)) | ||
dm3 = apply_demag(mesh, susceptibility=[4] * 8) | ||
dm4 = apply_demag(mesh, susceptibility=[(4, 4, 4)] * 8) | ||
|
||
zone = magpy.magnet.Cuboid( | ||
dimension=(1, 1, 1), | ||
polarization=(0, 0, 1), | ||
) | ||
zone.susceptibility = 4 | ||
mesh = mesh_Cuboid(zone, (2, 2, 2)) | ||
dm5 = apply_demag(mesh) | ||
|
||
zone = magpy.magnet.Cuboid( | ||
dimension=(1, 1, 1), | ||
polarization=(0, 0, 1), | ||
) | ||
zone.susceptibility = (4, 4, 4) | ||
mesh = mesh_Cuboid(zone, (2, 2, 2)) | ||
dm6 = apply_demag(mesh) | ||
|
||
b1 = dm1.getB((1, 2, 3)) | ||
for dm in [dm2, dm3, dm4, dm5, dm6]: | ||
bb = dm.getB((1, 2, 3)) | ||
np.testing.assert_allclose(b1, bb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import magpylib as magpy | ||
import numpy as np | ||
|
||
from magpylib_material_response import demag, meshing | ||
|
||
|
||
def test_isotropic_susceptibility(): | ||
|
||
cells = 1000 # should be >=1000, otherwise discretization error too large | ||
|
||
magnet = magpy.magnet.Cuboid(dimension=(1e-3, 1e-3, 1e-3), polarization=(0, 0, 1.1)) | ||
grid = np.loadtxt("tests/testdata/grid_points.pts") | ||
field_ansys = np.loadtxt("tests/testdata/isotropic_results_ansys.txt", skiprows=1) | ||
field_ansys = field_ansys[:, 3:] | ||
|
||
# isotropic | ||
magnet.susceptibility = 0.1 | ||
magnet_meshed = meshing.mesh_Cuboid(magnet, cells) | ||
|
||
demag.apply_demag(magnet_meshed, inplace=True) | ||
|
||
field_magpylib = magnet_meshed.getB(grid) | ||
|
||
np.testing.assert_allclose(field_ansys, field_magpylib, rtol=0, atol=0.0012) | ||
|
||
|
||
def test_anisotropic_susceptibility(): | ||
|
||
cells = 1000 # should be >=1000, otherwise discretization error too large | ||
|
||
magnet = magpy.magnet.Cuboid(dimension=(1e-3, 1e-3, 1e-3), polarization=(0, 0, 1.1)) | ||
grid = np.loadtxt("tests/testdata/grid_points.pts") | ||
field_ansys = np.loadtxt("tests/testdata/anisotropic_results_ansys.txt", skiprows=1) | ||
field_ansys = field_ansys[:, 3:] | ||
|
||
# anisotropic | ||
magnet.susceptibility = (0.3, 0.2, 0.1) | ||
magnet_meshed = meshing.mesh_Cuboid(magnet, cells) | ||
|
||
demag.apply_demag(magnet_meshed, inplace=True) | ||
|
||
field_magpylib = magnet_meshed.getB(grid) | ||
|
||
np.testing.assert_allclose(field_ansys, field_magpylib, rtol=0, atol=0.0012) | ||
|
||
|
||
def test_negative_susceptibility(): | ||
|
||
cells = 1000 # should be >=1000, otherwise discretization error too large | ||
|
||
magnet = magpy.magnet.Cuboid( | ||
dimension=(1e-3, 1e-3, 1e-3), polarization=(0, 0, -0.1) | ||
) | ||
grid = np.loadtxt("tests/testdata/grid_points.pts") | ||
field_ansys = np.loadtxt( | ||
"tests/testdata/negative_susceptibility_ansys.txt", skiprows=1 | ||
) | ||
field_ansys = field_ansys[:, 3:] | ||
|
||
# isotropic | ||
magnet.susceptibility = -1.1 | ||
magnet_meshed = meshing.mesh_Cuboid(magnet, cells) | ||
|
||
demag.apply_demag(magnet_meshed, inplace=True) | ||
|
||
field_magpylib = magnet_meshed.getB(grid) | ||
|
||
np.testing.assert_allclose(field_ansys, field_magpylib, rtol=0, atol=0.0065) |
Oops, something went wrong.