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

txt directly to mx3 #54

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
17 changes: 16 additions & 1 deletion mumax3c/drivers/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
17 changes: 16 additions & 1 deletion mumax3c/scripts/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down