Skip to content

Commit

Permalink
adds large-scale flow energy and enstrophy
Browse files Browse the repository at this point in the history
  • Loading branch information
navidcy committed Jan 24, 2018
1 parent 505c665 commit 03c83ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
38 changes: 15 additions & 23 deletions examples/barotropicqg/ACConelayer_JPO2018.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ using FourierFlows, PyPlot, JLD2


import FourierFlows.BarotropicQG
import FourierFlows.BarotropicQG: energy, enstrophy
import FourierFlows.BarotropicQG: energy, energy00, enstrophy, enstrophy00

nx = 128*2
nx = 512
ν = 8.0e-10
νn = 2
f0 = -1.0
Expand All @@ -16,31 +16,19 @@ F = 0.0012

FU(t) = F

η(x, y) = 2*cos.(10*x).*cos.(10*y)
η(x, y) = 2*cos.(10x).*cos.(10y)


g = BarotropicQG.Grid(nx, Lx)
p = BarotropicQG.Params(g, f0, β, FU, η, μ, ν, νn)
v = BarotropicQG.Vars(g)
eq = BarotropicQG.Equation(p, g)

# eta = 2*cos.(10*g.X).*cos.(10*g.Y)
# v = cos(10*g.X).*cos(10*g.Y) + cos(10*g.X-10*g.Y)/2
#
# mean(eta.*v)
#
# etah = fft(eta)
# vh = fft(v)
# println(sum(conj(vh).*etah).re / (g.nx^2.0*g.ny^2.0))
#
# pcolormesh(g.X, g.Y, eta)



# Time-stepping
dt = 1e-2
nsteps = 1000
nsubs = 1000
dt = 2e-2
nsteps = 20000
nsubs = 500


# ts = FilteredETDRK4TimeStepper(dt, eq.LC, g)
Expand All @@ -67,7 +55,9 @@ BarotropicQG.set_zeta!(prob, 0*g.X)
# at the top.
E = Diagnostic(energy, prob; nsteps=nsteps)
Q = Diagnostic(enstrophy, prob; nsteps=nsteps)
diags = [E, Q]
E00 = Diagnostic(energy00, prob; nsteps=nsteps)
Q00 = Diagnostic(enstrophy00, prob; nsteps=nsteps)
diags = [E, E00, Q, Q00]

# Create Output
get_sol(prob) = prob.state.sol # extracts the Fourier-transformed solution
Expand All @@ -94,21 +84,23 @@ function plot_output(prob, fig, axs; drawcolorbar=false)

sca(axs[2])
cla()
plot*E.time[1:E.prob.step], E.data[1:prob.step])
plot*E.time[1:E.prob.step], E.data[1:prob.step], label=L"$E_{\psi}$")
plot*E.time[1:E00.prob.step], E00.data[1:prob.step], label=L"$E_U$")
xlabel(L"\mu t")
ylabel(L"E")
legend()

sca(axs[3])
cla()
plot*Q.time[1:Q.prob.step], Q.data[1:prob.step])
plot*Q.time[1:Q.prob.step], Q.data[1:prob.step], label=L"$Q_{\psi}$")
plot*Q00.time[1:Q00.prob.step], Q00.data[1:prob.step], label=L"$Q_U$")
xlabel(L"\mu t")
ylabel(L"Q")

legend()
pause(0.001)
end



fig, axs = subplots(ncols=3, nrows=1, figsize=(15, 4))
plot_output(prob, fig, axs; drawcolorbar=true)

Expand Down
20 changes: 20 additions & 0 deletions src/physics/barotropicqg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,25 @@ function enstrophy(prob::AbstractProblem)
0.5*FourierFlows.parsevalsum2(s.sol, g)/(g.Lx*g.Ly)
end

"""
Returns the domain-averaged enstrophy.
"""

function U00(prob::AbstractProblem)
s = prob.state
s.sol[1, 1]
end

function energy00(prob::AbstractProblem)
s = prob.state
0.5*s.sol[1, 1].^2
end

function enstrophy00(prob::AbstractProblem)
s, p = prob.state, prob.params
p.beta*s.sol[1, 1]
end



end # module

0 comments on commit 03c83ce

Please sign in to comment.