def simulation(tend, dt): """ starts the simulation, plots and writes the data creates a Surface Object and starts the simulation. the correct timestep is calculated with the timestep function from the advance module. Writes all calculated datapoints to a file with the filenname: basic_<tend>_<dt>.srf plots the simulation fpr t = 0 and t = tend :param tend: endtime of the simulation :param dt: timestep of the simulation """ s = Surface() time = 0 filename = f"basic_{tend}_{dt}.srf" s.plot(time) while time < tend: s.write(time, filename) advance(s, timestep(dt, time, tend)) time += timestep(dt, time, tend) s.write(time, filename) s.plot(time) plt.legend() plt.show()
def main(argv): sim_start_time = clock() # check if config is given as parameter if len(sys.argv) < 2: usage() exit() init_beam() cfg_file = sys.argv[1] srf_file = os.path.splitext(cfg_file)[0] + '.srf' par.LoadConfig(sys.argv[1]) init_sputtering() if par.INITIAL_SURFACE_FILE == 'False': dtime = par.TIME_STEP dt = dtime time = 0 end_time = par.TOTAL_TIME surface_start = Surface(par.XMAX, par.XMIN, par.DELTA_X, par.FUN_PEAK_TO_PEAK, par.TYPE, par.FUN_XMIN, par.FUN_XMAX, 0) surface = Surface(par.XMAX, par.XMIN, par.DELTA_X, par.FUN_PEAK_TO_PEAK, par.TYPE, par.FUN_XMIN, par.FUN_XMAX) #empty the file f = open(srf_file, 'w') f.close() surface.write(srf_file, time, surface_start.x.size, end_time, dtime) while time < end_time: advance( surface, dt, time ) #dtime is not needed -> par.TIME_STEP (not changing), current time is needed! surface.write(srf_file, time, surface.x.size, end_time, dtime) time, dt = timestep(dtime, time, end_time) surface.write(srf_file, time, surface_start.x.size, end_time, dtime) sim_end_time = clock() print("Execution time:" + str(sim_end_time - sim_start_time) + "s") if par.PLOT_SURFACE: surface_start.plot('OF Start', '-+r') surface.plot('OF Stop', '-+b') else: plot_cosine_cont()
def simulate(config_file, do_plotting=True): """ Performs a simulation with the parameters given inside the config file :param config_file: parameters for simulation :return the surface object after last simulation step """ #time_start = clock() time_start = perf_counter() try: par.set_parameters(config_file) except FileNotFoundError as err: print(err) sys.exit(-1) config = "config" if (config_file.find(".cfg") != -1): config = config_file.replace(".cfg", "") tend = float(par.TOTAL_TIME) dt = float(par.TIME_STEP) time = 0 init_sputtering() surface = Surface() surface_filename = '{}.srf'.format(config) surface.write(surface_filename, time, 'w') while time < tend: try: adv.advance(surface, dt) except ValueError as Err: print(Err) break else: dt = adv.timestep(dt, time, tend) time += dt finally: surface.write(surface_filename, time, 'a') #time_compute = clock() - time_start time_compute = perf_counter() - time_start print("Computing Time = " + str(time_compute)) if par.PLOT_SURFACE and do_plotting: if os.path.isfile(surface_filename + "_save"): plot.plot(surface_filename, surface_filename + "_save") else: plot.plot(surface_filename) return surface
def mini_topsim(): """ Reads the Simulation parameters, starts the sim, plots and writes to file the first sys.argv[1] is the simulation time the second sys.argv[2] is the timestep if no sys arguments are passed the simulation starts with tend=10 and dt=1 creates a Surface Object and starts the simulation. the correct timestep is calculated with the timestep function from the advance module. Writes all calculated datapoints to a file with the filenname: basic_<tend>_<dt>.srf plots the simulation fpr t = 0 and t = tend """ print('Running miniTopSim ...') if len(sys.argv) > 1: config_filename = sys.argv[1] else: config_filename = './config1.cfg' config_file = os.path.join(os.path.dirname(__file__), config_filename) if not config_file.endswith('.cfg'): print('Error: Incorrect config.') sys.exit() filename = config_file[:-4] + '.srf' if os.path.exists(filename): os.remove(filename) par.load_parameters(config_file) tend = par.TOTAL_TIME dt = par.TIME_STEP surface = Surface() time = 0 while time < tend: surface.write(time, filename) dtime = timestep(dt, time, tend) advance(surface, dtime) time += dtime surface.write(time, filename) if par.PLOT_SURFACE: plot.plot(filename)
def main(argv): Deltas = np.arange(1, 21, 1) sim_time = [] for DELTA_X in Deltas: sim_start_time = clock() # check if config is given as parameter if len(sys.argv) < 2: usage() exit() par.LoadConfig(sys.argv[1]) dtime = par.TIME_STEP dt = dtime time = 0 end_time = par.TOTAL_TIME surface_start = sf.Surface(par.XMAX, par.XMIN, DELTA_X) surface = sf.Surface(par.XMAX, par.XMIN, DELTA_X) while time < end_time: ad.advance(surface,dt) surface.write(time, surface.x.size, end_time, dtime) time, dt = ad.timestep(dtime, time, end_time) surface.write(time, surface.x.size, end_time, dtime) sim_end_time = clock() print("Execution time:" + str(sim_end_time - sim_start_time) + "s") sim_time.append(sim_end_time - sim_start_time) plt.plot(Deltas, np.array(sim_time)) plt.ylabel('Simulationtime in s') plt.xlabel('DELTA_X') plt.show() sim_time_table = np.column_stack((Deltas, np.array(sim_time))) sim_time_table.tofile('timing.dat', sep= ',', format='%s') if par.PLOT_SURFACE: surface_start.plot(end_time, dtime, 'OF Start', '-+r') surface.plot(end_time, dtime, 'OF Stop','-+b')
def simulation(path_to_cfg, path_to_srf=None): """Main Method to Simulate the etching process. :param path_to_cfg: path to the config file """ par.initPar(path_to_cfg) init_sputtering() #Define Parameters surface = srf.Surface() time = 0 # Path for Surface file = Path of Config file file_name = path_to_cfg.replace(".cfg", ".srf") # Create .srf file and write down initialization Surface surface.write(time, file_name, 'w') # Simulate Etching process until Max. Time is reached while time < par.TOTAL_TIME: adv.advance(surface) dt = adv.timestep(time) time += dt surface.write(time, file_name, 'a') # Stop the timer t_2 = timer() # Print out the computation time of the program print(t_2 - t_1) # Check if surface was already saved filelist = os.listdir() search_strg = file_name + '_save' is_saved = False for i in range(len(filelist)): if filelist[i] == search_strg: is_saved = True saved_file = str(filelist[i].split('.')[0]) + '.srf' # Plot the Surface # If the file was already saved print both original and saved file # in one plot if par.PLOT_SURFACE: if is_saved: plot.plot(file_name, saved_file) else: plot.plot(file_name) return surface
def mini_topsim(): """ Reads the Simulation parameters, starts the sim, plots and writes to file the first sys.argv[1] is the config file name. if no sys argument is passed the programm will stop. Writes all calculated datapoints to a file with the filenname: <config_file_name>.srf """ print('Running miniTopSim ...') if len(sys.argv) > 1: config_filename = sys.argv[1] else: print("Error: No config passed.") sys.exit() config_file = os.path.join(os.path.dirname(__file__), config_filename) if not config_file.endswith('.cfg'): print('Error: Incorrect config.') sys.exit() filename = os.path.splitext(config_file)[0] + '.srf' if os.path.exists(filename): os.remove(filename) par.load_parameters(config_file) tend = par.TOTAL_TIME dt = par.TIME_STEP surface = Surface() time = 0 while time < tend: surface.write(time, filename) dtime = timestep(dt, time, tend) advance(surface, dtime) time += dtime surface.write(time, filename) if par.PLOT_SURFACE: plot.plot(filename)
def main(argv): Deltas = np.arange(1, 21, 1) sim_time = [] for DELTA_X in Deltas: sim_start_time = clock() # check if config is given as parameter if len(sys.argv) < 2: usage() exit() par.LoadConfig(sys.argv[1]) dtime = par.TIME_STEP dt = dtime time = 0 end_time = par.TOTAL_TIME surface_start = sf.Surface(par.XMAX, par.XMIN, DELTA_X) surface = sf.Surface(par.XMAX, par.XMIN, DELTA_X) while time < end_time: ad.advance(surface, dt) surface.write(time, surface.x.size, end_time, dtime) time, dt = ad.timestep(dtime, time, end_time) surface.write(time, surface.x.size, end_time, dtime) sim_end_time = clock() print("Execution time:" + str(sim_end_time - sim_start_time) + "s") sim_time.append(sim_end_time - sim_start_time) plt.plot(Deltas, np.array(sim_time)) plt.ylabel('Simulationtime in s') plt.xlabel('DELTA_X') plt.show() sim_time_table = np.column_stack((Deltas, np.array(sim_time))) sim_time_table.tofile('timing.dat', sep=',', format='%s') if par.PLOT_SURFACE: surface_start.plot(end_time, dtime, 'OF Start', '-+r') surface.plot(end_time, dtime, 'OF Stop', '-+b')
def simulation(in_file): """ Main simulation function. Calculates the progress one timestep at a time until the end time has been reached. """ par.set_Parameters(os.path.abspath(in_file)) init_sputtering() #splitting filename at position of the last point out_file, cfg_type = os.path.splitext(in_file) # if srf file exists, it has to be remove, # because you have to generate a new file with other possible values if os.path.exists(os.path.abspath('{}.srf'.format(out_file))): os.remove(os.path.abspath('{}.srf'.format(out_file))) t = 0.0 total_time = par.TOTAL_TIME if par.INITIAL_SURFACE_FILE != None and par.INITIAL_SURFACE_FILE != '': surface = Surface(filename= os.path.join(os.path.dirname(in_file), \ par.INITIAL_SURFACE_FILE)) total_time = total_time + 1 else: #set x steps to step size of cfg file surface = Surface(par.DELTA_X) while t < total_time: surface.write(out_file, t) # Retrieve next possible timestep delta = advance.timestep(par.TIME_STEP, t, total_time) # Update surface values advance.advance(surface, par.TIME_STEP) t += delta if par.PLOT_SURFACE: if os.path.exists(os.path.abspath('{}.srf_save'.format(out_file))): pt.plot(os.path.abspath('{}.srf'.format(out_file)), os.path.abspath('{}.srf_save'.format(out_file))) print('Start plot with srf_save file') else: pt.plot(os.path.abspath('{}.srf'.format(out_file))) print('Start plot without srf_save file')
def simulate(config_file, setconfig=True): """ Performs a simulation with the parameters given inside the config file :param config_file: parameters for simulation :return the surface object after last simulation step """ if setconfig is True: try: par.set_parameters(config_file) except FileNotFoundError as err: print(err) sys.exit(-1) config = "config" if (config_file.find(".cfg") != -1): config = config_file.replace(".cfg", "") tend = float(par.TOTAL_TIME) dt = float(par.TIME_STEP) #dt = float(par.DWELL_TIME) time = 0 init_sputtering() surface = Surface() surface_filename = '{}.srf'.format(config) surface.write(surface_filename, time, 'w') while time < tend: adv.advance(surface, dt) dt = adv.timestep(dt, time, tend) time += dt surface.write(surface_filename, time, 'a') return surface_filename, surface
def main(argv): sim_start_time = clock() # check if config is given as parameter if len(sys.argv) < 2: usage() exit() cfg_file = sys.argv[1] srf_file = os.path.splitext(cfg_file)[0] + '.srf' par.LoadConfig(sys.argv[1]) init_sputtering() dtime = par.TIME_STEP dt = dtime time = 0 end_time = par.TOTAL_TIME surface_start = Surface(par.XMAX, par.XMIN, par.DELTA_X) surface = Surface(par.XMAX, par.XMIN, par.DELTA_X) while time < end_time: advance(surface, dt) surface.write(srf_file, time, surface.x.size, end_time, dtime) time, dt = timestep(dtime, time, end_time) surface.write(srf_file, time, surface.x.size, end_time, dtime) sim_end_time = clock() print("Execution time:" + str(sim_end_time - sim_start_time) + "s") if par.PLOT_SURFACE: surface_start.plot('OF Start', '-+r') surface.plot('OF Stop','-+b')
def mini_topsim(config_file=None): """ Loads parameters from config_file, starts the sim, plots and writes to file :param config_file: config_file with simulation parameters Loads parameters from config_file. If no config_file is passed passed, None is returned. Creates a Surface Object and starts the simulation. The correct timestep is calculated with the timestep function from the advance module. If a *.srf_save file with the same filename exists, the plot function with both surfaces is called. """ print('Running miniTopSim ...') if config_file is None: if len(sys.argv) > 1: config_filename = sys.argv[1] else: sys.exit('No Config file passed') #config_filename = 'cosine.cfg' config_file = config_filename if not config_file.endswith('.cfg'): print('Error: Incorrect config.') sys.exit() filename = os.path.splitext(config_file)[0] + '.srf' if os.path.exists(filename): os.remove(filename) par.load_parameters(config_file) dir_path = os.path.dirname(os.path.realpath(config_file)) par.INITIAL_SURFACE_FILE = os.path.join(dir_path, par.INITIAL_SURFACE_FILE) tend = par.TOTAL_TIME dt = par.TIME_STEP surface = Surface() sputter.init_sputtering() time = 0 start_simulation_time = currenttime() while time < tend: surface.write(time, filename) dtime = timestep(dt, time, tend) advance(surface, dtime) surface.eliminate_overhangs() time += dtime stop_simulation_time = currenttime() simulation_time = stop_simulation_time - start_simulation_time print('The Simulation took: {}s'.format(float(simulation_time))) surface.write(time, filename) filename_save = filename + '_save' if par.PLOT_SURFACE: if os.path.exists(filename_save): print('*.srf_save file exists... plotting both!') plot.plot(filename, filename_save) else: plot.plot(filename)
def mini_topsim_timing(): """ Reads the Simulation parameters, starts the sim, plots and writes to file the first sys.argv[1] is the config file name. if no sys argument is passed the programm will stop. Writes all calculated datapoints to a file with the filenname: <config_file_name>.srf """ print('Running miniTopSim ...') if len(sys.argv) > 1: config_filename = sys.argv[1] else: print("Error: No config passed.") sys.exit() config_file = os.path.join(os.path.dirname(__file__), config_filename) if not config_file.endswith('.cfg'): print('Error: Incorrect config.') sys.exit() filename = os.path.splitext(config_file)[0] + '.srf' if os.path.exists(filename): os.remove(filename) par.load_parameters(config_file) tend = par.TOTAL_TIME dt = par.TIME_STEP par.DELTA_X = 10 simulation_time_array = np.empty((2, 0)) while par.DELTA_X > 0.2: # print(par.DELTA_X) surface = Surface() time = 0 start_simulation_time = currenttime() while time < tend: surface.write(time, filename) dtime = timestep(dt, time, tend) advance(surface, dtime) time += dtime stop_simulation_time = currenttime() simulation_time = stop_simulation_time - start_simulation_time simulation_time_array = np.append(simulation_time_array, np.array( (int(100 / par.DELTA_X), simulation_time)).reshape(2, 1), axis=1) # print('The Simulation took: {}s'.format(float(simulation_time))) # print(np.array((int(100/par.DELTA_X)))) # print(par.DELTA_X) surface.write(time, filename) par.DELTA_X = par.DELTA_X - 0.6 # print(par.DELTA_X) plt.title('Simulationtime in dependence of the number of points') plt.plot(simulation_time_array[0], simulation_time_array[1], 'b+-') plt.xscale('log') plt.yscale('log') plt.xlabel('Number of points') plt.ylabel('Time in Seconds') plt.grid(which='both') plt.show() if par.PLOT_SURFACE: plot.plot(filename)
for i in np.fromfunction(lambda i: 10**(i / 10 - 1), (11, )): dx = i time_start = clock() time = 0 surface = Surface() surface.set_dx(dx) #surface.write('{}_{}_{}.srf'.format(config, int(tend), int(dt)), time, 'w') while time < tend: adv.advance(surface, dt) dt = adv.timestep(dt, time, tend) time += dt #surface.write('{}_{}_{}.srf'.format(config, int(tend), int(dt)), time, 'a') time_program = clock() - time_start times.append(time_program) n.append(100 / dx) print("x values = " + str(100 / dx)) print("Computingn Time = " + str(time_program)) if par.PLOT_SURFACE: plot.plot('{}_{}_{}.srf'.format(config, int(tend), int(dt))) plt.title("Computing time") plt.plot(n, times, 'o-')