diff --git a/README.md b/README.md index 03742c0..f489205 100644 --- a/README.md +++ b/README.md @@ -83,3 +83,19 @@ 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 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) +``` 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. 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" diff --git a/mumax3c/scripts/driver.py b/mumax3c/scripts/driver.py index ada3e4e..23abecd 100644 --- a/mumax3c/scripts/driver.py +++ b/mumax3c/scripts/driver.py @@ -9,6 +9,7 @@ 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 isinstance(driver, mc.MinDriver): for attr, value in driver: if attr != "evolver": @@ -32,7 +33,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 @@ -78,12 +79,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"] + if isinstance(driver, mc.TimeDriver): + 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): + torque_val0 = kwargs["maxtorque"] - 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 += "}" + mx3 += f"RunWhile(maxtorque > {torque_val0})\n" + mx3 += "save(m_full)\n" + mx3 += "tablesave()\n" return mx3