def start_kdv(infile, rho, z, depthfile): # Parse the yaml file with open(infile, 'r') as f: args = yaml.load(f) kdvargs = args['kdvargs'] kdvargs.update({'wavefunc': zeroic}) kdvargs.update({'verbose': False}) #kdvargs.update({'nonlinear':False}) # Testing runtime = args['runtime']['runtime'] ntout = args['runtime']['ntout'] xpt = args['runtime']['xpt'] # Parse the density and depth files depthtxt = np.loadtxt(depthfile, delimiter=',') # Initialise the KdV class mykdv = vKdV(rho,\ z,\ depthtxt[:,1],\ x=depthtxt[:,0],\ **kdvargs) return mykdv
def start_kdv(infile, rho, z, depthfile): # Parse the yaml file with open(infile, 'r') as f: args = yaml.load(f, Loader=yaml.FullLoader) kdvargs = args['kdvargs'] kdvargs.update({'verbose': False}) #kdvargs.update({'nonlinear':False}) # Testing #kdvargs['Nsubset'] = 1 runtime = args['runtime']['runtime'] ntout = args['runtime']['ntout'] xpt = args['runtime']['xpt'] # Parse the density and depth files depthtxt = np.loadtxt(depthfile, delimiter=',') N = depthtxt[:, 0].shape[0] dx = depthtxt[1, 0] - depthtxt[0, 0] # Initialise the KdV class mykdv = vKdV(rho, z, depthtxt[:, 1], depthtxt[:, 0], N=N, dx=dx, **kdvargs) return mykdv
params = pd.read_csv(strat_param_file, index_col='time', parse_dates=True) pp = params[tstart[0:8]:'20100101'] rhoz = lamb_tanh_rho(z, pp['rho0'][0], pp['dp'][0], pp['z1'][0], pp['h1'][0]) # In[4]: ### # Intitialise the class mykdv = vKdV(rhoz, z, \ h, x=x,\ mode=mode,\ a0=a0,\ Lw=Lw,\ x0=Lw,\ Cmax=Cmax,\ nonlinear=nonlinear,\ nonhydrostatic=nonhydrostatic,\ #timesolver=timesolver,\ dt=dt) # #mykdv.print_params() # #print 'Lamb values:\n r01 = -2.91e3\n r10 = 8.31e-3\n r20 = 2.35e-5' ########## # run the model nsteps = int(runtime // mykdv.dt_s) print nsteps, mykdv.dt_s
def run_solver( a0_sample, beta_sample, infile, depthfile, ): """ instantiate an run the actual PDE solver, returning the full list of output amplitudes, plus the (signed) maximum amplitude. """ # Parse the yaml file with open(infile, 'r') as f: args = yaml.load(f) kdvargs = args['kdvargs'] kdvargs.update({'wavefunc': zeroic}) # Set the buoyancy eigenfunction to save time (not used here...) kdvargs.update({'D10': -1}) kdvargs.update({'D01': -1}) kdvargs.update({'D20': -1}) runtime = args['runtime']['runtime'] ntout = args['runtime']['ntout'] output_x = args['runtime']['xpt'] # Parse the density and depth files depthtxt = np.loadtxt(depthfile, delimiter=',') x_domain = depthtxt[:, 0] # print("p2 for a0 {}".format(a0_sample)) omega = 2 * np.pi / (12.42 * 3600) #x_domain = np.arange(0,L_d+dx, dx) # print("running kdv solver for a0 {}".format(a0_sample)) rho_std = 1.5 rho_mu = 1024. z_std = 100. #z_new = np.arange(0, zmax,-dz) dz = 5 z_new = np.arange(-depthtxt[0, 1], dz, dz)[::-1] #rho_sample = double_tanh(z_new, beta_sample) rho_sample = double_tanh(z_new / z_std, beta_sample) * rho_std + rho_mu # Find the ouput x location xpt = np.argwhere(x_domain >= output_x)[0, 0] # Boundary forcing function def bcfunc(t): return a0_sample * np.sin(omega * t) def amp_at_x(kdv): #u_vel, w_vel = kdv.calc_velocity() u_vel = calc_u_velocity_1d(kdv, kdv.B[xpt], xpt) # u_vel is now a matrix size [Nx, Nz] u_surface = u_vel[0] u_seabed = u_vel[-1] return kdv.B[xpt], u_surface, u_seabed # Parse the density and depth files depthtxt = np.loadtxt(depthfile, delimiter=',') # Initialise the KdV class mykdv = vKdV(rho_sample, z_new, depthtxt[:,1], \ x=depthtxt[:,0], **kdvargs) ## Run the model nsteps = int(runtime // kdvargs['dt']) nn = 0 output_amplitude = [] for ii in range(nsteps): if mykdv.solve_step(bc_left=bcfunc(mykdv.t)) != 0: print('Blowing up at step: %d' % ii) break # Evalute the function output_amplitude.append(amp_at_x(mykdv)) output = np.array([[aa[0], aa[1], aa[2]] for aa in output_amplitude]) output_amplitude = output[:, 0] output_u_surface = output[:, 1] output_u_seabed = output[:, 2] #if rank == 0: # plt.figure() # plt.plot(output_u_seabed) # plt.show() max_output_amplitude, tidx = maximum_amplitude_finder(output_amplitude) max_output_u_surface, _ = maximum_amplitude_finder(output_u_surface) max_output_u_seabed, _ = maximum_amplitude_finder(output_u_seabed) tmax = tidx * mykdv.dt_s return max_output_amplitude, output_amplitude, \ max_output_u_surface, max_output_u_seabed, tmax, mykdv, xpt
def vkdv_from_netcdf(ncfile, a0=None, wavefunc=None, mode=None): """ Wrapper to load an object directly from a pre-saved file """ ds = xray.open_dataset(ncfile) if a0 is None: a0 = ds.a0 if wavefunc is None: args = {} else: args = {'wavefunc':wavefunc} if mode is None: args.update({'mode':0}) # Need this for backward compatability... if hasattr(ds,'r20'): r20 = ds.r20.values D20 = ds.D20.values phi20 = ds.phi20.values ekdv = ds.ekdv else: r20 = np.zeros_like(ds.x.values) ekdv = False D20 = np.zeros_like(ds.D10) phi20 = np.zeros_like(ds.D10) mykdv = vKdV( ds.rhoZ.values[:,0], ds.Z.values[:,0], ds.h.values, x=ds.x.values,\ #mode=ds.mode,\ a0=a0,\ #Lw=ds.Lw,\ x0=0,\ ekdv=ekdv, #nu_H=ds.nu_H,\ #spongedist=ds.spongedist,\ #Cmax=ds.Cmax,\ #dt=ds.dt_s, Cn=ds.Cn.values, Phi=ds.Phi.values, Alpha=ds.Alpha.values, Beta=ds.Beta.values, Qterm=ds.Qterm.values, phi01=ds.phi01.values, phi10=ds.phi10.values, D01=ds.D01.values, D10=ds.D10.values, phi20=phi20, D20=D20, r20=r20, **args ) # Return the time-variable amplitude array as well if 'B_t' in list(ds.variables.keys()): B_t = ds['B_t'] else: B_t = None return mykdv, B_t