Пример #1
0
def compute_field(mesh, nx=1, ny=1, m0=(1, 0, 0), pbc=None):

    Ms = 1e6
    sim = Simulation(mesh, Ms, unit_length=1e-9, name='dy', pbc=pbc)

    sim.set_m(m0)

    parameters = {
        'absolute_tolerance': 1e-10,
        'relative_tolerance': 1e-10,
        'maximum_iterations': int(1e5)
    }

    demag = Demag(macrogeometry=MacroGeometry(nx=nx, ny=ny))

    demag.parameters['phi_1'] = parameters
    demag.parameters['phi_2'] = parameters

    sim.add(demag)

    field = sim.llg.effective_field.get_dolfin_function('Demag')

    # XXX TODO: Would be good to compare all the field values, not
    #           just the value at a single point!  (Max, 25.7.2014)
    return field(0, 0, 0) / Ms
Пример #2
0
def test_dmi_pbc2d_1D(plot=False):
    def m_init_fun(p):
        if p[0] < 10:
            return [0.5, 0, 1]
        else:
            return [-0.5, 0, -1]

    mesh = df.RectangleMesh(df.Point(0, 0), df.Point(20, 2), 10, 1)
    m_init = vector_valued_function(m_init_fun, mesh)

    Ms = 8.6e5
    sim = Simulation(mesh, Ms, pbc='2d', unit_length=1e-9)

    sim.set_m(m_init_fun)

    A = 1.3e-11
    D = 5e-3
    sim.add(Exchange(A))
    sim.add(DMI(D))

    sim.relax(stopping_dmdt=0.0001)

    if plot:
        sim.m_field.plot_with_dolfin()

    mx = [sim.m_field.probe([x + 0.5, 1])[0] for x in range(20)]

    assert np.max(np.abs(mx)) < 1e-6
Пример #3
0
def test_compute_skyrmion_number_2d_pbc():

    mesh = df.RectangleMesh(df.Point(0, 0), df.Point(100, 100), 40, 40)

    Ms = 8.6e5
    sim = Simulation(mesh, Ms, pbc='2d', unit_length=1e-9)
    sim.set_m(init_skx_down)

    sim.add(Exchange(1.3e-11))
    sim.add(DMI(D=4e-3))
    sim.add(Zeeman((0, 0, 0.45 * Ms)))

    sim.do_precession = False

    sim.relax(stopping_dmdt=1, dt_limit=1e-9)

    #df.plot(sim.m_field.f)
    #df.interactive()
    print np.max(sim.m_field.as_array())

    sky_num = compute_skyrmion_number_2d(sim.m_field.f)

    print 'sky_num = %g' % sky_num

    assert sky_num < -0.95 and sky_num > -1.0
Пример #4
0
def compute_field(n=1, m0=(1, 0, 0), pbc=None):

    assert n >= 1 and n % 2 == 1

    Ms = 1e6
    sim = Simulation(mesh, Ms, unit_length=1e-9, name='dy', pbc=pbc)

    sim.set_m(m0)

    parameters = {
        'absolute_tolerance': 1e-10,
        'relative_tolerance': 1e-10,
        'maximum_iterations': int(1e5)
    }

    Ts = []
    for i in range(-n / 2 + 1, n / 2 + 1):
        Ts.append((10. * i, 0, 0))

    demag = Demag(Ts=Ts)

    demag.parameters['phi_1'] = parameters
    demag.parameters['phi_2'] = parameters

    sim.add(demag)

    sim.set_m((1, 0, 0))
    field1 = sim.llg.effective_field.get_dolfin_function('Demag')

    sim.set_m((0, 0, 1))
    field2 = sim.llg.effective_field.get_dolfin_function('Demag')

    return (field1(0, 0, 0) / Ms, field2(0, 0, 0) / Ms)
Пример #5
0
def relax_system():
    Ms = 8.6e5
    sim = Simulation(mesh, Ms, unit_length=1e-9, name = 'dy')
    
    sim.alpha = 0.001
    sim.set_m(np.load('m_000088.npy'))
    
    #sim.set_tol(1e-6, 1e-6)

    A = 1.3e-11
    
    sim.add(Exchange(A))
    
    
    parameters = {
            'absolute_tolerance': 1e-10,
            'relative_tolerance': 1e-10,
            'maximum_iterations': int(1e5)
    }
    
    demag = Demag()
    
    demag.parameters['phi_1'] = parameters
    demag.parameters['phi_2'] = parameters
    
    print demag.parameters
    
    sim.add(demag)
    
    sim.schedule('save_ndt', every=2e-12)
    sim.schedule('save_vtk', every=2e-12, filename='vtks/m.pvd')
    sim.schedule('save_m', every=2e-12, filename='npys/m.pvd')
    
    sim.run_until(1e-9)
Пример #6
0
def run_finmag():
    # Setup
    setupstart = time.time()
    mesh = df.Box(0, 0, 0, 30, 30, 100, 15, 15, 50)
    sim = Simulation(mesh, Ms=0.86e6, unit_length=1e-9)
    sim.set_m((1, 0, 1))
    demag = Demag("FK")
    demag.parameters["poisson_solver"]["method"] = "cg"
    demag.parameters["poisson_solver"]["preconditioner"] = "jacobi"
    demag.parameters["laplace_solver"]["method"] = "cg"
    demag.parameters["laplace_solver"]["preconditioner"] = "bjacobi"
    sim.add(demag)
    sim.add(Exchange(13.0e-12))

    # Dynamics
    dynamicsstart = time.time()
    sim.run_until(3.0e-10)
    endtime = time.time()

    # Write output to results.txt
    output = open(os.path.join(MODULE_DIR, "results.txt"), "a")
    output.write("\nBackend %s:\n" % df.parameters["linear_algebra_backend"])
    output.write("\nSetup: %.3f sec.\n" % (dynamicsstart - setupstart))
    output.write("Dynamics: %.3f sec.\n\n" % (endtime - dynamicsstart))
    output.write(str(default_timer))
    output.close()
Пример #7
0
def test_differentiate_heff():
    ns = [2, 2, 2]
    mesh = df.BoxMesh(0, 0, 0, 1, 1, 1, *ns)
    sim = Simulation(mesh, 1.2)
    sim.set_m([1, 0, 0])
    sim.add(Demag())
    sim.add(Exchange(2.3 * mu0))

    compute_H = compute_H_func(sim)

    # Check that H_eff is linear without Zeeman
    np.random.seed(1)
    m1 = fnormalise(np.random.randn(*sim.m.shape))
    m2 = fnormalise(np.random.randn(*sim.m.shape))
    # TODO: need to use a non-iterative solver here to increase accuracy
    assert np.max(
        np.abs(compute_H(m1) + compute_H(m2) - compute_H(m1 + m2))) < 1e-6
    # Add the zeeman field now
    sim.add(Zeeman([2.5, 3.5, 4.3]))

    # Check that both fd2 and fd4 give the same result
    assert np.max(
        np.abs(
            differentiate_fd4(compute_H, m1, m2) -
            differentiate_fd2(compute_H, m1, m2))) < 1e-10
Пример #8
0
def macrospin(Ms=0.86e6,
              m_init=(1, 0, 0),
              H_ext=(0, 0, 1e6),
              alpha=0.1,
              name='macrospin'):
    """
    Minimal mesh with two vertices (1 nm apart). No anisotropy,
    exchange coupling or demag is present so that magnetic moments at
    the two vertices behave identical under the influence of the
    external field. (Ideally, we would only have a single vertex but
    Dolfin doesn't support this.)

    Default values for the arguments:

        Ms = 0.86e6  (saturation magnetisation in A/m)

        m_init = (1, 0, 0)  (initial magnetisation pointing along the x-axis)

        H_ext = (0, 0, 1e6)  (external field in A/m)

        alpha = 0.1  (Gilbert damping coefficient)

    """
    mesh = df.UnitIntervalMesh(1)

    sim = Simulation(mesh, Ms=Ms, unit_length=1e-9, name=name)
    sim.alpha = alpha
    sim.set_m(m_init)
    sim.add(Zeeman(H_ext))

    return sim
Пример #9
0
def ring_down(m0=(1, 0.01, 0), pbc=None):

    n = 49

    assert n >= 1 and n % 2 == 1

    Ms = 8.6e5

    sim = Simulation(mesh, Ms, unit_length=1e-9, name='dy', pbc='1d')
    sim.alpha = 1e-3

    sim.set_m(m0)
    sim.set_tol(1e-8, 1e-8)

    parameters = {
        'absolute_tolerance': 1e-10,
        'relative_tolerance': 1e-10,
        'maximum_iterations': int(1e5)
    }

    Ts = []
    for i in range(-n / 2 + 1, n / 2 + 1):
        Ts.append((10. * i, 0, 0))

    demag = Demag(Ts=Ts)

    demag.parameters['phi_1'] = parameters
    demag.parameters['phi_2'] = parameters

    sim.add(demag)
    sim.add(Exchange(1.3e-11))

    sim.schedule('save_ndt', every=2e-12)

    sim.run_until(4e-9)
Пример #10
0
def _test_scipy_advance_time():
    mesh = df.UnitIntervalMesh(10)
    sim = Simulation(mesh, Ms=1, unit_length=1e-9, integrator_backend="scipy")
    sim.set_m((1, 0, 0))
    sim.advance_time(1e-12)
    sim.advance_time(2e-12)
    sim.advance_time(2e-12)
    sim.advance_time(2e-12)
Пример #11
0
def test_anisotropy():
    mesh = df.IntervalMesh(1, 0, 1)
    sim = Simulation(mesh, Ms, unit_length=1e-9)
    sim.set_m((mx, my, mz))

    sim.add(UniaxialAnisotropy(K1, axis=[1, 0, 0]))

    expected = 2 * K1 / (mu0 * Ms) * mx
    field = sim.effective_field()
    assert abs(field[0] - expected) / Ms < 1e-15
Пример #12
0
def test_deviations_over_alpha_and_tol(number_of_alphas=5, do_plot=False):
    alphas = numpy.linspace(0.01, 1.00, number_of_alphas)

    max_deviationss = []
    for rtol_power_of_ten in rtols_powers_of_ten:
        rtol = pow(10, rtol_power_of_ten)
        print "#### New series for rtol={0}. ####".format(rtol)

        # One entry in this array corresponds to the maximum deviation between
        # the analytical solution and the computed solution for one value of alpha.
        max_deviations = []
        for alpha in alphas:
            print "Solving for alpha={0}.".format(alpha)

            sim = Simulation(mesh, 1, unit_length=1e-9)
            sim.alpha = alpha
            sim.set_m((1, 0, 0))
            sim.add(Zeeman((0, 0, 1e5)))

            ts = numpy.linspace(0, 1e-9, num=50)
            ys = odeint(sim.llg.solve_for,
                        sim.llg._m_field.get_numpy_array_debug(),
                        ts,
                        rtol=rtol,
                        atol=rtol)

            # One entry in this array corresponds to the deviation between the two
            # solutions for one particular moment during the simulation.
            deviations = []
            M_analytical = make_analytic_solution(1e5, alpha, sim.gamma)
            for i in range(len(ts)):
                M_computed = numpy.mean(ys[i].reshape((3, -1)), 1)
                M_ref = M_analytical(ts[i])
                # The difference of the two vectors has 3 components. The
                # deviation is the average over these components.
                deviation = numpy.mean(numpy.abs(M_computed - M_ref))
                assert deviation < TOLERANCE
                deviations.append(deviation)

            # This represents the addition of one point to the graph.
            max_deviations.append(numpy.max(deviations))

        # This represents one additional series in the graph.
        max_deviationss.append(max_deviations)

    if do_plot:
        for i in range(len(rtols_powers_of_ten)):
            label = r"$rtol=1\cdot 10^{" + str(rtols_powers_of_ten[i]) + r"}$"
            plt.plot(alphas, max_deviationss[i], ".", label=label)
        plt.legend()
        plt.title(r"Influence of $\alpha$ and rtol on the Deviation")
        plt.ylabel("deviation")
        plt.xlabel(r"$\alpha$")
        plt.ylim((0, 1e-6))
        plt.savefig(os.path.join(MODULE_DIR, "deviation_over_alpha_rtols.pdf"))
Пример #13
0
def test_spatially_varying_anisotropy_axis(tmpdir, debug=False):
    Ms = 1e6
    A = 1.3e-11
    K1 = 6e5
    lb = bloch_parameter(A, K1)

    unit_length = 1e-9
    nx = 20
    Lx = nx * lb / unit_length
    mesh = df.IntervalMesh(nx, 0, Lx)

    # anisotropy axis goes from (0, 1, 0) at x=0 to (1, 0, 0) at x=Lx
    expr_a = df.Expression(("x[0] / sqrt(pow(x[0], 2) + pow(Lx-x[0], 2))",
                            "(Lx-x[0]) / sqrt(pow(x[0], 2) + pow(Lx-x[0], 2))",
                            "0"), Lx=Lx, degree=1)
    # in theory, a discontinuous Galerkin (constant over the cell) is a good
    # choice to represent material parameters. In this case though, the
    # parameter varies linearly, so we use the usual CG.
    V = df.VectorFunctionSpace(mesh, "CG", 1, dim=3)
    a = Field(V, expr_a)

    sim = Simulation(mesh, Ms, unit_length)
    sim.set_m((1, 1, 0))
    sim.add(UniaxialAnisotropy(K1, a))
    sim.relax()

    # probe the easy axis and the magnetisation along the interval
    points = 100
    xs = np.linspace(0, Lx, points)
    axis_xs = np.zeros((points, 3))
    m_xs = np.zeros((points, 3))

    for i, x in enumerate(xs):
        axis_xs[i] = a(x)
        m_xs[i] = sim.m_field(x)

    # we want to the magnetisation to follow the easy axis
    # it does so, except at x=0, what is happening there?
    diff = np.abs(m_xs - axis_xs)
    assert diff.max() < 0.02

    if debug:
        old = os.getcwd()
        os.chdir(tmpdir)
        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.plot(xs, axis_xs[:, 0], "b+", label="a_x")
        ax.plot(xs, m_xs[:, 0], "r--", label="m_x")
        ax.legend(loc="upper left")
        ax.set_ylim((0, 1.05))
        ax.set_xlabel("x (nm)")
        plt.savefig('spatially_varying_easy_axis.png')
        plt.close()
        sim.m_field.save_pvd('spatially_varying_easy_axis.pvd')
        os.chdir(old)
Пример #14
0
def run_simulation(plot=False):
    mu0 = 4.0 * np.pi * 10**-7  # vacuum permeability N/A^2
    Ms = 1.0e6  # saturation magnetisation A/m
    A = 13.0e-12  # exchange coupling strength J/m
    Km = 0.5 * mu0 * Ms**2  # magnetostatic energy density scale kg/ms^2
    lexch = (A / Km)**0.5  # exchange length m
    unit_length = 1e-9
    K1 = Km

    L = lexch / unit_length
    nx = 10
    Lx = nx * L
    ny = 1
    Ly = ny * L
    nz = 30
    Lz = nz * L
    mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(Lx, Ly, Lz), nx, ny, nz)

    # Anisotropy easy axis is (0, 0, 1) in the lower half of the film and
    # (1, 0, 0) in the upper half. This is a toy model of the exchange spring
    # systems that Bob Stamps is working on.
    boundary = Lz / 2.0
    expr_a = df.Expression(("x[2] <= b ? 0 : 1", "0", "x[2] <= b ? 1 : 0"),
                           b=boundary,
                           degree=1)
    V = df.VectorFunctionSpace(mesh, "DG", 0, dim=3)
    a = Field(V, expr_a)

    sim = Simulation(mesh, Ms, unit_length)
    sim.set_m((1, 0, 1))
    sim.add(UniaxialAnisotropy(K1, a))
    sim.add(Exchange(A))
    sim.relax()

    if plot:
        points = 200
        zs = np.linspace(0, Lz, points)
        axis_zs = np.zeros((points, 3))  # easy axis probed along z-axis
        m_zs = np.zeros((points, 3))  # magnetisation probed along z-axis

        for i, z in enumerate(zs):
            axis_zs[i] = a((Lx / 2.0, Ly / 2.0, z))
            m_zs[i] = sim.m_field((Lx / 2.0, Ly / 2.0, z))

        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.plot(zs, axis_zs[:, 0], "-o", label="a_x")
        ax.plot(zs, axis_zs[:, 2], "-x", label="a_z")
        ax.plot(zs, m_zs[:, 0], "-", label="m_x")
        ax.plot(zs, m_zs[:, 2], "-", label="m_z")
        ax.set_xlabel("z (nm)")
        ax.legend(loc="upper left")
        plt.savefig(os.path.join(MODULE_DIR, "profile.png"))
        sim.m_field.save_pvd(os.path.join(MODULE_DIR, 'exchangespring.pvd'))
Пример #15
0
def example_simulation():
    Ms = 8.6e5
    mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(40, 20, 20), 10, 5, 5)

    example = Simulation(mesh, Ms, name="sim_with_scheduling")
    example.set_m((0.1, 1, 0))
    example.add(Exchange(13.0e-12))
    example.add(Demag())
    example.add(Zeeman((Ms/2, 0, 0)))

    return example
Пример #16
0
def run_simulation(stop_when_mx_eq_zero):
    """
    Runs the simulation using field #1 from the problem description.

    Stores the average magnetisation components regularly, as well as the
    magnetisation when the x-component of the average magnetisation crosses
    the value 0 for the first time.

    """
    mesh = from_geofile(os.path.join(MODULE_DIR, "bar.geo"))

    sim = Simulation(mesh, Ms, name="dynamics", unit_length=1e-9)
    sim.alpha = alpha
    sim.gamma = gamma
    sim.set_m(np.load(m_0_file))
    sim.add(Demag())
    sim.add(Exchange(A))
    """
    Conversion between mu0 * H in mT and H in A/m.

                   mu0 * H = 1               mT
                           = 1 * 1e-3        T
                           = 1 * 1e-3        Vs/m^2
    divide by mu0 with mu0 = 4pi * 1e-7      Vs/Am
    gives                H = 1 / 4pi * 1e4   A/m

    with the unit A/m which is indeed what we want.
    Consequence:
        Just divide the value of mu0 * H in Tesla
        by mu0 to get the value of H in A/m.

    """
    Hx = -24.6e-3 / mu0
    Hy = 4.3e-3 / mu0
    Hz = 0
    sim.add(Zeeman((Hx, Hy, Hz)))

    def check_if_crossed(sim):
        mx, _, _ = sim.m_average
        if mx <= 0:
            print "The x-component of the spatially averaged magnetisation first crossed zero at t = {}.".format(
                sim.t)
            np.save(m_at_crossing_file, sim.m)
            # When this function returns True, it means this event is done
            # and doesn't need to be triggered anymore.
            # When we return False, it means we want to stop the simulation.
            return not stop_when_mx_eq_zero

    sim.schedule(check_if_crossed, every=1e-12)
    sim.schedule('save_averages', every=10e-12, at_end=True)
    sim.schedule('save_vtk', every=10e-12, at_end=True, overwrite=True)
    sim.run_until(2.0e-9)
    return sim.t
Пример #17
0
def excite_system():
    Ms = 8.6e5
    sim = Simulation(mesh, Ms, pbc='1d', unit_length=1e-9)

    sim.alpha = 0.0001
    sim.set_m(np.load('relaxed.npy'))

    alpha_expr = AlphaExpression()
    alpha_mult = df.interpolate(alpha_expr, sim.llg.S1)
    sim.spatial_alpha(0.0001, alpha_mult)

    #df.plot(alpha_mult)
    #df.interactive()
    #xs=find_skyrmion_center(sim.llg._m)
    #
    #assert(1==2)

    A = 1.3e-11
    D = 4e-3
    sim.add(Exchange(A))
    sim.add(DMI(D))
    sim.add(Zeeman((0, 0, 0.4 * Ms)))

    GHz = 1e9
    omega = 50 * 2 * np.pi * GHz

    def time_fun(t):
        return np.sinc(omega * (t - 50e-12))

    h0 = 1e3
    kc = 1.0 / 45.0
    H0 = MyExpression(h0, kc)

    sim.add(TimeZeemanPython(H0, time_fun))

    xs = find_skyrmion_center(sim.llg._m)
    ts = np.linspace(0, 8e-9, 4001)

    np.save('xs.npy', xs)

    sim.create_integrator()
    sim.integrator.integrator.set_scalar_tolerances(1e-8, 1e-8)

    index = 0
    for t in ts:

        sim.run_until(t)

        np.save('data/m_%d.npy' % index, sim.llg.m)

        index += 1
def test_spatially_varying_alpha_using_Simulation_class():
    """
    test that I can change the value of alpha through the property sim.alpha
    and that I get an df.Function back.

    """
    length = 20
    simplices = 10
    mesh = df.IntervalMesh(simplices, 0, length)

    sim = Simulation(mesh, Ms=1, unit_length=1e-9)
    sim.alpha = 1
    expected_alpha = np.ones(simplices + 1)
    assert np.array_equal(sim.alpha.vector().array(), expected_alpha)
Пример #19
0
def cubic_anisotropy(K1=520e3, K2=0, K3=0):
    mesh = df.RectangleMesh(df.Point(0, 0), df.Point(50, 2), 20, 1)

    sim = Simulation(mesh, Ms, unit_length=1e-9)
    sim.set_m(m_init)

    sim.add(
        CubicAnisotropy(K1=K1,
                        K2=K2,
                        K3=K3,
                        u1=(1, 0, 0),
                        u2=(0, 1, 0),
                        assemble=False))

    field1 = sim.effective_field()
Пример #20
0
def excite_system():
    Ms = 8.0e5
    sim = Simulation(mesh, Ms, unit_length=1e-9, name='dy')

    sim.alpha = 0.001
    sim.set_m((1, 0, 0))
    sim.set_tol(1e-6, 1e-6)

    A = 1.3e-11

    sim.add(Exchange(A))
    sim.add(Zeeman(varying_field))

    sim.schedule('save_ndt', every=2e-12)
    sim.run_until(0.5e-9)
Пример #21
0
    def setup_sim(self, m0):
        Hz = [8e4, 0, 0] # A/m
        A = 1.3e-11 # J/m
        Ms = 800e3 # A/m
        alpha = 1.

        mesh = df.BoxMesh(0, 0, 0, *(self.box_size + self.box_divisions))

        sim = Simulation(mesh, Ms)
        sim.alpha = alpha
        sim.set_m(m0)
        sim.add(Demag())
        sim.add(Exchange(A))
        sim.add(Zeeman(Hz))

        return sim
Пример #22
0
def test_compute_main():
    Ms = 1700e3
    A = 2.5e-6 * 1e-5
    Hz = [10e3 * Oersted_to_SI(1.), 0, 0]

    mesh = df.BoxMesh(0, 0, 0, 50, 50, 10, 6, 6, 2)
    mesh = df.BoxMesh(0, 0, 0, 5, 5, 5, 1, 1, 1)
    print mesh

    # Find the ground state
    sim = Simulation(mesh, Ms)
    sim.set_m([1, 0, 0])
    sim.add(Demag())
    sim.add(Exchange(A))
    sim.add(Zeeman(Hz))
    sim.relax()
Пример #23
0
def test_compute_A():
    Ms = 1700e3
    A = 2.5e-6 * 1e-5
    Hz = [10e3 * Oersted_to_SI(1.), 0, 0]
    mesh = df.BoxMesh(0, 0, 0, 5, 5, 5, 2, 2, 2)
    sim = Simulation(mesh, Ms)
    sim.set_m([1, 0, 0])
    sim.add(Demag())
    #    sim.add(Exchange(A))
    #    sim.add(Zeeman(Hz))
    sim.relax()

    print mesh
    A0, m0 = compute_A(sim)
    print A0[:3, :3]
    print m0
Пример #24
0
def run_simulation(do_precession):
    Ms = 0.86e6

    mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(30e-9, 30e-9, 100e-9), 6, 6,
                      20)
    sim = Simulation(mesh, Ms)
    sim.set_m((1, 0, 1))
    sim.do_precession = do_precession
    sim.add(Demag())
    sim.add(Exchange(13.0e-12))

    averages = []
    for t in ts:
        sim.run_until(t)
        averages.append(sim.m_average)
    return np.array(averages)
Пример #25
0
def compare_with_analytic_solution(alpha=0.5, max_t=1e-9):
    """
    Compares the C/dolfin/odeint solution to the analytical one.

    """
    print "Running comparison with alpha={0}.".format(alpha)

    # define 3d mesh
    x0 = y0 = z0 = 0
    x1 = y1 = z1 = 10e-9
    nx = ny = nz = 1
    mesh = dolfin.BoxMesh(dolfin.Point(x0, x1, y0), dolfin.Point(y1, z0, z1),
                          nx, ny, nz)

    sim = Simulation(mesh, Ms=1)
    sim.alpha = alpha
    sim.set_m((1, 0, 0))
    sim.add(Zeeman((0, 0, 1e6)))

    # plug in an integrator with lower tolerances
    sim.set_tol(abstol=1e-12, reltol=1e-12)

    ts = numpy.linspace(0, max_t, num=100)
    ys = numpy.array([(sim.advance_time(t), sim.m.copy())[1] for t in ts])
    tsfine = numpy.linspace(0, max_t, num=1000)
    m_analytical = make_analytic_solution(1e6, alpha, sim.gamma)
    save_plot(ts, ys, tsfine, m_analytical, alpha)

    TOLERANCE = 1e-6  # tolerance on Ubuntu 11.10, VM Hans, 25/02/2012

    rel_diff_maxs = list()
    for i in range(len(ts)):
        m = numpy.mean(ys[i].reshape((3, -1)), axis=1)
        m_ref = m_analytical(ts[i])
        diff = numpy.abs(m - m_ref)
        diff_max = numpy.max(diff)
        rel_diff_max = numpy.max(diff / numpy.max(m_ref))
        rel_diff_maxs.append(rel_diff_max)

        print "t= {0:.3g}, diff_max= {1:.3g}.".format(ts[i], diff_max)

        msg = "Diff at t= {0:.3g} too large.\nAllowed {1:.3g}. Got {2:.3g}."
        assert diff_max < TOLERANCE, msg.format(ts[i], TOLERANCE, diff_max)
    print "Maximal relative difference: "
    print numpy.max(numpy.array(rel_diff_maxs))
Пример #26
0
def relax_system(mesh=mesh):

    Ms = 8.6e5
    sim = Simulation(mesh, Ms, pbc='1d', unit_length=1e-9, name='relax')
    sim.set_m(m_init_skyrmion)

    A = 1.3e-11
    D = 4e-3
    sim.add(Exchange(A))
    sim.add(DMI(D))
    sim.add(Zeeman((0, 0, 0.4 * Ms)))

    #sim.run_until(1e-9)
    #sim.schedule('save_vtk', at_end=True)
    #sim.schedule(plot_m, every=1e-10, at_end=True)

    sim.relax()
    df.plot(sim.llg._m)
    np.save('relaxed.npy', sim.m)
Пример #27
0
def run_simulation(verbose=False):
    mesh = from_geofile('bar.geo')

    sim = Simulation(mesh, Ms=0.86e6, unit_length=1e-9, name="finmag_bar")
    sim.set_m((1, 0, 1))
    sim.set_tol(1e-6, 1e-6)
    sim.alpha = 0.5

    sim.add(Exchange(13.0e-12))
    sim.add(Demag())

    sim.schedule('save_averages', every=5e-12)
    sim.schedule("eta", every=10e-12)
    sim.run_until(3e-10)

    print timer
    if verbose:
        print "The RHS was evaluated {} times, while the Jacobian was computed {} times.".format(
            sim.integrator.stats()['nfevals'],
            timer.get("sundials_jtimes", "LLG").calls)
Пример #28
0
def relax(mesh):

    Ms = 8.6e5
    sim = Simulation(mesh, Ms, pbc='2d',unit_length=1e-9)
    sim.set_m(m_init_fun)

    sim.add(Exchange(1.3e-11))
    sim.add(DMI(D = 4e-3))
    sim.add(Zeeman((0,0,0.45*Ms)))

    sim.alpha = 0.5

    ts = np.linspace(0, 1e-9, 101)
    for t in ts:
        sim.run_until(t)
        p = df.plot(sim.llg._m)
    sim.save_vtk()
        
    df.plot(sim.llg._m).write_png("vortex")
    df.interactive()
Пример #29
0
def move_skyrmion(mesh):
    Ms = 8.6e5
    sim = Simulation(mesh, Ms, pbc='2d',unit_length=1e-9, kernel='llg_stt')
    sim.set_m(np.load('m0.npy'))

    sim.add(Exchange(1.3e-11))
    sim.add(DMI(D = 4e-3))
    sim.add(Zeeman((0,0,0.45*Ms)))
    
    sim.alpha=0.01
    
    sim.llg.set_parameters(J_profile=init_J, speedup=50)
    
    ts = np.linspace(0, 5e-9, 101)
    for t in ts:
        sim.run_until(t)
        print t
        #p = df.plot(sim.llg._m)
        sim.save_vtk(filename='nonlocal/v1e7_.pvd')
        
    df.plot(sim.llg._m).write_png("vortex")
Пример #30
0
def move_skyrmion(mesh):
    Ms = 8.6e5
    sim = Simulation(mesh, Ms, pbc='2d', unit_length=1e-9)
    sim.set_m(np.load('m0.npy'))

    sim.add(Exchange(1.3e-11))
    sim.add(DMI(D=4e-3))
    sim.add(Zeeman((0, 0, 0.45 * Ms)))

    sim.alpha = 0.01

    sim.set_zhangli(init_J, 1.0, 0.01)

    ts = np.linspace(0, 10e-9, 101)
    for t in ts:
        sim.run_until(t)
        print t
        #p = df.plot(sim.llg._m)
        sim.save_vtk(filename='vtks/v1e7_.pvd')

    df.plot(sim.llg._m).write_png("vortex")