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


Python Sim.add方法代码示例

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


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

示例1: relax_system

# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.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.driver.alpha = 0.5
    sim.driver.gamma = 2.211e5
    sim.Ms = 8.6e5
    sim.do_precession = False

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

    # Energies
    A = 1.3e-11
    exch = UniformExchange(A=A)
    sim.add(exch)

    anis = UniaxialAnisotropy(5e4)
    sim.add(anis)

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

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

示例2: test_dmi_field_oommf

# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import add [as 别名]
def test_dmi_field_oommf(D=4.1e-3, Ms=2.6e5):

    mesh = CuboidMesh(nx=10, ny=3, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = Ms

    dmi = DMI(D=D, type='interfacial')
    sim.add(dmi)

    def init_m(pos):

        x, y, z = pos

        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

    field = dmi.compute_field()

    init_m0 = (r'return [list [expr {sin($x * 1e9) + $y * 1e9 + $z * 2.3e9}] '
               + r' [expr {cos($x * 1e9) + $y * 1e9 + $z * 1.3e9}] '
               + r'0 '
               + r'] ')

    # TODO: check the sign of DMI in OOMMF.
    field_oommf = compute_dmi_field(mesh, Ms=Ms, init_m0=init_m0, D=-D)

    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    assert max([mx0, mx1, mx2]) < 1e-12
开发者ID:River315,项目名称:fidimag,代码行数:33,代码来源:tes_oommf.py

示例3: test_exch_field_oommf

# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import add [as 别名]
def test_exch_field_oommf(A=1e-11, Ms=2.6e5):

    mesh = CuboidMesh(nx=10, ny=3, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = Ms

    exch = UniformExchange(A=A)
    sim.add(exch)

    def init_m(pos):

        x, y, z = pos

        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

    field = exch.compute_field()

    init_m0 = """
    return [list [expr {sin($x*1e9)+$y*1e9+$z*2.3e9}] [expr {cos($x*1e9)+$y*1e9+$z*1.3e9}] 0]
    """
    omf_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            'omfs',
                            'test_exch_field_oommf.ohf'
                            )
    ovf = OMF2(omf_file)
    field_oommf = ovf.get_all_mags()

    #field_oommf = compute_exch_field(mesh, Ms=Ms, init_m0=init_m0, A=A)

    mx0, mx1, mx2 = compare_fields(field_oommf, field)
    assert max([mx0, mx1, mx2]) < 1e-12
开发者ID:fangohr,项目名称:fidimag,代码行数:36,代码来源:test_oommf_without_run.py

示例4: test_dmi_field_oommf

# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import add [as 别名]
def test_dmi_field_oommf(D=4.1e-3, Ms=2.6e5):

    mesh = CuboidMesh(nx=10, ny=3, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = Ms

    dmi = DMI(D=D, dmi_type='interfacial')
    sim.add(dmi)

    def init_m(pos):

        x, y, z = pos

        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

    field = dmi.compute_field()

    init_m0 = """
        return [list [expr {sin($x*1e9)+$y*1e9+$z*2.3e9}] [expr {cos($x*1e9)+$y*1e9+$z*1.3e9}] 0]
        """
    # TODO: check the sign of DMI in OOMMF.
    #field_oommf = compute_dmi_field(mesh, Ms=Ms, init_m0=init_m0, D=-D)
    omf_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),'omfs','test_dmi_field_oommf.ohf')
    ovf = OMF2(omf_file)
    field_oommf = ovf.get_all_mags()

    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    assert max([mx0, mx1, mx2]) < 1e-12
开发者ID:fangohr,项目名称:fidimag,代码行数:34,代码来源:test_oommf_without_run.py

示例5: test_exch_field_oommf

# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import add [as 别名]
def test_exch_field_oommf(A=1e-11, Ms=2.6e5):
    """
    Compare the exchange field from Fidimag with an equivalent
    OOMMF simulation. OOMMF field data is taken from an OVF file.
    """
    mesh = CuboidMesh(nx=10, ny=3, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = Ms

    exch = UniformExchange(A=A)
    sim.add(exch)

    def init_m(pos):
        x, y, z = pos
        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

    field = exch.compute_field()

    # An equivalent initial magnetisation for OOMMF
    # The spatial variables are rescale since they are in nm
    init_m0 = (r'return [list [expr {sin($x * 1e9) + $y * 1e9 + $z * 2.3e9}] '
               + r' [expr {cos($x * 1e9) + $y * 1e9 + $z * 1.3e9}] '
               + r'0 '
               + r'] ')

    field_oommf = compute_exch_field(mesh, Ms=Ms, init_m0=init_m0, A=A)

    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    # Test if the maximum relative errors between both simulations
    # is small enough, for every field component
    assert max([mx0, mx1, mx2]) < 1e-12
开发者ID:River315,项目名称:fidimag,代码行数:37,代码来源:tes_oommf.py

示例6: compute_field

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

    mesh = CuboidMesh(nx=1, ny=1, nz=1, dx=2.0, dy=2.0, dz=2.0, unit_length=1e-9, periodicity=(True, True, False))

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

    sim.set_tols(rtol=1e-10, atol=1e-14)
    sim.alpha = 0.5
    sim.gamma = 2.211e5
    sim.Ms = 8.6e5
    sim.do_precession = False

    sim.set_m((0,0,1))
    # sim.set_m(np.load('m0.npy'))

    A = 1.3e-11
    exch = UniformExchange(A=A)
    sim.add(exch)

    demag = Demag(pbc_2d=True)
    sim.add(demag)
    field=demag.compute_field()
    print field

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

示例7: test_energy_dmi

# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import add [as 别名]
def test_energy_dmi(Ms=8e5, D=1.32e-3):

    mesh = CuboidMesh(nx=40, ny=50, nz=1, dx=2.5, dy=2.5, dz=3, unit_length=1e-9)
    sim = Sim(mesh)

    sim.Ms = Ms

    dmi = DMI(D=D, type='interfacial')
    #dmi = DMI(D=D, type='bulk')
    sim.add(dmi)

    def init_m(pos):

        x, y, z = pos

        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 1)

    sim.set_m(init_m)

    dmi_energy = dmi.compute_energy()

    # init_m0="""
    # return [list [expr {sin($x*1e9)+$y*1e9+$z*2.3e9}] [expr {cos($x*1e9)+$y*1e9+$z*1.3e9}] 1]
    #"""

    #field_oommf = compute_dmi_field(mesh, Ms=Ms, init_m0=init_m0, D=D)

    dmi_energy_oommf = -4.5665527749090378e-20

    print 'dmi energy', dmi_energy

    assert abs(dmi_energy - dmi_energy_oommf) / dmi_energy_oommf < 1e-15
开发者ID:River315,项目名称:fidimag,代码行数:34,代码来源:tes_oommf.py

示例8: setup_simulation

# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import add [as 别名]
def setup_simulation(mesh, m0, simulation_name, integrator="sundials", use_jac=False):
    sim = Sim(mesh, name=simulation_name, integrator=integrator, use_jac)
    sim.set_m(m0)
    sim.Ms = Ms
    sim.alpha = alpha
    sim.gamma = gamma
    sim.add(UniformExchange(A))
    sim.add(Demag())
    return sim
开发者ID:fangohr,项目名称:paper-supplement-finite-difference-time-integration,代码行数:11,代码来源:std_4.py

示例9: test_with_oommf_spatial_Ms

# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import add [as 别名]
def test_with_oommf_spatial_Ms(A=1e-11):

    def spatial_Ms(pos):
        x, y = pos[0], pos[1]

        if x ** 2 + y ** 2 < 5 ** 2:
            return 2e4
        else:
            return 0

    init_m0 = (r'return [list [expr {sin($x * 1e9) + $y * 1e9 + $z * 2.3e9}] '
               + r' [expr {cos($x * 1e9) + $y * 1e9 + $z * 1.3e9}] '
               + r'0 '
               + r'] ')

    init_Ms = """

    if { ($x * $x + $y * $y) < 5e-9 * 5e-9 } {
        return 2e4
    } else {
        return 0
    }

    """

    mesh = CuboidMesh(nx=12, ny=10, nz=2, dx=0.5, unit_length=1e-9)

    sim = Sim(mesh)
    sim.Ms = spatial_Ms

    def init_m(pos):
        x, y, z = pos
        return (np.sin(x) + y + 2.3 * z, np.cos(x) + y + 1.3 * z, 0)

    sim.set_m(init_m)

    exch = UniformExchange(A=A)
    sim.add(exch)

    demag = Demag()
    sim.add(demag)

    field = exch.compute_field()
    field_oommf = compute_exch_field(
        mesh, init_m0=init_m0, A=A, spatial_Ms=init_Ms)
    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    assert max([mx0, mx1, mx2]) < 1e-12

    field = demag.compute_field()
    field_oommf = compute_demag_field(
        mesh, spatial_Ms=init_Ms, init_m0=init_m0)

    mx0, mx1, mx2 = compare_fields(field_oommf, field)

    assert max([mx0, mx1, mx2]) < 1e-11
开发者ID:River315,项目名称:fidimag,代码行数:58,代码来源:tes_oommf.py

示例10: test_sim_single_spin

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

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

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

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

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

    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)
        mx.append(sim.spin[0])
        my.append(sim.spin[1])
        mz.append(sim.spin[2])

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

    print sim.stat()

    if do_plot:
        ts_ns = np.array(real_ts) * 1e9
        plt.plot(ts_ns, mx, ".", label="mx", color='DarkGreen')
        plt.plot(ts_ns, my, ".", label="my", color='darkslateblue')
        plt.plot(ts_ns, mz, ".", label="mz", color='m')
        plt.plot(ts_ns, a_mx, "--", label="analytical", color='b')
        plt.plot(ts_ns, a_my, "--",  color='b')
        plt.plot(ts_ns, a_mz, "--",  color='b')
        plt.xlabel("time (ns)")
        plt.ylabel("m")
        plt.title("integrating a macrospin")
        plt.legend()
        plt.savefig("single_spin.pdf")

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

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

示例11: setup_domain_wall_cobalt

# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import add [as 别名]
def setup_domain_wall_cobalt(node_count=NODE_COUNT, A=A_Co, Ms=Ms_Co, K1=K1_Co, length=LENGTH, do_precession=True, unit_length=UNIT_LENGTH):
    a = length / node_count  # cell size
    mesh = CuboidMesh(dx=a, dy=a, dz=a, nx=node_count, ny=1, nz=1, unit_length=unit_length)
    sim = Sim(mesh, "dw_cobalt")
    sim.Ms = Ms
    sim.set_m(lambda r: initial_m(r, length))
    sim.do_precession = do_precession
    sim.add(UniformExchange(A))
    sim.add(UniaxialAnisotropy(K1, (0, 0, 1)))
    sim.pins = lambda r: 1 if (r[0] < a or r[0] > LENGTH - a) else 0
    return sim
开发者ID:computationalmodelling,项目名称:fidimag,代码行数:13,代码来源:test_domain_wall_cobalt.py

示例12: relax_neb

# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import add [as 别名]
def relax_neb(k, maxst, simname, init_im, interp, save_every=10000):
    """
    Execute a simulation with the NEB function of the FIDIMAG code, for a
    nano disk

    The simulations are made for a specific spring constant 'k' (a float),
    number of images 'init_im', interpolations between images 'interp'
    (an array) and a maximum of 'maxst' steps.
    'simname' is the name of the simulation, to distinguish the
    output files.

    --> vtks and npys are saved in folders starting with the 'simname'

    """

    # Prepare simulation
    # We define the small cylinder with the Magnetisation function
    sim = Sim(mesh)
    sim.Ms = cylinder

    # Energies

    # Exchange
    sim.add(UniformExchange(A=A))

    # Bulk DMI --> This produces a Bloch DW - like skyrmion
    sim.add(DMI(D=D))

    # No Demag, but this could have some effect
    # Demagnetization energy
    # sim.add(Demag())

    # Initial images (npy files or functions)
    init_images = init_im

    # Number of images between each state specified before (here we need only
    # two, one for the states between the initial and intermediate state
    # and another one for the images between the intermediate and final
    # states). Thus, the number of interpolations must always be
    # equal to 'the number of initial states specified', minus one.
    interpolations = interp

    # Initiate the NEB algorithm driver
    neb = NEB_Sundials(sim,
                       init_images,
                       interpolations=interpolations,
                       spring=k,
                       name=simname)

    # Start the relaxation
    neb.relax(max_steps=maxst,
              save_vtk_steps=save_every,
              save_npy_steps=save_every,
              stopping_dmdt=1)
开发者ID:River315,项目名称:fidimag,代码行数:56,代码来源:neb_skyrmion_d50nm.py

示例13: create_simulation

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

    sim = Sim(mesh)
    sim.Ms = 8.6e5

    sim.set_m((1, 0, 0))
    sim.add(UniformExchange(A=1.3e-11))
    # sim.add(Demag())
    #sim.add(UniaxialAnisotropy(Kx, (1, 0, 0), name='Kx'))
    anis = UniaxialAnisotropy(1e5, axis=(1, 0, 0))
    sim.add(anis)

    return sim
开发者ID:fangohr,项目名称:fidimag,代码行数:15,代码来源:dw.py

示例14: relax_system

# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import add [as 别名]
def relax_system():
    mesh = CuboidMesh(nx=1, ny=1, nz=1)
    sim = Sim(mesh, name='relax')
    sim.driver.set_tols(rtol=1e-10, atol=1e-10)
    sim.driver.alpha = 0.5

    sim.set_m((1.0, 0, 0))

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

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

    for t in ts:
        sim.run_until(t)
开发者ID:logicabrity,项目名称:fidimag,代码行数:16,代码来源:single_spin.py

示例15: test_zeeman

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

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

    sim = Sim(mesh)
    sim.set_m((1, 0, 0))

    zeeman = Zeeman(varying_field)
    sim.add(zeeman)

    field = zeeman.compute_field()

    assert field[6] == 1.2 * (2 + 0.5)
    assert field[7] == 2.3 * 0.5
开发者ID:River315,项目名称:fidimag,代码行数:16,代码来源:test_micromagnetic_zeeman.py


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