How to use micromagneticmodel - 10 common examples

To help you get started, we’ve selected a few micromagneticmodel 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 / evolvers / spintevolver.py View on Github external
import micromagneticmodel as mm


class SpinTEvolver(mm.Evolver):
    """Zhang-Li evolver.

    Only attributes in ``_allowed_attributes`` can be defined. For details on
    possible values for individual attributes and their default values, please
    refer to ``Anv_SpinTEvolve`` documentation
    (https://www.zurich.ibm.com/st/nanomagnetism/spintevolve.html).

    Examples
    --------
    1. Defining evolver with a keyword argument.

    >>> import oommfc as oc
    ...
    >>> evolver = oc.SpinTEvolver(method='rk4')

    2. Passing an argument which is not allowed.
github ubermag / oommfc / oommfc / evolvers / cgevolver.py View on Github external
import micromagneticmodel as mm


class CGEvolver(mm.Evolver):
    """Conjugate-Gradient evolver.

    Only attributes in ``_allowed_attributes`` can be defined. For details on
    possible values for individual attributes and their default values, please
    refer to ``Oxs_CGEvolver`` documentation (https://math.nist.gov/oommf/).

    Examples
    --------
    1. Defining evolver with a keyword argument.

    >>> import oommfc as oc
    ...
    >>> evolver = oc.CGEvolver(method='Polak-Ribiere')

    2. Passing an argument which is not allowed.
github ubermag / oommfc / oommfc / evolvers / eulerevolver.py View on Github external
import micromagneticmodel as mm


class EulerEvolver(mm.Evolver):
    """Euler evolver.

    Only attributes in ``_allowed_attributes`` can be defined. For details on
    possible values for individual attributes and their default values, please
    refer to ``Oxs_EulerEvolver`` documentation (https://math.nist.gov/oommf/).

    Examples
    --------
    1. Defining evolver with a keyword argument.

    >>> import oommfc as oc
    ...
    >>> evolver = oc.EulerEvolver(min_timestep=0)

    2. Passing an argument which is not allowed.
github ubermag / oommfc / oommfc / evolvers / rungekuttaevolver.py View on Github external
import micromagneticmodel as mm


class RungeKuttaEvolver(mm.Evolver):
    """Runge-Kutta evolver.

    Only attributes in ``_allowed_attributes`` can be defined. For details on
    possible values for individual attributes and their default values, please
    refer to ``Oxs_RungeKuttaEvolver`` documentation
    (https://math.nist.gov/oommf/).

    Examples
    --------
    1. Defining evolver with a keyword argument.

    >>> import oommfc as oc
    ...
    >>> evolver = oc.RungeKuttaEvolver(method='rk4')

    2. Passing an argument which is not allowed.
github ubermag / oommfc / oommfc / dynamics / damping.py View on Github external
import micromagneticmodel as mm


class Damping(mm.Damping):
    """Gilbert damping dynamics term.

    This dynamics term models the Gilbert damping in the
    Landau-Lifshitz-Gilbert equation. It is defined by the Gilbert
    damping `alpha`. `alpha` is a scalar value with no units.

    .. math::

           \\frac{\\text{d}\\mathbf{m}}{\\text{d}t} = -\\alpha
           \\left(\\mathbf{m} \\times
           \\frac{\\text{d}\\mathbf{m}}{\\text{d}t} \\right)

    `alpha` can be either contant in space or spatially varying. If it
    is constant, a single value is passed, e.g. `alpha = 0.01`. On
    the other hand, if it varies in space, there are two ways how that
    can be defined. The first one is using a dictionary, where the
github ubermag / oommfc / oommfc / scripts / driver.py View on Github external
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.
        if mm.Precession() in system.dynamics:
            driver.evolver.gamma_G = system.dynamics.precession.gamma0
        else:
            driver.evolver.do_precess = 0
        if mm.Damping() in system.dynamics:
            driver.evolver.alpha = system.dynamics.damping.alpha
        else:
            driver.evolver.alpha = 0
        if mm.ZhangLi() in system.dynamics:
            driver.evolver.u = system.dynamics.zhangli.u
            driver.evolver.beta = system.dynamics.zhangli.beta
        if mm.Slonczewski() in system.dynamics:
            driver.evolver.J = system.dynamics.slonczewski.J
            driver.evolver.mp = system.dynamics.slonczewski.mp
            driver.evolver.P = system.dynamics.slonczewski.P
            driver.evolver.Lambda = system.dynamics.slonczewski.Lambda
            driver.evolver.eps_prime = system.dynamics.slonczewski.eps_prime

        mif += oc.scripts.evolver_script(driver.evolver)

        # Extract time and number of steps.
github ubermag / oommfc / oommfc / hamiltonian / hamiltonian.py View on Github external
import micromagneticmodel as mm


class Hamiltonian(mm.Energy):
    """Hamiltonian

    This class implements the sum of individual energy terms. It is
    obtained as a result of addition of two or more energy terms.

    Examples
    --------
    1. Adding an energy term to the Hamiltonian.

    >>> import oommfc as oc
    ...
    >>> hamiltonian = oc.Hamiltonian()
    >>> hamiltonian += mm.DMI(D=1e-3, crystalclass='Cnv')

    2. Creating the Hamiltoninan as a sum of two energy terms
github ubermag / oommfc / oommfc / compute.py View on Github external
def schedule_script(func, system):
    """Generate OOMMF ``Schedule...`` line for saving an individual value.

    """
    if func.__name__ == 'energy':
        return ''  # Datatable with energies is saved by default.
    elif func.__name__ == 'effective_field':
        if isinstance(func.__self__, mm.Energy):
            output = 'Oxs_RungeKuttaEvolve:evolver:Total field'
        else:
            output = (f'Oxs_{oxs_class(func.__self__, system)}:'
                      f'{func.__self__.name}:Field')
    elif func.__name__ == 'density':
        if isinstance(func.__self__, mm.Energy):
            output = 'Oxs_RungeKuttaEvolve:evolver:Total energy density'
        else:
            output = (f'Oxs_{oxs_class(func.__self__, system)}:'
                      f'{func.__self__.name}:Energy density')
    else:
        msg = f'Computing the value of {func} is not supported.'
        raise ValueError(msg)

    return 'Schedule \"{}\" archive Step 1\n'.format(output)
github ubermag / oommfc / oommfc / compute.py View on Github external
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)
        if isinstance(func.__self__, mm.Energy):
            output = table.data['RungeKuttaEvolve:evolver:Total energy'][0]
        else:
            output = table.data[(f'{oxs_class(func.__self__, system)}:'
                                 f'{func.__self__.name}:Energy')][0]
    else:
        output = df.Field.fromfile(output_file)

    return output
github ubermag / oommfc / oommfc / scripts / driver.py View on Github external
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.
        if mm.Precession() in system.dynamics:
            driver.evolver.gamma_G = system.dynamics.precession.gamma0
        else:
            driver.evolver.do_precess = 0
        if mm.Damping() in system.dynamics:
            driver.evolver.alpha = system.dynamics.damping.alpha
        else:
            driver.evolver.alpha = 0
        if mm.ZhangLi() in system.dynamics:
            driver.evolver.u = system.dynamics.zhangli.u
            driver.evolver.beta = system.dynamics.zhangli.beta
        if mm.Slonczewski() in system.dynamics:
            driver.evolver.J = system.dynamics.slonczewski.J
            driver.evolver.mp = system.dynamics.slonczewski.mp
            driver.evolver.P = system.dynamics.slonczewski.P
            driver.evolver.Lambda = system.dynamics.slonczewski.Lambda
            driver.evolver.eps_prime = system.dynamics.slonczewski.eps_prime