import joommfutil.typesystem as ts from .energyterm import EnergyTerm @ts.typesystem(H=ts.RealVector(size=3), name=ts.ConstantObjectName) class Zeeman(EnergyTerm): _latex = "$-\mu_{0}M_\\text{s} \mathbf{m} \cdot \mathbf{H}$" def __init__(self, H, name="zeeman"): """A Zeeman energy class. This method internally calls set_H method. Refer to its documentation. """ self.H = H self.name = name @property def _repr(self): """A representation string property. Returns: A representation string. """ return "Zeeman(H={}, name=\"{}\")".format(self.H, self.name)
import joommfutil.typesystem as ts from .dynamicsterm import DynamicsTerm @ts.typesystem(u=ts.RealVector(size=3), beta=ts.Real, name=ts.ConstantObjectName) class STT(DynamicsTerm): _latex = ("$-(\mathbf{u} \cdot \\boldsymbol\\nabla)\mathbf{m} + " "\\beta\mathbf{m} \\times \\big[(\mathbf{u} \cdot " "\\boldsymbol\\nabla)\mathbf{m}\\big]$") def __init__(self, u, beta, name="stt"): """A spin transfer torque term. Args: u (RealVector): velocity vector beta (Real): non-adiabatic parameter """ self.u = u self.beta = beta self.name = name @property def _repr(self): """A representation string property. Returns: A representation string.
import joommfutil.typesystem as ts from .energyterm import EnergyTerm @ts.typesystem(K1=ts.Real, K2=ts.Real, u=ts.RealVector(size=3), name=ts.ConstantObjectName) class UniaxialAnisotropy(EnergyTerm): def __init__(self, K1, u, K2=0, name="uniaxialanisotropy"): """Uniaxial anisotropy energy abstract class. Parameters ---------- K1, K2 : Real Uniaxial anisotropy energy constant (J/m**3) u : (3,) array_like Uniaxial anisotropy axis Examples -------- Creating a uniaxial anisotropy object >>> import micromagneticmodel as mm >>> ua = mm.UniaxialAnisotropy(K1=5e6, K2=1e3, u=(0, 0, 1)) """ self.K1 = K1 self.K2 = K2 self.u = u self.name = name
import joommfutil.typesystem as ts from .energyterm import EnergyTerm @ts.typesystem(K1=ts.Real, u1=ts.RealVector(size=3), u2=ts.RealVector(size=3), name=ts.ConstantObjectName) class CubicAnisotropy(EnergyTerm): def __init__(self, K1, u1, u2, name="cubicanisotropy"): """Cubic anisotropy energy abstract class. Parameters ---------- K1 : Real Cubic anisotropy energy constant (J/m**3) u1, u2 : (3,) array_like Cubic anisotropy axes """ self.K1 = K1 self.u1 = u1 self.u2 = u2 self.name = name @property def _latex(self): a1 = "(\mathbf{m} \cdot \mathbf{u}_{1})^{2}" a2 = "(\mathbf{m} \cdot \mathbf{u}_{2})^{2}" a3 = "(\mathbf{m} \cdot \mathbf{u}_{3})^{2}" return "$-K_{{1}} [{0}{1}+{1}{2}+{2}{0}]$".format(a1, a2, a3)
def test_typesystem(): @ts.typesystem(a=ts.Real, b=ts.Int, c=ts.String, d=ts.UnsignedReal, e=ts.PositiveReal, f=ts.Vector, g=ts.SizedVector(size=2), h=ts.RealVector(size=3), i=ts.PositiveRealVector(size=3), j=ts.TypedAttribute(expected_type=dict), k=ts.ObjectName, l=ts.IntVector(size=3), m=ts.PositiveIntVector(size=3)) class DummyClass: def __init__(self, a, b, c, d, e, f, g, h, i, j, k, l, m): self.a = a self.b = b self.c = c self.d = d self.e = e self.f = f self.g = g self.h = h self.i = i self.j = j self.k = k self.l = l self.m = m a = 1.7 b = 2 c = "abc" d = 9.5 e = 11. f = (1, 3, -4, 9) g = (1, 2) h = (-1, 2, 3.1) i = (1, 2, 31.1) j = {} k = "exchange_energy_name" l = (-1, 2, -3) m = (1, 2, 3) dc = DummyClass(a=a, b=b, c=c, d=d, e=e, f=f, g=g, h=h, i=i, j=j, k=k, l=l, m=m) # Simple assertions assert dc.a == a assert dc.b == b assert dc.c == c assert dc.d == d assert dc.e == e assert dc.f == f assert dc.g == g assert dc.h == h assert dc.i == i assert dc.j == j assert dc.k == k assert dc.l == l assert dc.m == m # Valid settings dc.a = 77.4 assert dc.a == 77.4 dc.b = -77 assert dc.b == -77 dc.c = "dummystring" assert dc.c == "dummystring" dc.d = 61.2 assert dc.d == 61.2 dc.e = 0.1 assert dc.e == 0.1 dc.f = [1, 2, 3, 4, 5, 6.1] assert dc.f == [1, 2, 3, 4, 5, 6.1] dc.g = (3, 2.1) assert dc.g == (3, 2.1) dc.h = (-5, 6, 8) assert dc.h == (-5, 6, 8) dc.i = (1, 2, 3.2) assert dc.i == (1, 2, 3.2) dc.j = {"a": 1} assert dc.j == {"a": 1} dc.k = "_new_name2" assert dc.k == "_new_name2" dc.l = (-11, -5, 6) assert dc.l == (-11, -5, 6) dc.m = (5, 9, 879) assert dc.m == (5, 9, 879) # Invalid settings with pytest.raises(TypeError): dc.a = 1 + 2j with pytest.raises(TypeError): dc.b = -77.1 with pytest.raises(TypeError): dc.c = 5 with pytest.raises(TypeError): dc.d = -61.2 with pytest.raises(TypeError): dc.e = -0.1 with pytest.raises(TypeError): dc.f = "abc" with pytest.raises(TypeError): dc.g = (3, 2.1, -6) with pytest.raises(TypeError): dc.h = (-5, 6, 8, 9) with pytest.raises(TypeError): dc.h = (-5 + 1j, 8, 9) with pytest.raises(TypeError): dc.i = (1, -2, 3.2) with pytest.raises(TypeError): dc.j = 5 with pytest.raises(TypeError): dc.k = "new name2" with pytest.raises(TypeError): dc.k = "2newname2" with pytest.raises(TypeError): dc.l = (1.1, 2, 5) with pytest.raises(TypeError): dc.m = (0, 2, 5) # Attempt deleting attribute with pytest.raises(AttributeError): del dc.i