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)
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)
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)
def excite_system(mesh): sim = Sim(mesh, name='dyn', driver='sllg') sim.set_options(dt=1e-14, gamma=const.gamma, k_B=const.k_B) sim.alpha = 0.1 sim.mu_s = const.mu_s_1 sim.T = temperature_gradient sim.set_m(np.load("m0.npy")) J = 50.0 * const.k_B exch = UniformExchange(J) sim.add(exch) D = 0.5 * J dmi = DMI(D) sim.add(dmi) Hz = 0.2 * J / const.mu_s_1 zeeman = Zeeman([0, 0, Hz]) sim.add(zeeman) dt = 2e-14 * 50 # 1e-12 ts = np.linspace(0, 1000 * dt, 501) for t in ts: sim.run_until(t) sim.save_vtk() sim.save_m() print 'sim t=%g' % t
def relax_system(mesh): sim=Sim(mesh,name='relax') sim.set_options(rtol=1e-12,atol=1e-14) sim.do_precession = False sim.alpha = 0.5 sim.gamma = 1.0 sim.mu_s = 1.0 sim.set_m(init_m) J = 1.0 exch = UniformExchange(J) sim.add(exch) D = 0.18 dmi = DMI(D) sim.add(dmi) zeeman = Zeeman([0,0e-3,2e-2],name='H') sim.add(zeeman) sim.relax(dt=2.0, stopping_dmdt=1e-8, max_steps=10000, save_m_steps=None, save_vtk_steps=100) np.save('m0.npy',sim.spin)
def relax_system(mesh): sim = Sim(mesh, name='relax') sim.set_options(rtol=1e-12, atol=1e-14) sim.do_procession = False sim.alpha = 0.5 sim.gamma = 1.0 sim.mu_s = 1.0 sim.set_m(init_m) J = 1.0 exch = UniformExchange(J) sim.add(exch) D = 0.18 dmi = DMI(D) sim.add(dmi) zeeman = Zeeman([0, 0e-3, 2e-2], name='H') sim.add(zeeman) sim.relax(dt=2.0, stopping_dmdt=1e-8, max_steps=10000, save_m_steps=None, save_vtk_steps=100) np.save('m0.npy', sim.spin)
def relax_system_stage1(): mesh = CuboidMesh(nx=140 , ny=140, nz=1) sim = Sim(mesh, name='relax', driver='llg') #sim.set_options(dt=1e-14, gamma=const.gamma, k_B=const.k_B) sim.alpha = 0.5 sim.do_precession = False sim.gamma = const.gamma sim.mu_s = spatial_mu sim.set_m(init_m) J = 50 * const.k_B exch = UniformExchange(J) sim.add(exch) D = 0.27 * J dmi = DMI(D) sim.add(dmi) zeeman = Zeeman(spatial_H) sim.add(zeeman) sim.relax(dt=1e-14, stopping_dmdt=1e10, max_steps=1000, save_m_steps=100, save_vtk_steps=10) np.save('skx.npy', sim.spin) plot_m(mesh, 'skx.npy', comp='z')
def excite_system(mesh, Hy=0): sim = Sim(mesh, name='dyn') sim.driver.set_tols(rtol=1e-10, atol=1e-12) 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.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) sim.save_m() print("step {}/{}".format(i, steps))
def relax_system(mesh): sim = Sim(mesh, name='relax') # sim.set_options(rtol=1e-10,atol=1e-14) sim.driver.alpha = 1.0 sim.driver.gamma = 1.0 sim.mu_s = 1.0 sim.set_m(init_m) # sim.set_m(random_m) # sim.set_m(np.load('m_10000.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]) sim.add(zeeman) sim.relax(dt=2.0, stopping_dmdt=1e-6, max_steps=1000, save_m_steps=100, save_vtk_steps=50) np.save('m0.npy', sim.spin)
def relax_system(mesh): sim = Sim(mesh, name='relax') sim.set_default_options(gamma=const.gamma) sim.driver.alpha = 0.5 sim.mu_s = const.mu_s_1 sim.set_m(init_m) J = 50.0 * const.k_B exch = UniformExchange(J) sim.add(exch) D = 0.5 * J dmi = DMI(D) sim.add(dmi) Hz = 0.2 * J / const.mu_s_1 zeeman = Zeeman([0, 0, Hz]) sim.add(zeeman) ONE_DEGREE_PER_NS = 17453292.52 sim.relax(dt=1e-13, stopping_dmdt=0.01 * ONE_DEGREE_PER_NS, max_steps=1000, save_m_steps=100, save_vtk_steps=50) np.save('m0.npy', sim.spin)
def relax_system(mesh, Hy=0): sim = Sim(mesh, name='relax') sim.driver.set_tols(rtol=1e-10, atol=1e-12) sim.driver.alpha = 0.5 sim.driver.gamma = 1.0 sim.mu_s = 1.0 sim.do_precession = False sim.set_m(init_m) #sim.set_m(random_m) #sim.set_m(np.load('m_10000.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) sim.relax(dt=2.0, stopping_dmdt=1e-7, max_steps=10000, save_m_steps=100, save_vtk_steps=50) np.save('m0.npy', sim.spin)
def relax_system(mesh): sim = Sim(mesh, name='relax') # sim.set_options(rtol=1e-10,atol=1e-14) sim.driver.alpha = 1.0 sim.driver.gamma = 1.0 sim.mu_s = 1.0 sim.set_m(init_m) # sim.set_m(random_m) # sim.set_m(np.load('m_10000.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.relax(dt=2.0, stopping_dmdt=1e-6, max_steps=1000, save_m_steps=100, save_vtk_steps=50) np.save('m0.npy', sim.spin)
def dynamic(mesh): sim = Sim(mesh, name='dyn', driver='slonczewski') # sim.set_options(rtol=1e-10,atol=1e-14) 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) Kx = Anisotropy(Ku=0.005, axis=(1, 0, 0), name='Kx') sim.add(Kx) sim.p = (0, 0, 1) sim.u0 = 0.03 sim.driver.alpha = 0.1 ts = np.linspace(0, 1e3, 101) for t in ts: sim.run_until(t) sim.save_vtk() print t
def test_skx_num(): mesh = CuboidMesh(nx=120, ny=120, nz=1, periodicity=(True, True, False)) sim = Sim(mesh, name='skx_num') sim.set_tols(rtol=1e-6, atol=1e-6) sim.alpha = 1.0 sim.gamma = 1.0 sim.mu_s = 1.0 sim.set_m(init_m) sim.do_procession = False J = 1.0 exch = UniformExchange(J) sim.add(exch) D = 0.09 dmi = DMI(D) sim.add(dmi) zeeman = Zeeman([0, 0, 5e-3]) sim.add(zeeman) sim.relax(dt=2.0, stopping_dmdt=1e-2, max_steps=1000, save_m_steps=None, save_vtk_steps=None) skn = sim.skyrmion_number() print 'skx_number', skn assert skn > -1 and skn < -0.99
def excite_system(mesh): sim = Sim(mesh, name='dyn', driver='sllg') sim.set_options(dt=1e-14, gamma=const.gamma, k_B=const.k_B) sim.driver.alpha = 0.1 sim.mu_s = const.mu_s_1 sim.T = temperature_gradient sim.set_m(np.load("m0.npy")) J = 50.0 * const.k_B exch = UniformExchange(J) sim.add(exch) D = 0.5 * J dmi = DMI(D) sim.add(dmi) Hz = 0.2 * J / const.mu_s_1 zeeman = Zeeman([0, 0, Hz]) sim.add(zeeman) dt = 2e-14 * 50 # 1e-12 ts = np.linspace(0, 1000 * dt, 501) for t in ts: sim.run_until(t) sim.save_vtk() sim.save_m() print 'sim t=%g' % t
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
def relax_system(mesh): sim = Sim(mesh, name='relax') # sim.set_options(rtol=1e-10,atol=1e-14) sim.alpha = 1.0 sim.gamma = 1.0 sim.mu_s = 1.0 sim.set_m(init_m) # sim.set_m(random_m) # sim.set_m(np.load('m_10000.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]) sim.add(zeeman) sim.relax(dt=2.0, stopping_dmdt=1e-6, max_steps=1000, save_m_steps=100, save_vtk_steps=50) np.save('m0.npy', sim.spin)
def relax_system(mesh): sim = Sim(mesh, name='relax') sim.set_default_options(gamma=const.gamma) sim.alpha = 0.5 sim.mu_s = const.mu_s_1 sim.set_m(init_m) J = 50.0 * const.k_B exch = UniformExchange(J) sim.add(exch) D = 0.5 * J dmi = DMI(D) sim.add(dmi) Hz = 0.2 * J / const.mu_s_1 zeeman = Zeeman([0, 0, Hz]) sim.add(zeeman) ONE_DEGREE_PER_NS = 17453292.52 sim.relax(dt=1e-13, stopping_dmdt=0.01 * ONE_DEGREE_PER_NS, max_steps=1000, save_m_steps=100, save_vtk_steps=50) np.save('m0.npy', sim.spin)
def relax_system(mesh, Hy=0): sim = Sim(mesh, name="relax") sim.set_options(rtol=1e-10, atol=1e-12) sim.alpha = 0.5 sim.gamma = 1.0 sim.mu_s = 1.0 sim.do_precession = False sim.set_m(init_m) # sim.set_m(random_m) # sim.set_m(np.load('m_10000.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) sim.relax(dt=2.0, stopping_dmdt=1e-8, max_steps=10000, save_m_steps=100, save_vtk_steps=50) np.save("m0.npy", sim.spin)
def relax_system_stage2(): mesh = CuboidMesh(nx=140 , ny=140, nz=1) sim = Sim(mesh, name='dyn', driver='llg') sim.alpha = 0.1 sim.do_precession = True sim.gamma = const.gamma sim.mu_s = spatial_mu sim.set_m(np.load('skx.npy')) J = 50 * const.k_B exch = UniformExchange(J) sim.add(exch) D = 0.27 * J dmi = DMI(D) sim.add(dmi) zeeman = Zeeman(spatial_H) sim.add(zeeman) ts = np.linspace(0, 2e-9, 201) for t in ts: sim.run_until(t) sim.save_vtk() sim.save_m() print(t)
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
def excite_system(T=0.1, H=0.15): mesh = CuboidMesh(nx=28 * 3, ny=16 * 5, nz=1, pbc='2d') sim = Sim(mesh, name='dyn', driver='sllg') sim.set_options(dt=1e-14, gamma=const.gamma, k_B=const.k_B) sim.alpha = 0.1 sim.mu_s = const.mu_s_1 sim.set_m(random_m) J = 50 * const.k_B exch = UniformExchange(J) sim.add(exch) D = 0.5 * J dmi = DMI(D) sim.add(dmi) Hz = H * J / const.mu_s_1 zeeman = Zeeman([0, 0, Hz]) sim.add(zeeman) sim.T = J / const.k_B * T ts = np.linspace(0, 5e-11, 51) for t in ts: sim.run_until(t) # sim.save_vtk() np.save('m.npy', sim.spin) plot_m(mesh, 'm.npy', comp='z')
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
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
def excite_system(mesh): sim = Sim(mesh, name='dyn') # sim.set_options(rtol=1e-10,atol=1e-14) 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.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
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
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('DemagFull').compute_field() sim.get_interaction('DemagFull').field DemagFull_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('DemagHexagonal').compute_field() sim2.compute_energy() demag_2fft_energy = sim2.compute_energy() / const.meV # We compare both energies scaled in meV assert (DemagFull_energy - demag_2fft_energy) < 1e-10
def relax_neb(k, maxst, simname, init_im, interp, save_every=10000): """ Execute a simulation with the NEB function of the FIDIMAG code 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 files starting with the 'simname' string """ # Prepare simulation sim = Sim(mesh, name=simname) sim.gamma = const.gamma # magnetisation in units of Bohr's magneton sim.mu_s = 2. * const.mu_B # Exchange constant in Joules: E = Sum J_{ij} S_i S_j J = 12. * const.meV exch = UniformExchange(J) sim.add(exch) # DMI constant in Joules: E = Sum D_{ij} S_i x S_j D = 2. * const.meV dmi = DMI(D, dmi_type='interfacial') sim.add(dmi) # Anisotropy along +z axis ku = Anisotropy(Ku=0.5 * const.meV, axis=[0, 0, 1], name='ku') sim.add(ku) # Initial images 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 neb = NEB_Sundials(sim, init_images, interpolations=interpolations, spring=k, name=simname) neb.relax(max_steps=maxst, save_vtk_steps=save_every, save_npy_steps=save_every, stopping_dmdt=1e-2)
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
def relax_neb(k, maxst, simname, init_im, interp, save_every=10000): """ Execute a simulation with the NEB function of the FIDIMAG code 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 files starting with the 'simname' string """ # Prepare simulation sim = Sim(mesh, name=simname) sim.driver.gamma = const.gamma # magnetisation in units of Bohr's magneton sim.mu_s = 2. * const.mu_B # Exchange constant in Joules: E = Sum J_{ij} S_i S_j J = 12. * const.meV exch = UniformExchange(J) sim.add(exch) # DMI constant in Joules: E = Sum D_{ij} S_i x S_j D = 2. * const.meV dmi = DMI(D, dmi_type='interfacial') sim.add(dmi) # Anisotropy along +z axis ku = Anisotropy(Ku=0.5 * const.meV, axis=[0, 0, 1], name='ku') sim.add(ku) # Initial images 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 neb = NEB_Sundials(sim, init_images, interpolations=interpolations, spring=k, name=simname) neb.relax(max_steps=maxst, save_vtk_steps=save_every, save_npy_steps=save_every, stopping_dmdt=1e-2)
def test_skx_num_atomistic(): """ Test the *finite spin chirality* or skyrmion number for a discrete spins simulation in a two dimensional lattice The expression is (PRL 108, 017601 (2012)) : Q = S_i \dot ( S_{i+1} X S_{j+1} ) + S_i \dot ( S_{i-1} X S_{j-1} ) which measures the chirality taking two triangles of spins per lattice site i: S_{i} , S_{i + x} , S_{i + y} and S_{i} , S_{i - x} , S_{i - y} The area of the two triangles cover a unit cell, thus the sum cover the whole area of the atomic lattice This test generate a skyrmion pointing down with unrealistic paremeters. """ mesh = CuboidMesh(nx=120, ny=120, nz=1, periodicity=(True, True, False)) sim = Sim(mesh, name='skx_num') sim.set_tols(rtol=1e-6, atol=1e-6) sim.alpha = 1.0 sim.gamma = 1.0 sim.mu_s = 1.0 sim.set_m(lambda pos: init_m(pos, 60, 60, 20)) sim.do_precession = False J = 1.0 exch = UniformExchange(J) sim.add(exch) D = 0.09 dmi = DMI(D) sim.add(dmi) zeeman = Zeeman([0, 0, 5e-3]) sim.add(zeeman) sim.relax(dt=2.0, stopping_dmdt=1e-2, max_steps=1000, save_m_steps=None, save_vtk_steps=None) skn = sim.skyrmion_number() print('skx_number', skn) assert skn > -1 and skn < -0.99
def test_cuboid_demags_1Dchain(): """ Test a brute force calculation of the demagnetising field, called DemagFull, based on the sum of the dipolar contributions of the whole system for every lattice site, against the default FFT approach for the demag field. We compute the energies scaled in meV. This test is performed in a cuboid mesh to assure that the DemagFull library is calculating the same than the default demag function """ N = 12 a = 0.4 mesh = CuboidMesh(a, a, a, N, 1, 1, unit_length=1e-9) mu_s = 2 * const.mu_B sim = Sim(mesh) sim.mu_s = mu_s sim.set_m(lambda pos: m_init_dw(pos, N, a)) # Brute force demag calculation sim.add(DemagFull()) sim.get_interaction('DemagFull').compute_field() # print sim.get_interaction('DemagFull').field DemagFull_energy = sim.compute_energy() / const.meV # Demag using the FFT approach sim2 = Sim(mesh) sim2.mu_s = mu_s sim2.set_m(lambda pos: m_init_dw(pos, N, a)) sim2.add(Demag()) sim2.get_interaction('Demag').compute_field() sim2.compute_energy() demag_fft_energy = sim2.compute_energy() / const.meV # We compare both energies scaled in meV assert (DemagFull_energy - demag_fft_energy) < 1e-10
def test_cuboid_demags_1Dchain(): """ Test a brute force calculation of the demagnetising field, called DemagFull, based on the sum of the dipolar contributions of the whole system for every lattice site, against the default FFT approach for the demag field. We compute the energies scaled in meV. This test is performed in a cuboid mesh to assure that the DemagFull library is calculating the same than the default demag function """ N = 12 a = 0.4 mesh = CuboidMesh(a, a, a, N, 1, 1, unit_length=1e-9) mu_s = 2 * const.mu_B sim = Sim(mesh) sim.mu_s = mu_s sim.set_m(lambda pos: m_init_dw(pos, N, a)) # Brute force demag calculation sim.add(DemagFull()) sim.get_interaction('demag_full').compute_field() # print sim.get_interaction('demag_full').field demag_full_energy = sim.compute_energy() / const.meV # Demag using the FFT approach sim2 = Sim(mesh) sim2.mu_s = mu_s sim2.set_m(lambda pos: m_init_dw(pos, N, a)) sim2.add(Demag()) sim2.get_interaction('demag').compute_field() sim2.compute_energy() demag_fft_energy = sim2.compute_energy() / const.meV # We compare both energies scaled in meV assert (demag_full_energy - demag_fft_energy) < 1e-10
def test_sim_single_spin_sllg(do_plot=False): mesh = CuboidMesh(nx=1, ny=1, nz=1) sim = Sim(mesh, name='spin', driver='sllg') alpha = 0.1 gamma = 2.21e5 sim.set_options(dt=5e-15, gamma=gamma) sim.alpha = alpha sim.mu_s = 1.0 sim.set_m((1, 0, 0)) H0 = 1e5 sim.add(Zeeman((0, 0, H0))) ts = np.linspace(0, 1e-10, 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) a_mx, a_my, a_mz = single_spin(alpha, gamma, H0, ts) if do_plot: plot(real_ts, mx, my, mz, a_mx, a_my, a_mz, name='spin_sllg.pdf', title='integrating a spin') print(("Max Deviation = {0}".format(np.max(np.abs(mz - a_mz))))) assert np.max(np.abs(mz - a_mz)) < 1e-8
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
def relax_system(): # 1D chain of 50 spins with a lattice constant of 0.27 A mesh = CuboidMesh( nx=nx, dx=dx, unit_length=1e-9, # pbc='1d' ) # Initiate the simulation sim = Sim(mesh, name=sim_name) sim.gamma = const.gamma # magnetisation in units of Bohr's magneton sim.mu_s = 2 * const.mu_B # sim.set_options(gamma=const.gamma, k_B=const.k_B) # Initial magnetisation profile sim.set_m(init_m) # Exchange constant in Joules: E = Sum J_{ij} S_i S_j J = 12. * const.meV exch = UniformExchange(J) sim.add(exch) # DMI constant in Joules: E = Sum D_{ij} S_i x S_j D = 2. * const.meV dmi = DMI(D, dmi_type='interfacial') sim.add(dmi) # Anisotropy along +z axis ku = Anisotropy(Ku=0.5 * const.meV, axis=[0, 0, 1], name='ku') sim.add(ku) # Faster convergence sim.alpha = 0.5 sim.do_precession = False sim.relax(dt=1e-13, stopping_dmdt=0.05, max_steps=700, save_m_steps=1000, save_vtk_steps=1000) # Save the last relaxed state np.save(sim_name + '.npy', sim.spin)
def relax_system(): # 1D chain of 50 spins with a lattice constant of 0.27 A mesh = CuboidMesh(nx=nx, dx=dx, unit_length=1e-9, # pbc='1d' ) # Initiate the simulation. PBCs are specified in the mesh sim = Sim(mesh, name=sim_name) sim.gamma = const.gamma # magnetisation in units of Bohr's magneton sim.mu_s = 2. * const.mu_B # sim.set_options(gamma=const.gamma, k_B=const.k_B) # Initial magnetisation profile sim.set_m((0, 0, 1)) # Exchange constant in Joules: E = Sum J_{ij} S_i S_j J = 12. * const.meV exch = UniformExchange(J) sim.add(exch) # DMI constant in Joules: E = Sum D_{ij} S_i x S_j D = 2. * const.meV dmi = DMI(D, dmi_type='interfacial') sim.add(dmi) # Anisotropy along +z axis ku = Anisotropy(Ku=0.5 * const.meV, axis=[0, 0, 1], name='ku') sim.add(ku) # Faster convergence sim.alpha = 0.5 sim.do_precession = False sim.relax(dt=1e-13, stopping_dmdt=0.05, max_steps=700, save_m_steps=1000, save_vtk_steps=1000) # Save the last relaxed state np.save(sim_name + '.npy', sim.spin)
def test_dw_dmi_atomistic(do_plot=False): mesh = CuboidMesh(nx=300, ny=1, nz=1) sim = Sim(mesh, name='relax') sim.set_default_options(gamma=const.gamma) sim.alpha = 0.5 sim.mu_s = const.mu_s_1 sim.do_precession = False sim.set_m(m_init_dw) J = 50.0 * const.k_B exch = UniformExchange(J) sim.add(exch) D = 0.01 * J dmi = DMI(D) sim.add(dmi) K = 0.005 * J anis = Anisotropy(K, axis=[1, 0, 0]) sim.add(anis) ONE_DEGREE_PER_NS = 17453292.52 sim.relax(dt=1e-13, stopping_dmdt=0.01 * ONE_DEGREE_PER_NS, max_steps=1000, save_m_steps=100, save_vtk_steps=50) np.save('m0.npy', sim.spin) xs = np.array([p[0] for p in mesh.coordinates]) - 150 mx, my, mz = analytical(xs, A=J / 2.0, D=-D, K=K) mxyz = sim.spin.copy() mxyz = mxyz.reshape(-1, 3).T assert max(abs(mxyz[0, :] - mx)) < 0.001 assert max(abs(mxyz[1, :] - my)) < 0.001 assert max(abs(mxyz[2, :] - mz)) < 0.0006 if do_plot: save_plot(xs, mxyz, mx, my, mz)
def relax_system(rtol=1e-10, atol=1e-12): """numerical solution""" mesh = CuboidMesh(nx=1, ny=1, nz=1) sim = Sim(mesh, name='relax') sim.driver.set_tols(rtol=rtol, atol=atol) sim.driver.alpha = 0.5 sim.driver.gamma = 2.21e5 sim.mu_s = 1.0 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.driver.run_until(t)
def relax_system(mesh): sim = Sim(mesh, name='relax') sim.mu_s = 1e-23 sim.driver.gamma = 1.76e11 sim.driver.alpha = 1.0 J = 1e-22 exch = UniformExchange(J) sim.add(exch) demag = Demag() sim.add(demag) sim.set_m(init_m) ts = np.linspace(0, 5e-10, 101) for t in ts: sim.driver.run_until(t) sim.save_vtk() np.save('m0.npy', sim.spin)
def test_sim_single_spin_sllg(do_plot=False): mesh = CuboidMesh(nx=1, ny=1, nz=1) sim = Sim(mesh, name='spin', driver='sllg') alpha = 0.1 gamma = 2.21e5 sim.set_options(dt=5e-15, gamma=gamma) sim.alpha = alpha sim.mu_s = 1.0 sim.set_m((1, 0, 0)) H0 = 1e5 sim.add(Zeeman((0, 0, H0))) ts = np.linspace(0, 1e-10, 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) a_mx, a_my, a_mz = single_spin(alpha, gamma, H0, ts) if do_plot: plot(real_ts, mx, my, mz, a_mx, a_my, a_mz, name='spin_sllg.pdf', title='integrating a spin') print(("Max Deviation = {0}".format( np.max(np.abs(mz - a_mz))))) assert np.max(np.abs(mz - a_mz)) < 1e-8
def test_dw_dmi_atomistic(do_plot=False): mesh = CuboidMesh(nx=300, ny=1, nz=1) sim = Sim(mesh, name='relax') sim.set_default_options(gamma=const.gamma) sim.alpha = 0.5 sim.mu_s = const.mu_s_1 sim.do_procession = False sim.set_m(m_init_dw) J = 50.0 * const.k_B exch = UniformExchange(J) sim.add(exch) D = 0.01 * J dmi = DMI(D) sim.add(dmi) K = 0.005 * J anis = Anisotropy(K, axis=[1,0,0]) sim.add(anis) ONE_DEGREE_PER_NS = 17453292.52 sim.relax(dt=1e-13, stopping_dmdt=0.01 * ONE_DEGREE_PER_NS, max_steps=1000, save_m_steps=100, save_vtk_steps=50) np.save('m0.npy', sim.spin) xs = np.array([p[0] for p in mesh.coordinates]) - 150 mx, my, mz = analytical(xs, A=J/2.0, D=-D, K=K) mxyz = sim.spin.copy() mxyz = mxyz.reshape(-1, 3).T assert max(abs(mxyz[0, :] - mx)) < 0.001 assert max(abs(mxyz[1, :] - my)) < 0.001 assert max(abs(mxyz[2, :] - mz)) < 0.0006 if do_plot: save_plot(xs, mxyz, mx, my, mz)
def test_sim_single_spin_vode(do_plot=False): mesh = CuboidMesh(nx=1, ny=1, nz=1) sim = Sim(mesh, name='spin') alpha = 0.1 gamma = 2.21e5 sim.driver.alpha = alpha sim.driver.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.driver.run_until(t) real_ts.append(sim.driver.t) #print sim.driver.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) a_mx, a_my, a_mz = single_spin(alpha, gamma, H0, ts) print(sim.driver.stat()) if do_plot: plot(real_ts, mx, my, mz, a_mx, a_my, a_mz) print(("Max Deviation = {0}".format( np.max(np.abs(mz - a_mz))))) assert np.max(np.abs(mz - a_mz)) < 5e-7
def test_sim_single_spin_vode(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) 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) print("Max Deviation = {0}".format( np.max(np.abs(mz - a_mz)))) assert np.max(np.abs(mz - a_mz)) < 5e-7
def relax_system(mesh): sim = Sim(mesh, name='relax') sim.set_default_options(gamma=const.gamma) sim.alpha = 0.5 sim.mu_s = const.mu_s_1 sim.do_procession = False sim.set_m(m_init_dw) J = 50.0 * const.k_B exch = UniformExchange(J) sim.add(exch) D = 0.1 * J dmi = DMI(D, dmi_type='interfacial') sim.add(dmi) K = 0.02 * J anis = Anisotropy(K, axis=[0, 0, 1]) sim.add(anis) ONE_DEGREE_PER_NS = 17453292.52 sim.relax(dt=1e-13, stopping_dmdt=0.01 * ONE_DEGREE_PER_NS, max_steps=1000, save_m_steps=100, save_vtk_steps=50) np.save('m0.npy', sim.spin) xs = np.array([p[0] for p in mesh.pos]) - 150 mx, my, mz = analytical(xs, A=J / 2.0, D=-D, K=K) mxyz = sim.spin.copy() mxyz.shape = (3, -1) save_plot(xs, mxyz, mx, my, mz)
def dynamic(mesh): sim = Sim(mesh, name='dyn_spin', driver='slonczewski') # sim.set_options(rtol=1e-10,atol=1e-14) sim.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.u0 = 0.005 sim.alpha = 0.1 ts = np.linspace(0, 1200, 401) for t in ts: sim.run_until(t) #sim.save_vtk() print t
def dynamic(mesh): sim = Sim(mesh, name='dyn_spin', driver='slonczewski') # 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.u0 = 0.005 sim.driver.alpha = 0.1 ts = np.linspace(0, 1200, 401) for t in ts: sim.run_until(t) #sim.save_vtk() print t
def excite_system(mesh, time=0.1, snaps=11): # Specify the stt dynamics in the simulation sim = Sim(mesh, name='dyn', driver='llg_stt') # Set the simulation parameters sim.driver.set_tols(rtol=1e-12, atol=1e-12) sim.driver.gamma = 2.211e5 / mu0 sim.mu_s = 1e-27 / mu0 sim.alpha = 0.05 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) # Set the current in the x direction, in A / m # beta is the parameter in the STT torque sim.driver.jz = -1e12 sim.driver.beta = 0.1 # The simulation will run for x ns and save # 'snaps' snapshots of the system in the process ts = np.linspace(0, time * 1e-9, snaps) for t in ts: print('time', t) sim.driver.run_until(t) #sim.save_vtk() np.save('m1.npy', sim.spin) print(np.load('m1.npy')[:100])
def single_spin(alpha=0.01): mat = Material() mesh = CuboidMesh(nx=1, ny=1, nz=1) sim = Sim(mesh, driver='sllg') sim.alpha = alpha sim.gamma = mat.gamma sim.mu_s = mat.mu_s sim.T = 10000 sim.set_m((1, 1, 1)) #sim.add(Zeeman(1,(0, 0, 1))) anis = Anisotropy(mat.K, direction=(0, 0, 1)) sim.add(anis) dt = 0.5e-12 ts = np.linspace(0, 1000 * dt, 1001) sx = [] sy = [] for t in ts: sim.run_until(t) sx.append(sim.spin[0]) sy.append(sim.spin[1]) print(t) plt.plot(sx, sy) plt.xlabel("$S_x$") plt.ylabel("$S_y$") plt.grid() plt.axis((-0.9, 0.9, -0.9, 0.9)) plt.axes().set_aspect('equal') plt.savefig("macrospin.pdf")
def excite_system(mesh, time=0.1, snaps=11): # Specify the stt dynamics in the simulation sim = Sim(mesh, name='dyn', driver='llg_stt') # Set the simulation parameters sim.driver.set_tols(rtol=1e-12, atol=1e-12) sim.driver.gamma = 2.211e5 / mu0 sim.mu_s = 1e-27 / mu0 sim.alpha = 0.05 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) # Set the current in the x direction, in A / m # beta is the parameter in the STT torque sim.driver.jz = -1e12 sim.driver.beta = 0.1 # The simulation will run for x ns and save # 'snaps' snapshots of the system in the process ts = np.linspace(0, time * 1e-9, snaps) for t in ts: print('time', t) sim.driver.run_until(t) #sim.save_vtk() np.save('m1.npy', sim.spin) print(np.load('m1.npy')[:100])
def relax_system(mesh): sim = Sim(mesh, name='relax') # sim.set_options(rtol=1e-10,atol=1e-14) sim.alpha = 1.0 sim.gamma = 1.0 sim.mu_s = 1.0 sim.set_m(init_m) # sim.set_m(random_m) # sim.set_m(np.load('m_10000.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.relax(dt=2.0, stopping_dmdt=1e-6, max_steps=1000, save_m_steps=100, save_vtk_steps=50) np.save('m0.npy', sim.spin)
def relax_system(mesh): sim = Sim(mesh, name='dmi_2d') sim.driver.alpha = 0.1 sim.driver.gamma=1.76e11 sim.mu_s = 1e-22 J = 1e-20 exch = UniformExchange(J) sim.add(exch) dmi = DMI(0.1 * J) sim.add(dmi) sim.set_m(init_m) ts = np.linspace(0, 5e-10, 101) for t in ts: print(t) sim.run_until(t) #sim.save_vtk() return sim.spin
def create_sim(): mesh = CuboidMesh(nx=121,ny=121,nz=1) sim=Sim(mesh,name='relax') sim.alpha = 1.0 sim.gamma = 0.5 sim.mu_s = mu_s sim.set_m(init_m) J = 1.0 exch = UniformExchange(J) sim.add(exch) D = 0.08 dmi = DMI(D) sim.add(dmi) K = 4e-3 anis=Anisotropy(K, direction=(0,0,1),name='Ku') sim.add(anis) return sim