Skip to content

Commit

Permalink
add tests for checking energy and dynamics in the system
Browse files Browse the repository at this point in the history
  • Loading branch information
kzqureshi committed Jan 30, 2024
1 parent 2df6c99 commit 37b6673
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
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_check_for_energy, test_simple_hysteresis_loop
from .info_file import test_info_file
from .mesh import TestMesh
from .mindriver import TestMinDriver
Expand Down
10 changes: 10 additions & 0 deletions micromagnetictests/calculatortests/hysteresisdriver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import discretisedfield as df
import micromagneticmodel as mm
import numpy as np
import pytest


def test_simple_hysteresis_loop(calculator):
Expand Down Expand Up @@ -30,3 +31,12 @@ def test_simple_hysteresis_loop(calculator):
assert system.table.x == "B_hysteresis"

calculator.delete(system)


def test_check_for_energy(calculator):
system = mm.examples.macrospin()
system.energy = 0
td = calculator.TimeDriver()

with pytest.raises(RuntimeError, match="System's energy is not defined"):
td.drive(system, t=1e-12, n=1)
8 changes: 8 additions & 0 deletions micromagnetictests/calculatortests/mindriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,11 @@ def test_wrong_evolver(self):
md.drive(system)

self.calculator.delete(system)

def test_check_for_energy(self):
system = mm.examples.macrospin()
system.energy = 0
td = self.calculator.TimeDriver()

with pytest.raises(RuntimeError, match="System's energy is not defined"):
td.drive(system, t=1e-12, n=1)
13 changes: 13 additions & 0 deletions micromagnetictests/calculatortests/timedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,16 @@ def test_wrong_evolver(self):
td.drive(system, t=1e-12, n=1)

self.calculator.delete(system)

def test_check_for_energy_and_dynamics(self):
system = mm.examples.macrospin()
system.energy = 0
td = self.calculator.TimeDriver()

with pytest.raises(RuntimeError, match="System's energy is not defined"):
td.drive(system, t=1e-12, n=1)

system.dynamics = 0

with pytest.raises(RuntimeError, match="System's dynamics is not defined"):
td.drive(system, t=1e-12, n=1)
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

0 comments on commit 37b6673

Please sign in to comment.