Skip to content

Commit

Permalink
Support dict and Field for ZhangLi.u
Browse files Browse the repository at this point in the history
  • Loading branch information
lang-m committed Jul 14, 2024
1 parent e536a94 commit 7406065
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
24 changes: 18 additions & 6 deletions mumax3c/scripts/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,30 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs):

if system.dynamics.get(type=mm.ZhangLi):
(zh_li_term,) = system.dynamics.get(type=mm.ZhangLi)
if isinstance(zh_li_term.u, df.Field):
raise RuntimeError("Setting Zhang Li u with a 'Fiel' is not supported.")
if isinstance(zh_li_term.u, df.Field) and zh_li_term.u.nvdim == 3:
u = zh_li_term.u
elif isinstance(zh_li_term.u, df.Field) and zh_li_term.u.nvdim == 1:
zero_field = df.Field(
mesh=system.m.mesh,
nvdim=1,
value=0.0,
)
u = zh_li_term.u << zero_field << zero_field
elif isinstance(zh_li_term.u, numbers.Real):
u = df.Field(
mesh=system.m.mesh,
nvdim=3,
value=(1.0, 0.0, 0.0),
norm=zh_li_term.u,
value=(zh_li_term.u, 0.0, 0.0),
)
elif isinstance(zh_li_term.u, dict):
raise NotImplementedError(
"Setting Zhang Li u with a 'dict' is not yet supported."
if isinstance(list(zh_li_term.u.values())[0], numbers.Real):
u_values = {key: (value, 0.0, 0.0) for key, value in zh_li_term.u.items()}
else:
u_values = zh_li_term.u
u = df.Field(
mesh=system.m.mesh,
nvdim=3,
value=u_values,
)
else: # array_like
u = df.Field(mesh=system.m.mesh, nvdim=3, value=zh_li_term.u)
Expand Down
5 changes: 2 additions & 3 deletions mumax3c/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"TestDamping.test_field",
"TestDynamics.test_field_field",
"TestSlonczewski.test_field_values",
"TestZhangLi.test_field_scalar",
"TestZhangLi.test_time_tcl_scalar_u",
"TestUniaxialAnisotropy.test_field_vector",
"TestUniaxialAnisotropy.test_scalar_field",
"TestUniaxialAnisotropy.test_field_field",
Expand All @@ -54,8 +54,7 @@
"TestSlonczewski.test_single_values",
"TestSlonczewski.test_single_values_finite_temperature",
"TestSlonczewski.test_dict_values",
"TestZhangLi.test_dict_scalar",
"TestZhangLi.test_time_scalar_scalar",
"TestZhangLi.test_time_func_scalar_u",
"test_multiple_drives_compute",
"TestPrecession.test_scalar",
"TestDMI.test_scalar",
Expand Down

0 comments on commit 7406065

Please sign in to comment.