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)
    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)
    def test_nonuniform_user_fn_field(self):
        H_ext = VectorField(self.solver.world.mesh)
        H_ext.fill((1.0, 2.0, 3.0))  # this counts as non-uniform because H_ext is not a Python 3-vector.

        self.solver.state.H_ext_amp   = (0.0, 0.0, 0.0)
        self.solver.state.H_ext_phase = (0.0, 0.0, 0.0)
        self.solver.state.H_ext_freq  = (0.0, 0.0, 0.0)
        self.solver.state.H_ext_offs  = (0.0, 0.0, 0.0)
        self.solver.state.H_ext_fn    = lambda t: H_ext
        self.assertEqual((1.0, 2.0, 3.0), self.solver.state.H_ext.average())
Example #4
0
    def test_nonuniform_user_fn_field(self):
        H_ext = VectorField(self.solver.world.mesh)
        H_ext.fill(
            (1.0, 2.0, 3.0)
        )  # this counts as non-uniform because H_ext is not a Python 3-vector.

        self.solver.state.H_ext_amp = (0.0, 0.0, 0.0)
        self.solver.state.H_ext_phase = (0.0, 0.0, 0.0)
        self.solver.state.H_ext_freq = (0.0, 0.0, 0.0)
        self.solver.state.H_ext_offs = (0.0, 0.0, 0.0)
        self.solver.state.H_ext_fn = lambda t: H_ext
        self.assertEqual((1.0, 2.0, 3.0), self.solver.state.H_ext.average())
    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)
    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)
    def test_interpolate(self):
        mesh0 = RectangularMesh((100, 100, 1), (1e-9, 1e-9, 6e-9))
        mesh1 = RectangularMesh((50, 50, 1), (2e-9, 2e-9, 6e-9))

        M = VectorField(mesh0)
        M.fill((10, 20, 30))

        M2 = M.interpolate(mesh1)
        M2_avg = M2.average()

        self.assertEqual(10, M2_avg[0])
        self.assertEqual(20, M2_avg[1])
        self.assertEqual(30, M2_avg[2])
Example #8
0
    def test_interpolate(self):
        mesh0 = RectangularMesh((100, 100, 1), (1e-9, 1e-9, 6e-9))
        mesh1 = RectangularMesh((50, 50, 1), (2e-9, 2e-9, 6e-9))

        M = VectorField(mesh0)
        M.fill((10, 20, 30))

        M2 = M.interpolate(mesh1)
        M2_avg = M2.average()

        self.assertEqual(10, M2_avg[0])
        self.assertEqual(20, M2_avg[1])
        self.assertEqual(30, M2_avg[2])
Example #9
0
    def test_llge(self):
        mesh = RectangularMesh((10, 10, 10), (1e-9, 1e-9, 1e-9))
        f1, f2, M, H, dM = Field(mesh), Field(mesh), 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))
Example #10
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))
    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)
Example #12
0
    def doTest(self, M_file, H_file, epsilon):
        # load ref
        M = readOMF(M_file)
        H_ref = readOMF(H_file)
        H = VectorField(H_ref.mesh)

        # setup
        stray = StrayFieldCalculator(M.mesh)
        H.fill((1.0, 2.0, 3.0))

        # calculate
        for t in range(1):
            stray.calculate(M, H)

        # compare
        self.assertVectorFieldEqual(H_ref, H, epsilon)
Example #13
0
def left_rotate_vector_field(M):
    pbc, pbc_rep = M.mesh.periodic_bc
    pbc2, pbc_rep2 = "", pbc_rep
    if "x" in pbc: pbc2 += "z"
    if "y" in pbc: pbc2 += "x"
    if "z" in pbc: pbc2 += "y"

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

    M2 = VectorField(mesh)
    for x, y, z in M.mesh.iterateCellIndices():
        a = M.get(x, y, z)
        M2.set(y, z, x, (a[1], a[2], a[0]))
    return M2
Example #14
0
def left_rotate_vector_field(M):
    pbc, pbc_rep = M.mesh.periodic_bc
    pbc2, pbc_rep2 = "", pbc_rep
    if "x" in pbc: pbc2 += "z"
    if "y" in pbc: pbc2 += "x"
    if "z" in pbc: pbc2 += "y"

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

    M2 = VectorField(mesh)
    for x, y, z in M.mesh.iterateCellIndices():
        a = M.get(x,y,z)
        M2.set(y,z,x, (a[1], a[2], a[0]))
    return M2
Example #15
0
 def compute(M, rotations=1):
     for _ in range(rotations):
         M = right_rotate_vector_field(M)
     H = VectorField(M.mesh)
     stray = StrayFieldCalculator(M.mesh)
     stray.calculate(M, H)
     for _ in range(rotations):
         H = left_rotate_vector_field(H)
     return H
Example #16
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)
Example #17
0
 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
Example #18
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)
Example #19
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)
Example #20
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)
Example #21
0
    def test_rotated_magnetization_produces_same_rotated_strayfield(self):

        def compute(M, rotations=1):
            for _ in range(rotations):
                M = right_rotate_vector_field(M)
            H = VectorField(M.mesh)
            stray = StrayFieldCalculator(M.mesh)
            stray.calculate(M, H)
            for _ in range(rotations):
                H = left_rotate_vector_field(H)
            return H

        mesh = RectangularMesh((20, 20, 6), (5e-9, 5e-9, 5e-9), "xy", 20)

        M0 = VectorField(mesh)
        M0.randomize()
        M0.scale(8e5)

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

        self.assertVectorFieldEqual(H0, H1, 1e0)
        self.assertVectorFieldEqual(H0, H2, 1e0)
 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
 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
Example #24
0
    def test_findExtremum(self):
        mesh = RectangularMesh((100, 100, 1), (1e-9, 1e-9, 6e-9))

        M = VectorField(mesh)
        M.fill((100, 100, 100))
        M.findExtremum(z_slice=0, component=0)
Example #25
0
 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
Example #26
0
 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
    def test_findExtremum(self):
        mesh = RectangularMesh((100, 100, 1), (1e-9, 1e-9, 6e-9))

        M = VectorField(mesh)
        M.fill((100, 100, 100))
        M.findExtremum(z_slice=0, component=0)