Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for new Hsteps keyword argument #46

Merged
6 changes: 5 additions & 1 deletion micromagnetictests/calculatortests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from .energy import TestEnergy
from .exchange import TestExchange
from .fixedsubregions import TestFixedSubregions
from .hysteresisdriver import test_check_for_energy, test_simple_hysteresis_loop
from .hysteresisdriver import (
test_check_for_energy,
test_simple_hysteresis_loop,
test_stepped_hysteresis_loop,
)
from .info_file import test_info_file
from .mesh import TestMesh
from .mindriver import TestMinDriver
Expand Down
37 changes: 33 additions & 4 deletions micromagnetictests/calculatortests/hysteresisdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
import pytest


def test_simple_hysteresis_loop(calculator):
"""Simple hysteresis loop between Hmin and Hmax with symmetric number of steps."""
@pytest.fixture
def Ms():
return 1e6


@pytest.fixture
def system(Ms):
system = mm.System(name="hysteresisdriver_noevolver_nodriver")

A = 1e-12
Expand All @@ -15,15 +20,18 @@ def test_simple_hysteresis_loop(calculator):
p1 = (0, 0, 0)
p2 = (5e-9, 5e-9, 5e-9)
n = (5, 5, 5)
Ms = 1e6
region = df.Region(p1=p1, p2=p2)
mesh = df.Mesh(region=region, n=n)
system.m = df.Field(mesh, nvdim=3, value=(0, 1, 0), norm=Ms)
return system


def test_simple_hysteresis_loop(calculator, system, Ms):
"""Simple hysteresis loop between Hmin and Hmax with symmetric number of steps."""
hd = calculator.HysteresisDriver()
hd.drive(system, Hmin=(0, 0, -1e6), Hmax=(0, 0, 1e6), n=3)

value = system.m(mesh.region.random_point())
value = system.m(system.m.mesh.region.random_point())
assert np.linalg.norm(np.subtract(value, (0, 0, Ms))) < 1e-3

assert len(system.table.data.index) == 5
Expand All @@ -33,6 +41,27 @@ def test_simple_hysteresis_loop(calculator):
calculator.delete(system)


def test_stepped_hysteresis_loop(calculator, system, Ms):
"""Simple hysteresis loop with uneven steps using `Hsteps` as keyword argument."""
hd = calculator.HysteresisDriver()
hd.drive(
system,
Hsteps=[
[(0, 0, -1e6), (0, 0, 1e6), 3],
[(0, 0, 1e6), (0, 0, -1e6), 5],
],
)

value = system.m(system.m.mesh.region.random_point())
assert np.linalg.norm(np.subtract(value, (0, 0, Ms))) < 1e-3

assert len(system.table.data.index) == 7

assert system.table.x == "B_hysteresis"

calculator.delete(system)


def test_check_for_energy(calculator):
system = mm.examples.macrospin()
system.energy = 0
Expand Down
2 changes: 1 addition & 1 deletion micromagnetictests/tests/test_get_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

def test_get_tests():
tests = list(mt.get_tests())
assert len(tests) == 33
assert len(tests) == 34
Loading