From 44883e0997aa946d0229a3538f278c68ecd017a6 Mon Sep 17 00:00:00 2001 From: Sergei Date: Fri, 16 Feb 2024 09:42:49 +0100 Subject: [PATCH 01/12] Update driver.py --- mumax3c/scripts/driver.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mumax3c/scripts/driver.py b/mumax3c/scripts/driver.py index ada3e4e..c894164 100644 --- a/mumax3c/scripts/driver.py +++ b/mumax3c/scripts/driver.py @@ -9,6 +9,11 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): mx3 = "tableadd(E_total)\n" mx3 += "tableadd(dt)\n" mx3 += "tableadd(maxtorque)\n" + + if system.T > 0: + TK = system.T + mx3 += f"Temp = {TK}\n" + if isinstance(driver, mc.MinDriver): for attr, value in driver: if attr != "evolver": From 5ba6b84d3f965f8462d9357dfd46845c221bd536 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 08:44:54 +0000 Subject: [PATCH 02/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mumax3c/scripts/driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mumax3c/scripts/driver.py b/mumax3c/scripts/driver.py index c894164..27e7737 100644 --- a/mumax3c/scripts/driver.py +++ b/mumax3c/scripts/driver.py @@ -13,7 +13,7 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): if system.T > 0: TK = system.T mx3 += f"Temp = {TK}\n" - + if isinstance(driver, mc.MinDriver): for attr, value in driver: if attr != "evolver": From 1356da24b0e43fbfc0bb8360f4325a7eefbf01f7 Mon Sep 17 00:00:00 2001 From: Sergei Date: Fri, 23 Feb 2024 10:11:25 +0100 Subject: [PATCH 03/12] Update README.md Added description of the changes --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 03742c0..95acf87 100644 --- a/README.md +++ b/README.md @@ -83,3 +83,20 @@ Licensed under the BSD 3-Clause "New" or "Revised" License. For details, please - [OpenDreamKit](http://opendreamkit.org/) – Horizon 2020 European Research Infrastructure project (676541) - EPSRC Programme Grant on [Skyrmionics](http://www.skyrmions.ac.uk) (EP/N032128/1) +- + +## My changes +- Added support for simulations with temperature (pass system.T to mx3 file, so mumax3 can deal with it). +- Added TimeTorqueDriver with limited support of RunWhile() mumax3 simulation. Requires passing maxtorque parameter. The example and corresponding mx3 file lines are below. + +''' +import mumax3c as mc #import the package + +max_torque_allowed = 0.005 # the desired value of MaxTorque to pass into RunWhile() +td = mc.TimeTorqueDriver() # set the driver +td.drive(system, maxtorque=max_torque_allowed, verbose=2) #start simulation +''' + +''' +RunWhile(maxtorque > 0.005) +''' From 22d51974841c98955e42eecc656270deae01e90a Mon Sep 17 00:00:00 2001 From: Sergei Date: Fri, 23 Feb 2024 10:12:11 +0100 Subject: [PATCH 04/12] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 95acf87..8a8d57c 100644 --- a/README.md +++ b/README.md @@ -89,14 +89,14 @@ Licensed under the BSD 3-Clause "New" or "Revised" License. For details, please - Added support for simulations with temperature (pass system.T to mx3 file, so mumax3 can deal with it). - Added TimeTorqueDriver with limited support of RunWhile() mumax3 simulation. Requires passing maxtorque parameter. The example and corresponding mx3 file lines are below. -''' +``` import mumax3c as mc #import the package max_torque_allowed = 0.005 # the desired value of MaxTorque to pass into RunWhile() td = mc.TimeTorqueDriver() # set the driver td.drive(system, maxtorque=max_torque_allowed, verbose=2) #start simulation -''' +``` -''' +``` RunWhile(maxtorque > 0.005) -''' +``` From 92174d4cfa434098fb699b760ef8f8e2a1c60639 Mon Sep 17 00:00:00 2001 From: Sergei Date: Fri, 23 Feb 2024 10:14:25 +0100 Subject: [PATCH 05/12] Add files via upload Add TimeTorque driver --- mumax3c/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mumax3c/__init__.py b/mumax3c/__init__.py index 0765f02..123813c 100644 --- a/mumax3c/__init__.py +++ b/mumax3c/__init__.py @@ -8,7 +8,7 @@ # from .compute import compute # compute is not yet supported from .delete import delete -from .drivers import MinDriver, RelaxDriver, TimeDriver +from .drivers import MinDriver, RelaxDriver, TimeDriver, TimeTorqueDriver runner = mumax3c.mumax3.Runner() """Controls the default runner. From fd39445b3eac331190e3672d27e24b9c82913ada Mon Sep 17 00:00:00 2001 From: Sergei Date: Fri, 23 Feb 2024 10:16:28 +0100 Subject: [PATCH 06/12] Add files via upload timetorque driver --- mumax3c/drivers/__init__.py | 1 + mumax3c/drivers/timetorquedriver.py | 61 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 mumax3c/drivers/timetorquedriver.py diff --git a/mumax3c/drivers/__init__.py b/mumax3c/drivers/__init__.py index 602ee8b..abe7bd9 100644 --- a/mumax3c/drivers/__init__.py +++ b/mumax3c/drivers/__init__.py @@ -2,3 +2,4 @@ from .mindriver import MinDriver from .relaxdriver import RelaxDriver from .timedriver import TimeDriver +from .timetorquedriver import TimeTorqueDriver diff --git a/mumax3c/drivers/timetorquedriver.py b/mumax3c/drivers/timetorquedriver.py new file mode 100644 index 0000000..f8d563b --- /dev/null +++ b/mumax3c/drivers/timetorquedriver.py @@ -0,0 +1,61 @@ +from .driver import Driver + + +class TimeTorqueDriver(Driver): + """Time driver. + + Only attributes in ``_allowed_attributes`` can be defined. For details on + possible values for individual attributes and their default values, please + refer to ``Mumax3`` documentation (https://mumax.github.io). + + Examples + -------- + 1. Defining driver with a keyword argument. + + >>> import mumax3c as mc + ... + >>> td = mc.TimeTorqueDriver(MaxTorque=1e-3) + + 2. Passing an argument which is not allowed. + + >>> import mumax3c as mc + ... + >>> td = mc.TimeTorqueDriver(myarg=1) + Traceback (most recent call last): + ... + AttributeError: ... + + 3. Getting the list of allowed attributes. + + >>> import mumax3c as mc + ... + >>> td = mc.TimeTorqueDriver() + >>> td._allowed_attributes + [...] + + """ + + _allowed_attributes = [ + "DemagAccuracy", + "dt", + "FixDt", + "Headroom", + "LastErr", + "MaxDt", + "MaxErr", + "MinDt", + "NEval", + "PeakErr", + "step", + "maxtorque", + ] + + def _checkargs(self, **kwargs): + maxtorque = kwargs["maxtorque"] + if maxtorque <= 0: + msg = f"Cannot drive with {maxtorque=}." + raise ValueError(msg) + + @property + def _x(self): + return "maxtorque" From f70878eaf3c0aa1242ec148bf620a1eee9f90be9 Mon Sep 17 00:00:00 2001 From: Sergei Date: Fri, 23 Feb 2024 10:17:07 +0100 Subject: [PATCH 07/12] Add files via upload timetorque driver --- mumax3c/scripts/driver.py | 59 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/mumax3c/scripts/driver.py b/mumax3c/scripts/driver.py index 27e7737..01a5dc6 100644 --- a/mumax3c/scripts/driver.py +++ b/mumax3c/scripts/driver.py @@ -9,11 +9,10 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): mx3 = "tableadd(E_total)\n" mx3 += "tableadd(dt)\n" mx3 += "tableadd(maxtorque)\n" - + if system.T > 0: - TK = system.T - mx3 += f"Temp = {TK}\n" - + mx3 += f"Temp = {system.T}\n" + if isinstance(driver, mc.MinDriver): for attr, value in driver: if attr != "evolver": @@ -91,4 +90,56 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): mx3 += " tablesave()\n" mx3 += "}" + if isinstance(driver, mc.TimeTorqueDriver): + # Extract dynamics equation parameters. + gamma0 = ( + precession[0].gamma0 + if (precession := system.dynamics.get(type=mm.Precession)) + else 0 + ) + if system.dynamics.get(type=mm.Damping): + alpha = system.dynamics.damping.alpha + else: + alpha = 0 + + mx3 += f"alpha = {alpha}\n" + if not gamma0: + mx3 += "doprecess = false\n" + else: + mx3 += f"gammaLL = {gamma0/mm.consts.mu0}\n" + mx3 += "doprecess = true\n" + + if system.dynamics.get(type=mm.ZhangLi): + (zh_li_term,) = system.dynamics.get(type=mm.ZhangLi) + u = ( + zh_li_term.u + if isinstance(zh_li_term.u, df.Field) + else df.Field( + mesh=system.m.mesh, + nvdim=3, + value=(1.0, 0.0, 0.0), + norm=zh_li_term.u, + ) + ) + + mu_B = mm.consts.e * mm.consts.hbar / (2.0 * mm.consts.me) + + j = -np.multiply( + u * 2 * (1 + zh_li_term.beta**2) * mm.consts.e / (mm.consts.g * mu_B), + system.m.norm, + ) + j.to_file("j.ovf", representation=ovf_format) + mx3 += f"Xi = {zh_li_term.beta}\n" + mx3 += "Pol = 1\n" # Current polarization is 1. + mx3 += 'J.add(LoadFile("j.ovf"), 1)\n' # 1 means constant in time. + + mx3 += "setsolver(5)\n" + mx3 += "fixDt = 0\n\n" + + torque_val0 = kwargs["maxtorque"] + + mx3 += f"RunWhile(maxtorque > {torque_val0})\n" + mx3 += "save(m_full)\n" + mx3 += "tablesave()\n" + return mx3 From 00082e80eeadd5bf96531af73fc1237936d06460 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 23 Feb 2024 09:17:33 +0000 Subject: [PATCH 08/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mumax3c/scripts/driver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mumax3c/scripts/driver.py b/mumax3c/scripts/driver.py index 01a5dc6..722a9e6 100644 --- a/mumax3c/scripts/driver.py +++ b/mumax3c/scripts/driver.py @@ -9,10 +9,10 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): mx3 = "tableadd(E_total)\n" mx3 += "tableadd(dt)\n" mx3 += "tableadd(maxtorque)\n" - + if system.T > 0: mx3 += f"Temp = {system.T}\n" - + if isinstance(driver, mc.MinDriver): for attr, value in driver: if attr != "evolver": From 0949ddf7b937628a2bbfb47397b691997ea48426 Mon Sep 17 00:00:00 2001 From: Sergei Date: Fri, 23 Feb 2024 10:30:29 +0100 Subject: [PATCH 09/12] Add files via upload Optimized the code --- mumax3c/scripts/driver.py | 74 ++++++++------------------------------- 1 file changed, 15 insertions(+), 59 deletions(-) diff --git a/mumax3c/scripts/driver.py b/mumax3c/scripts/driver.py index 722a9e6..0f3c40a 100644 --- a/mumax3c/scripts/driver.py +++ b/mumax3c/scripts/driver.py @@ -9,10 +9,10 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): mx3 = "tableadd(E_total)\n" mx3 += "tableadd(dt)\n" mx3 += "tableadd(maxtorque)\n" - + if system.T > 0: mx3 += f"Temp = {system.T}\n" - + if isinstance(driver, mc.MinDriver): for attr, value in driver: if attr != "evolver": @@ -36,7 +36,7 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): mx3 += "save(m_full)\n" mx3 += "tablesave()\n\n" - if isinstance(driver, mc.TimeDriver): + if isinstance(driver, mc.TimeDriver) or isinstance(driver, mc.TimeTorqueDriver): # Extract dynamics equation parameters. gamma0 = ( precession[0].gamma0 @@ -82,64 +82,20 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): mx3 += "setsolver(5)\n" mx3 += "fixDt = 0\n\n" - t, n = kwargs["t"], kwargs["n"] - - mx3 += f"for snap_counter:=0; snap_counter<{n}; snap_counter++{{\n" - mx3 += f" run({t/n})\n" - mx3 += " save(m_full)\n" - mx3 += " tablesave()\n" - mx3 += "}" - - if isinstance(driver, mc.TimeTorqueDriver): - # Extract dynamics equation parameters. - gamma0 = ( - precession[0].gamma0 - if (precession := system.dynamics.get(type=mm.Precession)) - else 0 - ) - if system.dynamics.get(type=mm.Damping): - alpha = system.dynamics.damping.alpha - else: - alpha = 0 - - mx3 += f"alpha = {alpha}\n" - if not gamma0: - mx3 += "doprecess = false\n" - else: - mx3 += f"gammaLL = {gamma0/mm.consts.mu0}\n" - mx3 += "doprecess = true\n" - - if system.dynamics.get(type=mm.ZhangLi): - (zh_li_term,) = system.dynamics.get(type=mm.ZhangLi) - u = ( - zh_li_term.u - if isinstance(zh_li_term.u, df.Field) - else df.Field( - mesh=system.m.mesh, - nvdim=3, - value=(1.0, 0.0, 0.0), - norm=zh_li_term.u, - ) - ) - - mu_B = mm.consts.e * mm.consts.hbar / (2.0 * mm.consts.me) - - j = -np.multiply( - u * 2 * (1 + zh_li_term.beta**2) * mm.consts.e / (mm.consts.g * mu_B), - system.m.norm, - ) - j.to_file("j.ovf", representation=ovf_format) - mx3 += f"Xi = {zh_li_term.beta}\n" - mx3 += "Pol = 1\n" # Current polarization is 1. - mx3 += 'J.add(LoadFile("j.ovf"), 1)\n' # 1 means constant in time. + if isinstance(driver, mc.TimeDriver): + t, n = kwargs["t"], kwargs["n"] - mx3 += "setsolver(5)\n" - mx3 += "fixDt = 0\n\n" + mx3 += f"for snap_counter:=0; snap_counter<{n}; snap_counter++{{\n" + mx3 += f" run({t/n})\n" + mx3 += " save(m_full)\n" + mx3 += " tablesave()\n" + mx3 += "}" - torque_val0 = kwargs["maxtorque"] + if isinstance(driver, mc.TimeTorqueDriver): + torque_val0 = kwargs["maxtorque"] - mx3 += f"RunWhile(maxtorque > {torque_val0})\n" - mx3 += "save(m_full)\n" - mx3 += "tablesave()\n" + mx3 += f"RunWhile(maxtorque > {torque_val0})\n" + mx3 += "save(m_full)\n" + mx3 += "tablesave()\n" return mx3 From bae664a3b71d49243d9868592f718521397bf903 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 23 Feb 2024 09:31:12 +0000 Subject: [PATCH 10/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mumax3c/scripts/driver.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mumax3c/scripts/driver.py b/mumax3c/scripts/driver.py index 0f3c40a..de3ad90 100644 --- a/mumax3c/scripts/driver.py +++ b/mumax3c/scripts/driver.py @@ -9,10 +9,10 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): mx3 = "tableadd(E_total)\n" mx3 += "tableadd(dt)\n" mx3 += "tableadd(maxtorque)\n" - + if system.T > 0: mx3 += f"Temp = {system.T}\n" - + if isinstance(driver, mc.MinDriver): for attr, value in driver: if attr != "evolver": @@ -83,7 +83,7 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): mx3 += "fixDt = 0\n\n" if isinstance(driver, mc.TimeDriver): - t, n = kwargs["t"], kwargs["n"] + t, n = kwargs["t"], kwargs["n"] mx3 += f"for snap_counter:=0; snap_counter<{n}; snap_counter++{{\n" mx3 += f" run({t/n})\n" From 5c9578f5e4979cd56647cf920762058e1f03c6b0 Mon Sep 17 00:00:00 2001 From: Sergei Date: Fri, 1 Mar 2024 10:47:09 +0100 Subject: [PATCH 11/12] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 8a8d57c..f489205 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,6 @@ Licensed under the BSD 3-Clause "New" or "Revised" License. For details, please - ## My changes -- Added support for simulations with temperature (pass system.T to mx3 file, so mumax3 can deal with it). - Added TimeTorqueDriver with limited support of RunWhile() mumax3 simulation. Requires passing maxtorque parameter. The example and corresponding mx3 file lines are below. ``` From 29459fe7c7849ac692399f092700f809da457234 Mon Sep 17 00:00:00 2001 From: Sergei Date: Fri, 1 Mar 2024 10:47:52 +0100 Subject: [PATCH 12/12] Update driver.py --- mumax3c/scripts/driver.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/mumax3c/scripts/driver.py b/mumax3c/scripts/driver.py index de3ad90..23abecd 100644 --- a/mumax3c/scripts/driver.py +++ b/mumax3c/scripts/driver.py @@ -10,9 +10,6 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): mx3 += "tableadd(dt)\n" mx3 += "tableadd(maxtorque)\n" - if system.T > 0: - mx3 += f"Temp = {system.T}\n" - if isinstance(driver, mc.MinDriver): for attr, value in driver: if attr != "evolver":