当前位置: 首页>>代码示例>>Python>>正文


Python Sim.add方法代码示例

本文整理汇总了Python中fidimag.atomistic.Sim.add方法的典型用法代码示例。如果您正苦于以下问题:Python Sim.add方法的具体用法?Python Sim.add怎么用?Python Sim.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fidimag.atomistic.Sim的用法示例。


在下文中一共展示了Sim.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_exch_2d_pbc2d

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def test_exch_2d_pbc2d():
    """
    Test the exchange field components in a 2D mesh with PBCs
    The mesh sites:

            3     4     5    -->    (0,1,0)  (1,1,0)  (2,1,0)
     y ^    0     1     2           (0,0,0)  (1,0,0)  (2,0,0)
       |
       x -->

    The expected components are in increasing order along x

    """

    mesh = CuboidMesh(nx=3, ny=2, nz=1, periodicity=(True, True, False))
    print mesh.neighbours
    sim = Sim(mesh)
    exch = UniformExchange(1)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()

    expected_x = np.array([3, 4, 5, 3, 4, 5])
    expected_y = np.array([2, 2, 2, 2, 2, 2])

    # Since the field ordering is now: fx1 fy1 fz1 fx2 ...
    # We extract the x components jumping in steps of 3
    assert np.max(abs(field[::3] - expected_x)) == 0
    # For the y component is similar, now we start at the 1th
    # entry and jump in steps of 3
    assert np.max(abs(field[1::3] - expected_y)) == 0
    # Similar fot he z component
    assert np.max(field[2::3]) == 0
开发者ID:River315,项目名称:fidimag,代码行数:37,代码来源:test_exch.py

示例2: relax_system

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def relax_system(mesh):

    # Only relaxation
    sim = Sim(mesh, name='relax')

    # Simulation parameters
    sim.driver.set_tols(rtol=1e-8, atol=1e-10)
    sim.alpha = 0.5
    sim.driver.gamma = 2.211e5 / mu0
    sim.mu_s = 1e-27 / mu0
    sim.driver.do_precession = False

    # The initial state passed as a function
    sim.set_m(init_m)
    # sim.set_m(np.load('m0.npy'))

    # Energies
    exch = UniformExchange(J=2e-20)
    sim.add(exch)

    anis = Anisotropy(0.01*2e-20, axis=(0, 0, 1))
    sim.add(anis)

    # dmi = DMI(D=8e-4)
    # sim.add(dmi)

    # Start relaxation and save the state in m0.npy
    sim.relax(dt=1e-14, stopping_dmdt=1e4, max_steps=5000,
              save_m_steps=None, save_vtk_steps=None)

    np.save('m0.npy', sim.spin)
开发者ID:computationalmodelling,项目名称:fidimag,代码行数:33,代码来源:test_stt_dw_atomistic.py

示例3: test_exch_1d

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def test_exch_1d():
    """
    Test the x component of the exchange field
    in a 1D mesh, with the spin ordering:

    0 1 2 3 4 5

    """
    mesh = CuboidMesh(nx=5, ny=1, nz=1)
    sim = Sim(mesh)
    exch = Exchange(1.0)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()

    assert field[0] == 1
    assert field[1 * 3] == 2
    assert field[2 * 3] == 4
    assert field[3 * 3] == 6
    assert field[4 * 3] == 3

    assert np.max(field[2::3]) == 0
    assert np.max(field[1::3]) == 0
开发者ID:fangohr,项目名称:fidimag,代码行数:27,代码来源:test_exch.py

示例4: test_exch_3d

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def test_exch_3d():
    """
    Test the exchange field of the spins in this 3D mesh:

    bottom layer:
    8  9  10  11
    4  5  6   7       x 2
    0  1  2   3

    The assertions are the mx component
    of the: 0, 1, 2, .. 7 spins

    Remember the new new ordering: fx1, fy1, fz1, fx2, ...

    """
    mesh = CuboidMesh(nx=4, ny=3, nz=2)
    sim = Sim(mesh)
    exch = UniformExchange(1)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()
    # print field
    assert field[0] == 1
    assert field[3] == 0 + 1 + 2 + 1
    assert field[6] == 1 + 2 + 3 + 2
    assert field[9] == 2 + 3 + 3

    assert field[4 * 3] == 1
    assert field[5 * 3] == 5
    assert field[6 * 3] == 10
    assert field[7 * 3] == 11
开发者ID:River315,项目名称:fidimag,代码行数:35,代码来源:test_exch.py

示例5: test_dynamic

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def test_dynamic():

    mesh = CuboidMesh(nx=1, ny=1, nz=1)

    sim = Sim(mesh, name='dyn_spin', driver='llg_stt_cpp')
    # sim.set_options(rtol=1e-10,atol=1e-14)
    sim.driver.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m((0.8,0,-1))

    Kx = Anisotropy(Ku=-0.05, axis=(0, 0, 1), name='Kz')
    sim.add(Kx)

    sim.p = (0,0,1)

    sim.a_J = 0.0052
    sim.alpha = 0.1

    ts = np.linspace(0, 1200, 401)
    for t in ts:
        sim.driver.run_until(t)


    mz = sim.spin[2]
    alpha, K, u = 0.1, 0.05, 0.0052
    print(mz, u/(2*alpha*K))

    #########################################################
    # The system used in this test can be solved analytically, which gives that mz = u/(2*alpha*K),
    # where K represents the easy-plane anisotropy.
    ###
    assert abs(mz - u/(2*alpha*K))/mz< 5e-4
开发者ID:computationalmodelling,项目名称:fidimag,代码行数:35,代码来源:test_stt_slonczewski.py

示例6: dynamic

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def dynamic(mesh):

    sim = Sim(mesh, name='dyn', driver='slonczewski')
    # sim.set_options(rtol=1e-10,atol=1e-14)
    sim.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m(np.load('m0.npy'))

    J = 1.0
    exch = UniformExchange(J)
    sim.add(exch)

    Kx = Anisotropy(Ku=0.005, axis=(1, 0, 0), name='Kx')
    sim.add(Kx)

    sim.p = (0,0,1)

    sim.u0 = 0.03
    sim.alpha = 0.1

    ts = np.linspace(0, 1e3, 101)
    for t in ts:
        sim.run_until(t)
        sim.save_vtk()
        print t
开发者ID:River315,项目名称:fidimag,代码行数:28,代码来源:stt.py

示例7: test_exch_energy_1d

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def test_exch_energy_1d():
    mesh = CuboidMesh(nx=2, ny=1, nz=1)
    sim = Sim(mesh)
    exch = UniformExchange(1.23)
    sim.add(exch)

    sim.set_m((0, 0, 1))

    energy = exch.compute_energy()
    assert energy == -1.23
开发者ID:River315,项目名称:fidimag,代码行数:12,代码来源:test_exch.py

示例8: test_demag_two_spin_xx

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def test_demag_two_spin_xx():
    mesh = CuboidMesh(nx=2, ny=1, nz=1)
    sim = Sim(mesh)

    demag = Demag()
    sim.add(demag)

    sim.set_m((1, 0, 0))
    field = demag.compute_field()
    print field
    assert(field[0] == 2e-7)
    assert(field[3] == 2e-7)
开发者ID:River315,项目名称:fidimag,代码行数:14,代码来源:test_demag.py

示例9: test_sim_pin

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def test_sim_pin():
    mesh = CuboidMesh(nx=3, ny=2, nz=1)
    sim = Sim(mesh)
    sim.set_m((0, 0.8, 0.6))
    sim.alpha = 0.1
    sim.gamma = 1.0
    sim.pins = pin_fun

    anis = Anisotropy(Ku=1.0, axis=[0, 0, 1], name='Dx')
    sim.add(anis)

    sim.run_until(1.0)
    assert sim.spin[0] == 0
    assert sim.spin[2] != 0
开发者ID:fangohr,项目名称:fidimag,代码行数:16,代码来源:test_llg_atomistic.py

示例10: excite_system

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def excite_system(mesh, Hy=0):

    sim = Sim(mesh, name="dyn")

    sim.set_options(rtol=1e-10, atol=1e-12)
    sim.alpha = 0.04
    sim.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m(np.load("m0.npy"))

    J = 1.0
    exch = UniformExchange(J)
    sim.add(exch)

    D = 0.18
    dmi = DMI(D)
    sim.add(dmi)

    zeeman = Zeeman([0, Hy, 2e-2], name="H")
    sim.add(zeeman)

    hx = TimeZeeman([0, 0, 1e-5], sinc_fun, name="h")
    sim.add(hx, save_field=True)

    dt = 5
    steps = 2001
    for i in range(steps):

        sim.run_until(i * dt)
开发者ID:ww1g11,项目名称:fidimag,代码行数:32,代码来源:dyn.py

示例11: excite_system

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def excite_system(mesh):

    sim = Sim(mesh, name='dyn')

    # sim.set_options(rtol=1e-10,atol=1e-14)
    sim.driver.alpha = 0.04
    sim.driver.gamma = 1.0
    sim.mu_s = 1.0

    sim.set_m(np.load('m0.npy'))

    J = 1.0
    exch = UniformExchange(J)
    sim.add(exch)

    D = 0.09
    dmi = DMI(D)
    sim.add(dmi)

    zeeman = Zeeman([0, 0, 3.75e-3], name='H')
    sim.add(zeeman)

    w0 = 0.02

    def time_fun(t):
        return np.exp(-w0 * t)

    hx = TimeZeeman([0, 0, 1e-5], sinc_fun, name='h')
    sim.add(hx, save_field=True)

    ts = np.linspace(0, 20000, 5001)
    for t in ts:
        sim.run_until(t)
        print 'sim t=%g' % t
开发者ID:computationalmodelling,项目名称:fidimag,代码行数:36,代码来源:figure2.py

示例12: test_sim_spins

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def test_sim_spins(do_plot=False):

    mesh = CuboidMesh(nx=10, ny=5, nz=1)

    sim = Sim(mesh, name='10spin')

    alpha = 0.1
    gamma = 2.21e5
    sim.alpha = alpha
    sim.gamma = gamma
    sim.mu_s = 1.0

    sim.set_m((1, 0, 0))
    print(sim.spin)

    H0 = 1e5
    sim.add(Zeeman((0, 0, H0)))

    ts = np.linspace(0, 1e-9, 101)

    mx = []
    my = []
    mz = []
    real_ts = []

    for t in ts:
        sim.run_until(t)
        real_ts.append(sim.t)
        #print sim.t, abs(sim.spin_length()[0] - 1)
        av = sim.compute_average()
        mx.append(av[0])
        my.append(av[1])
        mz.append(av[2])

        #sim.save_vtk()

    mz = np.array(mz)
    # print mz
    a_mx, a_my, a_mz = single_spin(alpha, gamma, H0, ts)

    print(sim.stat())

    if do_plot:
        plot(real_ts, mx, my, mz, a_mx, a_my, a_mz, name='spins.pdf', title='integrating spins')

    print(("Max Deviation = {0}".format(
        np.max(np.abs(mz - a_mz)))))

    assert np.max(np.abs(mz - a_mz)) < 5e-7
开发者ID:fangohr,项目名称:fidimag,代码行数:51,代码来源:test_llg_atomistic.py

示例13: test_exch_1d_pbc

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def test_exch_1d_pbc():
    mesh = CuboidMesh(nx=5, ny=1, nz=1, periodicity=(True, False, False))
    sim = Sim(mesh)
    exch = UniformExchange(1)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()
    assert field[0] == 1 + 4
    assert field[3] == 2
    assert field[6] == 4
    assert field[9] == 6
    assert field[12] == 3 + 0
    assert np.max(field[2::3]) == 0
    assert np.max(field[1::3]) == 0
开发者ID:River315,项目名称:fidimag,代码行数:18,代码来源:test_exch.py

示例14: test_hexagonal_demags_2D

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def test_hexagonal_demags_2D():
    """
    Comparison of the FFT approach for hexagonal meshes, named
    DemagHexagonal, where it is used a system with the double number
    of nodes along the x direction (i.e. a mesh with twice the number
    of nodes of the original mesh), against the full calculation
    of the Demag field
    """
    # Number of atoms
    N = 15
    a = 0.4
    mesh = HexagonalMesh(a * 0.5, N, N,
                         unit_length=1e-9,
                         alignment='square')

    # Centre
    xc = (mesh.Lx * 0.5)
    yc = (mesh.Ly * 0.5)

    mu_s = 2 * const.mu_B

    sim = Sim(mesh)
    sim.mu_s = mu_s

    sim.set_m(lambda pos: m_init_2Dvortex(pos, (xc, yc)))
    # Brute force demag calculation
    sim.add(DemagFull())

    sim.get_interaction('demag_full').compute_field()
    sim.get_interaction('demag_full').field
    demag_full_energy = sim.compute_energy() / const.meV

    # Demag using the FFT approach and a larger mesh
    sim2 = Sim(mesh)
    sim2.mu_s = mu_s

    sim2.set_m(lambda pos: m_init_2Dvortex(pos, (xc, yc)))

    sim2.add(DemagHexagonal())
    sim2.get_interaction('demag_hex').compute_field()
    sim2.compute_energy()

    demag_2fft_energy = sim2.compute_energy() / const.meV

    # We compare both energies scaled in meV
    assert (demag_full_energy - demag_2fft_energy) < 1e-10
开发者ID:River315,项目名称:fidimag,代码行数:48,代码来源:test_demag_libraries.py

示例15: test_exch_2d

# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import add [as 别名]
def test_exch_2d():
    mesh = CuboidMesh(nx=5, ny=2, nz=1)
    sim = Sim(mesh)
    exch = UniformExchange(1)
    sim.add(exch)

    sim.set_m(init_m, normalise=False)

    field = exch.compute_field()

    assert np.max(field[2::3]) == 0

    assert field[0] == 1
    assert field[3] == 2 + 1
    assert field[6] == 1 + 2 + 3
    assert field[9] == 2 + 3 + 4
    assert field[12] == 3 + 4
开发者ID:River315,项目名称:fidimag,代码行数:19,代码来源:test_exch.py


注:本文中的fidimag.atomistic.Sim.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。