def test_write_between(): OUTPUT_FILE = os.path.join(SCRIPT_DIR, "output_test_chain_io.ovf") with state.State(INPUT_FILE, QUIET) as p_state: configuration.plus_z(p_state) chain.image_to_clipboard(p_state) noi = 10 chain.set_length(p_state, noi) for idx_image in range(noi): configuration.skyrmion(p_state, radius=2*idx_image, idx_image=idx_image) # Test write between idx_1 = 2 idx_2 = 5 old_spin_directions = [] for idx in range(idx_1, idx_2+1): old_spin_directions.append( np.array(system.get_spin_directions(p_state, idx_image=idx)) ) chain_io.chain_write_between(p_state, OUTPUT_FILE, idx_1, idx_2) chain.set_length(p_state, 1) io.chain_read(p_state, OUTPUT_FILE) for i, idx in enumerate(range(idx_1, idx_2 + 1)): new_spin_directions = np.array( np.array(system.get_spin_directions(p_state, idx_image=i)) ) print( "Testing image {}, original idx {}".format(i, idx) ) res = np.max( np.ravel(old_spin_directions[i] ) - np.ravel(new_spin_directions ) ) print( res ) assert( res < 1e-10 )
def run(self): passed = True with state.State(self.inputfile, quiet=True) as p_state: configuration.plus_z(p_state) # simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_SIB, n_iterations=1) system.update_data(p_state) E_Bf, E_Spirit = self.test_energy(p_state) Gradient_Bf, Gradient_Spirit = self.test_gradient(p_state) passed = True print('>>> Result 1: plus_z') print('E (Brute Force) = ', E_Bf) print('E (Spirit) = ', E_Spirit) print('Avg. Grad (Brute Force) = ', np.mean(Gradient_Bf, axis=0)) print('Avg. Grad (Spirit) = ', np.mean(Gradient_Spirit, axis=0)) if np.abs(E_Bf - E_Spirit) > 1e-4: passed = False configuration.random(p_state) simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_SIB, n_iterations=1) system.update_data(p_state) E_Bf, E_Spirit = self.test_energy(p_state) Gradient_Bf, Gradient_Spirit = self.test_gradient(p_state) passed = True print('\n>>> Result 2: random') print('E (Brute Force) = ', E_Bf) print('E (Spirit) = ', E_Spirit) print('Avg. Grad (Brute Force) = ', np.mean(Gradient_Bf, axis=0)) print('Avg. Grad (Spirit) = ', np.mean(Gradient_Spirit, axis=0)) if np.abs(E_Bf - E_Spirit) > 1e-4: passed = False configuration.hopfion(p_state, 4) simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_SIB, n_iterations=1) system.update_data(p_state) E_Bf, E_Spirit = self.test_energy(p_state) Gradient_Bf, Gradient_Spirit = self.test_gradient(p_state) passed = True print('\n>>> Result 3: hopfion') print('E (Brute Force) = ', E_Bf) print('E (Spirit) = ', E_Spirit) print('Avg. Grad (Brute Force) = ', np.mean(Gradient_Bf, axis=0)) print('Avg. Grad (Spirit) = ', np.mean(Gradient_Spirit, axis=0)) if np.abs(E_Bf - E_Spirit) > 1e-4: passed = False return passed
def test(): INPUT_FILE = os.path.join(SCRIPT_DIR, "inputs/test_plotting.cfg") from spirit import state, configuration with state.State(INPUT_FILE) as p_state: configuration.plus_z(p_state) configuration.hopfion(p_state, 7) # configuration.skyrmion(p_state, 7) system = data.spin_system_from_p_state(p_state) plotter = pyvista_plotting.Spin_Plotter(system) plotter.camera_position = 'yz' plotter.camera_azimuth = 45 plotter.camera_elevation = 50 # plotter.compute_delaunay() # plotter.save_delaunay("delaunay.vtk") plotter.load_delaunay("delaunay.vtk") # plotter.add_preimage([1,0,0], tol=0.02) plotter.isosurface(0, "spins_z") # plotter.show() plotter.render_to_png("test")
def run(enable_output = True): passed = True field_center = [] E = [] for size in system_sizes: with state.State("") as p_state: parameters.llg.set_output_general(p_state, any=False) #turn ddi on hamiltonian.set_ddi(p_state, 1) #turn everything else off hamiltonian.set_exchange(p_state, 0, []) hamiltonian.set_dmi(p_state, 0, []) hamiltonian.set_anisotropy(p_state, 0, [0,0,1]) hamiltonian.set_boundary_conditions(p_state, [0,0,0]) hamiltonian.set_field(p_state, 0, [0,0,1]) geometry.set_n_cells(p_state, [size, size, 1]) configuration.plus_z(p_state) nos = system.get_nos(p_state) simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_VP, n_iterations = 1) Gradient_Spirit = np.array(system.get_effective_field(p_state)).reshape(nos, 3) E_Spirit = system.get_energy(p_state) field_center.append(Gradient_Spirit[int(size/2 + size/2 * size)]) E.append(E_Spirit) if enable_output: with open(outputfile, 'w') as out: out.write("#system_size, field_center_z, energy\n") for i in range(len(E)): out.write("{0}, {1}, {2}\n".format(system_sizes[i], field_center[i][2], E[i]))
def test_write_split_at(): with state.State(INPUT_FILE, QUIET) as p_state: configuration.plus_z(p_state) chain.image_to_clipboard(p_state) noi = 10 chain.set_length(p_state, noi) for idx_image in range(noi): configuration.skyrmion(p_state, radius=2*idx_image, idx_image=idx_image) # Test write split_at filenames = [ os.path.join(SCRIPT_DIR, n) for n in ["output_1.ovf", "output_2.ovf"] ] idx_list = [2,3,9] idx_pairs = [[2,3], [3,9]] old_spin_directions = [] for p in idx_pairs: old_spin_directions.append([]) for idx in range(p[0], p[1]+1): old_spin_directions[-1].append( np.array(system.get_spin_directions(p_state, idx_image=idx)) ) chain_io.chain_write_split_at(p_state, idx_list=idx_list, filename_list=filenames) for j,(f,p) in enumerate(zip(filenames, idx_pairs)): chain.set_length(p_state, 1) io.chain_read(p_state, f) idx_1 = p[0] idx_2 = p[1] for i, idx in enumerate(range(idx_1, idx_2 + 1)): new_spin_directions = np.array( np.array(system.get_spin_directions(p_state, idx_image=i)) ) print( "Testing image {}, original idx {}".format(i, idx) ) res = np.max( np.ravel(old_spin_directions[j][i] ) - np.ravel(new_spin_directions ) ) print( res ) assert( res < 1e-10 )
def test_get_spin_directions(self): configuration.plus_z(self.p_state) nos = system.get_nos(self.p_state) arr = system.get_spin_directions(self.p_state) for i in range(nos): self.assertAlmostEqual(arr[i][0], 0.) self.assertAlmostEqual(arr[i][1], 0.) self.assertAlmostEqual(arr[i][2], 1.)
def run(): with state.State("input/input_brute_force.cfg", quiet = True) as p_state: #turn ddi on hamiltonian.set_ddi(p_state, hamiltonian.DDI_METHOD_FFT, [4,4,4], 20) #turn everything else off hamiltonian.set_exchange(p_state, 0, []) hamiltonian.set_dmi(p_state, 0, []) hamiltonian.set_anisotropy(p_state, 0, [0,0,1]) hamiltonian.set_boundary_conditions(p_state, [0,0,0]) hamiltonian.set_field(p_state, 0, [0,0,1]) #set a reasonable amount of basis cells geometry.set_n_cells(p_state, [5,5,5]) configuration.plus_z(p_state) simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_SIB, n_iterations=1) E_Bf, E_Spirit = test_energy(p_state) Gradient_Bf, Gradient_Spirit = test_gradient(p_state) passed = True print('>>> Result 1: plus_z') print('E (Brute Force) = ', E_Bf) print('E (Spirit) = ', E_Spirit) print('Avg. Grad (Brute Force) = ', np.mean(Gradient_Bf, axis = 0)) print('Avg. Grad (Spirit) = ', np.mean(Gradient_Spirit, axis = 0)) if np.abs(E_Bf - E_Spirit) > tolerance: passed = False configuration.random(p_state) simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_SIB, n_iterations=1) E_Bf, E_Spirit = test_energy(p_state) Gradient_Bf, Gradient_Spirit = test_gradient(p_state) passed = True print('\n>>> Result 2: random') print('E (Brute Force) = ', E_Bf) print('E (Spirit) = ', E_Spirit) print('Avg. Grad (Brute Force) = ', np.mean(Gradient_Bf, axis = 0)) print('Avg. Grad (Spirit) = ', np.mean(Gradient_Spirit, axis = 0)) if np.abs(E_Bf - E_Spirit) > tolerance: passed = False configuration.hopfion(p_state, 4) simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_SIB, n_iterations=1) E_Bf, E_Spirit = test_energy(p_state) Gradient_Bf, Gradient_Spirit = test_gradient(p_state) passed = True print('\n>>> Result 3: hopfion') print('E (Brute Force) = ', E_Bf) print('E (Spirit) = ', E_Spirit) print('Avg. Grad (Brute Force) = ', np.mean(Gradient_Bf, axis = 0)) print('Avg. Grad (Spirit) = ', np.mean(Gradient_Spirit, axis = 0)) if np.abs(E_Bf - E_Spirit) > tolerance: passed = False return passed
def test_singleshot(self): configuration.plus_z(self.p_state) simulation.start(self.p_state, LLG, SIB, n_iterations=1, single_shot=True) simulation.single_shot(self.p_state) simulation.start(self.p_state, LLG, SIB, single_shot=True) simulation.single_shot(self.p_state) simulation.stop(self.p_state)
def test_write(self): configuration.plus_z(self.p_state) configuration.skyrmion(self.p_state, radius=5, phase=-90) simulation.start(self.p_state, "LLG", "VP") system.update_eigenmodes(self.p_state) io.eigenmodes_write(self.p_state, io_image_test, io.FILEFORMAT_OVF_TEXT) io.image_append(self.p_state, io_image_test, io.FILEFORMAT_OVF_TEXT, "python io test") io.image_append(self.p_state, io_image_test, io.FILEFORMAT_OVF_TEXT, "python io test")
def test(self): with state.State(cfgfile) as p_state: # Noise configuration.random(p_state) configuration.add_noise(p_state, 5) # Homogeneous configuration.plus_z(p_state) configuration.minus_z(p_state) configuration.domain(p_state, [1, 1, 1]) # Skyrmion configuration.skyrmion(p_state, 5) # Hopfion configuration.hopfion(p_state, 5) # Spin Spiral configuration.spin_spiral(p_state, "Real Lattice", [0, 0, 0.1], [0, 0, 1], 30)
def run(self): passed = True l_cube = 100 radius = l_cube / 4 with state.State(self.inputfile, quiet=True) as p_state: configuration.plus_z(p_state) simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_SIB, n_iterations=1) system.update_data(p_state) #query some quantities nos = system.get_nos(p_state) field = np.array(system.get_effective_field(p_state)).reshape( nos, 3) pos = np.array(geometry.get_positions(p_state)).reshape(nos, 3) spins = np.array(system.get_spin_directions(p_state)).reshape( nos, 3) #get quantitities in sphere center = np.array([l_cube / 2, l_cube / 2, l_cube / 2], dtype=int) idx_in_sphere = np.linalg.norm(pos - center, axis=1) <= radius mu_s = np.array([1 if idx_in_sphere[i] else 0 for i in range(nos)]) # field_bf = self.Gradient_DDI_BF(pos, spins, mu_s) # field_bf_in_sphere = field_bf[idx_in_sphere] field_in_sphere = field[idx_in_sphere] # deviation_sphere = np.std(field_in_sphere - mean_grad_sphere, axis=0) theory = np.array( [0, 0, 1]) * 2 / 3 * self.mu_0 * self.mu_B * self.mu_B * 1e30 print("Mean field = ", np.mean(field / self.mu_B, axis=0)) # print("Mean field (BF) = ", np.mean(field_bf/self.mu_B, axis=0)) print("Mean field in sphere = ", np.mean(field_in_sphere / self.mu_B, axis=0)) # print("Mean field in sphere (BF) = ", np.mean(field_bf_in_sphere/self.mu_B, axis=0)) print("Theory = ", theory) return passed
def test_append_to_file_from_file(): FILE_IN = os.path.join(SCRIPT_DIR, "in.ovf") FILE_OUT = os.path.join(SCRIPT_DIR, "out.ovf") if os.path.exists(FILE_OUT): os.remove(FILE_OUT) with state.State(INPUT_FILE, QUIET) as p_state: configuration.plus_z(p_state) chain.image_to_clipboard(p_state) noi = 2 chain.set_length(p_state, noi) for idx_image in range(noi): configuration.skyrmion(p_state, radius=2*idx_image, idx_image=idx_image) old_spin_directions = [] for idx in range(noi): old_spin_directions.append( np.array(system.get_spin_directions(p_state, idx_image=idx)) ) io.chain_write(p_state, FILE_IN) chain.set_length(p_state, 1) configuration.random(p_state) chain_io.chain_append_to_file_from_file(p_state, FILE_OUT, FILE_IN) chain_io.chain_append_to_file_from_file(p_state, FILE_OUT, FILE_IN) chain_io.chain_append_to_file_from_file(p_state, FILE_OUT, FILE_IN) chain_io.chain_append_to_file_from_file(p_state, FILE_OUT, FILE_IN) chain.set_length(p_state, 1) io.chain_read(p_state, FILE_OUT) for i in range(4): print( "Testing image {}, original idx {}".format(i, idx) ) new_spin_directions = np.array( np.array(system.get_spin_directions(p_state, idx_image=2*i)) ) res = np.max( np.ravel(old_spin_directions[0] ) - np.ravel(new_spin_directions ) ) print( res ) assert( res < 1e-10 ) new_spin_directions = np.array( np.array(system.get_spin_directions(p_state, idx_image=2*i+1)) ) res = np.max( np.ravel(old_spin_directions[1] ) - np.ravel(new_spin_directions ) ) print( res ) assert( res < 1e-10 )
def test_chain_write(self): # add two more images chain.image_to_clipboard(self.p_state) chain.insert_image_after(self.p_state) chain.insert_image_after(self.p_state) # set different configuration in each image chain.jump_to_image(self.p_state, 0) configuration.minus_z(self.p_state) chain.jump_to_image(self.p_state, 1) configuration.random(self.p_state) chain.jump_to_image(self.p_state, 2) configuration.plus_z(self.p_state, ) # write and append chain io.chain_write(self.p_state, io_chain_test, io.FILEFORMAT_OVF_TEXT, "python io chain") # this must be overwritten io.chain_write(self.p_state, io_chain_test, io.FILEFORMAT_OVF_TEXT, "python io chain") io.chain_append(self.p_state, io_chain_test, io.FILEFORMAT_OVF_TEXT, "python io chain")
def run(self): passed = True with state.State(self.inputfile1, quiet=True) as p_state: configuration.plus_z(p_state) system.update_data(p_state) E_1 = system.get_energy(p_state) print('>>> Result 1: mu_s = 1') print('E_DDI = ', E_1) with state.State(self.inputfile2, quiet=True) as p_state: configuration.plus_z(p_state) system.update_data(p_state) E_2 = system.get_energy(p_state) print('\n>>> Result 2: mu_s = 2') print('E_DDI = ', E_2) if np.abs(E_1 * 2**2 - E_2) > 1e-1: passed = False return passed
def run(self, enable_output=True): passed = True self.inputfile = "test_cases/input/input_saturated_film.cfg" theory = 0.5 N_ITERATIONS = 1 system_sizes = [10 * (i + 1) for i in range(5)] field_center = [] E = [] for size in system_sizes: with state.State(self.inputfile) as p_state: parameters.llg.set_output_general(p_state, any=False) geometry.set_n_cells(p_state, [size, size, 1]) configuration.plus_z(p_state) nos = system.get_nos(p_state) simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_VP, n_iterations=1) Gradient_Spirit = np.array( system.get_effective_field(p_state)).reshape(nos, 3) E_Spirit = system.get_energy(p_state) field_center.append(Gradient_Spirit[int(size / 2 + size / 2 * size)]) E.append(E_Spirit) if enable_output: with open('output_' + self.name + '.txt', 'w') as out: out.write("#system_size, field_center_z, energy\n") for i in range(len(E)): out.write("{0}, {1}, {2}\n".format(system_sizes[i], field_center[i][2], E[i]))
def test_read(self): nos = system.get_nos(self.p_state) configuration.plus_z(self.p_state) io.image_write(self.p_state, io_image_test, io.FILEFORMAT_OVF_TEXT, "python io test") io.image_read(self.p_state, io_image_test) spins = system.get_spin_directions(self.p_state) for i in range(nos): self.assertAlmostEqual(spins[i][0], 0.) self.assertAlmostEqual(spins[i][1], 0.) self.assertAlmostEqual(spins[i][2], 1.) configuration.minus_z(self.p_state) io.image_write(self.p_state, io_image_test, io.FILEFORMAT_OVF_TEXT, "python io test") io.image_read(self.p_state, io_image_test) spins = system.get_spin_directions(self.p_state) for i in range(nos): self.assertAlmostEqual(spins[i][0], 0.) self.assertAlmostEqual(spins[i][1], 0.) self.assertAlmostEqual(spins[i][2], -1.)
def run_simulation(i_state, Mtd, Slvr, convThr, tS, K, Kdir, Exchange, DMI, Dij, alphaD, x_size, y_size, read_config, lc): Skyrmion_size = 0 calc_ittr = 0 js = 0 # current value STTdir = [0, 0, 0] # polarization direction hdir = [0.0, 0.0, 1.0] # magnetic Field direction hval = 0 sim_count = 0 load_fname = 'start.ovf' startup = True while True: clear_screen() if startup: # load initial state or set up new state #initialize ddi usr_in = collect_input(int, 'Load state from file (0/1)?: ') if usr_in == 1: load_fname = collect_input(str, 'Enter filename to load: ') print('\nLoading {:s}...\n'.format(load_fname)) io.chain_read(i_state, load_fname) print('Done!\n') startup = False continue #end if startup block usr_in = collect_input( str, 'Enter command:\nl to load\nm to minimize\nr to run simulation\np to plot\nmtd for set method\nq to quit\n' ) print('\n') if usr_in == 'l': clear_screen() usr_in = collect_input( int, 'Create or ammend to state, Load state from file, or exit (0/1/-1)?: ' ) if usr_in == 1: load_fname = collect_input(str, 'Enter filename to load: ') print('\nLoading {:s}...\n'.format(load_fname)) io.chain_read(i_state, load_fname) print('Done!\n') elif usr_in == 0: usr_in = collect_input( int, 'Set state None, Random, skyrmion, plus-z, minus-z, other settings (0/1/2/3/4/5): ' ) #initialize initial conditions of simulation print('Setting up initial state...\n') if not read_config: #if config file was set, dont set custom lattice size or BC hamiltonian.set_dmi(i_state, 1, [DMI], 1) geometry.set_n_cells(i_state, [x_size, y_size, 1]) hamiltonian.set_boundary_conditions(i_state, [1, 1, 0]) parameters.llg.set_temperature(i_state, 0.0) parameters.llg.set_damping(i_state, alphaD) parameters.llg.set_convergence(i_state, convThr) parameters.llg.set_output_configuration(i_state, True, True, 4) hamiltonian.set_field(i_state, hval, hdir) parameters.llg.set_stt(i_state, True, 0, STTdir) parameters.llg.set_timestep(i_state, tS) parameters.llg.set_iterations(i_state, 1, 1) #hamiltonian.set_dmi(i_state,1,[40],chirality=2) if usr_in == 1: print('Initilizing random state...\n') configuration.random(i_state) #initialize random pass elif usr_in == 2: Skyrmion_size = collect_input(int, "Enter Skyrmion size: ") phase = collect_input(float, 'Enter Skyrmion phase: ') anti = collect_input(int, 'Antiskyrmion or skyrmion (0/1)?: ') pos = [0, 0, 0] for i in range(len(pos)): pos[i] = collect_input( int, 'Enter position {:d} for skyrmion (keep z = 0): '. format(i + 1)) print('Initilizing Skyrmion...\n') configuration.skyrmion(i_state, Skyrmion_size, 1, phase, False, anti, pos) #initialize skyrmion if os.path.isfile("start.ovf"): os.remove("start.ovf") pass pass elif usr_in == 3: print('Setting all spins to +z...\n') configuration.plus_z(i_state) pass elif usr_in == 4: print('Setting all spins to -z...\n') configuration.minus_z(i_state) elif usr_in == 5: convThr = collect_input( float, 'enter Value for convergance threshold (default is 1e-12): ' ) #end load block elif usr_in == 'p': usr_in = 1 while usr_in == 1: usr_in = collect_input(int, '-1 to exit, 1 to plot.') if usr_in == 1: usr_in = input("enter file name to plot: ") xs = collect_input(int, 'x = ') ys = collect_input(int, 'y = ') plot_out.Plot_Lattice(usr_in, xs, ys) usr_in = 1 #end plotting block elif usr_in == 'm': clear_screen() sim_count = 0 usr_in = 0 while usr_in != -1: usr_in = collect_input(int, 'preform minimization?(-1/1): ') if usr_in == 1: sim_time = collect_input(float, 'set minimize time in fs: ') calc_ittr = int(sim_time * 0.001 / tS) #n_fs * fs/(dt*ps) hval = collect_input( float, 'enter H field strength: ') # magnetic Field direction js = 0 hval = convert_from_dimcord_j(DMI, Exchange, js, hval, x_size, y_size, lc)[1] print('H = {:f}T'.format(hval)) parameters.llg.set_temperature(i_state, 0.0) parameters.llg.set_damping(i_state, alphaD) parameters.llg.set_convergence(i_state, convThr) parameters.llg.set_timestep(i_state, tS) hamiltonian.set_field(i_state, hval, hdir) parameters.llg.set_stt(i_state, True, 0, [0, 0, 0]) #minimize print('Minimizing\n') parameters.llg.set_iterations(i_state, calc_ittr, calc_ittr) simulation.start(i_state, simulation.METHOD_LLG, simulation.SOLVER_VP) cur_fname = 'min_{:d}.ovf'.format(sim_count) if os.path.isfile(cur_fname): os.remove(cur_fname) pass io.chain_write(i_state, cur_fname) simulation.stop_all(i_state) plot_out.Plot_Lattice(cur_fname, x_size, y_size) print('Done!\n') sim_count += 1 continue #end minimize block elif usr_in == 'mtd': clear_screen() #set values divider = 2 current_time = collect_input(float, "amount of time to apply current: ") relax_time = collect_input(float, "amount of time to relax: ") begin = collect_input(float, 'enter begining: ') end = collect_input(float, 'enter end: ') count = collect_input(float, 'enter step size: ') current_time = int(current_time * 0.001 / tS) relax_time = int(relax_time * 0.001 / tS) for i, sim_num in enumerate( np.linspace(begin, end, (end - begin) / count, endpoint=True)): configuration.plus_z(i_state) hval = sim_num temp = convert_from_dimcord_j(DMI, Exchange, 0.883, hval, x_size, y_size, lc) hval = temp[1] current = temp[0] print('running set method...\n') #set per-run parameters parameters.llg.set_temperature(i_state, 0) parameters.llg.set_damping(i_state, alphaD) parameters.llg.set_convergence(i_state, convThr) parameters.llg.set_timestep(i_state, tS) #apply current block parameters.llg.set_stt(i_state, True, current, [0, -1, 0]) hamiltonian.set_field(i_state, hval, [0, 0, 1]) calc_ittr = int(6000 * 0.001 / tS) parameters.llg.set_iterations(i_state, calc_ittr / divider, 0) start = time.time() for i in range(1, divider + 1): simulation.start(i_state, Mtd, Slvr) io.chain_write( i_state, '{:d}of{:d}_current_{:4.2f}.ovf'.format( i, divider, hval)) simulation.stop_all(i_state) end = time.time() print(end - start) #turn off current and relax parameters.llg.set_stt(i_state, True, 0, [0, 0, 0]) hamiltonian.set_field(i_state, 16, [0, 0, 1]) calc_ittr = int(6000 * 0.001 / tS) parameters.llg.set_iterations(i_state, relax_time, 0) simulation.start(i_state, Mtd, Slvr) simulation.stop_all(i_state) io.chain_write(i_state, 'current_off_{:4.2f}.ovf'.format(hval)) #end set method elif usr_in == 'r': clear_screen() sim_count = 0 sim_time = 0 prev_ittr = 0 prev_sim_time = 0 calc_ittr = 0 #set per-run parameters parameters.llg.set_temperature(i_state, 0) parameters.llg.set_damping(i_state, alphaD) parameters.llg.set_convergence(i_state, convThr) parameters.llg.set_timestep(i_state, tS) while True: sim_time = collect_input( float, 'set time to run in fs, 0 to use last used values, -1 to exit simulation mode: ' ) if isclose(sim_time, -1, 1e-8): break elif isclose(sim_time, 0, 1e-8): if sim_count == 0: print('Run one simulation first!\n') continue calc_ittr = prev_ittr print( 'H = {:f}T\nJ = {:f}microAmps\nP = ({:f},{:f},{:f})\nItterations = {:d} = {:f}fs' .format(hval, 1e+6 * js, STTdir[0], STTdir[1], STTdir[2], int(prev_ittr), prev_sim_time)) elif (sim_time < (tS / 0.001)) and (not isclose(sim_time, (tS / 0.001), (tS / 0.001) / 10.0)): print('Enter a larger value!\n') continue else: calc_ittr = int(float(sim_time) * 0.001 / tS) #n_fs * fs/(dt*ps) prev_ittr = calc_ittr prev_sim_time = sim_time hval = collect_input( float, 'enter H field strength: ') # magnetic Field direction js = collect_input( float, 'enter current val: ' ) # Spin Torque magnitude EDIT SET TO 0 norm 3e-04 temp = convert_from_dimcord_j(DMI, Exchange, js, hval, x_size, y_size, lc) if isclose(0, js, 1e-7): js = 0.0 else: js = temp[0] hval = temp[1] for i in range(len(STTdir)): STTdir[i] = collect_input( float, 'input Polerization element {:d}: '.format(i + 1)) print( 'H = {:f}T\nJ = {:f}microAmps\nP = ({:f},{:f},{:f})\nItterations = {:d} = {:f}fs' .format(hval, 1e+6 * js, STTdir[0], STTdir[1], STTdir[2], int(prev_ittr), sim_time)) #end quit/re-run/new-sim block print('Running simulation...\n') cur_fname = 'r_{:d}.ovf'.format(sim_count) if os.path.isfile(cur_fname): #if current filename already exists within directory #remove it os.remove(cur_fname) parameters.llg.set_stt(i_state, True, js, STTdir) hamiltonian.set_field(i_state, hval, hdir) parameters.llg.set_iterations(i_state, calc_ittr, 0) start = time.time() simulation.start(i_state, Mtd, Slvr) end = time.time() io.chain_write(i_state, cur_fname) simulation.stop_all(i_state) print('Done! Elapsed time: {:f}\n'.format(end - start)) plot_out.Plot_Lattice(cur_fname, x_size, y_size) sim_count += 1 continue #while not (sim_time == -1): #end run simulation block elif usr_in == 'q': #break and exit loop to quit program break clear_screen() return (0) #run_simulation
def test_write(self): configuration.plus_z(self.p_state) io.image_write(self.p_state, io_image_test)
cfgfile = "ui-python/input.cfg" # Input File with state.State(cfgfile) as p_state: # State setup # Set parameters hamiltonian.set_field(p_state, 0.0, [0, 0, 1]) hamiltonian.set_exchange(p_state, Jij, [1.0]) hamiltonian.set_dmi(p_state, 0, []) parameters.mc.set_output_general(p_state, any=False) # Disallow any output geometry.set_mu_s(p_state, 1.0) geometry.set_n_cells(p_state, [system_size, system_size, system_size]) NOS = system.get_nos(p_state) # Ferromagnet in z-direction configuration.plus_z(p_state) # configuration.Random(p_state) # Loop over temperatures for iT, T in enumerate(sample_temperatures): parameters.mc.set_temperature(p_state, T) # Cumulative average variables E = 0 E2 = 0 M = 0 M2 = 0 M4 = 0 # Thermalisation parameters.mc.set_iterations(
def test_magnetization(self): configuration.plus_z(self.p_state) M = quantities.get_magnetization(self.p_state) self.assertAlmostEqual(M[0], 0) self.assertAlmostEqual(M[1], 0) self.assertAlmostEqual(M[2], 1)
from spirit import state from spirit import configuration from spirit import simulation from spirit import hamiltonian from spirit import io cfgfile = "../input/input.cfg" quiet = False with state.State(cfgfile, quiet) as p_state: ### Read Image from file # spinsfile = "input/spins.ovf" # io.image_from_file(state.get(), spinsfile, idx_image=0); ### First image is homogeneous with a skyrmion in the center configuration.plus_z(p_state, idx_image=0) configuration.skyrmion(p_state, 200.0, phase=0.0, idx_image=0) configuration.set_region(p_state, region_id=1, pos=[0, 0, 0], border_rectangular=[100, 100, 1], idx_image=0) hamiltonian.set_field_m(p_state, 200, [0, 0, 1], 0) hamiltonian.set_field_m(p_state, 200, [0, 0, -1], 1) ### LLG dynamics simulation LLG = simulation.METHOD_LLG LBFGS_OSO = simulation.SOLVER_LBFGS_OSO # Velocity projection minimiser simulation.start(p_state, LLG, LBFGS_OSO) io.image_write(p_state, "out.ovf")
def test_playpause(self): configuration.plus_z(self.p_state) configuration.skyrmion(p_state, 5) simulation.start(self.p_state, LLG, SIB)