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
2 changes: 1 addition & 1 deletion micromagnetictests/calculatortests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .energy import TestEnergy
from .exchange import TestExchange
from .fixedsubregions import TestFixedSubregions
from .hysteresisdriver import test_simple_hysteresis_loop
from .hysteresisdriver import 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
38 changes: 34 additions & 4 deletions micromagnetictests/calculatortests/hysteresisdriver.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import discretisedfield as df
import micromagneticmodel as mm
import numpy as np
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 @@ -14,19 +20,43 @@ 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

assert system.table.x == "B_hysteresis"

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)
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) == 30
assert len(tests) == 31
samjrholt marked this conversation as resolved.
Show resolved Hide resolved
Loading