Exemplo n.º 1
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)
Exemplo n.º 2
0
    def test_construction(self):
        # Ok.
        world = World(self.mesh, Material.Py())
        self.assertEqual(len(world.bodies), 1)

        # Not ok: Need direct Material if no body is given.
        try:
            World(self.mesh)
            self.fail()
        except:
            pass

        # Not ok: Duplicate Material
        try:
            world = World(self.mesh, Material.Py(), Material.Py())
            self.fail()
        except:
            pass

        # Not ok: Material and Body(s) given
        try:
            world = World(self.mesh, Material.Py(),
                          Body("body1", Material.Py()))
            self.fail()
        except:
            pass
Exemplo n.º 3
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)
Exemplo n.º 4
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.º 5
0
 def test_default_shape_is_everywhere(self):
     body2 = Body("body2", Material.Py())
     self.assertTrue(isinstance(body2.shape, Everywhere))
Exemplo n.º 6
0
 def test_construction(self):
     body1 = Body("body1", Material.Py(), Cuboid((0, 0, 0), (1, 1, 1)))
     self.assertEqual(body1.id, "body1")
     self.assertTrue(isinstance(body1.material, Material))
     self.assertTrue(isinstance(body1.shape, Cuboid))
Exemplo n.º 7
0
 def test_getter(self):
     mat = Material({'Ms':8e3})
     self.assertEqual(8e3, mat.get('Ms'))
     self.assertEqual(8e3, mat.Ms)
Exemplo n.º 8
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.º 9
0
 def test_modified_permallow(self):
     mod_py = Material.Py(Ms=7e5)
     self.assertEqual(7e5, mod_py.Ms)
Exemplo n.º 10
0
 def test_permalloy(self):
     py = Material.Py()
     self.assertEqual(8e5, py.Ms)
Exemplo n.º 11
0
 def test_getter(self):
     mat = Material({'Ms': 8e3})
     self.assertEqual(8e3, mat.Ms)