Skip to content

Commit

Permalink
tests_diagnostics.jl includes update! resize! increment
Browse files Browse the repository at this point in the history
  • Loading branch information
navidcy committed Jul 1, 2018
1 parent b6996c8 commit 3de4563
Showing 1 changed file with 63 additions and 107 deletions.
170 changes: 63 additions & 107 deletions test/test_diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,112 +63,68 @@ import mytestmodule
import mytestmodule: pseudoenergy, pseudoenstrophy


#
# function testsimplediagnostics()
# nx = 16
# Lx = 2π
# mu = 0.02
# dt = 0.01
#
# g = OneDGrid(nx, Lx)
# p = mytestmodule.Params(mu)
# v = mytestmodule.Vars(g)
# eq = mytestmodule.Equation(p, g)
# ts = FourierFlows.ETDRK4TimeStepper(dt, eq.LC)
# prob = FourierFlows.Problem(g, v, p, eq, ts)
#
# u0 = randn(size(g.x))
#
# mytestmodule.set_u!(prob, u0)
#
# nsteps = 200
# extrasteps = 20
#
# freqE = 2
# E = Diagnostic(pseudoenergy, prob; nsteps=nsteps, freq=freqE)
#
# freqZ = 1
# Z = Diagnostic(pseudoenstrophy, prob; nsteps=nsteps, freq=freqZ)
#
# diags = [E, Z]
#
#
# nstepstot = nsteps + extrasteps
# while prob.step < nstepstot
# stepforward!(prob, diags, 1)
# end
#
# println(E.count)
#
# (
# isapprox(length(E.data), Int(round(nstepstot/freqE+1))) &&
# isapprox(length(Z.data), Int(round(nstepstot/freqZ+1))) &&
# isapprox(norm(E.data), norm(E.data[1]*exp.(-2*mu*E.time)), rtol=1e-13) &&
# isapprox(norm(Z.data), norm(Z.data[1]*exp.(-2*mu*Z.time)), rtol=1e-13)
# )
#
# end
#
# @test testsimplediagnostics()


nx = 16
Lx = 2π
mu = 0.02
dt = 0.01

g = OneDGrid(nx, Lx)
p = mytestmodule.Params(mu)
v = mytestmodule.Vars(g)
eq = mytestmodule.Equation(p, g)
ts = FourierFlows.ETDRK4TimeStepper(dt, eq.LC)
prob = FourierFlows.Problem(g, v, p, eq, ts)

srand(1234)
u0 = randn(size(g.x))

mytestmodule.set_u!(prob, u0)

nsteps = 200
extrasteps = 20

freqE = 2
E = Diagnostic(pseudoenergy, prob; nsteps=nsteps, freq=freqE)

freqZ = 1
Z = Diagnostic(pseudoenstrophy, prob; nsteps=nsteps, freq=freqZ)

diags = [E, Z]


nstepstot = nsteps + extrasteps
while prob.step < nstepstot
stepforward!(prob, diags, 1)

function testsimplediagnostics()
nx = 16
Lx = 2π
mu = 0.02
dt = 0.01

g = OneDGrid(nx, Lx)
p = mytestmodule.Params(mu)
v = mytestmodule.Vars(g)
eq = mytestmodule.Equation(p, g)
ts = FourierFlows.ETDRK4TimeStepper(dt, eq.LC)
prob = FourierFlows.Problem(g, v, p, eq, ts)

srand(1234)
u0 = randn(size(g.x))

mytestmodule.set_u!(prob, u0)

nsteps = 200
extrasteps = 20

freqE = 2
E = Diagnostic(pseudoenergy, prob; nsteps=nsteps, freq=freqE)

freqZ = 1
Z = Diagnostic(pseudoenstrophy, prob; nsteps=nsteps, freq=freqZ)

diags = [E, Z]


nstepstot = nsteps + extrasteps
while prob.step < nstepstot
stepforward!(prob, diags, 1)
end

stepforward!(prob, 1)
increment!(Z)
stepforward!(prob, 1)
increment!([E,Z])


resize!(Z, Z.count+2)
Z.count += 1
resize!(E, E.count+1)
E.count += 1

stepforward!(prob, 1)
update!(Z)
Z.count += 1
stepforward!(prob, 1)
update!(E)
E.count += 1
update!(Z)
Z.count += 1

(
isapprox(length(E.data), 2+Int(round(nstepstot/freqE+1))) &&
isapprox(length(Z.data), 4+Int(round(nstepstot/freqZ+1))) &&
isapprox(norm(E.data), norm(E.data[1]*exp.(-2*mu*E.time)), rtol=1e-13) &&
isapprox(norm(Z.data), norm(Z.data[1]*exp.(-2*mu*Z.time)), rtol=1e-13)
)
end

stepforward!(prob, 1)
increment!(Z)
stepforward!(prob, 1)
increment!([E,Z])


resize!(Z, Z.count+2)
Z.count += 1
resize!(E, E.count+1)
E.count += 1

stepforward!(prob, 1)
update!(Z)
Z.count += 1
stepforward!(prob, 1)
update!(E)
E.count += 1
update!(Z)
Z.count += 1

(
isapprox(length(E.data), 2+Int(round(nstepstot/freqE+1))) &&
isapprox(length(Z.data), 4+Int(round(nstepstot/freqZ+1))) &&
isapprox(norm(E.data), norm(E.data[1]*exp.(-2*mu*E.time)), rtol=1e-13) &&
isapprox(norm(Z.data), norm(Z.data[1]*exp.(-2*mu*Z.time)), rtol=1e-13)
)
@test testsimplediagnostics()

0 comments on commit 3de4563

Please sign in to comment.