def test_1(self):
        mesh = RectangularMesh((10, 10, 10), (1e-9, 1e-9, 1e-9))

        M = VectorField(mesh); M.fill((-8e5, 0, 0))
        Ms = Field(mesh); Ms.fill(8e5)

        sam = magneto.scaled_abs_max(M, Ms)
        self.assertEqual(1.0, sam)
Ejemplo n.º 2
0
    def test_1(self):
        mesh = RectangularMesh((10,10,10), (1e-9,1e-9,1e-9))

        M = VectorField(mesh); M.fill((-8e5,0,0))
        Ms = Field(mesh); Ms.fill(8e5)

        sam = magneto.scaled_abs_max(M, Ms)
        self.assertEqual(1.0, sam)
Ejemplo n.º 3
0
    def test_llge(self):
        mesh = RectangularMesh((10, 10, 10), (1e-9, 1e-9, 1e-9))
        f1, f2 = Field(mesh), Field(mesh)
        M, H, dM = VectorField(mesh), VectorField(mesh), VectorField(mesh)

        # dM = f1*MxH + f2*Mx(MxH)
        f1.fill(10)
        f2.fill(20)
        M.fill((5, 10, 15))
        H.fill((20, 25, 30))
        magneto.llge(f1, f2, M, H, dM)

        for idx in range(dM.size()):
            self.assertEqual(dM.get(idx), (-60750.0, -13500.0, 29250.0))
Ejemplo n.º 4
0
    def test_rotated_magnetization_produces_same_rotated_exchange_field(self):

        def compute(M, Ms, A, rotations=1):
            for _ in range(rotations):
                M = right_rotate_vector_field(M)
                Ms = right_rotate_field(Ms); A = right_rotate_field(A)
            H = VectorField(M.mesh)
            nx, ny, nz = M.mesh.num_nodes
            dx, dy, dz = M.mesh.delta
            pbc, pbc_rep = M.mesh.periodic_bc
            bcx, bcy, bcz = "x" in pbc, "y" in pbc, "z" in pbc
            magneto.exchange(nx, ny, nz, dx, dy, dz, bcx, bcy, bcz, Ms, A, M, H)
            for _ in range(rotations): H = left_rotate_vector_field(H)
            return H

        #mesh = RectangularMesh((32,16,8), (1e-9,1e-9,1e-9), "z", 20)
        mesh = RectangularMesh((20, 20, 6), (5e-9, 5e-9, 5e-9), "xy", 20)
        M0 = VectorField(mesh); M0.randomize(); M0.scale(8e5)
        A  = Field(mesh);  A.fill(Material.Py().A)
        Ms = Field(mesh); Ms.fill(Material.Py().Ms)

        H0 = compute(M0, Ms, A, 0)
        H1 = compute(M0, Ms, A, 1)
        H2 = compute(M0, Ms, A, 2)

        self.assertVectorFieldEqual(H0, H1, 1e0)
        self.assertVectorFieldEqual(H0, H2, 1e0)
Ejemplo n.º 5
0
    def test_llge(self):
        mesh = RectangularMesh((10, 10, 10), (1e-9, 1e-9, 1e-9))
        f1, f2 = Field(mesh), Field(mesh)
        M, H, dM = VectorField(mesh), VectorField(mesh), VectorField(mesh)

        # dM = f1*MxH + f2*Mx(MxH)
        f1.fill(10)
        f2.fill(20)
        M.fill((5, 10, 15))
        H.fill((20, 25, 30))
        magneto.llge(f1, f2, M, H, dM)

        for idx in range(dM.size()):
            self.assertEqual(dM.get(idx), (-60750.0, -13500.0, 29250.0))
Ejemplo n.º 6
0
def right_rotate_field(M):
    pbc, pbc_rep = M.mesh.periodic_bc
    pbc2, pbc_rep2 = "", pbc_rep
    if "x" in pbc: pbc2 += "y"
    if "y" in pbc: pbc2 += "z"
    if "z" in pbc: pbc2 += "x"

    nn = M.mesh.num_nodes
    dd = M.mesh.delta
    mesh = RectangularMesh((nn[2], nn[0], nn[1]), (dd[2], dd[0], dd[1]), pbc2, pbc_rep2)

    M2 = Field(mesh)
    for x, y, z in M.mesh.iterateCellIndices():
        a = M.get(x, y, z)
        M2.set(z, x, y, a)
    return M2
Ejemplo n.º 7
0
def right_rotate_field(M):
    pbc, pbc_rep = M.mesh.periodic_bc
    pbc2, pbc_rep2 = "", pbc_rep
    if "x" in pbc: pbc2 += "y"
    if "y" in pbc: pbc2 += "z"
    if "z" in pbc: pbc2 += "x"

    nn = M.mesh.num_nodes
    dd = M.mesh.delta
    mesh = RectangularMesh((nn[2], nn[0], nn[1]), (dd[2], dd[0], dd[1]), pbc2, pbc_rep2)

    M2 = Field(mesh)
    for x, y, z in M.mesh.iterateCellIndices():
        a = M.get(x,y,z)
        M2.set(z,x,y, a)
    return M2
Ejemplo n.º 8
0
    def test_2(self):
        mesh = RectangularMesh((10, 10, 10), (1e-9, 1e-9, 1e-9))

        M = VectorField(mesh)
        M.fill((-8e5, 0, 0))
        Ms = Field(mesh)
        Ms.fill(8e5)
        Ms.set(0, 0)
        Ms.set(0, 8e5)
        self.assertFalse(Ms.isUniform())

        sam = magneto.scaled_abs_max(M, Ms)
        self.assertEqual(1.0, sam)
Ejemplo n.º 9
0
    def test_parallel_and_orthogonal_anisotropy(self):
        mesh = RectangularMesh((40, 40, 40), (1e-9, 1e-9, 1e-9))
        k = Field(mesh)
        k.fill(520e3)
        Ms = Field(mesh)
        Ms.fill(8e5)

        def calc(axis_vec, M_vec):
            axis = VectorField(mesh)
            axis.fill(axis_vec)
            M = VectorField(mesh)
            M.fill(M_vec)
            H = VectorField(mesh)
            H.fill((0, 0, 0))
            E = magneto.uniaxial_anisotropy(axis, k, Ms, M,
                                            H) * mesh.cell_volume
            return H.average(), E

        # parallel cases
        E_ref = 0.0

        H, E = calc((1, 0, 0), (8e5, 0, 0))
        self.assertAlmostEqual(E_ref, E)

        H, E = calc((0, 1, 0), (0, -8e5, 0))
        self.assertAlmostEqual(E_ref, E)

        H, E = calc((0, 0, -1), (0, 0, -1))
        self.assertAlmostEqual(E_ref, E)

        # orthogonal cases
        E_ref = k.average() * mesh.volume

        H, E = calc((0, 0, 1), (8e5, 0, 0))
        self.assertAlmostEqual(E_ref, E)
        for i in range(3):
            self.assertAlmostEqual(0, H[i])

        H, E = calc((1, 0, 0), (0, -8e5, 0))
        self.assertAlmostEqual(E_ref, E)
        for i in range(3):
            self.assertAlmostEqual(0, H[i])

        H, E = calc((0, -1, 0), (0, 0, 1))
        self.assertAlmostEqual(E_ref, E)
        for i in range(3):
            self.assertAlmostEqual(0, H[i])
Ejemplo n.º 10
0
    def test_2(self):
        mesh = RectangularMesh((10, 10, 10), (1e-9, 1e-9, 1e-9))

        M = VectorField(mesh)
        M.fill((-8e5, 0, 0))
        Ms = Field(mesh)
        Ms.fill(8e5)
        Ms.set(0, 0)
        Ms.set(0, 8e5)
        self.assertFalse(Ms.isUniform())

        sam = magneto.scaled_abs_max(M, Ms)
        self.assertEqual(1.0, sam)
Ejemplo n.º 11
0
    def test_parallel_anisotropy(self):
        mesh = RectangularMesh((40, 40, 40), (1e-9, 1e-9, 1e-9))
        k = Field(mesh); k.fill(520e3)
        Ms = Field(mesh); Ms.fill(8e5)

        def calc(axis1_vec, axis2_vec, M_vec):
            axis1 = VectorField(mesh); axis1.fill(axis1_vec)
            axis2 = VectorField(mesh); axis2.fill(axis2_vec)
            M = VectorField(mesh); M.fill(M_vec)
            H = VectorField(mesh); H.fill((0,0,0))
            E = magneto.cubic_anisotropy(axis1, axis2, k, Ms, M, H) * mesh.cell_volume
            return H.average(), E

        # parallel cases
        E_ref = 0.0

        H, E = calc((1,0,0), (0,1,0), (8e5,0,0))
        self.assertEqual(E_ref, E)
        for i in range(3): self.assertEqual(0.0, H[i])

        H, E = calc((1,0,0), (0,-1,0), (0,-8e5,0))
        self.assertEqual(E_ref, E)
        for i in range(3): self.assertEqual(0, H[i])

        H, E = calc((0,-1,0), (0,0,-1), (0,0,8e5))
        self.assertAlmostEqual(E_ref, E)
        for i in range(3): self.assertAlmostEqual(0, H[i])
Ejemplo n.º 12
0
    def do_test(self, M_file, H_file, epsilon):
        # load ref
        M     = readOMF(M_file)
        H_ref = readOMF(H_file)
        H     = VectorField(M.mesh)
        A     = Field(M.mesh); A.fill(Material.Py().A)
        Ms    = Field(M.mesh); Ms.fill(Material.Py().Ms)

        # calculate
        mesh = M.mesh
        nx, ny, nz = mesh.num_nodes
        dx, dy, dz = mesh.delta
        bcx, bcy, bcz = False, False, False
        magneto.exchange(nx, ny, nz, dx, dy, dz, bcx, bcy, bcz, Ms, A, M, H)

        # compare
        self.assertVectorFieldEqual(H_ref, H, epsilon)
Ejemplo n.º 13
0
    def pbc_exchange(self, nx, ny, nz):
        dx, dy, dz = 1e-9, 1e-9, 1e-9

        mesh = RectangularMesh((nx, ny, nz), (dx, dy, dz))
        A  = Field(mesh); A.fill(Material.Py().A)
        Ms = Field(mesh); Ms.fill(Material.Py().Ms)
        M  = VectorField(mesh)
        H  = VectorField(mesh)

        for bcx, bcy, bcz in itertools.product([False, True], [False, True], [False, True]):
            M.fill(tuple((random.random()-0.5) * 2e5 for i in range(3)))
            #M.fill((8e5, 8e5, -8e5))
            magneto.exchange(nx, ny, nz, dx, dy, dz, bcx, bcy, bcz, Ms, A, M, H)
            for i in range(nx*ny*nz):
                #self.assertEqual(H.get(i), (0.0, 0.0, 0.0))
                self.assertAlmostEqual(H.get(i)[0], 0.0)
                self.assertAlmostEqual(H.get(i)[1], 0.0)
                self.assertAlmostEqual(H.get(i)[2], 0.0)
Ejemplo n.º 14
0
    def doTest(self, M_file, H_file, epsilon):
        # load ref
        M = readOMF(M_file)
        H_ref = readOMF(H_file)
        H = VectorField(M.mesh)

        axis = VectorField(M.mesh)
        axis.fill(
            (1.0 / math.sqrt(3.0), 1.0 / math.sqrt(3.0), 1.0 / math.sqrt(3.0)))
        k = Field(M.mesh)
        k.fill(520e3)
        Ms = Field(M.mesh)
        Ms.fill(8e5)

        # calculate
        magneto.uniaxial_anisotropy(axis, k, Ms, M, H)

        # compare
        self.assertVectorFieldEqual(H_ref, H, epsilon)
Ejemplo n.º 15
0
    def doTest(self, M_file, H_file, epsilon):
        # load ref
        M     = readOMF(M_file)
        H_ref = readOMF(H_file)
        H     = VectorField(M.mesh)

        axis = VectorField(M.mesh); axis.fill((1.0/math.sqrt(3.0), 1.0/math.sqrt(3.0), 1.0/math.sqrt(3.0)))
        k = Field(M.mesh); k.fill(520e3)
        Ms = Field(M.mesh); Ms.fill(8e5)

        # calculate
        magneto.uniaxial_anisotropy(axis, k, Ms, M, H)

        # compare
        self.assertVectorFieldEqual(H_ref, H, epsilon)
Ejemplo n.º 16
0
    def test_parallel_anisotropy(self):
        mesh = RectangularMesh((40, 40, 40), (1e-9, 1e-9, 1e-9))
        k = Field(mesh)
        k.fill(520e3)
        Ms = Field(mesh)
        Ms.fill(8e5)

        def calc(axis1_vec, axis2_vec, M_vec):
            axis1 = VectorField(mesh)
            axis1.fill(axis1_vec)
            axis2 = VectorField(mesh)
            axis2.fill(axis2_vec)
            M = VectorField(mesh)
            M.fill(M_vec)
            H = VectorField(mesh)
            H.fill((0, 0, 0))
            E = magneto.cubic_anisotropy(axis1, axis2, k, Ms, M,
                                         H) * mesh.cell_volume
            return H.average(), E

        # parallel cases
        E_ref = 0.0

        H, E = calc((1, 0, 0), (0, 1, 0), (8e5, 0, 0))
        self.assertEqual(E_ref, E)
        for i in range(3):
            self.assertEqual(0.0, H[i])

        H, E = calc((1, 0, 0), (0, -1, 0), (0, -8e5, 0))
        self.assertEqual(E_ref, E)
        for i in range(3):
            self.assertEqual(0, H[i])

        H, E = calc((0, -1, 0), (0, 0, -1), (0, 0, 8e5))
        self.assertAlmostEqual(E_ref, E)
        for i in range(3):
            self.assertAlmostEqual(0, H[i])
Ejemplo n.º 17
0
    def test_parallel_and_orthogonal_anisotropy(self):
        mesh = RectangularMesh((40, 40, 40), (1e-9, 1e-9, 1e-9))
        k = Field(mesh); k.fill(520e3)
        Ms = Field(mesh); Ms.fill(8e5)

        def calc(axis_vec, M_vec):
            axis = VectorField(mesh); axis.fill(axis_vec)
            M = VectorField(mesh); M.fill(M_vec)
            H = VectorField(mesh); H.fill((0, 0, 0))
            E = magneto.uniaxial_anisotropy(axis, k, Ms, M, H) * mesh.cell_volume
            return H.average(), E

        # parallel cases
        E_ref = 0.0

        H, E = calc((1,0,0), (8e5,0,0))
        self.assertAlmostEqual(E_ref, E)

        H, E = calc((0,1,0), (0,-8e5,0))
        self.assertAlmostEqual(E_ref, E)

        H, E = calc((0,0,-1), (0,0,-1))
        self.assertAlmostEqual(E_ref, E)

        # orthogonal cases
        E_ref = k.average() * mesh.volume

        H, E = calc((0,0,1), (8e5,0,0))
        self.assertAlmostEqual(E_ref, E)
        for i in range(3): self.assertAlmostEqual(0, H[i])

        H, E = calc((1,0,0), (0,-8e5,0))
        self.assertAlmostEqual(E_ref, E)
        for i in range(3): self.assertAlmostEqual(0, H[i])

        H, E = calc((0,-1,0), (0,0,1))
        self.assertAlmostEqual(E_ref, E)
        for i in range(3): self.assertAlmostEqual(0, H[i])