Example #1
0
import ubermagutil as uu
import discretisedfield as df
import ubermagutil.typesystem as ts
from .dynamicsterm import DynamicsTerm


@uu.inherit_docs
@ts.typesystem(J=ts.Parameter(descriptor=ts.Scalar(), otherwise=df.Field),
               mp=ts.Parameter(descriptor=ts.Vector(size=3),
                               otherwise=df.Field),
               Lambda=ts.Parameter(descriptor=ts.Scalar(positive=True),
                                   otherwise=df.Field),
               P=ts.Parameter(descriptor=ts.Scalar(positive=True),
                              otherwise=df.Field),
               eps_prime=ts.Parameter(descriptor=ts.Scalar(),
                                      otherwise=df.Field))
class Slonczewski(DynamicsTerm):
    """Slonczewski spin transfer torque dynamics term.

    .. math::

        \\frac{\\text{d}\\mathbf{m}}{\\text{d}t} =
        \\gamma_{0}\\beta\\epsilon(\\mathbf{m} \\times \\mathbf{m}_\\text{p}
        \\times \\mathbf{m}) - \\gamma_{0}\\beta\\epsilon' (\\mathbf{m} \\times
        \\mathbf{m}_\\text{p})

    .. math::

        \\beta = \\left| \\frac{\\hbar}{\\mu_{0}e} \\right|
        \\frac{J}{tM_\\text{s}}
Example #2
0
import ubermagutil as uu
import discretisedfield as df
import ubermagutil.typesystem as ts
from .energyterm import EnergyTerm


@uu.inherit_docs
@ts.typesystem(A=ts.Parameter(descriptor=ts.Scalar(), otherwise=df.Field))
class Exchange(EnergyTerm):
    """Exchange energy term.

    .. math::

        w = - A \\mathbf{m} \\cdot \\nabla^{2} \\mathbf{m}

    Parameters
    ----------
    A : numbers.Real, dict, discretisedfield.Field

        If a single unsigned value ``numbers.Real`` is passed, a spatially
        constant parameter is defined. For a spatially varying parameter,
        either a dictionary, e.g. ``A={'region1': 1e-12, 'region2': 5e-12}``
        (if the parameter is defined "per region") or
        ``discretisedfield.Field`` is passed.

    Examples
    --------
    1. Defining the exchange energy term using scalar.

    >>> import micromagneticmodel as mm
    ...
import ubermagutil as uu
import discretisedfield as df
import ubermagutil.typesystem as ts
from .energyterm import EnergyTerm


@uu.inherit_docs
@ts.typesystem(K=ts.Parameter(descriptor=ts.Scalar(), otherwise=df.Field),
               u=ts.Parameter(descriptor=ts.Vector(size=3),
                              otherwise=df.Field))
class UniaxialAnisotropy(EnergyTerm):
    """Uniaxial anisotropy energy term.

    .. math::

        w = -K (\\mathbf{m} \\cdot \\mathbf{u})^{2}

    Parameters
    ----------
    K : numbers.Real, dict, discretisedfield.Field

        If a single value ``numbers.Real`` is passed, a spatially constant
        parameter is defined. For a spatially varying parameter, either a
        dictionary, e.g. ``K={'region1': 1e6, 'region2': 5e5}`` (if the
        parameter is defined "per region") or ``discretisedfield.Field`` is
        passed.

    u : (3,) array_like, dict, discretisedfield.Field

        If a single length-3 array_like (tuple, list, ``numpy.ndarray``) is
        passed, which consists of ``numbers.Real``, a spatially constant
import ubermagutil as uu
import discretisedfield as df
import ubermagutil.typesystem as ts
from .energyterm import EnergyTerm


@uu.inherit_docs
@ts.typesystem(H=ts.Parameter(descriptor=ts.Vector(size=3),
                              otherwise=df.Field),
               wave=ts.Subset(sample_set={'sin', 'sinc'}, unpack=False),
               f=ts.Scalar(positive=True),
               t0=ts.Scalar())
class Zeeman(EnergyTerm):
    """Zeeman energy term.

    .. math::

        w = -\\mu_{0}M_\\text{s} \\mathbf{m} \\cdot \\mathbf{H}

    Zeeman energy term allows defining time-dependent as well as
    time-independent external magnetic field. If only external magnetic field
    ``H`` is passed, a time-constant field is defined. On the other hand, in
    order to define a time-dependent field, ``wave`` must be passed as a
    string. ``wave`` can be either ``'sine'`` or ``'sinc'``. If time-dependent
    external magnetic field is defined, apart from ``wave``, ``f`` and ``t0``
    must be passed. For ``wave='sine'``, energy density is:

    .. math::

        w = -\\mu_{0}M_\\text{s} \\mathbf{m} \\cdot \\mathbf{H} \\sin[2\\pi
        f(t-t_{0})]
import ubermagutil as uu
import discretisedfield as df
import ubermagutil.typesystem as ts
from .energyterm import EnergyTerm


@uu.inherit_docs
@ts.typesystem(B1=ts.Parameter(descriptor=ts.Scalar(), otherwise=df.Field),
               B2=ts.Parameter(descriptor=ts.Scalar(), otherwise=df.Field),
               e_diag=ts.Parameter(descriptor=ts.Vector(size=3),
                                   otherwise=df.Field),
               e_offdiag=ts.Parameter(descriptor=ts.Vector(size=3),
                                      otherwise=df.Field))
class MagnetoElastic(EnergyTerm):
    """Magneto-elastic energy term.

    .. math::

        w = B_{1}\\sum_{i} m_{i}\\epsilon_{ii} + B_{2}\\sum_{i}\\sum_{j\\ne i}
        m_{i}m_{j}\\epsilon_{ij}

    Parameters
    ----------
    B1/B2 : numbers.Real, dict, discretisedfield.Field

        If a single value ``numbers.Real`` is passed, a spatially constant
        parameter is defined. For a spatially varying parameter, either a
        dictionary, e.g. ``B1={'region1': 1e7, 'region2': 5e7}`` (if the
        parameter is defined "per region") or ``discretisedfield.Field`` is
        passed.
Example #6
0
import ubermagutil as uu
import discretisedfield as df
import ubermagutil.typesystem as ts
from .dynamicsterm import DynamicsTerm


@uu.inherit_docs
@ts.typesystem(gamma0=ts.Parameter(descriptor=ts.Scalar(unsigned=True),
                                   otherwise=df.Field))
class Precession(DynamicsTerm):
    """Precession dynamics term.

    .. math::

        \\frac{\\text{d}\\mathbf{m}}{\\text{d}t} = -\\frac{\\gamma_{0}}{1 +
        \\alpha^{2}} \\mathbf{m} \\times \\mathbf{H}_\\text{eff}

    Parameters
    ----------
    gamma0 : numbers.Real, dict, discretisedfield.Field

        If a single unsigned value ``numbers.Real`` is passed, a spatially
        constant parameter is defined. For a spatially varying parameter,
        either a dictionary, e.g. ``gamma={'region1': 1e5, 'region2': 5e5}``
        (if the parameter is defined "per region") or
        ``discretisedfield.Field`` is passed.

    Examples
    --------
    1. Defining the precession dynamics term using scalar.
Example #7
0
        key_descriptor=ts.Scalar(),
        value_descriptor=ts.Vector(size=3),
        otherwise=str,
        allow_empty=False,
    ),
    d3=ts.Dictionary(key_descriptor=ts.Name(), value_descriptor=ts.Scalar()),
    d4c=ts.Dictionary(
        key_descriptor=ts.Name(),
        value_descriptor=ts.Typed(expected_type=str),
        const=True,
    ),
    ss1=ts.Subset(sample_set=set([1, 2, "5"]), unpack=False),
    ss2=ts.Subset(sample_set=set([-1, 5]), unpack=False),
    ss3=ts.Subset(sample_set="xyz", unpack=True, otherwise=float),
    ss4c=ts.Subset(sample_set="abc", unpack=True, const=True),
    p1=ts.Parameter(),
    p2=ts.Parameter(descriptor=ts.Scalar(expected_type=int)),
    p3=ts.Parameter(descriptor=ts.Scalar(positive=True)),
    p4=ts.Parameter(descriptor=ts.Vector(size=3), otherwise=float),
    p5c=ts.Parameter(descriptor=ts.Scalar(), const=True),
)
class DecoratedClass:
    def __init__(self, **kwargs):
        for key, value in kwargs.items():
            setattr(self, key, value)


def test_typed():
    dc = DecoratedClass()

    # Valid sets