Beispiel #1
0
    def test_or(self):
        p1 = (-50e-9, -25e-9, 0)
        p2 = (50e-9, 25e-9, 5e-9)
        cell = (5e-9, 5e-9, 5e-9)
        mesh1 = df.Mesh(region=df.Region(p1=p1, p2=p2), cell=cell)

        p1 = (-45e-9, -20e-9, 0)
        p2 = (10e-9, 20e-9, 5e-9)
        cell = (5e-9, 5e-9, 5e-9)
        mesh2 = df.Mesh(region=df.Region(p1=p1, p2=p2), cell=cell)

        p1 = (-42e-9, -20e-9, 0)
        p2 = (13e-9, 20e-9, 5e-9)
        cell = (5e-9, 5e-9, 5e-9)
        mesh3 = df.Mesh(region=df.Region(p1=p1, p2=p2), cell=cell)

        p1 = (-50e-9, -25e-9, 0)
        p2 = (50e-9, 25e-9, 5e-9)
        cell = (2.5e-9, 2.5e-9, 2.5e-9)
        mesh4 = df.Mesh(region=df.Region(p1=p1, p2=p2), cell=cell)

        assert mesh1 | mesh2 is True
        assert mesh1 | mesh3 is False
        assert mesh1 | mesh4 is False
        assert mesh1 | mesh1 is True
Beispiel #2
0
    def test_pmin_pmax_edges_centre_volume(self):
        p1 = (0, -4, 16.5)
        p2 = (15, -6, 11)
        region = df.Region(p1=p1, p2=p2)

        check_region(region)
        assert region.pmin == (0, -6, 11)
        assert region.pmax == (15, -4, 16.5)
        assert region.edges == (15, 2, 5.5)
        assert region.centre == (7.5, -5, 13.75)
        assert region.volume == 165

        p1 = (-10e6, 0, 0)
        p2 = (10e6, 1e6, 1e6)
        region = df.Region(p1=p1, p2=p2)

        check_region(region)
        assert region.pmin == (-10e6, 0, 0)
        assert region.pmax == (10e6, 1e6, 1e6)
        assert region.edges == (20e6, 1e6, 1e6)
        assert region.centre == (0, 0.5e6, 0.5e6)
        assert abs(region.volume - 20 * (1e6)**3) < 1

        p1 = (-18.5e-9, 10e-9, 0)
        p2 = (10e-9, 5e-9, -10e-9)
        region = df.Region(p1=p1, p2=p2)

        check_region(region)
        assert np.allclose(region.pmin, (-18.5e-9, 5e-9, -10e-9))
        assert np.allclose(region.pmax, (10e-9, 10e-9, 0))
        assert np.allclose(region.edges, (28.5e-9, 5e-9, 10e-9))
        assert np.allclose(region.centre, (-4.25e-9, 7.5e-9, -5e-9))
        assert abs(region.volume - 1425 * (1e-9**3)) < 1e-30
Beispiel #3
0
    def test_init_subregions(self):
        p1 = (0, 0, 0)
        p2 = (100, 50, 10)
        cell = (10, 10, 10)
        subregions = {
            'r1': df.Region(p1=(0, 0, 0), p2=(50, 50, 10)),
            'r2': df.Region(p1=(50, 0, 0), p2=(100, 50, 10))
        }
        mesh = df.Mesh(p1=p1, p2=p2, cell=cell, subregions=subregions)
        check_mesh(mesh)

        # Invalid subregions.
        p1 = (0, 0, 0)
        p2 = (100e-9, 50e-9, 10e-9)
        cell = (10e-9, 10e-9, 10e-9)

        # Subregion not an aggregate.
        subregions = {'r1': df.Region(p1=(0, 0, 0), p2=(45e-9, 50e-9, 10e-9))}
        with pytest.raises(ValueError):
            mesh = df.Mesh(p1=p1, p2=p2, cell=cell, subregions=subregions)

        # Subregion not aligned.
        subregions = {
            'r1': df.Region(p1=(5e-9, 0, 0), p2=(45e-9, 50e-9, 10e-9))
        }
        with pytest.raises(ValueError):
            mesh = df.Mesh(p1=p1, p2=p2, cell=cell, subregions=subregions)

        # Subregion not in the mesh region.
        subregions = {'r1': df.Region(p1=(0, 0, 0), p2=(45e-9, 50e-9, 200e-9))}
        with pytest.raises(ValueError):
            mesh = df.Mesh(p1=p1, p2=p2, cell=cell, subregions=subregions)
Beispiel #4
0
 def setup(self):
     p1 = (-10e-9, -5e-9, -3e-9)
     p2 = (10e-9, 5e-9, 3e-9)
     self.region = df.Region(p1=p1, p2=p2)
     self.cell = (1e-9, 1e-9, 1e-9)
     self.subregions = {
         'r1': df.Region(p1=(-10e-9, -5e-9, -3e-9), p2=(10e-9, 0, 3e-9)),
         'r2': df.Region(p1=(-10e-9, 0, -3e-9), p2=(10e-9, 5e-9, 3e-9))
     }
Beispiel #5
0
 def setup(self):
     p1 = (-5e-9, -5e-9, -3e-9)
     p2 = (5e-9, 5e-9, 3e-9)
     self.region = df.Region(p1=p1, p2=p2)
     self.n = (10, 10, 10)
     self.subregions = {
         'r1': df.Region(p1=(-5e-9, -5e-9, -3e-9), p2=(5e-9, 0, 3e-9)),
         'r2': df.Region(p1=(-5e-9, 0, -3e-9), p2=(5e-9, 5e-9, 3e-9))
     }
Beispiel #6
0
 def setup(self):
     p1 = (-100e-9, 0, 0)
     p2 = (100e-9, 1e-9, 1e-9)
     self.region = df.Region(p1=p1, p2=p2)
     self.cell = (1e-9, 1e-9, 1e-9)
     self.subregions = {
         'r1': df.Region(p1=(-100e-9, 0, 0), p2=(0, 1e-9, 1e-9)),
         'r2': df.Region(p1=(0, 0, 0), p2=(100e-9, 1e-9, 1e-9))
     }
Beispiel #7
0
 def setup(self):
     p1 = (-7e-9, -5e-9, -4e-9)
     p2 = (7e-9, 5e-9, 4e-9)
     self.region = df.Region(p1=p1, p2=p2)
     self.cell = (1e-9, 1e-9, 1e-9)
     self.subregions = {'r1': df.Region(p1=(-7e-9, -5e-9, -4e-9),
                                        p2=(0, 5e-9, 4e-9)),
                        'r2': df.Region(p1=(0, -5e-9, -4e-9),
                                        p2=(7e-9, 5e-9, 4e-9))}
 def set_with_dict(self):
     p1 = (0, 0, 0)
     p2 = (10e-9, 10e-9, 10e-9)
     n = (5, 5, 5)
     regions = {'r1': df.Region(p1=(0, 0, 0), p2=(5e-9, 10e-9, 10e-9)),
                'r2': df.Region(p1=(5e-9, 0, 0), p2=(10e-9, 10e-9, 10e-9))}
     mesh = df.Mesh(p1=p1, p2=p2, cell=cell, regions=regions)
              
     field = df.Field(mesh, dim=2, value={'r1': (0, 0, 1), 'r2': (0, 0, 2)})
     assert np.all(field(3e-9, 7e-9, 9e-9) == (0, 0, 1))
     assert np.all(field(5.5e-9, 2e-9, 9e-9) == (0, 0, 1))
Beispiel #9
0
    def test_eq(self):
        region1 = df.Region(p1=(0, 0, 0), p2=(10, 10, 10))
        region2 = df.Region(p1=(0, 0, 0), p2=(10, 10, 10))
        region3 = df.Region(p1=(3, 3, 3), p2=(10, 10, 10))

        check_region(region1)
        check_region(region2)
        check_region(region3)
        assert region1 == region2
        assert not region1 != region2
        assert region1 != region3
        assert not region1 == region3
Beispiel #10
0
    def test_k3d_mpl_subregions(self):
        p1 = (0, 0, 0)
        p2 = (100, 80, 10)
        cell = (100, 5, 10)
        subregions = {
            'r1': df.Region(p1=(0, 0, 0), p2=(100, 10, 10)),
            'r2': df.Region(p1=(0, 10, 0), p2=(100, 20, 10)),
            'r3': df.Region(p1=(0, 20, 0), p2=(100, 30, 10)),
            'r4': df.Region(p1=(0, 30, 0), p2=(100, 40, 10)),
            'r5': df.Region(p1=(0, 40, 0), p2=(100, 50, 10)),
            'r6': df.Region(p1=(0, 50, 0), p2=(100, 60, 10)),
            'r7': df.Region(p1=(0, 60, 0), p2=(100, 70, 10)),
            'r8': df.Region(p1=(0, 70, 0), p2=(100, 80, 10))
        }
        mesh = df.Mesh(p1=p1, p2=p2, cell=cell, subregions=subregions)

        # matplotlib tests
        mesh.mpl_subregions()

        filename = 'figure.pdf'
        with tempfile.TemporaryDirectory() as tmpdir:
            tmpfilename = os.path.join(tmpdir, filename)
            mesh.mpl_subregions(filename=tmpfilename)

        plt.close('all')

        # k3d tests
        mesh.k3d_subregions()
def test_outputstep(calculator):
    name = 'output_step'

    p1 = (0, 0, 0)
    p2 = (5e-9, 5e-9, 5e-9)
    n = (2, 2, 2)
    Ms = 1e6
    A = 1e-12
    H = (0, 0, 1e6)
    region = df.Region(p1=p1, p2=p2)
    mesh = df.Mesh(region=region, n=n)

    system = mm.System(name=name)
    system.energy = mm.Exchange(A=A) + mm.Zeeman(H=H)
    system.m = df.Field(mesh, dim=3, value=(0, 0.1, 1), norm=Ms)

    md = calculator.MinDriver()
    md.drive(system, output_step=True)

    dirname = os.path.join(name, 'drive-0')
    assert os.path.exists(dirname)

    assert len(system.table.data.index) > 1

    calculator.delete(system)
Beispiel #12
0
def test_dirname(calculator):
    name = 'specifying_dirname'
    mydirname = './my_dirname'

    p1 = (0, 0, 0)
    p2 = (5e-9, 5e-9, 5e-9)
    n = (2, 2, 2)
    Ms = 1e6
    A = 1e-12
    H = (0, 0, 1e6)
    region = df.Region(p1=p1, p2=p2)
    mesh = df.Mesh(region=region, n=n)

    system = mm.System(name=name)
    system.energy = mm.Exchange(A=A) + mm.Zeeman(H=H)
    system.dynamics = (mm.Precession(gamma0=mm.consts.gamma0) +
                       mm.Damping(alpha=1))
    system.m = df.Field(mesh, dim=3, value=(0, 0.1, 1), norm=Ms)

    md = calculator.MinDriver()
    md.drive(system, dirname=mydirname)

    dirname = os.path.join(mydirname, name, 'drive-0')
    assert os.path.exists(dirname)

    system.energy.zeeman.H = (1e6, 0, 0)

    td = calculator.TimeDriver()
    td.drive(system, t=100e-12, n=10, dirname=mydirname)

    dirname = os.path.join(mydirname, name, 'drive-1')
    assert os.path.exists(dirname)

    shutil.rmtree(mydirname)
Beispiel #13
0
    def minimise_system_energy(L, m_init):
        N = 16  # discretisation in one dimension
        cubesize = 100e-9  # cube edge length (m)
        cellsize = cubesize/N  # discretisation in all three dimensions.
        lex = cubesize/L  # exchange length.

        Km = 1e6  # magnetostatic energy density (J/m**3)
        Ms = np.sqrt(2*Km/mm.consts.mu0)  # magnetisation saturation (A/m)
        A = 0.5 * mm.consts.mu0 * Ms**2 * lex**2  # exchange energy constant
        K = 0.1*Km  # Uniaxial anisotropy constant
        u = (0, 0, 1)  # Uniaxial anisotropy easy-axis

        p1 = (0, 0, 0)  # Minimum sample coordinate.
        p2 = (cubesize, cubesize, cubesize)  # Maximum sample coordinate.
        cell = (cellsize, cellsize, cellsize)  # Discretisation.
        region = df.Region(p1=p1, p2=p2)
        mesh = df.Mesh(region=region, cell=cell)

        system = mm.System(name=name)
        system.energy = (mm.Exchange(A=A) + mm.UniaxialAnisotropy(K=K, u=u) +
                         mm.Demag())
        system.m = df.Field(mesh, dim=3, value=m_init, norm=Ms)

        md = calculator.MinDriver()
        md.drive(system)

        calculator.delete(system)

        return system
def test_integral():
    p1 = (0, 0, 0)
    p2 = (10, 10, 10)
    cell = (1, 1, 1)
    region = df.Region(p1=p1, p2=p2)
    mesh = df.Mesh(region=region, cell=cell)
    field = df.Field(mesh, dim=3, value=(1, -2, 3))

    for attr in ['dx', 'dy', 'dz', 'dV']:
        assert df.integral(field * getattr(df, attr)) == (1000, -2000, 3000)
        assert df.integral(getattr(df, attr) * field) == (1000, -2000, 3000)
        assert df.integral(field * abs(getattr(df, attr))) == (1000, -2000,
                                                               3000)

    assert df.integral(field * (2 * df.dx)) == (2000, -4000, 6000)
    assert df.integral(field * (df.dx * 2)) == (2000, -4000, 6000)

    assert df.integral(field.plane('z') @ df.dS) == 300
    assert df.integral(df.dS @ field.plane('z')) == 300

    assert df.integral(field.plane('z') * (df.dS @ df.dS)) == (100, -200, 300)

    assert (field.plane('z') * (df.dS @ (0, 0, 1))).average == (1, -2, 3)
    assert (field.plane('z') * ((0, 0, 1) @ df.dS)).average == (1, -2, 3)

    dV = df.dx * df.dy * df.dz
    assert df.integral(field * dV) == df.integral(field * df.dV)

    with pytest.raises(TypeError):
        res = df.dx * 'dy'

    with pytest.raises(TypeError):
        res = df.dS @ 'dy'
Beispiel #15
0
    def test_dV(self):
        p1 = (0, 0, 0)
        p2 = (100, 80, 10)
        cell = (1, 2, 2.5)
        mesh = df.Mesh(region=df.Region(p1=p1, p2=p2), cell=cell)

        assert mesh.dV == 5
Beispiel #16
0
    def test_pad(self):
        p1 = (-1, 2, 7)
        p2 = (5, 9, 4)
        cell = (1, 1, 1)
        region = df.Region(p1=p1, p2=p2)
        mesh = df.Mesh(region=region, cell=cell)

        padded_mesh = mesh.pad({'x': (0, 1)})
        assert padded_mesh.region.pmin == (-1, 2, 4)
        assert padded_mesh.region.pmax == (6, 9, 7)
        assert padded_mesh.n == (7, 7, 3)

        padded_mesh = mesh.pad({'y': (1, 1)})
        assert padded_mesh.region.pmin == (-1, 1, 4)
        assert padded_mesh.region.pmax == (5, 10, 7)
        assert padded_mesh.n == (6, 9, 3)

        padded_mesh = mesh.pad({'z': (2, 3)})
        assert padded_mesh.region.pmin == (-1, 2, 2)
        assert padded_mesh.region.pmax == (5, 9, 10)
        assert padded_mesh.n == (6, 7, 8)

        padded_mesh = mesh.pad({'x': (1, 1), 'y': (1, 1), 'z': (1, 1)})
        assert padded_mesh.region.pmin == (-2, 1, 3)
        assert padded_mesh.region.pmax == (6, 10, 8)
        assert padded_mesh.n == (8, 9, 5)
Beispiel #17
0
    def test_dir(self):
        p1 = (0, 0, 0)
        p2 = (100e-9, 80e-9, 10e-9)
        cell = (1e-9, 5e-9, 10e-9)
        mesh = df.Mesh(region=df.Region(p1=p1, p2=p2), cell=cell)

        assert all([i in dir(mesh) for i in ['dx', 'dy', 'dz']])
Beispiel #18
0
    def test_init_invalid_args(self):
        for p1, p2, n, cell in self.invalid_args:
            with pytest.raises((TypeError, ValueError)):
                mesh = df.Mesh(region=df.Region(p1=p1, p2=p2), n=n, cell=cell)

            with pytest.raises((TypeError, ValueError)):
                mesh = df.Mesh(p1=p1, p2=p2, n=n, cell=cell)
Beispiel #19
0
    def test_neighbours(self):
        p1 = (0, 0, 0)
        p2 = (5, 3, 2)
        n = (5, 3, 2)
        mesh = df.Mesh(region=df.Region(p1=p1, p2=p2), n=n)

        neighbours = mesh.neighbours((1, 1, 1))
        assert isinstance(neighbours, list)
        assert len(neighbours) == 5
        assert (0, 1, 1) in neighbours
        assert (2, 1, 1) in neighbours
        assert (1, 0, 1) in neighbours
        assert (1, 2, 1) in neighbours
        assert (1, 1, 0) in neighbours

        neighbours = mesh.neighbours((0, 0, 0))
        assert isinstance(neighbours, list)
        assert len(neighbours) == 3
        assert (1, 0, 0) in neighbours
        assert (0, 1, 0) in neighbours
        assert (0, 0, 1) in neighbours

        p1 = (0, 0, 0)
        p2 = (5, 5, 5)
        n = (5, 5, 5)
        mesh = df.Mesh(region=df.Region(p1=p1, p2=p2), n=n, bc='xy')

        neighbours = mesh.neighbours((0, 0, 0))
        assert isinstance(neighbours, list)
        assert len(neighbours) == 5
        assert (4, 0, 0) in neighbours
        assert (1, 0, 0) in neighbours
        assert (0, 1, 0) in neighbours
        assert (0, 4, 0) in neighbours
        assert (0, 0, 1) in neighbours

        neighbours = mesh.neighbours((4, 4, 4))
        assert isinstance(neighbours, list)
        assert len(neighbours) == 5
        assert (3, 4, 4) in neighbours
        assert (0, 4, 4) in neighbours
        assert (4, 0, 4) in neighbours
        assert (4, 3, 4) in neighbours
        assert (4, 4, 3) in neighbours

        with pytest.raises(ValueError):
            neighbours = mesh.neighbours((10, 4, 4))
 def setup(self):
     p1 = (0, 0, 0)
     p2 = (10e-9, 10e-9, 10e-9)
     n = (10, 10, 10)
     Ms = 1e6
     region = df.Region(p1=p1, p2=p2)
     mesh = df.Mesh(region=region, n=n)
     self.m = df.Field(mesh=mesh, dim=3, value=(0, 1, 1), norm=Ms)
Beispiel #21
0
    def test_repr(self):
        p1 = (-1, -4, 11)
        p2 = (15, 10.1, 12.5)
        region = df.Region(p1=p1, p2=p2)

        check_region(region)
        rstr = 'Region(p1=(-1.0, -4.0, 11.0), p2=(15.0, 10.1, 12.5))'
        assert repr(region) == rstr
Beispiel #22
0
    def test_init_zero_edge_length(self):
        args = [[(0, 100e-9, 1e-9), (150e-9, 100e-9, 6e-9)],
                [(0, 101e-9, -1), (150e-9, 101e-9, 0)],
                [(10e9, 10e3, 0), (0.01e12, 11e3, 5)]]

        for p1, p2 in args:
            with pytest.raises(ValueError) as excinfo:
                region = df.Region(p1=p1, p2=p2)
            assert 'is zero' in str(excinfo.value)
Beispiel #23
0
    def test_axis_points(self):
        p1 = (0, 0, 0)
        p2 = (10, 6, 8)
        cell = (2, 2, 2)
        mesh = df.Mesh(region=df.Region(p1=p1, p2=p2), cell=cell)

        assert list(mesh.axis_points('x')) == [1.0, 3.0, 5.0, 7.0, 9.0]
        assert list(mesh.axis_points('y')) == [1.0, 3.0, 5.0]
        assert list(mesh.axis_points('z')) == [1.0, 3.0, 5.0, 7.0]
Beispiel #24
0
    def test_init_with_region_and_points(self):
        p1 = (0, -4, 16.5)
        p2 = (15, 10.1, 11)
        region = df.Region(p1=p1, p2=p2)
        n = (10, 10, 10)

        with pytest.raises(ValueError) as excinfo:
            mesh = df.Mesh(region=region, p1=p1, p2=p2, n=n)
        assert 'not both.' in str(excinfo.value)
Beispiel #25
0
    def test_regions(self):
        p1 = (0, 0, 0)
        p2 = (100, 50, 10)
        cell = (1, 1, 1)
        regions = {
            'r1': df.Region(p1=(0, 0, 0), p2=(50, 50, 10)),
            'r2': df.Region(p1=(50, 0, 0), p2=(100, 50, 10))
        }
        mesh = df.Mesh(p1=p1, p2=p2, cell=cell, regions=regions)

        assert (0, 0, 0) in mesh.regions['r1']
        assert (0, 0, 0) not in mesh.regions['r2']
        assert (25, 25, 5) in mesh.regions['r1']
        assert (25, 25, 5) not in mesh.regions['r2']
        assert (51, 10, 10) in mesh.regions['r2']
        assert (51, 10, 10) not in mesh.regions['r1']
        assert (100, 50, 10) in mesh.regions['r2']
        assert (100, 50, 10) not in mesh.regions['r1']
Beispiel #26
0
    def test_init_valid_args(self):
        for p1, p2, n, cell in self.valid_args:
            mesh1 = df.Mesh(region=df.Region(p1=p1, p2=p2), n=n, cell=cell)
            check_mesh(mesh1)

            mesh2 = df.Mesh(p1=p1, p2=p2, n=n, cell=cell)
            check_mesh(mesh2)

            assert mesh1 == mesh2
Beispiel #27
0
    def test_k3d(self):
        p1 = (-50e9, -50e9, 0)
        p2 = (50e9, 50e9, 20e9)
        region = df.Region(p1=p1, p2=p2)

        check_region(region)

        # Check if runs.
        region.k3d()
        region.k3d(multiplier=1e9, color=dfu.cp_int[3], wireframe=True)
Beispiel #28
0
    def __init__(self, *, region=None, p1=None, p2=None, n=None, cell=None,
                 bc='', subregions=dict()):
        if region is not None and p1 is None and p2 is None:
            self.region = region
        elif region is None and p1 is not None and p2 is not None:
            self.region = df.Region(p1=p1, p2=p2)
        else:
            msg = 'Either region or p1 and p2 can be passed, not both.'
            raise ValueError(msg)

        if cell is not None and n is None:
            self.cell = tuple(cell)
            n = np.divide(self.region.edges, self.cell).round().astype(int)
            self.n = dfu.array2tuple(n)
        elif n is not None and cell is None:
            self.n = tuple(n)
            cell = np.divide(self.region.edges, self.n).astype(float)
            self.cell = dfu.array2tuple(cell)
        else:
            msg = 'Either n or cell can be passed, not both.'
            raise ValueError(msg)

        # Check if the mesh region is an aggregate of the discretisation cell.
        tol = 1e-12  # picometre tolerance
        rem = np.remainder(self.region.edges, self.cell)
        if np.logical_and(np.greater(rem, tol),
                          np.less(rem, np.subtract(self.cell, tol))).any():
            msg = (f'Region cannot be divided into '
                   f'discretisation cells of size {self.cell=}.')
            raise ValueError(msg)

        self.bc = bc.lower()

        # Check if subregions are aligned with the mesh
        for key, value in subregions.items():
            # Is the subregion in the mesh region?
            if value not in self.region:
                msg = f'Subregion {key} is not in the mesh region.'
                raise ValueError(msg)

            # Is the subregion an aggregate of discretisation cell?
            try:
                submesh = self.__class__(region=value, cell=self.cell)
            except ValueError:
                msg = (f'Subregion {key} cannot be divided into '
                       f'discretisation cells of size {self.cell=}.')
                raise ValueError(msg)

            # Is the subregion aligned with the mesh?
            if not (self.__class__(region=self.region, cell=self.cell) |
                    self.__class__(region=value, cell=self.cell)):
                msg = f'Subregion {key} is not aligned with the mesh.'
                raise ValueError(msg)

        self.subregions = subregions
Beispiel #29
0
    def test_mpl(self):
        for p1, p2, n, cell in self.valid_args:
            mesh = df.Mesh(region=df.Region(p1=p1, p2=p2), n=n, cell=cell)
            mesh.mpl()

            filename = 'figure.pdf'
            with tempfile.TemporaryDirectory() as tmpdir:
                tmpfilename = os.path.join(tmpdir, filename)
                mesh.mpl(filename=tmpfilename)

            plt.close('all')
 def setup(self):
     p1 = (0, 0, 0)
     p2 = (5e-9, 5e-9, 5e-9)
     n = (5, 5, 5)
     self.Ms = 1e6
     A = 1e-12
     H = (0, 0, 1e6)
     region = df.Region(p1=p1, p2=p2)
     self.mesh = df.Mesh(region=region, n=n)
     self.energy = mm.Exchange(A=A) + mm.Zeeman(H=H)
     self.m = df.Field(self.mesh, dim=3, value=(0, 1, 0), norm=self.Ms)