def test(): sim = Simulation() # Geometry and Model Equations sim.geomy = 'periodic' sim.stepper = Step.AB3 sim.method = 'Spectral' sim.dynamics = 'Linear' sim.flux_method = Flux.spectral_sw # Specify paramters sim.Ly = 4000e3 sim.Ny = 256 sim.f0 = 0. sim.Hs = [100.] sim.rho = [1025.] sim.end_time = sim.Ly/(np.sqrt(sim.Hs[0]*sim.g)) # Plotting parameters sim.animate = 'None' sim.output = False sim.diagnose = False # Initialize the grid and zero solutions sim.initialize() for ii in range(sim.Nz): sim.soln.h[:,:,ii] = sim.Hs[ii] # Gaussian initial conditions x0 = 1.*sim.Lx/2. W = 200.e3 amp = 1. sim.soln.h[:,:,0] += amp*np.exp(-(sim.Y)**2/(W**2)) IC = sim.soln.h[:,:,0].copy() sim.run() # Compare final state to initial conditions # error_h is normalized using the triangle inequality error_h = np.linalg.norm(IC - sim.soln.h[:,:,0])/(np.linalg.norm(IC) + np.linalg.norm(sim.soln.h[:,:,0])) error_v = np.linalg.norm(sim.soln.v[:,:,0]) assert (error_h < 1e-6) and (error_v < 5e-5)
def test(): sim = Simulation() # Create a simulation object # Geometry and Model Equations sim.geomx = 'walls' sim.geomy = 'walls' sim.stepper = Step.AB3 sim.method = 'Spectral' sim.dynamics = 'Nonlinear' sim.flux_method = Flux.spectral_sw # Specify paramters sim.Lx = 4000e3 sim.Ly = 4000e3 sim.Nx = 128 sim.Ny = 128 sim.Nz = 1 sim.g = 9.81 sim.f0 = 1.e-4 sim.beta = 0e-11 sim.cfl = 0.1 sim.Hs = [100.] sim.rho = [1025.] sim.end_time = 5. * minute sim.animate = 'None' sim.output = False sim.diagnose = False # Initialize the grid and zero solutions sim.initialize() for ii in range(sim.Nz): # Set mean depths sim.soln.h[:, :, ii] = sim.Hs[ii] # Gaussian initial conditions W = 200.e3 # Width amp = 1. # Amplitude sim.soln.h[:, :, 0] += amp * np.exp(-(sim.X / W)**2 - (sim.Y / W)**2) # Run the simulation sim.run()
def test(): sim = Simulation() # Create a simulation object # Geometry and Model Equations sim.geomx = 'periodic' sim.geomy = 'periodic' sim.stepper = Step.AB3 sim.method = 'Spectral' sim.dynamics = 'Nonlinear' sim.flux_method = Flux.spectral_sw # Specify paramters sim.Lx = 4000e3 sim.Ly = 4000e3 sim.Nx = 128 sim.Ny = 128 sim.Nz = 1 sim.g = 9.81 sim.f0 = 1.e-4 sim.beta = 0e-11 sim.cfl = 0.1 sim.Hs = [100.] sim.rho = [1025.] sim.end_time = 5.*minute sim.animate = 'None' sim.output = False sim.diagnose = False # Initialize the grid and zero solutions sim.initialize() for ii in range(sim.Nz): # Set mean depths sim.soln.h[:,:,ii] = sim.Hs[ii] # Gaussian initial conditions W = 200.e3 # Width amp = 1. # Amplitude sim.soln.h[:,:,0] += amp*np.exp(-(sim.X/W)**2 - (sim.Y/W)**2) # Run the simulation sim.run()
def test(): sim = Simulation() # Geometry and Model Equations sim.geomy = 'periodic' sim.stepper = Step.AB2 sim.method = 'Spectral' sim.dynamics = 'Nonlinear' sim.flux_method = Flux.spectral_sw # Specify paramters sim.Ly = 4000e3 sim.Ny = 128 sim.cfl = 0.5 sim.Hs = [100.] sim.rho = [1025.] sim.end_time = 5. * minute # Plotting parameters sim.animate = 'None' sim.output = False sim.diagnose = False # Initialize the grid and zero solutions sim.initialize() for ii in range(sim.Nz): sim.soln.h[:, :, ii] = sim.Hs[ii] # Gaussian initial conditions x0 = 1. * sim.Lx / 2. W = 200.e3 amp = 1. sim.soln.h[:, :, 0] += amp * np.exp(-(sim.Y)**2 / (W**2)) sim.run()
def test(): sim = Simulation() # Geometry and Model Equations sim.geomy = 'periodic' sim.stepper = Step.Euler sim.method = 'Spectral' sim.dynamics = 'Nonlinear' sim.flux_method = Flux.spectral_sw # Specify paramters sim.Ly = 4000e3 sim.Ny = 128 sim.cfl = 0.5 sim.Hs = [100.] sim.rho = [1025.] sim.end_time = 5.*minute # Plotting parameters sim.animate = 'None' sim.output = False sim.diagnose = False # Initialize the grid and zero solutions sim.initialize() for ii in range(sim.Nz): sim.soln.h[:,:,ii] = sim.Hs[ii] # Gaussian initial conditions x0 = 1.*sim.Lx/2. W = 200.e3 amp = 1. sim.soln.h[:,:,0] += amp*np.exp(-(sim.Y)**2/(W**2)) sim.run()
sim.plott = 15.*minute # Period of plots sim.animate = 'Anim' # 'Save' to create video frames, # 'Anim' to animate, # 'None' otherwise sim.plot_vars = ['h'] #sim.plot_vars = ['vort','div'] #sim.clims = [[-0.015, 0.015],[-0.001, 0.001]] # Output parameters sim.output = False # True or False sim.savet = 1.*hour # Time between saves # Diagnostics parameters sim.diagt = 2.*minute # Time for output sim.diagnose = False # True or False # Initialize the grid and zero solutions sim.initialize() for ii in range(sim.Nz): # Set mean depths sim.soln.h[:,:,ii] = sim.Hs[ii] # Gaussian initial conditions W = 200.e3 # Width amp = 1. # Amplitude sim.soln.h[:,:,0] += amp*np.exp(-(sim.X/W)**2 - (sim.Y/W)**2) # Run the simulation sim.run()
sim.clims = [[-0.8, 0.8], [-0.5, 0.5], [], []] # Output parameters sim.output = True # True or False sim.savet = 10. * day # Time between saves # Diagnostics parameters sim.diagt = 2. * minute # Time for output sim.diagnose = False # True or False # Initialize the grid and zero solutions sim.initialize() for ii in range(sim.Nz): # Set mean depths sim.soln.h[:, :, ii] = sim.Hs[ii] # Bickley Jet initial conditions # First we define the jet Ljet = 10e3 # Jet width amp = 0.1 # Elevation of free-surface in basic state sim.soln.h[:, :, 0] += -amp * np.tanh(sim.Y / Ljet) sim.soln.u[:, :, 0] = sim.g * amp / (sim.f0 * Ljet) / (np.cosh(sim.Y / Ljet)**2) # Then we add on a random perturbation np.random.seed(seed=100) sim.soln.u[:, :, 0] += 1e-3 * np.exp(-(sim.Y / Ljet)**2) * np.random.randn( sim.Nx, sim.Ny) sim.run() # Run the simulation
sim.diagt = 2.*minute # Time for output sim.diagnose = False # True or False # Initialize the grid and zero solutions sim.initialize() for ii in range(sim.Nz): # Set mean depths sim.soln.h[:,:,ii] = sim.Hs[ii] # Gaussian initial conditions x0 = 1.*sim.Lx/2. # Centre W = 200.e3 # Width amp = 1. # Amplitude sim.soln.h[:,:,0] += amp*np.exp(-(sim.Y)**2/(W**2)) sim.run() # Run the simulation # Hovmuller plot plt.figure() t = np.arange(0,sim.end_time+sim.plott,sim.plott)/86400. if sim.Ny==1: x = sim.x/1e3 elif sim.Nx == 1: x = sim.y/1e3 for L in range(sim.Nz): field = sim.hov_h[:,0,:].T - np.sum(sim.Hs[L:]) cv = np.max(np.abs(field.ravel())) plt.subplot(sim.Nz,1,L+1)
# Initialize the grid and zero solutions sim.initialize() for ii in range(sim.Nz): # Set mean depths sim.soln.h[:, :, ii] = sim.Hs[ii] # Gaussian initial conditions x0 = 1. * sim.Lx / 2. # Centre W = 200.e3 # Width amp = 1. # Amplitude sim.soln.h[:, :, 0] += amp * np.exp(-(sim.grid_y.h + sim.Ly / 4.)**2 / (W**2)) #sim.soln.h[:,:,0] += amp*np.exp(-(sim.grid_x.h + sim.Lx/4.)**2/(W**2)) # Run the simulation sim.run() # Hovmuller plot #plt.figure() #t = np.arange(0,sim.end_time+sim.plott,sim.plott)/86400. #if sim.Ny==1: # x = sim.x/1e3 #elif sim.Nx == 1: # x = sim.y/1e3 #for L in range(sim.Nz): # field = sim.hov_h[:,0,:].T - np.sum(sim.Hs[L:]) # cv = np.max(np.abs(field.ravel())) # plt.subplot(sim.Nz,1,L+1) # plt.pcolormesh(x,t, field,