Ejemplo n.º 1
0
 def test_init_exceptions(self):
     # Invalid arguments (ValueError expected).
     for arg in self.args2:
         evolver = arg[0]
         stopping_mxHxm = arg[1]
         mesh = arg[2]
         Ms = arg[3]
         m0 = arg[4]
         basename = arg[5]
         with pytest.raises(ValueError):
             driver = MinDriver(evolver, stopping_mxHxm,
                                mesh, Ms, m0, basename)
Ejemplo n.º 2
0
    def relax(self, stopping_mxHxm=0.01):
        self.m.write_oommf_file(self.dirname + 'm0file.omf')
        self.m0 = 'm0file.omf'

        self.evolver = CGEvolve()
        self.driver = MinDriver('evolver',
                                stopping_mxHxm,
                                'mesh',
                                self.Ms,
                                self.m0,
                                basename=self.name)
        self.relaxation = True
        self.execute_mif()
Ejemplo n.º 3
0
    def test_init(self):
        # Valid arguments.
        for arg in self.args1:
            evolver = arg[0]
            stopping_mxHxm = arg[1]
            mesh = arg[2]
            Ms = arg[3]
            m0 = arg[4]
            basename = arg[5]

            driver = MinDriver(evolver, stopping_mxHxm, mesh, Ms, m0, basename)

            assert driver.evolver == evolver
            assert driver.stopping_mxHxm == stopping_mxHxm
            assert driver.mesh == mesh
            assert driver.Ms == Ms
            assert driver.m0 == m0
            assert driver.basename == basename
Ejemplo n.º 4
0
    def test_get_mif(self):
        for arg in self.args1:
            evolver = arg[0]
            stopping_mxHxm = arg[1]
            mesh = arg[2]
            Ms = arg[3]
            m0 = arg[4]
            basename = arg[5]

            driver = MinDriver(evolver, stopping_mxHxm, mesh, Ms, m0, basename)

            mif = driver.get_mif()
            mif_lines = driver.get_mif().split('\n')

            # Assert comment.
            l = mif_lines[0].split()
            assert l[0] == '#'
            assert l[1] == 'MinDriver'

            # Assert Specify line.
            l = mif_lines[1].split()
            assert l[0] == 'Specify'
            assert l[1].split(':')[0] == 'Oxs_MinDriver'
            assert l[2] == '{'

            # Assert parameters lines
            assert mif_lines[2][0] == '\t'
            l = mif_lines[2].split()
            assert l[0] == 'evolver'
            assert l[1] == evolver

            # Assert parameters lines
            assert mif_lines[3][0] == '\t'
            l = mif_lines[3].split()
            assert l[0] == 'stopping_mxHxm'
            assert float(l[1]) == stopping_mxHxm

            # Assert parameters lines
            assert mif_lines[4][0] == '\t'
            l = mif_lines[4].split()
            assert l[0] == 'mesh'
            assert l[1] == ':' + mesh

            # Assert parameters lines
            assert mif_lines[5][0] == '\t'
            l = mif_lines[5].split()
            assert l[0] == 'Ms'
            assert float(l[1]) == Ms

            # Assert parameters lines
            assert mif_lines[6][0] == '\t'
            l = mif_lines[6].split()
            assert l[0] == 'm0'
            assert l[1] == '{'

            # Assert initial state definition.
            if isinstance(m0, (list, tuple)):
                assert mif_lines[7][0:2] == '\t\t'
                l = mif_lines[7].split()
                assert l[0] == 'Oxs_UniformVectorField'
                assert l[1] == '{'

                assert mif_lines[8][0:3] == '\t\t\t'
                l = mif_lines[8].split()
                assert l[0] == 'vector'
                assert l[1] == '{'
                assert float(l[2]) == m0[0]
                assert float(l[3]) == m0[1]
                assert float(l[4]) == m0[2]
                assert l[5] == '}'

                assert mif_lines[9][0:2] == '\t\t'
                l = mif_lines[9].split()
                assert l[0] == '}'

                n = 9

            elif isinstance(m0, str):
                assert mif_lines[7][0:2] == '\t\t'
                l = mif_lines[7].split()
                assert l[0] == 'Oxs_FileVectorField'
                assert l[1] == '{'

                assert mif_lines[8][0:3] == '\t\t\t'
                l = mif_lines[8].split()
                assert l[0] == 'atlas'
                assert l[1] == ':atlas'

                assert mif_lines[9][0:3] == '\t\t\t'
                l = mif_lines[9].split()
                assert l[0] == 'norm'
                assert float(l[1]) == 1

                assert mif_lines[10][0:3] == '\t\t\t'
                l = mif_lines[10].split()
                assert l[0] == 'file'
                assert l[1] == m0

                assert mif_lines[11][0:2] == '\t\t'
                l = mif_lines[11].split()
                assert l[0] == '}'

                n = 11

            assert mif_lines[n+1] == '\t}'

            assert mif_lines[n+2][0] == '\t'
            l = mif_lines[n+2].split()
            assert l[0] == 'basename'
            assert l[1] == basename

            l = mif_lines[n+3]
            assert l == '\tvector_field_output_format {text %\#.8g}'

            # Assert mif end.
            assert mif_lines[n+4] == '}'

            # Assert new lines at the end of the string.
            assert mif[-2:] == '\n\n'