def run_strat_sim(set_ICs, name, params): snapshots_dir = SNAPSHOTS_DIR % name logger = logging.getLogger(name) solver, domain = get_solver(params) # Initial conditions set_ICs(solver, domain, params) cfl = CFL(solver, initial_dt=params['DT'], cadence=10, max_dt=params['DT'], threshold=0.10) cfl.add_velocities(('ux', 'uz')) snapshots = solver.evaluator.add_file_handler(snapshots_dir, sim_dt=params['T_F'] / params['NUM_SNAPSHOTS']) snapshots.add_system(solver.state) # Main loop logger.info('Starting sim...') while solver.ok: cfl_dt = cfl.compute_dt() if params.get('USE_CFL') else params['DT'] solver.step(cfl_dt) curr_iter = solver.iteration if curr_iter % int( (params['T_F'] / params['DT']) / params['NUM_SNAPSHOTS']) == 0: logger.info('Reached time %f out of %f, timestep %f vs max %f', solver.sim_time, solver.stop_sim_time, cfl_dt, params['DT'])
def run_strat_sim(setup_problem, set_ICs, XMAX, ZMAX, N_X, N_Z, T_F, DT, KX, KZ, H, RHO0, NUM_SNAPSHOTS, G, A, name=None, USE_CFL=True, **_): snapshots_dir = SNAPSHOTS_DIR % name try: os.makedirs(snapshots_dir) except FileExistsError: print('snapshots already exist, exiting...') return logger = logging.getLogger(name or __name__) solver, domain = get_solver(setup_problem, XMAX=XMAX, ZMAX=ZMAX, N_X=N_X, N_Z=N_Z, T_F=T_F, KX=KX, KZ=KZ, H=H, RHO0=RHO0, G=G, A=A) # Initial conditions set_ICs(solver, domain) cfl = CFL(solver, initial_dt=DT, cadence=10, max_dt=DT, threshold=0.10) cfl.add_velocities(('ux', 'uz')) snapshots = solver.evaluator.add_file_handler(snapshots_dir, sim_dt=T_F / NUM_SNAPSHOTS) snapshots.add_system(solver.state) # Main loop logger.info('Starting sim...') while solver.ok: cfl_dt = cfl.compute_dt() if USE_CFL else DT solver.step(cfl_dt) curr_iter = solver.iteration if curr_iter % int((T_F / DT) / NUM_SNAPSHOTS) == 0: logger.info('Reached time %f out of %f, timestep %f vs max %f', solver.sim_time, solver.stop_sim_time, cfl_dt, DT)
def run_strat_sim(set_ICs, name, params): snapshots_dir = SNAPSHOTS_DIR % name logger = logging.getLogger(name) solver, domain = get_solver(params) # Initial conditions set_ICs(solver, domain, params) # filename = '{s}/{s}_s1.h5'.format(s=snapshots_dir) # write, dt = solver.load_state(filename, -30) # print("=====strat_helper.py=====", "loaded", write) cfl = CFL(solver, initial_dt=params['DT'], cadence=10, max_dt=5, min_dt=0.01, safety=0.5, threshold=0.10) cfl.add_velocities(('ux', 'uz')) cfl.add_frequency(params['DT']) snapshots = solver.evaluator.add_file_handler(snapshots_dir, sim_dt=params['T_F'] / params['NUM_SNAPSHOTS']) snapshots.add_system(solver.state) # Flow properties flow = GlobalFlowProperty(solver, cadence=10) flow.add_property("sqrt(ux*ux + uz*uz) / NU", name='Re') # Main loop logger.info('Starting sim...') slices = domain.dist.coeff_layout.slices(scales=1) (len_x, len_z) = domain.dist.coeff_layout.global_shape(scales=1) # mask kicks in 1/3 of the way, gaussian decay len_x_damp = len_x - (len_x // 3) len_z_damp = len_z - (len_z // 3) x_mask = np.concatenate( (np.ones(len_x // 3), np.exp(-16 * np.arange(len_x_damp)**2 / len_x_damp**2))) z_mask = np.concatenate( (np.ones(len_z // 3), np.exp(-16 * np.arange(len_z_damp)**2 / len_z_damp**2))) mask = np.outer(x_mask, z_mask) while solver.ok: cfl_dt = cfl.compute_dt() if params.get('USE_CFL') else params['DT'] solver.step(cfl_dt) curr_iter = solver.iteration for field in solver.state.fields: field['c'] *= mask[slices] if curr_iter % int( (params['T_F'] / params['DT']) / params['NUM_SNAPSHOTS']) == 0: logger.info('Reached time %f out of %f, timestep %f vs max %f', solver.sim_time, solver.stop_sim_time, cfl_dt, params['DT']) logger.info('Max Re = %f' % flow.max('Re'))
def run_strat_sim(set_ICs, name, params): snapshots_dir = SNAPSHOTS_DIR % name filename = '{s}/{s}_s1.h5'.format(s=snapshots_dir) logger = logging.getLogger(name) solver, domain = get_solver(params) # Initial conditions dt = params['DT'] _, dt = set_ICs(name, solver, domain, params) cfl = CFL(solver, initial_dt=dt, cadence=10, max_dt=params['DT'], min_dt=0.01, safety=0.5, threshold=0.10) cfl.add_velocities(('ux', 'uz')) cfl.add_frequency(params['DT']) snapshots = solver.evaluator.add_file_handler(snapshots_dir, sim_dt=params['T_F'] / params['NUM_SNAPSHOTS']) snapshots.add_system(solver.state) # Flow properties flow = GlobalFlowProperty(solver, cadence=10) flow.add_property('sqrt((ux / NU)**2 + (uz / NU)**2)', name='Re') # Main loop logger.info('Starting sim...') while solver.ok: cfl_dt = cfl.compute_dt() if params.get('USE_CFL') else params['DT'] # if cfl_dt < params['DT'] / 8: # small step sizes if strongly cfl limited # cfl_dt /= 2 solver.step(cfl_dt) curr_iter = solver.iteration if curr_iter % int( (params['T_F'] / params['DT']) / params['NUM_SNAPSHOTS']) == 0: logger.info('Reached time %f out of %f, timestep %f vs max %f', solver.sim_time, solver.stop_sim_time, cfl_dt, params['DT']) logger.info('Max Re = %f' % flow.max('Re'))
def run_strat_sim(name, params): populate_globals(params) snapshots_dir = SNAPSHOTS_DIR % name solver, domain = get_solver(params) # Initial conditions _, dt = set_ic(name, solver, domain, params) cfl = CFL(solver, initial_dt=dt, cadence=5, max_dt=DT, min_dt=0.007, safety=0.5, threshold=0.10) cfl.add_velocities(('ux', 'uz')) cfl.add_frequency(DT) snapshots = solver.evaluator.add_file_handler(snapshots_dir, sim_dt=T_F / NUM_SNAPSHOTS) snapshots.add_system(solver.state) snapshots.add_task("integ(RHO0 * ux * uz, 'x') / XMAX", name='S_{px}') # Flow properties flow = GlobalFlowProperty(solver, cadence=10) flow.add_property('sqrt(ux**2 + ux**2)', name='u') # Main loop logger.info('Starting sim...') while solver.ok: cfl_dt = cfl.compute_dt() if NL else DT solver.step(cfl_dt) curr_iter = solver.iteration if curr_iter % int((T_F / DT) / NUM_SNAPSHOTS) == 0: logger.info('Reached time %f out of %f, timestep %f vs max %f', solver.sim_time, solver.stop_sim_time, cfl_dt, DT) logger.info('Max u = %e' % flow.max('u'))
def __init__(self, *args, **kwargs): CFL.__init__(self, *args, **kwargs)
problem.add_bc('left(W) = 0', condition='nx == 0') problem.add_bc('left(uz) = 0', condition='nx != 0') problem.add_bc('left(ux) = 0') problem.add_bc('right(ux) = 0') problem.add_bc('right(U) = 0') problem.add_bc('left(U) = 0') # Build solver solver = problem.build_solver(de.timesteppers.RK443) solver.stop_sim_time = T_F solver.stop_wall_time = np.inf solver.stop_iteration = np.inf # Initial conditions are zero by default cfl = CFL(solver, initial_dt=DT, cadence=10, max_dt=DT, threshold=0.10) cfl.add_velocities(('ux', 'uz')) snapshots = solver.evaluator.add_file_handler(snapshots_dir, sim_dt=T_F / NUM_SNAPSHOTS) snapshots.add_system(solver.state) # Main loop logger.info('Starting sim...') while solver.ok: # cfl_dt = cfl.compute_dt() cfl_dt = DT solver.step(cfl_dt) curr_iter = solver.iteration if curr_iter % int((T_F / DT) / NUM_SNAPSHOTS) == 0: logger.info('Reached time %f out of %f, timestep %f vs max %f',
# Initial conditions if os.path.exists(snapshots_dir): filename = '{s}/{s}_s{idx}.h5'.format(s=snapshots_dir, idx=1) # try to load snapshots_s1 print('Attempting to load snapshots in', filename) _, dt = solver.load_state(filename, -1) print('Loaded snapshots') else: print('No snapshots found') dt = DT cfl = CFL(solver, initial_dt=dt, cadence=5, max_dt=DT, min_dt=0.007, safety=0.5, threshold=0.10) cfl.add_velocities(('ux', 'uz')) cfl.add_frequency(DT) snapshots = solver.evaluator.add_file_handler(snapshots_dir, sim_dt=T_F / NUM_SNAPSHOTS) snapshots.add_system(solver.state) # Flow properties flow = GlobalFlowProperty(solver, cadence=10) flow.add_property('sqrt(ux**2 + ux**2)', name='u') # Main loop logger.info('Starting sim...')