dt = params.dt_max if dt < dt_old*(1+params.threshold) and dt > dt_old*(1-params.threshold): dt = dt_old return dt # Timestepping loop start_time = time.time() t = 0. iter = 0 dt = params.dt_max snapshots_time = -1e-20 while t < params.t_end: equations.nonlinear(state_vector, NL, t, M, params.R, params.Prandtl, params.Rayleigh, params.epsilon, psi) if iter % 10 == 0: Tmax = np.max(T['g']) Tmax = reducer.reduce_scalar(Tmax, MPI.MAX) logger.info("iter: {:d}, dt={:e}, t={:e}, T_max={:e}".format(iter, dt, t, Tmax)) if t > snapshots_time: snapshots_time += params.snapshots_cadence snapshots.process(time.time(), t, dt, iter) if iter % 10 == 0: dt = calculate_dt(dt) timestepper.step(dt, state_vector, B, L, M, P, NL, LU) t += dt iter += 1 end_time = time.time() logger.info('Simulation runtime: %f' %(end_time-start_time))
reducer = GlobalArrayReducer(domain.dist.comm_cart) while t < t_end: nonlinear(state_vector,NL,t) if iter % 5 == 0: state_vector.unpack(u,p,T,A,pi) # H = curl(A) for ell in range(ell_start,ell_end+1): ell_local = ell - ell_start B.curl(ell,1,A['c'][ell_local],H['c'][ell_local]) Ek = np.sum(weight_r*weight_theta* 0.5*u['g']**2)*(np.pi)/((L_max+1)*L_dealias) Em = np.sum(weight_r*weight_theta* 0.5/Rossby*H['g']**2)*np.pi/((L_max+1)*L_dealias) Ek = reducer.reduce_scalar(Ek, MPI.SUM) Em = reducer.reduce_scalar(Em, MPI.SUM) if rank == 0: print( t,iter,Ek,Em ) timestepper.step(dt, state_vector, B, L, M, P, NL, LU) t += dt iter += 1 end_time = time.time() if rank==0: print('simulation took: %f' %(end_time-start_time))
problem.add_equation(eq_eval("tau = 0"), condition="ntheta == 0") logger.info("Problem built") # Solver solver = solvers.InitialValueSolver(problem, ts) solver.stop_sim_time = t_end # Analysis t_list = [] E_list = [] weight_theta = b.local_colatitude_weights(1) weight_r = b.local_radial_weights(1) reducer = GlobalArrayReducer(d.comm_cart) vol_test = np.sum(weight_r * weight_theta + 0 * p['g']) * np.pi / (Lmax + 1) / L_dealias vol_test = reducer.reduce_scalar(vol_test, MPI.SUM) vol_correction = 4 * np.pi / 3 / vol_test # Main loop start_time = time.time() while solver.ok: if solver.iteration % 10 == 0: E0 = np.sum(vol_correction * weight_r * weight_theta * u['g'].real**2) E0 = 0.5 * E0 * (np.pi) / (Lmax + 1) / L_dealias E0 = reducer.reduce_scalar(E0, MPI.SUM) logger.info("t = %f, E = %e" % (solver.sim_time, E0)) t_list.append(solver.sim_time) E_list.append(E0) solver.step(dt) end_time = time.time() logger.info('Run time:', end_time - start_time)
# Solver solver = solvers.InitialValueSolver(problem, ts) solver.stop_sim_time = t_end logger.info("built IVP") # Analysis t_list = [] KE_list = [] ME_list = [] weight_theta = b.local_colatitude_weights(1) weight_r = b.local_radial_weights(1) reducer = GlobalArrayReducer(d.comm_cart) vol_test = np.sum(weight_r * weight_theta + 0 * p['g']) * np.pi / (Lmax + 1) / L_dealias vol_test = reducer.reduce_scalar(vol_test, MPI.SUM) vol_correction = 4 * np.pi / 3 / vol_test # Main loop report_cadence = 10 good_solution = True start_time = time.time() while solver.ok and good_solution: if solver.iteration % report_cadence == 0: KE = np.sum(vol_correction * weight_r * weight_theta * u['g'].real**2) KE = 0.5 * KE * (np.pi) / (Lmax + 1) / L_dealias KE = reducer.reduce_scalar(KE, MPI.SUM) B = (operators.Curl(A)).evaluate() ME = np.sum(vol_correction * weight_r * weight_theta * B['g'].real**2) ME = 0.5 * ME * (np.pi) / (Lmax + 1) / L_dealias ME /= Rossby
t_list = [] E_list = [] # timestepping loop start_time = time.time() iter = 0 while t < t_end: nonlinear(state_vector, NL, t) if iter % 10 == 0: E0 = np.sum(weight_r * weight_theta * 0.5 * u['g']**2) * (np.pi) / ( (L_max + 1) * L_dealias) E0 = reducer.reduce_scalar(E0, MPI.SUM) logger.info("iter: {:d}, dt={:e}, t/t_e={:e}, E0={:e}".format( iter, dt, t / t_end, E0)) if rank == 0: t_list.append(t) E_list.append(E0) timestepper.step(dt, state_vector, B, L, M, P, NL, LU) t += dt iter += 1 end_time = time.time() if rank == 0: print('simulation took: %f' % (end_time - start_time)) t_list = np.array(t_list) E_list = np.array(E_list)
tau_columns = np.zeros((shape[0], 4)) tau_columns[:N0, 0] = (C(Nmax))[:, -1] tau_columns[:N0, 1] = (C(Nmax))[:, -2] tau_columns[N0:N1, 2] = (C(Nmax))[:, -1] tau_columns[N0:N1, 3] = (C(Nmax))[:, -2] L[:, -4:] = tau_columns subproblem.L_min = subproblem.left_perm @ L subproblem.L_min.eliminate_zeros() subproblem.expand_matrices(['M', 'L']) weight_theta = b.local_colatitude_weights(1) weight_r = b.local_radial_weights(1) reducer = GlobalArrayReducer(d.comm_cart) vol_test = np.sum(weight_r * weight_theta + 0 * T['g']) * np.pi / (Lmax + 1) / L_dealias vol_test = reducer.reduce_scalar(vol_test, MPI.SUM) vol_correction = 4 * np.pi / 3 / vol_test report_cadence = 10 dt = 1e-3 plot_cadence = report_cadence plot = theta_target in theta var = T['g'] name = 'T_diff' if plot: i_theta = np.argmin(np.abs(theta[0, :, 0] - theta_target)) import matplotlib.pyplot as plt from dedalus.extras import plot_tools
# Solver solver = solvers.InitialValueSolver(problem, ts) solver.stop_sim_time = t_end + dt # Analysis t_list = [] E_list = [] T_list = [] T_err_list = [] weight_theta = b.local_colatitude_weights(1) weight_r = b.local_radial_weights(1) reducer = GlobalArrayReducer(d.comm_cart) vol_test = np.sum(weight_r * weight_theta + 0 * T['g']) * np.pi / (Lmax + 1) / L_dealias vol_test = reducer.reduce_scalar(vol_test, MPI.SUM) vol_correction = 4 * np.pi / 3 / vol_test report_cadence = 10 # Main loop start_time = time.time() while solver.ok: if args['--verbose'] and solver.iteration % report_cadence == 0 and solver.iteration > 0: E0 = np.sum(vol_correction * weight_r * weight_theta * u['g'].real**2) E0 = 0.5 * E0 * (np.pi) / (Lmax + 1) / L_dealias E0 = reducer.reduce_scalar(E0, MPI.SUM) T0 = np.sum(vol_correction * weight_r * weight_theta * T['g'].real**2) T0 = T0 * (np.pi) / (Lmax + 1) / L_dealias T0 = reducer.reduce_scalar(T0, MPI.SUM) T_err = np.sum(vol_correction * weight_r * weight_theta *
# plt.imshow(np.log10(np.abs(L.A))) # plt.colorbar() # plt.savefig("matrices/ell_%03i.png" %ell, dpi=300) # plt.clf() # print(subproblem.group, np.linalg.cond((M + L).A)) # Analysis t_list = [] E_list = [] weightB_theta = bB.local_colatitude_weights(1) weightB_r = bB.local_radial_weights(1) reducer = GlobalArrayReducer(d.comm_cart) vol_test = np.sum(weightB_r * weightB_theta + 0 * pB['g']) * np.pi / (Lmax + 1) / L_dealias vol_test = reducer.reduce_scalar(vol_test, MPI.SUM) vol_correctionB = 4 * np.pi / 3 * 0.5**3 / vol_test weightS_theta = bS.local_colatitude_weights(1) weightS_r = bS.local_radial_weights(1) * r_S**2 reducer = GlobalArrayReducer(d.comm_cart) vol_test = np.sum(weightS_r * weightS_theta + 0 * pS['g']) * np.pi / (Lmax + 1) / L_dealias vol_test = reducer.reduce_scalar(vol_test, MPI.SUM) vol_correctionS = 4 * np.pi / 3 * (1**3 - 0.5**3) / vol_test # Main loop start_time = time.time() while solver.ok: if solver.iteration % 10 == 0: