Example #1
0
    def test_init_invalid_args(self):
        for K, u1, u2 in self.invalid_args:
            with pytest.raises((TypeError, ValueError)):
                term = mm.CubicAnisotropy(K=K, u1=u1, u2=u2)

        with pytest.raises(AttributeError):
            term = mm.CubicAnisotropy(wrong=1)
    def test_repr(self):
        for K1, u1, u2 in self.valid_args:
            anisotropy = mm.CubicAnisotropy(K1=K1, u1=u1, u2=u2)
            exp_str = ("CubicAnisotropy(K1={}, u1={}, u2={}, "
                       "name=\"{}\")").format(K1, u1, u2, "cubicanisotropy")
            assert repr(anisotropy) == exp_str

        anisotropy = mm.CubicAnisotropy(1000, (0, 1, 0), (0, 0, 1),
                                        name="test_name")
        assert repr(anisotropy) == ("CubicAnisotropy(K1=1000, u1=(0, 1, 0), "
                                    "u2=(0, 0, 1), name=\"test_name\")")
    def test_repr(self):
        for K1, u1, u2 in self.valid_args:
            anisotropy = mm.CubicAnisotropy(K1=K1, u1=u1, u2=u2)
            exp_str = ('CubicAnisotropy(K1={}, u1={}, u2={}, '
                       'name=\'{}\')').format(K1, u1, u2, 'cubicanisotropy')
            assert repr(anisotropy) == exp_str

        anisotropy = mm.CubicAnisotropy(1000, (0, 1, 0), (0, 0, 1),
                                        name='test_name')
        assert repr(anisotropy) == ('CubicAnisotropy(K1=1000, u1=(0, 1, 0), '
                                    'u2=(0, 0, 1), name=\'test_name\')')
    def setup(self):
        A = 1e-12
        self.exchange = mm.Exchange(A=A)
        H = (0, 0, 1.2e6)
        self.zeeman = mm.Zeeman(H=H)
        K1 = 1e4
        K2 = 3e2
        u = (0, 1, 0)
        self.uniaxialanisotropy = mm.UniaxialAnisotropy(K1=K1, K2=K2, u=u)
        self.demag = mm.Demag()
        D = 1e-3
        crystalclass = 't'
        self.dmi = mm.DMI(D=D, crystalclass=crystalclass)
        K1 = 5e6
        u1 = (0, 0, 1)
        u2 = (0, 1, 0)
        self.cubicanisotropy = mm.CubicAnisotropy(K1=K1, u1=u1, u2=u2)

        self.terms = [
            self.exchange, self.zeeman, self.uniaxialanisotropy, self.demag,
            self.dmi, self.cubicanisotropy
        ]

        self.invalid_terms = [
            1, 2.5, 0, 'abc', [3, 7e-12], [self.exchange, self.zeeman]
        ]
Example #5
0
    def test_exchange_cubicanisotropy(self):
        name = 'exchange_cubicanisotropy'

        A = {'r1': 1e-12, 'r2': 0}
        K = 1e5
        u1 = (1, 0, 0)
        u2 = (0, 1, 0)
        Ms = 1e6

        mesh = df.Mesh(region=self.region,
                       cell=self.cell,
                       subregions=self.subregions)

        system = mm.System(name=name)
        system.energy = mm.Exchange(A=A) + \
            mm.CubicAnisotropy(K=K, u1=u1, u2=u2)
        system.m = df.Field(mesh, dim=3, value=(1, 0.3, 0), norm=Ms)

        md = self.calculator.MinDriver()
        md.drive(system)

        value = system.m(mesh.region.random_point())
        assert np.linalg.norm(np.subtract(value, (Ms, 0, 0))) < 1e-3

        self.calculator.delete(system)
    def test_field_vector_vector(self):
        name = 'cubicanisotropy_field_vector_vector'

        mesh = df.Mesh(region=self.region, cell=self.cell)

        def K_fun(pos):
            x, y, z = pos
            if x <= 0:
                return 0
            else:
                return 1e5

        K = df.Field(mesh, dim=1, value=K_fun)
        u1 = (0, 0, 1)
        u2 = (0, 1, 0)
        Ms = 1e6

        system = mm.System(name=name)
        system.energy = mm.CubicAnisotropy(K=K, u1=u1, u2=u2)
        system.m = df.Field(mesh, dim=3, value=(0, 0.3, 1), norm=Ms)

        md = self.calculator.MinDriver()
        md.drive(system)

        value = system.m((-2e-9, 1e-9, 1e-9))
        assert np.linalg.norm(np.cross(value, (0, 0.3 * Ms, Ms))) < 1e-3

        value = system.m((2e-9, 2e-9, 2e-9))
        assert np.linalg.norm(np.subtract(value, (0, 0, Ms))) < 1e-3

        self.calculator.delete(system)
    def test_scalar_vector_vector(self):
        name = 'cubicanisotropy_scalar_vector_vector'

        mesh = df.Mesh(region=self.region, cell=self.cell)

        K = 1e5
        u1 = (0, 0, 1)
        u2 = (0, 1, 0)
        Ms = 1e6

        system = mm.System(name=name)
        system.energy = mm.CubicAnisotropy(K=K, u1=u1, u2=u2)

        def m_fun(pos):
            x, y, z = pos
            if x <= 0:
                return (0, 0.2, 1)
            else:
                return (0, 1, 0.2)

        system.m = df.Field(mesh, dim=3, value=m_fun, norm=Ms)

        md = self.calculator.MinDriver()
        md.drive(system)

        value = system.m((-1e-9, 2e-9, 2e-9))
        assert np.linalg.norm(np.subtract(value, (0, 0, Ms))) < 1e-3

        value = system.m((1e-9, 2e-9, 2e-9))
        assert np.linalg.norm(np.subtract(value, (0, Ms, 0))) < 1e-3

        self.calculator.delete(system)
    def test_dict_vector_vector(self):
        name = 'cubicanisotropy_dict_vector_vector'

        mesh = df.Mesh(region=self.region,
                       cell=self.cell,
                       subregions=self.subregions)

        K = {'r1': 0, 'r2': 1e5}
        u1 = (0, 0, 1)
        u2 = (0, 1, 0)
        Ms = 1e6

        system = mm.System(name=name)
        system.energy = mm.CubicAnisotropy(K=K, u1=u1, u2=u2)
        system.m = df.Field(mesh, dim=3, value=(0, 0.3, 1), norm=Ms)

        md = self.calculator.MinDriver()
        md.drive(system)

        value = system.m((-2e-9, 1e-9, 1e-9))
        assert np.linalg.norm(np.cross(value, (0, 0.3 * Ms, Ms))) < 1e-3

        value = system.m((2e-9, 2e-9, 2e-9))
        assert np.linalg.norm(np.subtract(value, (0, 0, Ms))) < 1e-3

        self.calculator.delete(system)
Example #9
0
 def test_init_valid_args(self):
     for K, u1, u2 in self.valid_args:
         term = mm.CubicAnisotropy(K=K, u1=u1, u2=u2)
         check_term(term)
         assert hasattr(term, 'K')
         assert hasattr(term, 'u1')
         assert hasattr(term, 'u2')
         assert term.name == 'cubicanisotropy'
         assert re.search(r'^CubicAnisotropy\(K=.+, u1=.+\, u2=.+\)$',
                          repr(term))
 def test_init_valid_args(self):
     for K1, u1, u2 in self.valid_args:
         anisotropy = mm.CubicAnisotropy(K1=K1, u1=u1, u2=u2)
         assert anisotropy.K1 == K1
         assert isinstance(anisotropy.K1, numbers.Real)
         assert isinstance(anisotropy.u1, (tuple, list, np.ndarray))
         assert isinstance(anisotropy.u2, (tuple, list, np.ndarray))
         assert len(anisotropy.u1) == 3
         assert len(anisotropy.u2) == 3
         assert all([isinstance(i, numbers.Real) for i in anisotropy.u1])
         assert all([isinstance(i, numbers.Real) for i in anisotropy.u2])
Example #11
0
    def setup(self):
        name = 'compute_tests'
        p1 = (0, 0, 0)
        p2 = (10e-9, 2e-9, 2e-9)
        cell = (2e-9, 2e-9, 2e-9)
        region = df.Region(p1=p1, p2=p2)
        mesh = df.Mesh(region=region, cell=cell)

        self.system = mm.System(name=name)
        self.system.energy = (
            mm.Exchange(A=1e-12) + mm.Demag() + mm.Zeeman(H=(8e6, 0, 0)) +
            mm.UniaxialAnisotropy(K=1e4, u=(0, 0, 1)) +
            mm.CubicAnisotropy(K=1e3, u1=(1, 0, 0), u2=(0, 1, 0)))

        self.system.m = df.Field(mesh, dim=3, value=(0, 0, 1), norm=8e6)
    def test_repr_latex(self):
        for K1, u1, u2 in self.valid_args:
            anisotropy = mm.CubicAnisotropy(K1=K1, u1=u1, u2=u2)
            latex = anisotropy._repr_latex_()

            # Assert some characteristics of LaTeX string.
            assert isinstance(latex, str)
            assert latex[0] == latex[-1] == '$'
            assert 'K_{1}' in latex
            assert '\mathbf{u}_{1}' in latex
            assert '\mathbf{u}_{2}' in latex
            assert '\mathbf{m}' in latex
            assert '^{2}' in latex
            assert '\cdot' in latex
            assert latex.count("\mathbf{u}_{1}") == 2
            assert latex.count("\mathbf{u}_{2}") == 2
            assert latex.count("\mathbf{u}_{3}") == 2
    def setup(self):
        self.exchange = mm.Exchange(A=1e-12)
        self.zeeman = mm.Zeeman(H=(0, 0, 1.2e6))
        self.uniaxialanisotropy = mm.UniaxialAnisotropy(K=1e4, u=(0, 1, 0))
        self.demag = mm.Demag()
        self.dmi = mm.DMI(D=1e-3, crystalclass='T')
        self.cubicanisotropy = mm.CubicAnisotropy(K={
            'r1': 1e6,
            'r2': 5e6
        },
                                                  u1=(0, 0, 1),
                                                  u2=(0, 1, 0))

        self.terms = [
            self.exchange, self.zeeman, self.uniaxialanisotropy, self.demag,
            self.dmi, self.cubicanisotropy
        ]

        self.invalid_terms = [1, 2.5, 0, 'abc', [3, 7e-12], [self.exchange, 2]]
 def test_script(self):
     for K1, u1, u2 in self.valid_args:
         anisotropy = mm.CubicAnisotropy(K1=K1, u1=u1, u2=u2)
         with pytest.raises(NotImplementedError):
             script = anisotropy._script
 def test_name(self):
     for K1, u1, u2 in self.valid_args:
         anisotropy = mm.CubicAnisotropy(K1=K1, u1=u1, u2=u2)
         assert anisotropy.name == 'cubicanisotropy'
 def test_init_invalid_args(self):
     for K1, u1, u2 in self.invalid_args:
         with pytest.raises(Exception):
             anisotropy = mm.CubicAnisotropy(K1=K1, u1=u1, u2=u2)