print t, float(kk), float(ww) def regression_test(t, tstep, comm, U, curl, float64, dx, L, sum, rank, **kw): k = comm.reduce(sum(U.astype(float64)*U.astype(float64))*dx[0]*dx[1]*dx[2]/L[0]/L[1]/L[2]/2) # Compute energy with double precision if config.solver == 'NS': w = comm.reduce(sum(curl.astype(float64)*curl.astype(float64))*dx[0]*dx[1]*dx[2]/L[0]/L[1]/L[2]/2) elif config.solver == 'VV': w = comm.reduce(sum(kw['W'].astype(float64)*kw['W'].astype(float64))*dx[0]*dx[1]*dx[2]/L[0]/L[1]/L[2]/2) if rank == 0: assert round(k - 0.124953117517, 7) == 0 assert round(w - 0.375249930801, 7) == 0 if __name__ == "__main__": config.update( { 'nu': 0.00625, # Viscosity 'dt': 0.01, # Time step 'T': 0.1, # End time 'L': [2*pi, 4*pi, 2*pi], 'M': [5, 5, 5] }, "Isotropic" ) config.Isotropic.add_argument("--compute_energy", type=int, default=2) solver = get_solver(update=update) solver.hdf5file.fname = "NS7.h5" solver.hdf5file.components["W0"] = solver.curl[0] solver.hdf5file.components["W1"] = solver.curl[1] solver.hdf5file.components["W2"] = solver.curl[2] initialize(**vars(solver)) solver.solve()
N = self.shape[0] s = slice(self.rank*N, (self.rank+1)*N, 1) for i, name in enumerate(("U", "V", "W")): self.Umean[i, s] = self.f0["Average/"+name][s] self.Pmean[s] = self.f0["Average/P"][s] for i, name in enumerate(("UU", "VV", "WW", "UV", "UW", "VW")): self.UU[i, s] = self.f0["Reynolds Stress/"+name][s] if __name__ == "__main__": config.update( { 'solver': 'IPCS', 'nu': 1./180., # Viscosity 'Re_tau': 180., 'dt': 0.001, # Time step 'T': 100., # End time 'L': [2, 4*pi, 4.*pi/3.], 'M': [6, 6, 5] }, "Shen" ) config.Shen.add_argument("--compute_energy", type=int, default=100) config.Shen.add_argument("--plot_result", type=int, default=100) config.Shen.add_argument("--sample_stats", type=int, default=100) solver = get_solver(update=update, family="Shen") initialize(**vars(solver)) #init_from_file("IPCSRR.h5", **vars(solver)) set_Source(**vars(solver)) solver.stats = Stats(solver.U, solver.comm, filename="MKMstats") solver.hdf5file.fname = "IPCSRR.h5" solver.solve()
comm.Gather(u0, uall, root=0) if rank == 0: uall = uall.reshape((N[0],)) #x = points #pc = zeros(len(x)) #pc = ST.fct(uall, pc) # Cheb transform of result #solution at x = 0 #u = n_cheb.chebval(0, pc) #u_exact = reference(config.Re, config.t) u_exact = exact(points, config.Re, config.t) print "Computed error = %2.8e %2.8e " %(sqrt(sum((uall-u_exact)**2)/N[0]), config.dt) if __name__ == "__main__": config.update( { 'solver': 'IPCS', 'Re': 800., 'nu': 1./800., # Viscosity 'dt': 0.5, # Time step 'T': 50., # End time 'L': [2, 2*pi, 4*pi/3.], 'M': [6, 5, 1] }, "Shen" ) config.Shen.add_argument("--compute_energy", type=int, default=5) config.Shen.add_argument("--plot_step", type=int, default=10) solver = get_solver(update=update, regression_test=regression_test, family="Shen") initialize(**vars(solver)) set_Source(**vars(solver)) solver.solve()
im2.set_data(W[0, 0, :, ::-1].T) im2.autoscale() plt.pause(1e-6) print "Time = ", t def finalize(rank, Nf, X, U, W_hat, Curl, **soak): global im im.set_UVC(U[1, 0], U[2, 0]) plt.pause(1e-6) if __name__ == "__main__": config.update( { 'solver': 'VV', 'nu': 0.000625, # Viscosity 'dt': 0.01, # Time step 'T': 50, # End time 'write_result': 100 } ) config.Isotropic.add_argument("--init", default='random', choices=('random', 'vortex')) config.Isotropic.add_argument("--plot_result", type=int, default=10) # required to allow overloading through commandline solver = get_solver(update) assert config.decomposition == 'slab' solver.W, solver.W_hat = initialize(**vars(solver)) solver.Source = set_source(**vars(solver)) solver.solve() finalize(**vars(solver))
#e1 = 0.5*energy(pert, N, comm, rank, L) #exact = exp(2*imag(OS.eigval)*config.t) #if rank == 0: #print "Computed error = %2.8e %2.8e " %(sqrt(abs(e1/e0-exact)), config.dt) initOS(OS, U0, U_hat0, X, FST, ST, t=config.t) pert = (U[0] - U0[0])**2 + (U[1]-U0[1])**2 e1 = 0.5*energy(pert, N, comm, rank, L) #exact = exp(2*imag(OS.eigval)*config.t) if rank == 0: print "Computed error = %2.8e %2.8e " %(sqrt(e1), config.dt) if __name__ == "__main__": config.update( { 'solver': 'IPCS_GeneralBCs', 'Re': 8000., 'nu': 1./8000., # Viscosity 'dt': 0.01, # Time step 'T': 0.02, # End time 'L': [2, 2*pi, 4*pi/3.], 'M': [7, 6, 1] }, "ShenGeneralBCs" ) config.ShenGeneralBCs.add_argument("--compute_energy", type=int, default=1) config.ShenGeneralBCs.add_argument("--plot_step", type=int, default=10) solver = get_solver(update=update, regression_test=regression_test, family="ShenGeneralBCs") vars(solver).update(initialize(**vars(solver))) set_Source(**vars(solver)) solver.solve()
Ha = config.Ha u_exact = ( cosh(Ha) - cosh(Ha*X[0,:,0,0]))/(cosh(Ha) - 1.0) if rank == 0: print "Time %2.5f Error %2.12e" %(config.t, linalg.norm(u_exact-U[1,:,0,0],inf)) plt.plot(X[0,:,0,0], U[1,:,0,0], X[0,:,0,0], u_exact,'*r') plt.show() if __name__ == "__main__": config.update( { 'solver': 'IPCS_MHD', 'Re': 8000., 'Rm': 600., 'nu': 1./8000., # Viscosity 'eta': 1./600., # Resistivity 'dt': 0.001, # Time step 'T': 0.01, # End time 'B_strength': 0.000001, 'Ha': 0.0043817804600413289, 'L': [2, 2*pi, 4*pi/3.], 'M': [7, 6, 1] }, "ShenMHD" ) config.ShenMHD.add_argument("--compute_energy", type=int, default=1) config.ShenMHD.add_argument("--plot_step", type=int, default=10) solver = get_solver(update=update, regression_test=regression_test, family="ShenMHD") vars(solver).update(initialize(**vars(solver))) set_Source(**vars(solver)) solver.solve()
curl[:] = ifft2_mpi(1j*K[0]*U_hat[1]-1j*K[1]*U_hat[0], curl) P = ifft2_mpi(1j*P_hat, P) im.set_data(P[:, :].T) im.autoscale() plt.pause(1e-6) im2.set_data(curl[:,:].T) im2.autoscale() plt.pause(1e-6) if rank == 0: print tstep if __name__ == "__main__": config.update( { 'nu': 1.0e-05, 'dt': 0.007, 'T': 25.0, 'U1':-0.5, 'U2':0.5, 'l0': 0.001, # Smoothing parameter 'A': 0.01, # Amplitude of perturbation 'delta': 0.1, # Width of perturbations 'write_result': 500 } ) config.parser.add_argument("--plot_result", type=int, default=10) # required to allow overloading through commandline config.parser.add_argument("--compute_energy", type=int, default=10) solver = get_solver(update) initialize(**vars(solver)) solver.solve()
if tstep % config.compute_energy == 0: kk = comm.reduce(sum(U.astype(float64)*U.astype(float64))*dx[0]*dx[1]/L[0]/L[1]/2) if rank == 0: print tstep, kk if __name__ == "__main__": config.update( { 'solver': 'Bq2D', 'nu': 1.0e-08, 'dt': 0.001, 'T': 1.0, 'U1':-0.5, 'U2':0.5, 'l0': 0.001, # Smoothing parameter 'A': 0.01, # Amplitude of perturbation 'Ri': 0.167, # Richardson number 'Pr': 12.0, # Prantl number 'delta': 0.05, # Width of perturbations 'bb': 0.8, 'k0': 2, 'rho1': 1.0, 'rho2': 3.0, } ) config.parser.add_argument("--plot_result", type=int, default=10) # required to allow overloading through commandline config.parser.add_argument("--compute_energy", type=int, default=2) solver = get_solver(update) solver.hdf5file.components["curl"] = solver.curl initialize(**vars(solver)) solver.solve()
plt.draw() if tstep % config.write_result == 0: P = ifft2_mpi(P_hat*1j, P) curl = ifft2_mpi(1j*K[0]*U_hat[1]-1j*K[1]*U_hat[0], curl) hdf5file.write(tstep) if tstep % config.plot_result == 0 and config.plot_result > 0: curl = ifft2_mpi(1j*K[0]*U_hat[1]-1j*K[1]*U_hat[0], curl) im.set_data(curl[:, :]) im.autoscale() plt.pause(1e-6) if __name__ == '__main__': config.update( { 'solver': 'NS2D', 'nu': 0.001, 'dt': 0.005, 'T': 50, 'write_result': 100, 'M': [6, 6]} ) config.Isotropic.add_argument("--plot_result", type=int, default=10) # required to allow overloading through commandline solver = get_solver(update=update, regression_test=regression_test) solver.hdf5file.components["curl"] = solver.curl initialize(**vars(solver)) solver.solve()
if tstep % config.plot_result == 0 and config.plot_result > 0: curl = ifft2_mpi(1j*K[0]*U_hat[1]-1j*K[1]*U_hat[0], curl) im.set_data(curl[:, :]) im.autoscale() plt.pause(1e-6) def regression_test(t, tstep, comm, U, curl, float64, dx, L, sum, rank, X, nu, **kw): k = comm.reduce(sum(U.astype(float64)*U.astype(float64))*dx[0]*dx[1]/L[0]/L[1]/2) U[0] = -sin(X[1])*cos(X[0])*exp(-2*nu*t) U[1] = sin(X[0])*cos(X[1])*exp(-2*nu*t) ke = comm.reduce(sum(U.astype(float64)*U.astype(float64))*dx[0]*dx[1]/L[0]/L[1]/2) if rank == 0: assert round(k - ke, 7) == 0 if __name__ == '__main__': config.update( { 'nu': 0.01, 'dt': 0.05, 'T': 10, 'write_result': 100, 'M': [6, 6]} ) config.parser.add_argument("--plot_result", type=int, default=10) # required to allow overloading through commandline solver = get_solver(update=update, regression_test=regression_test) solver.hdf5file.components["curl"] = solver.curl initialize(**vars(solver)) solver.solve()
def update(t, tstep, N, curl, U_hat, ifft2_mpi, K, P, P_hat, hdf5file, **kw): global im # initialize plot if tstep == 1: im = plt.imshow(zeros((N[0], N[1]))) plt.colorbar(im) plt.draw() if tstep % config.write_result == 0: P = ifft2_mpi(P_hat * 1j, P) curl = ifft2_mpi(1j * K[0] * U_hat[1] - 1j * K[1] * U_hat[0], curl) hdf5file.write(tstep) if tstep % config.plot_result == 0 and config.plot_result > 0: curl = ifft2_mpi(1j * K[0] * U_hat[1] - 1j * K[1] * U_hat[0], curl) im.set_data(curl[:, :]) im.autoscale() plt.pause(1e-6) if __name__ == "__main__": config.update({"nu": 0.001, "dt": 0.005, "T": 50, "write_result": 100, "M": [6, 6]}) config.parser.add_argument( "--plot_result", type=int, default=10 ) # required to allow overloading through commandline solver = get_solver(update=update, regression_test=regression_test) solver.hdf5file.components["curl"] = solver.curl initialize(**vars(solver)) solver.solve()
if tstep % config.write_result == 0: P = ifft2_mpi(P_hat*1j, P) curl = ifft2_mpi(1j*K[0]*U_hat[1]-1j*K[1]*U_hat[0], curl) hdf5file.write(tstep) if tstep % config.plot_result == 0 and config.plot_result > 0: curl = ifft2_mpi(1j*K[0]*U_hat[1]-1j*K[1]*U_hat[0], curl) im.set_data(curl[:, :]) im.autoscale() plt.pause(1e-6) if __name__ == '__main__': from cbcdns import config, get_solver config.update( { 'nu': 0.001, 'dt': 0.005, 'T': 50, 'write_result': 100} ) config.parser.add_argument("--plot_result", type=int, default=10) # required to allow overloading through commandline solver = get_solver() solver.hdf5file.components["curl"] = solver.curl initialize(**vars(solver)) solver.update = update solver.regression_test = regression_test solver.solve()
def update(t, tstep, dt, comm, rank, P, P_hat, U, B, curl, float64, dx, L, sum, hdf5file, ifftn_mpi, **kw): if tstep % config.write_result == 0 or tstep % config.write_yz_slice[1] == 0: P = ifftn_mpi(P_hat*1j, P) hdf5file.write(tstep) def regression_test(t, tstep, comm, U, B, float64, dx, L, sum, rank, **kw): k = comm.reduce(sum(U.astype(float64)*U.astype(float64))*dx[0]*dx[1]*dx[2]/L[0]/L[1]/L[2]/2) # Compute energy with double precision b = comm.reduce(sum(B.astype(float64)*B.astype(float64))*dx[0]*dx[1]*dx[2]/L[0]/L[1]/L[2]/2) if rank == 0: assert round(k - 0.124565408177, 7) == 0 assert round(b - 0.124637762143, 7) == 0 if __name__ == "__main__": config.update( { 'nu': 0.000625, # Viscosity 'dt': 0.01, # Time step 'T': 0.1, # End time 'eta': 0.01, 'L': [2*pi, 4*pi, 6*pi], 'M': [4, 5, 6] } ) solver = get_solver(update=update, regression_test=regression_test) initialize(**vars(solver)) solver.solve()