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 new option "Hsteps" to HysteresisDriver #138

Merged
merged 16 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions oommfc/drivers/hysteresisdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,31 @@
]

def _checkargs(self, **kwargs):
lang-m marked this conversation as resolved.
Show resolved Hide resolved
Hmin, Hmax, n = kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]
for i in [Hmin, Hmax]:
# check the default arguments for a symmetric hysteresis loop
if any(item in kwargs for item in ["Hmin", "Hmax", "n"]) and "Hsteps" in kwargs:
msg = "Cannot define both (Hmin, Hmax, n) and Hsteps."
raise ValueError(msg)

Check warning on line 65 in oommfc/drivers/hysteresisdriver.py

View check run for this annotation

Codecov / codecov/patch

oommfc/drivers/hysteresisdriver.py#L64-L65

Added lines #L64 - L65 were not covered by tests

if all(item in kwargs for item in ["Hmin", "Hmax", "n"]):
newton-per-sqm marked this conversation as resolved.
Show resolved Hide resolved
self._checkvalues(kwargs["Hmin"], kwargs["Hmax"], kwargs["n"])
newton-per-sqm marked this conversation as resolved.
Show resolved Hide resolved
elif "Hsteps" in kwargs:
for Hstart, Hend, n in kwargs["Hsteps"]:
self._checkvalues(Hstart, Hend, n)

Check warning on line 71 in oommfc/drivers/hysteresisdriver.py

View check run for this annotation

Codecov / codecov/patch

oommfc/drivers/hysteresisdriver.py#L69-L71

Added lines #L69 - L71 were not covered by tests
lang-m marked this conversation as resolved.
Show resolved Hide resolved
else:
msg = (

Check warning on line 73 in oommfc/drivers/hysteresisdriver.py

View check run for this annotation

Codecov / codecov/patch

oommfc/drivers/hysteresisdriver.py#L73

Added line #L73 was not covered by tests
"Some of the required arguments are missing. "
"(Hmin, Hmax, n) or Hsteps must be defined."
)
raise ValueError(msg)

Check warning on line 77 in oommfc/drivers/hysteresisdriver.py

View check run for this annotation

Codecov / codecov/patch

oommfc/drivers/hysteresisdriver.py#L77

Added line #L77 was not covered by tests

@staticmethod
def _checkvalues(Hstart, Hend, n):
for i in [Hstart, Hend]:
if not isinstance(i, (list, tuple, np.ndarray)):
msg = "Hmin and Hmax must have array_like values."
msg = "Hstart (Hmin) and Hend (Hmax) must have array_like values."

Check warning on line 83 in oommfc/drivers/hysteresisdriver.py

View check run for this annotation

Codecov / codecov/patch

oommfc/drivers/hysteresisdriver.py#L83

Added line #L83 was not covered by tests
raise ValueError(msg)
if len(i) != 3:
msg = "Hmin and Hmax must have length 3."
msg = "Hstart (Hmin) and Hend (Hmax) must have length 3."

Check warning on line 86 in oommfc/drivers/hysteresisdriver.py

View check run for this annotation

Codecov / codecov/patch

oommfc/drivers/hysteresisdriver.py#L86

Added line #L86 was not covered by tests
raise ValueError(msg)
if not isinstance(n, int):
msg = f"Cannot drive with {type(n)=}."
Expand Down
10 changes: 7 additions & 3 deletions oommfc/scripts/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@
mif += oc.scripts.evolver_script(driver.evolver)

# Oxs_UZeeman
Hmin, Hmax, n = kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]
mif += "# OxS_UZeeman\n"
mif += "Specify Oxs_UZeeman:hysteresis {\n"
mif += " Hrange {\n"
mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hmin, *Hmax, n - 1)
mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hmax, *Hmin, n - 1)
if all(item in kwargs for item in ["Hmin", "Hmax", "n"]):
Hmin, Hmax, n = kwargs["Hmin"], kwargs["Hmax"], kwargs["n"]
mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hmin, *Hmax, n - 1)
mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hmax, *Hmin, n - 1)
elif "Hsteps" in kwargs:
for Hstart, Hend, n in kwargs["Hsteps"]:
mif += " {{ {} {} {} {} {} {} {} }}\n".format(*Hstart, *Hend, n - 1)

Check warning on line 41 in oommfc/scripts/driver.py

View check run for this annotation

Codecov / codecov/patch

oommfc/scripts/driver.py#L39-L41

Added lines #L39 - L41 were not covered by tests
lang-m marked this conversation as resolved.
Show resolved Hide resolved
mif += " }\n"
mif += "}\n\n"

Expand Down