Exemplo n.º 1
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])
Exemplo n.º 2
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)
 def test_2d(self):
     mesh = RectangularMesh((100, 100, 1), (1, 1, 1))
     self.assertEquals([0 + 0 * 100], self.shape0.getCellIndices(mesh))
     self.assertEquals([99 + 0 * 100], self.shape1.getCellIndices(mesh))
     self.assertEquals([0 + 99 * 100], self.shape2.getCellIndices(mesh))
     self.assertEquals([99 + 99 * 100],
                       self.shape3.getCellIndices(mesh))
        def setUp(self):
            mesh = RectangularMesh((100, 100, 1), (1, 1, 1))
            isc = ImageShapeCreator("image_shape_creator_test.png", mesh)

            self.shape0 = isc.pick("blue")  # bottom-left of img -> (0,0)
            self.shape1 = isc.pick("green")  # bottom-right -> (99,0)
            self.shape2 = isc.pick("black")  # top-left -> (0,99)
            self.shape3 = isc.pick("red")  # top-right -> (99,99)
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def test_derived_quantities(self):
     mesh = RectangularMesh((10, 10, 10), (2, 2, 2))
     self.assertEqual(mesh.cell_volume, 8)
     self.assertEqual(mesh.volume, 8000)
     self.assertEqual(mesh.size, (20, 20, 20))
     self.assertEqual(mesh.delta, (2, 2, 2))
     self.assertEqual(mesh.num_nodes, (10, 10, 10))
     self.assertEqual(mesh.total_nodes, 1000)
     self.assertEqual(mesh.periodic_bc, ("", 1))
Exemplo n.º 7
0
    def test_getCellIndices(self):
        mesh = RectangularMesh((20, 20, 20), (0.1, 0.1, 0.1))

        combo = self.cube1 | self.cube2
        cells = combo.getCellIndices(mesh)
        self.assertEqual(2000, len(cells))

        combo = self.cube1 & self.cube2
        cells = combo.getCellIndices(mesh)
        self.assertEqual(0, len(cells))
    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)
Exemplo n.º 9
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))
Exemplo n.º 10
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
Exemplo n.º 11
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])
Exemplo n.º 12
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)
Exemplo n.º 13
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])
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
0
 def setUp(self):
     world = World(RectangularMesh((10, 10, 10), (1e-9, 1e-9, 1e-9)))
     self.solver = create_solver(world, [ExternalField])
Exemplo n.º 17
0
 def setUp(self):
     self.sphere = Sphere((1, 1, 1), 1)
     self.mesh = RectangularMesh((20, 20, 20), (0.1, 0.1, 0.1))
Exemplo n.º 18
0
 def setUp(self):
     self.cube = Cuboid((0, 0, 0), (1, 1, 1))
     self.mesh = RectangularMesh((10, 10, 10), (1.0, 1.0, 1.0))
Exemplo n.º 19
0
 def setUp(self):
     self.mesh = RectangularMesh((100, 100, 1), (1e-9, 1e-9, 1e-9))
     self.world = World(
         self.mesh, Body("body1", Material.Py(), Everywhere()),
         Body("body2", Material.Py(),
              Cylinder((0, 0, 0), (0, 50e-9, 0), 20e-9)))
Exemplo n.º 20
0
 def test_getCellIndices(self):
     mesh = RectangularMesh((10, 10, 10), (1, 1, 1))
     ew = Everywhere()
     idx = ew.getCellIndices(mesh)
     self.assertEqual(1000, len(idx))
Exemplo n.º 21
0
 def test_properties(self):
     mesh = RectangularMesh((1, 2, 3), (4.0, 5.0, 6.0))
     self.assertEqual(mesh.num_nodes, (1, 2, 3))
     self.assertEqual(mesh.delta, (4.0, 5.0, 6.0))