def check_if_kill(folder): """Check if user has put a file named killoasis in folder.""" found = 0 if 'killoasis' in listdir(folder): found = 1 collective = MPI.sum(MPI.comm_world, found) if collective > 0: if MPI.rank(MPI.comm_world) == 0: remove(path.join(folder, 'killoasis')) info_red('killoasis Found! Stopping simulations cleanly...') return True else: return False
def check_if_reset_statistics(folder): """Check if user has put a file named resetoasis in folder.""" found = 0 if 'resetoasis' in listdir(folder): found = 1 collective = MPI.sum(MPI.comm_world, found) if collective > 0: if MPI.rank(MPI.comm_world) == 0: remove(path.join(folder, 'resetoasis')) info_red('resetoasis Found!') return True else: return False
def check_if_pause(folder): """Check if user has put a file named pauseoasis in folder.""" found = 0 if 'pauseoasis' in listdir(folder): found = 1 collective = MPI.sum(MPI.comm_world, found) if collective > 0: if MPI.rank(MPI.comm_world) == 0: info_red('pauseoasis Found! Simulations paused. Remove ' + path.join(folder, 'pauseoasis') + ' to resume simulations...') return True else: return False
def create_initial_folders(folder, restart_folder, sys_comp, tstep, info_red, scalar_components, output_timeseries_as_vector, **NS_namespace): """Create necessary folders.""" info_red("Creating initial folders") # To avoid writing over old data create a new folder for each run if MPI.rank(MPI.comm_world) == 0: try: makedirs(folder) except OSError: pass MPI.barrier(MPI.comm_world) newfolder = path.join(folder, 'data') if restart_folder: newfolder = path.join(newfolder, restart_folder.split('/')[-2]) else: if not path.exists(newfolder): newfolder = path.join(newfolder, '1') else: #previous = listdir(newfolder) previous = [f for f in listdir(newfolder) if not f.startswith('.')] previous = max(map(eval, previous)) if previous else 0 newfolder = path.join(newfolder, str(previous + 1)) MPI.barrier(MPI.comm_world) if MPI.rank(MPI.comm_world) == 0: if not restart_folder: #makedirs(path.join(newfolder, "Voluviz")) #makedirs(path.join(newfolder, "Stats")) #makedirs(path.join(newfolder, "VTK")) makedirs(path.join(newfolder, "Timeseries")) makedirs(path.join(newfolder, "Checkpoint")) tstepfolder = path.join(newfolder, "Timeseries") tstepfiles = {} comps = sys_comp if output_timeseries_as_vector: comps = ['p', 'u'] + scalar_components for ui in comps: tstepfiles[ui] = XDMFFile( MPI.comm_world, path.join(tstepfolder, ui + '_from_tstep_{}.xdmf'.format(tstep))) tstepfiles[ui].parameters["rewrite_function_mesh"] = False tstepfiles[ui].parameters["flush_output"] = True return newfolder, tstepfiles
def create_initial_folders(folder, restart_folder, sys_comp, tstep, info_red, scalar_components, output_timeseries_as_vector, **NS_namespace): """Create necessary folders.""" info_red("Creating initial folders") # To avoid writing over old data create a new folder for each run if MPI.rank(MPI.comm_world) == 0: try: makedirs(folder) except OSError: pass MPI.barrier(MPI.comm_world) newfolder = path.join(folder, 'data') if restart_folder: newfolder = path.join(newfolder, restart_folder.split('/')[-2]) else: if not path.exists(newfolder): newfolder = path.join(newfolder, '1') else: previous = listdir(newfolder) previous = max(map(eval, previous)) if previous else 0 newfolder = path.join(newfolder, str(previous + 1)) MPI.barrier(MPI.comm_world) if MPI.rank(MPI.comm_world) == 0: if not restart_folder: #makedirs(path.join(newfolder, "Voluviz")) #makedirs(path.join(newfolder, "Stats")) #makedirs(path.join(newfolder, "VTK")) makedirs(path.join(newfolder, "Timeseries")) makedirs(path.join(newfolder, "Checkpoint")) tstepfolder = path.join(newfolder, "Timeseries") tstepfiles = {} comps = sys_comp if output_timeseries_as_vector: comps = ['p', 'u'] + scalar_components for ui in comps: tstepfiles[ui] = XDMFFile(MPI.comm_world, path.join( tstepfolder, ui + '_from_tstep_{}.xdmf'.format(tstep))) tstepfiles[ui].parameters["rewrite_function_mesh"] = False tstepfiles[ui].parameters["flush_output"] = True return newfolder, tstepfiles
def check_if_kill(folder, killtime, total_timer): """Check if user has put a file named killoasis in folder or if given killtime has been reached.""" found = 0 if 'killoasis' in listdir(folder): found = 1 collective = MPI.sum(MPI.comm_world, found) if collective > 0: if MPI.rank(MPI.comm_world) == 0: remove(path.join(folder, 'killoasis')) info_red('killoasis Found! Stopping simulations cleanly...') return True else: elapsed_time = float(total_timer.elapsed()[0]) if killtime is not None and killtime <= elapsed_time: if MPI.rank(MPI.comm_world) == 0: info_red( 'Given killtime reached! Stopping simulations cleanly...') return True else: return False
def init_from_restart(restart_folder, sys_comp, uc_comp, u_components, q_, q_1, q_2, tstep, **NS_namespace): """Initialize solution from checkpoint files """ if restart_folder: if MPI.rank(MPI.comm_world) == 0: info_red( 'Restarting from checkpoint at time step {}'.format(tstep)) for ui in sys_comp: filename = path.join(restart_folder, ui + '.h5') hdf5_file = HDF5File(MPI.comm_world, filename, "r") hdf5_file.read(q_[ui].vector(), "/current", False) q_[ui].vector().apply('insert') # Check for the solution at a previous timestep as well if ui in uc_comp: q_1[ui].vector().zero() q_1[ui].vector().axpy(1., q_[ui].vector()) q_1[ui].vector().apply('insert') if ui in u_components: hdf5_file.read(q_2[ui].vector(), "/previous", False) q_2[ui].vector().apply('insert')