diff --git a/mumax3c/drivers/driver.py b/mumax3c/drivers/driver.py index 710efb1..666b37a 100644 --- a/mumax3c/drivers/driver.py +++ b/mumax3c/drivers/driver.py @@ -39,7 +39,15 @@ def schedule_kwargs_setup(self, abspath=True, **kwargs): def _write_input_files(self, system, **kwargs): self.write_mx3(system, **kwargs) - def write_mx3(self, system, dirname=".", ovf_format="bin8", abspath=True, **kwargs): + def write_mx3( + self, + system, + dirname=".", + ovf_format="bin8", + mx3_txt=None, + abspath=True, + **kwargs, + ): """Write the mx3 file and related files. Takes ``micromagneticmodel.System`` and write the mx3 file (and related files) @@ -75,6 +83,12 @@ def write_mx3(self, system, dirname=".", ovf_format="bin8", abspath=True, **kwar single precision) or ``'txt'`` (text-based, double precision). Defaults to ``'bin8'``. + mx3_txt : str, optional + + Directly input string into mx3 file at a position immediately + before the type of driver explicity written. + + abspath : bool, optional If ``abspath=True`` absolute paths for additional input files (e.g. initial @@ -92,6 +106,7 @@ def write_mx3(self, system, dirname=".", ovf_format="bin8", abspath=True, **kwar system, compute=None, # TODO does mumax3 support compute? ovf_format=ovf_format, + mx3_txt=mx3_txt, **kwargs, ) with open(self._mx3filename(system), "wt", encoding="utf-8") as mx3file: diff --git a/mumax3c/scripts/driver.py b/mumax3c/scripts/driver.py index 35d7daf..d2e80f8 100644 --- a/mumax3c/scripts/driver.py +++ b/mumax3c/scripts/driver.py @@ -5,7 +5,9 @@ import mumax3c as mc -def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): +def driver_script( + driver, system, compute=None, ovf_format="bin4", mx3_txt=None, **kwargs +): mx3 = "tableadd(E_total)\n" mx3 += "tableadd(dt)\n" mx3 += "tableadd(maxtorque)\n" @@ -14,6 +16,10 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): if attr != "evolver": mx3 += f"{attr} = {value}\n" + if mx3_txt is not None: + mx3 += "\n" + mx3 += mx3_txt + mx3 += "\n" mx3 += "minimize()\n\n" mx3 += "save(m_full)\n" mx3 += "tablesave()\n\n" @@ -28,6 +34,10 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): if attr != "evolver": mx3 += f"{attr} = {value}\n" + if mx3_txt is not None: + mx3 += "\n" + mx3 += mx3_txt + mx3 += "\n" mx3 += "relax()\n\n" mx3 += "save(m_full)\n" mx3 += "tablesave()\n\n" @@ -77,6 +87,11 @@ def driver_script(driver, system, compute=None, ovf_format="bin4", **kwargs): mx3 += "setsolver(5)\n" mx3 += "fixDt = 0\n\n" + if mx3_txt is not None: + mx3 += "\n" + mx3 += mx3_txt + mx3 += "\n" + t, n = kwargs["t"], kwargs["n"] mx3 += f"for snap_counter:=0; snap_counter<{n}; snap_counter++{{\n"