NXlist = [64, 128, 256, 256, 512] NZlist = [32, 64, 128, 128, 256] ddlist = [0.01, 0.005, 0.0025, 0.001, 0.00075] for ddindex in range(0, len(ddlist)): NX = NXlist[ddindex] NZ = NZlist[ddindex] # Density profile for this wave with specified d_d d_d = ddlist[ddindex] rho = lambda z: frho(z, d_d) intrho = lambda z: fintrho(z, d_d) rhoz = lambda z: frhoz(z, d_d) if ddindex == 0: djl = DJL(A, L, H, NX, NZ, rho, rhoz, intrho=intrho, relax=0.15) else: djl = DJL(A, L, H, NX, NZ, rho, rhoz, intrho=intrho, relax=0.15, initial_guess=djl) # Reduce epsilon, iterate to convergence djl = DJL(A, L,
# Find the solution start_time = time.time() #djl = DJL(A, L, H, NX, NZ, rho, rhoz) # Now solve DJL, bringing in the background velocity incrementally for ii, alpha in enumerate(numpy.linspace(0,1,4)): # Velocity profiles Ubg = lambda z: alpha * Utarget (z) Ubgz = lambda z: alpha * Utargetz (z) Ubgzz = lambda z: alpha * Utargetzz(z) # Use a larger epsilon for these intermediate waves # Iterate the DJL solution if ii == 0: djl = DJL(A, L, H, NX, NZ, rho, rhoz, epsilon = 1e-3, Ubg=Ubg, Ubgz = Ubgz, Ubgzz=Ubgzz) else: djl = DJL(A, L, H, NX, NZ, rho, rhoz, epsilon = 1e-3, Ubg=Ubg, Ubgz = Ubgz, Ubgzz=Ubgzz, initial_guess=djl) # Increase resolution, restore default epsilon, iterate to convergence NX, NZ =64, 64 # clear epsilon djl = DJL(A, L, H, NX, NZ, rho, rhoz, Ubg=Ubg, Ubgz = Ubgz, Ubgzz=Ubgzz, initial_guess = djl) # Increase resolution, iterate to convergence NX, NZ =128, 128 djl = DJL(A, L, H, NX, NZ, rho, rhoz, Ubg=Ubg, Ubgz = Ubgz, Ubgzz=Ubgzz, initial_guess = djl) # Increase to the final resolution, iterate to convergence NX, NZ = 512,256
fUbgzz = lambda z: interpolate.interp1d( zdata, uzzdata, fill_value="extrapolate")(z) # Now we have data, prepare for DJLES L, H = 600, 80 # domain width (m) and depth (m) rho0 = 1000 # reference density (kg/m^3) #verbose = 1; start_time = time.time() # Start at low resolution/epsilon, no background velocity, and raise amplitude NX, NZ = 32, 32 A1, A2 = 1e5, 1e6 for ii, A in enumerate(numpy.linspace(A1, A2, 3)): if ii == 0: djl = DJL(A, L, H, NX, NZ, rho, rhoz, rho0=rho0, epsilon=1e-3) else: djl = DJL(A, L, H, NX, NZ, rho, rhoz, rho0=rho0, epsilon=1e-3, initial_guess=djl) # Improve resolution, raise amplitude NX, NZ = 64, 64 A1, A2 = 1e6, 5e6
rhoz = lambda z: interpolate.interp1d(zdata, rhozdata)(z) L, H = 1200, 57 # domain width (m) and depth(m), estimated from Pineda et al's Figure 9 (a) ############################################################################ #### Find the wave showcased in Pineda et al. (2015) Figure 11 ############# ############################################################################ start_time = time.time() # Set initial resolution and large epsilon for intermediate waves NX, NZ = 32, 32 # Raise amplitude in a few increments for ii, A in enumerate(numpy.linspace(1e4, 3.62e5, 6)): # APE (kg m/s^2) if ii == 0: djl = DJL(A, L, H, NX, NZ, rho, rhoz, rho0=rho0, epsilon=1e-3) else: djl = DJL(A, L, H, NX, NZ, rho, rhoz, rho0=rho0, epsilon=1e-3, initial_guess=djl) # Increase resolution, reduce epsilon, iterate to convergence NX, NZ = 64, 64 djl = DJL(A,
rho = lambda z: 1 - a_d * numpy.tanh((z + z0_d) / d_d) intrho = lambda z: z - a_d * d_d * numpy.log(numpy.cosh((z + z0_d) / d_d)) rhoz = lambda z: -(a_d / d_d) * (1.0 / numpy.cosh((z + z0_d) / d_d)**2) # Specify general velocity profile that takes U0 as a second parameter (m/s) zj, dj = 0.5 * H, 0.4 * H fUbg = lambda z, U0: U0 * numpy.tanh((z + zj) / dj) fUbgz = lambda z, U0: (U0 / dj) * (1.0 / numpy.cosh((z + zj) / dj)**2) fUbgzz = lambda z, U0: (-2 * U0 / (dj * dj)) * (1.0 / numpy.cosh( (z + zj) / dj)**2) * numpy.tanh((z + zj) / dj) # Find the solution start_time = time.time() # Create DJL object djl = DJL(A, L, H, NX, NZ, rho, rhoz, intrho=intrho) # Start with U0=0, raise it to U0=0.1 over 6 increments for U0 in numpy.linspace(0, 0.1, 6): # Velocity profile for this wave djl.Ubg = lambda z: fUbg(z, U0) djl.Ubgz = lambda z: fUbgz(z, U0) djl.Ubgzz = lambda z: fUbgzz(z, U0) # Find the solution of the DJL equation # Use a reduced epsilon for these intermediate waves djl = DJL(A, L, H, NX, NZ,
#verbose=1; # # Use python's gradient function to find the derivative drho/dz rhozdata = numpy.gradient(rhodata, zdata) # Now build piecewise interpolating polynomials from the data, # and convert them to function handles for the solver #rho = lambda z: interpolate.PchipInterpolator(zdata, rhodata )(z) #rhoz = lambda z: interpolate.PchipInterpolator(zdata, rhozdata)(z) rho = lambda z: interpolate.interp1d(zdata, rhodata)(z) rhoz = lambda z: interpolate.interp1d(zdata, rhozdata)(z) # Find the solution start_time = time.time() djl = DJL(A, L, H, NX, NZ, rho, rhoz, rho0=rho0) # Increase resolution, iterate to convergence NX, NZ = 128, 128 djl = DJL(A, L, H, NX, NZ, rho, rhoz, rho0=rho0, initial_guess=djl) # Increase to the final resolution, iterate to convergence NX, NZ = 512, 512 djl = DJL(A, L, H, NX, NZ, rho, rhoz, rho0=rho0, initial_guess=djl) end_time = time.time() print('Total wall clock time: %f seconds\n' % (end_time - start_time)) # Compute and plot the diagnostics diag = Diagnostic(djl) plot(djl, diag, 2)
L, H = 8.0, 0.2 # domain width (m) and depth (m) NX, NZ = 32, 32 # grid size # The unitless density profile (normalized by a reference density rho0) a_d, z0_d, d_d = 0.02, 0.05, 0.01 rho = lambda z: 1 - a_d * numpy.tanh((z + z0_d) / d_d) intrho = lambda z: z - a_d * d_d * numpy.log(numpy.cosh((z + z0_d) / d_d)) rhoz = lambda z: -(a_d / d_d) * (1.0 / numpy.cosh((z + z0_d) / d_d) ** 2) # Find the solution start_time = time.time() # Start with 1% of target APE, raise to target APE in 5 steps for ii, Ai in enumerate(numpy.linspace(A / 100, A, 5)): if ii == 0: djl = DJL(Ai, L, H, NX, NZ, rho, rhoz, intrho=intrho) else: djl = DJL(Ai, L, H, NX, NZ, rho, rhoz, intrho=intrho, initial_guess=djl) # Increase the resolution, reduce epsilon, and iterate to convergence NX, NZ = 64, 64 djl = DJL(A, L, H, NX, NZ, rho, rhoz, intrho=intrho, epsilon=1e-5, initial_guess=djl) # Increase the resolution, and iterate to convergence NX, NZ = 512,256 djl = DJL(A, L, H, NX, NZ, rho, rhoz, intrho=intrho, epsilon=1e-5, initial_guess=djl) end_time = time.time() print('Total wall clock time: %f seconds\n'% (end_time - start_time)) # Compute and plot the diagnostics