Last active
May 3, 2020 00:32
-
-
Save navidcy/a00914618041580994a20b55e2cadf7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FourierFlows, Printf, Random | |
using Random: seed! | |
using FFTW: rfft, irfft | |
import GeophysicalFlows.TwoDNavierStokes | |
import GeophysicalFlows.TwoDNavierStokes: energy, enstrophy | |
import GeophysicalFlows: peakedisotropicspectrum | |
# ## Choosing a device: CPU or GPU | |
dev = GPU() # Device (CPU/GPU) | |
n, L = 256, 2π # grid resolution and domain length | |
dt = 2e-3 # timestep | |
nsteps = 2000 # total number of steps | |
nsubs = 400 # number of steps between each plot | |
prob = TwoDNavierStokes.Problem(; nx=n, Lx=L, ny=n, Ly=L, dt=dt, stepper="FilteredRK4", dev=dev) | |
sol, cl, vs, gr, filter = prob.sol, prob.clock, prob.vars, prob.grid, prob.timestepper.filter | |
# Initial condidtion | |
seed!(1234) | |
k0, E0 = 6, 0.5 | |
zetai = peakedisotropicspectrum(gr, k0, E0, mask=filter) | |
# Define a trivial diagnostics | |
trivial(prob) = 1.0 | |
# Diagnostics | |
E = Diagnostic(energy, prob; nsteps=nsteps) | |
Z = Diagnostic(enstrophy, prob; nsteps=nsteps) | |
trivialdiag = Diagnostic(trivial, prob; nsteps=nsteps) | |
diagsE = [E] | |
diagsZ = [Z] | |
diagstrivial = [trivialdiag] | |
println("we time-step without diagnostics") | |
TwoDNavierStokes.set_zeta!(prob, zetai) | |
startwalltime = time() | |
while cl.step < nsteps | |
stepforward!(prob, nsubs) | |
log = @sprintf("step: %04d, t: %d, walltime: %.2f sec", cl.step, cl.t, (time()-startwalltime)) | |
println(log) | |
end | |
println(" ") | |
println("re-initialize and run again with trivial diagnostic") | |
prob = TwoDNavierStokes.Problem(; nx=n, Lx=L, ny=n, Ly=L, dt=dt, stepper="FilteredRK4", dev=dev) | |
sol, cl, vs, gr, filter = prob.sol, prob.clock, prob.vars, prob.grid, prob.timestepper.filter | |
TwoDNavierStokes.set_zeta!(prob, zetai) | |
startwalltime = time() | |
while cl.step < nsteps | |
stepforward!(prob, diagstrivial, nsubs) | |
log = @sprintf("step: %04d, t: %d, walltime: %.2f sec", cl.step, cl.t, (time()-startwalltime)) | |
println(log) | |
end | |
println(" ") | |
println("re-initialize and run again with energy diagnostic") | |
prob = TwoDNavierStokes.Problem(; nx=n, Lx=L, ny=n, Ly=L, dt=dt, stepper="FilteredRK4", dev=dev) | |
sol, cl, vs, gr, filter = prob.sol, prob.clock, prob.vars, prob.grid, prob.timestepper.filter | |
TwoDNavierStokes.set_zeta!(prob, zetai) | |
startwalltime = time() | |
while cl.step < nsteps | |
stepforward!(prob, diagsE, nsubs) | |
log = @sprintf("step: %04d, t: %d, walltime: %.2f sec", cl.step, cl.t, (time()-startwalltime)) | |
println(log) | |
end | |
println(" ") | |
println("and last re-initialize and run again with enstrophy diagnostic") | |
prob = TwoDNavierStokes.Problem(; nx=n, Lx=L, ny=n, Ly=L, dt=dt, stepper="FilteredRK4", dev=dev) | |
sol, cl, vs, gr, filter = prob.sol, prob.clock, prob.vars, prob.grid, prob.timestepper.filter | |
TwoDNavierStokes.set_zeta!(prob, zetai) | |
startwalltime = time() | |
while cl.step < nsteps | |
stepforward!(prob, diagsZ, nsubs) | |
log = @sprintf("step: %04d, t: %d, walltime: %.2f sec", cl.step, cl.t, (time()-startwalltime)) | |
println(log) | |
end | |
println(" ") | |
println("finished") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment