Skip to content

Commit

Permalink
some bigfloats tests
Browse files Browse the repository at this point in the history
  • Loading branch information
navidcy committed Feb 12, 2018
1 parent 37aef6d commit 7b6e897
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions sandbox/test_getetdcoeffsBigFloat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ using FourierFlows
n, L = 128, 2π
g = TwoDGrid(n, L)
ν = 1e-3
LC = -ν*g.KKrsq.^2 + im*g.Kr
LC[1, 1]=0
dt = 0.1
LC = -ν*g.KKrsq + im*g.Kr
# LC = -ν*g.KKrsq.^8 + im*g.Kr
dt = 0.001




function getetdcoeffs(dt, LC; ncirc=32, rcirc=eltype(LC)(14))
function getetdcoeffs(dt, LC; ncirc=32, rcirc=eltype(LC)(1))

shape = Tuple(cat(1, ncirc, ones(Int, ndims(LC))))

Expand Down Expand Up @@ -50,36 +50,35 @@ function getetdcoeffsBigFloat(dt, LC)
expL2 = big.(exp.(L/2))
L = big.(L)

ζc = @. Complex{Float64}( ( expL2-1 ) / L )
αc = @. Complex{Float64}( (-4 - L + expL*(4-3L + L^2))/L^3 )
βc = @. Complex{Float64}( ( 2 + L + expL*(-2 + L))/L^3 )
Γc = @. Complex{Float64}( (-4 - 3L -L^2 + expL*(4 - L))/L^3 )


if eltype(LC) <: Real
ζ = dt*real.(ζc)
α = dt*real.(αc)
β = dt*real.(βc)
Γ = dt*real.(Γc)
ζ = @. dt*Float64( ( expL2-1 ) / L )
α = @. dt*Float64( (-4 - L + expL*(4-3L + L^2))/L^3 )
β = @. dt*Float64( ( 2 + L + expL*(-2 + L))/L^3 )
Γ = @. dt*Float64( (-4 - 3L -L^2 + expL*(4 - L))/L^3 )
else
ζ = dt*ζc
α = dt*αc
β = dt*βc
Γ = dt*Γc
ζ = @. dt*Complex{Float64}( ( expL2-1 ) / L )
α = @. dt*Complex{Float64}( (-4 - L + expL*(4-3L + L^2))/L^3 )
β = @. dt*Complex{Float64}( ( 2 + L + expL*(-2 + L))/L^3 )
Γ = @. dt*Complex{Float64}( (-4 - 3L -L^2 + expL*(4 - L))/L^3 )
end

if isnan(ζ[1, 1]); ζ[1, 1] = dt/2; end
if isnan(α[1, 1]); α[1, 1] = dt/6; end
if isnan(β[1, 1]); β[1, 1] = dt/6; end
if isnan(Γ[1, 1]); Γ[1, 1] = dt/6; end

ζ, α, β, Γ
end



@time ζ1, α1, β1, Γ1 = getetdcoeffs(dt, LC, ncirc=32)
ζ1[1, 1], α1[1, 1], β1[1, 1], Γ1[1, 1] = 0, 0, 0, 0
@time ζ1, α1, β1, Γ1 = getetdcoeffs(dt, LC, ncirc=32, rcirc=100)
# ζ1[1, 1], α1[1, 1], β1[1, 1], Γ1[1, 1] = 0, 0, 0, 0
@time ζ2, α2, β2, Γ2 = getetdcoeffsBigFloat(dt, LC)
ζ2[1, 1], α2[1, 1], β2[1, 1], Γ2[1, 1] = 0, 0, 0, 0
# ζ2[1, 1], α2[1, 1], β2[1, 1], Γ2[1, 1] = 0, 0, 0, 0


println("diff error ζ: ", norm(ζ1-ζ2, Inf))
println("diff error α: ", norm(α1-α2, Inf))
println("diff error β: ", norm(β1-β2, Inf))
println("diff error Γ: ", norm(Γ1-Γ2, Inf))
println("diff error ζ: ", norm(ζ1-ζ2, Inf)/norm(ζ1, Inf))
println("diff error α: ", norm(α1-α2, Inf)/norm(α1, Inf))
println("diff error β: ", norm(β1-β2, Inf)/norm(β1, Inf))
println("diff error Γ: ", norm(Γ1-Γ2, Inf)/norm(Γ1, Inf))

0 comments on commit 7b6e897

Please sign in to comment.