本文整理汇总了Python中fidimag.micro.Sim.set_m方法的典型用法代码示例。如果您正苦于以下问题:Python Sim.set_m方法的具体用法?Python Sim.set_m怎么用?Python Sim.set_m使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fidimag.micro.Sim
的用法示例。
在下文中一共展示了Sim.set_m方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply_field1
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [as 别名]
def apply_field1(mesh):
sim = Sim(mesh, name='dyn')
sim.set_tols(rtol=1e-10, atol=1e-10)
sim.alpha = 0.02
sim.gamma = 2.211e5
sim.Ms = 8.0e5
sim.set_m(np.load('m0.npy'))
A = 1.3e-11
exch = UniformExchange(A=A)
sim.add(exch)
demag = Demag()
sim.add(demag)
mT = 0.001 / mu0
print("Applied field = {}".format(mT))
zeeman = Zeeman([-24.6 * mT, 4.3 * mT, 0], name='H')
sim.add(zeeman, save_field=True)
ts = np.linspace(0, 1e-9, 201)
for t in ts:
sim.run_until(t)
print('sim t=%g' % t)
示例2: relax_system
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [as 别名]
def relax_system(mesh):
sim = Sim(mesh, chi=1e-3, name='relax', driver='llbar_full')
sim.driver.set_tols(rtol=1e-7, atol=1e-7)
sim.Ms = 8.0e5
sim.driver.alpha = 0.1
sim.beta = 0
sim.driver.gamma = 2.211e5
sim.set_m((1, 0.25, 0.1))
# sim.set_m(np.load('m0.npy'))
A = 1.3e-11
exch = UniformExchange(A=A)
sim.add(exch)
mT = 795.7747154594767
zeeman = Zeeman([-100 * mT, 4.3 * mT, 0], name='H')
sim.add(zeeman, save_field=True)
demag = Demag()
sim.add(demag)
ONE_DEGREE_PER_NS = 17453292.52
sim.relax(dt=1e-12, stopping_dmdt=0.01,
max_steps=5000, save_m_steps=100, save_vtk_steps=50)
np.save('m0.npy', sim.spin)
示例3: test_exch_field_oommf
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [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
示例4: test_exch_field_oommf
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [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
示例5: relax_system
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [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)
示例6: test_dmi_field_oommf
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [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
示例7: relax_system
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [as 别名]
def relax_system(mesh):
sim = Sim(mesh, name='relax')
sim.set_tols(rtol=1e-6, atol=1e-6)
sim.alpha = 0.5
sim.gamma = 2.211e5
sim.Ms = 8.6e5
sim.do_precession = False
sim.set_m(init_m)
#sim.set_m((0,0.1,1))
#sim.set_m(np.load('m0.npy'))
A = 1.3e-11
exch = UniformExchange(A=A)
sim.add(exch)
dmi = DMI(D=1.3e-3)
sim.add(dmi)
anis = UniaxialAnisotropy(-3.25e4, axis=(0, 0, 1))
sim.add(anis)
zeeman = Zeeman((0, 0, 6.014576e4))
sim.add(zeeman, save_field=True)
sim.relax(dt=1e-13, stopping_dmdt=0.5, max_steps=5000,
save_m_steps=None, save_vtk_steps=50)
np.save('m0.npy', sim.spin)
示例8: relax_system
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [as 别名]
def relax_system(mesh):
sim = Sim(mesh, name="relax")
sim.driver.set_tols(rtol=1e-10, atol=1e-14)
sim.driver.alpha = 0.5
sim.driver.gamma = 2.211e5
sim.Ms = 8.6e5
sim.do_precession = False
sim.set_m(init_m)
# sim.set_m(np.load('m0.npy'))
A = 1.3e-11
exch = UniformExchange(A=A)
sim.add(exch)
dmi = DMI(D=1e-3)
sim.add(dmi)
zeeman = Zeeman((0, 0, 2e4))
sim.add(zeeman, save_field=True)
sim.relax(dt=1e-13, stopping_dmdt=0.01, max_steps=5000, save_m_steps=None, save_vtk_steps=50)
np.save("m0.npy", sim.spin)
示例9: test_sim_init_m
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [as 别名]
def test_sim_init_m():
mesh = CuboidMesh(nx=3, ny=4, nz=5)
sim = Sim(mesh)
sim.set_m((0, 1, 0))
sim.spin.shape = (-1, 3)
spin_y = sim.spin[:, 1]
assert(spin_y.any() == 1)
示例10: relax_system
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [as 别名]
def relax_system(mesh):
sim = Sim(mesh, name='relax')
sim.driver.set_tols(rtol=1e-6, atol=1e-6)
sim.driver.alpha = 0.5
sim.driver.gamma = 2.211e5
sim.Ms = 8.6e5
sim.do_precession = False
sim.set_m(init_m)
exch = UniformExchange(A=1.3e-11)
sim.add(exch)
dmi = DMI(D=-4e-3)
sim.add(dmi)
zeeman = Zeeman((0, 0, 4e5))
sim.add(zeeman, save_field=True)
sim.relax(dt=1e-13, stopping_dmdt=1e-2,
save_m_steps=None, save_vtk_steps=50)
np.save('m0.npy', sim.spin)
示例11: test_dmi_field_oommf
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [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
示例12: run_fidimag
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [as 别名]
def run_fidimag(mesh):
mu0 = 4 * np.pi * 1e-7
Ms = 8.6e5
A = 16e-12
D = -3.6e-3
K = 510e3
sim = Sim(mesh)
sim.set_tols(rtol=1e-10, atol=1e-10)
sim.alpha = 0.5
sim.gamma = 2.211e5
sim.Ms = Ms
sim.do_precession = False
sim.set_m((0, 0, 1))
sim.add(UniformExchange(A))
sim.add(DMI(D, dmi_type='interfacial'))
sim.add(UniaxialAnisotropy(K, axis=(0, 0, 1)))
sim.relax(dt=1e-13, stopping_dmdt=0.01, max_steps=5000,
save_m_steps=None, save_vtk_steps=50)
m = sim.spin
return m.copy()
示例13: test_energy_dmi
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [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
示例14: test_dw_dmi
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [as 别名]
def test_dw_dmi(mesh=mesh, do_plot=False):
Ms = 8.0e5
sim = Sim(mesh, name='relax')
sim.set_m(m_init_dw)
sim.driver.set_tols(rtol=1e-8, atol=1e-12)
sim.Ms = Ms
sim.alpha = 0.5
sim.do_precession = False
A = 1.3e-11
D = 4e-4
Kx = 8e4
Kp = -6e5
sim.add(UniformExchange(A))
sim.add(DMI(D))
sim.add(UniaxialAnisotropy(Kx, axis=[1, 0, 0], name='Kx'))
sim.driver.relax(stopping_dmdt=0.01)
xs = np.array([p[0] for p in mesh.coordinates])
mx, my, mz = analytical(xs, A=A, D=D, K=Kx)
mxyz = sim.spin.copy()
mxyz = mxyz.reshape(-1, 3)
assert max(abs(mxyz[:, 0] - mx)) < 0.002
assert max(abs(mxyz[:, 1] - my)) < 0.002
assert max(abs(mxyz[:, 2] - mz)) < 0.0006
if do_plot:
save_plot(mxyz, mx, my, mz)
示例15: compute_field
# 需要导入模块: from fidimag.micro import Sim [as 别名]
# 或者: from fidimag.micro.Sim import set_m [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)