How to use the oommfc.TimeDriver function in oommfc

To help you get started, we’ve selected a few oommfc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ubermag / oommfc / oommfc / compute.py View on Github external
>>> import micromagneticmodel as mm
    >>> import oommfc as oc
    ...
    >>> system = mm.examples.macrospin()
    >>> oc.compute(system.energy.zeeman.energy, system)
    Running OOMMF...
    -8.8...e-22
    >>> oc.compute(system.energy.effective_field, system)
    Running OOMMF...
    Field(...)
    >>> oc.compute(system.energy.density, system)
    Running OOMMF...
    Field(...)

    """
    td = oc.TimeDriver(total_iteration_limit=1)
    td.drive(system, t=1e-25, n=1, append=True,
             compute=schedule_script(func, system))

    if func.__name__ == 'energy':
        extension = '*.odt'
    elif func.__name__ == 'effective_field':
        extension = '*.ohf'
    elif func.__name__ == 'density':
        extension = '*.oef'

    dirname = os.path.join(system.name, f'compute-{system.compute_number-1}')
    output_file = max(glob.iglob(os.path.join(dirname, extension)),
                      key=os.path.getctime)

    if func.__name__ == 'energy':
        table = ut.Table.fromfile(output_file, rename=False)
github ubermag / oommfc / oommfc / data.py View on Github external
def effective_field(self):
        _dict = {'Demag': 'Oxs_Demag::Field',
                 'Exchange': 'Oxs_UniformExchange::Field',
                 'UniaxialAnisotropy': 'Oxs_UniaxialAnisotropy::Field',
                 'Zeeman': 'Oxs_FixedZeeman::Field',
                 'Hamiltonian': 'Oxs_RungeKuttaEvolve:evolver:Total field'}

        td = oc.TimeDriver()
        td.drive(self.system, derive=_dict[self.cls])

        dirname = os.path.join(self.system.name,
                               f'drive-{self.system.drive_number-1}')
        ohf_file = max(glob.iglob(os.path.join(dirname, '*.ohf')),
                       key=os.path.getctime)

        return df.Field.fromfile(ohf_file)
github ubermag / oommfc / oommfc / oommf / oommf.py View on Github external
Examples
    --------
    1. Checking the OOMMF status.

    >>> import oommfc as oc
    ...
    >>> oc.oommf.status()
    Running OOMMF...
    OOMMF found and running.
    0

    """
    system = mm.examples.macrospin()
    try:
        td = oc.TimeDriver()
        td.drive(system, t=1e-12, n=1)
        print('OOMMF found and running.')
        return 0
    except (EnvironmentError, RuntimeError):
        print('Cannot find OOMMF.')
        return 1
github ubermag / oommfc / oommfc / data.py View on Github external
def energy_density(self):
        _dict = {'Demag': 'Oxs_Demag::Energy density',
                 'Exchange': 'Oxs_UniformExchange::Energy density',
                 'UniaxialAnisotropy': ('Oxs_UniaxialAnisotropy::'
                                        'Energy density'),
                 'Zeeman': 'Oxs_FixedZeeman::Energy density',
                 'Hamiltonian': ('Oxs_RungeKuttaEvolve:evolver:'
                                 'Total energy density')}

        td = oc.TimeDriver()
        td.drive(self.system, derive=_dict[self.cls])

        dirname = os.path.join(self.system.name,
                               f'drive-{self.system.drive_number-1}')
        oef_file = max(glob.iglob(os.path.join(dirname, '*.oef')),
                       key=os.path.getctime)

        return df.Field.fromfile(oef_file)
github ubermag / oommfc / oommfc / scripts / driver.py View on Github external
mif += '  evolver :evolver\n'
        mif += '  mesh :mesh\n'
        mif += '  Ms :m0_norm\n'
        mif += '  m0 :m0\n'
        for attr, value in driver:
            if attr != 'evolver':
                mif += f'  {attr} {value}\n'
        mif += '}\n\n'

        # Saving results.
        mif += 'Destination table mmArchive\n'
        mif += 'Destination mags mmArchive\n\n'
        mif += 'Schedule DataTable table Stage 1\n'
        mif += 'Schedule Oxs_MinDriver::Magnetization mags Stage 1'

    if isinstance(driver, oc.TimeDriver):
        # Check evolver and set default if not passed.
        if not hasattr(driver, 'evolver'):
            if mm.ZhangLi() in system.dynamics:
                driver.evolver = oc.SpinTEvolver()
            elif mm.Slonczewski() in system.dynamics:
                driver.evolver = oc.SpinXferEvolver()
            else:
                driver.evolver = oc.RungeKuttaEvolver()
        elif not isinstance(driver.evolver, (oc.EulerEvolver,
                                             oc.RungeKuttaEvolver,
                                             oc.SpinTEvolver,
                                             oc.SpinXferEvolver)):
            msg = f'Cannot use {type(driver.evolver)} for evolver.'
            raise TypeError(msg)

        # Extract dynamics equation parameters.
github ubermag / oommfc / oommfc / data.py View on Github external
def energy(self):
        _dict = {'Demag': 'Demag::Energy',
                 'Exchange': 'UniformExchange::Energy',
                 'UniaxialAnisotropy': 'UniaxialAnisotropy::Energy',
                 'Zeeman': 'FixedZeeman::Energy',
                 'Hamiltonian': 'RungeKuttaEvolve:evolver:Total energy'}
        td = oc.TimeDriver()
        td.drive(self.system, derive='energy')

        dirname = os.path.join(self.system.name,
                               f'drive-{self.system.drive_number-1}')
        odt_file = max(glob.iglob(os.path.join(dirname, '*.odt')),
                       key=os.path.getctime)

        dt = ut.read(odt_file, rename=False)

        return dt[_dict[self.cls]][0]
github ubermag / oommfc / oommfc / oommf / oommf.py View on Github external
and directly.

    Examples
    --------
    1. Getting the overhead time.

    >>> import oommfc as oc
    ...
    >>> isinstance(oc.oommf.overhead(), float)
    Running OOMMF...
    True

    """
    # Running OOMMF through oommfc.
    system = mm.examples.macrospin()
    td = oc.TimeDriver()
    oommfc_start = time.time()
    td.drive(system, t=1e-12, n=1, save=True, overwrite=True)
    oommfc_stop = time.time()
    oommfc_time = oommfc_stop - oommfc_start

    # Running OOMMF directly.
    oommf_runner = get_oommf_runner()
    mifpath = os.path.realpath(os.path.join(system.name,
                                            'drive-0',
                                            'macrospin.mif'))
    oommf_start = time.time()
    oommf_runner.call(mifpath)
    oommf_stop = time.time()
    oommf_time = oommf_stop - oommf_start
    oc.delete(system)