diff --git a/docs/src/Examples.md b/docs/src/Examples.md index 4d65630..b26f519 100644 --- a/docs/src/Examples.md +++ b/docs/src/Examples.md @@ -241,7 +241,7 @@ x₀ = [0, 0] # position of vortex center M = 8 # number of coefficients in Zernike expansion tol = 1e-8 # maximum error in solution evaluation cuda = false # use CuArrays for grid -K₀, a₀ = [4, 4], Nothing # guesses for K and a +K₀, a₀ = [4, 4], nothing # guesses for K and a # create grid @@ -283,7 +283,7 @@ x₀ = [0, 0] # position of vortex center M = 20 # number of coefficients in Zernike expansion tol = 1e-6 # maximum error in solution evaluation cuda = false # use CuArrays for grid -K₀, a₀ = 8, Nothing # guesses for K and a +K₀, a₀ = 8, nothing # guesses for K and a # Set grid parameters diff --git a/docs/src/Functions.md b/docs/src/Functions.md index 61e2c98..e8a4b31 100644 --- a/docs/src/Functions.md +++ b/docs/src/Functions.md @@ -48,8 +48,6 @@ Eval_w_SQG Calc_∇ CartesianGrid PolarGrid -Base.summary -Base.show ``` ## `energetics.jl` @@ -61,10 +59,30 @@ EnergySQG AreaInteg2 ``` +## `vortex_types.jl` + +```@docs +LQGParams +SQGParams +LQGVortex +SQGVortex +DefLQGParams +DefSQGParams +DefLQGVortex +DefSQGVortex +``` + ## `monopoles.jl` ```@docs CreateRankine CreateMonopole InvertVorticity1LQG +``` + +## `Base` + +```@docs +Base.summary +Base.show ``` \ No newline at end of file diff --git a/src/QGDipoles.jl b/src/QGDipoles.jl index 8c2f2df..3b74729 100644 --- a/src/QGDipoles.jl +++ b/src/QGDipoles.jl @@ -58,7 +58,17 @@ export EnstrophyLQG, EnergySQG, AreaInteg2, - + + # vortex_types.jl + LQGParams, + SQGParams, + LQGVortex, + SQGVortex, + DefLQGParams, + DefSQGParams, + DefLQGVortex, + DefSQGVortex, + # monopoles.jl CreateRankine, CreateMonopole, @@ -70,6 +80,7 @@ include("JJ_integ.jl") include("lin_sys.jl") include("create_modon.jl") include("energetics.jl") +include("vortex_types.jl") include("monopoles.jl") end diff --git a/src/create_modon.jl b/src/create_modon.jl index 8162fb1..230734f 100644 --- a/src/create_modon.jl +++ b/src/create_modon.jl @@ -434,7 +434,7 @@ function ΔNCalc(K²::Union{CuArray,Array}, R::Union{Number,Vector}, β::Union{N end """ -Function: `CreateModonLQG(grid, M, U=1, ℓ=1, R=1, β=0, ActiveLayers=1, x₀=[0, 0], α=0; K₀=Nothing, a₀=Nothing, tol=1e-6)` +Function: `CreateModonLQG(grid, M, U=1, ℓ=1, R=1, β=0, ActiveLayers=1, x₀=[0, 0], α=0; K₀=nothing, a₀=nothing, tol=1e-6)` High level wrapper function for calculating ψ and q for the Layered QG model using given parameters @@ -446,13 +446,14 @@ Arguments: - `ActiveLayers`: vector of 1s or 0s where 1 denotes an active layer, Number or Vector, (default: `[1,..,1]`) - `x₀`: position of vortex center, vector (default: `[0, 0]`) - `α`: initial angle of vortex, Number (default: 0) - - `K₀`, `a₀`: initial guesses for K and a, Arrays or Nothings (default: `Nothing`) + - `K₀`, `a₀`: initial guesses for K and a, Arrays or nothings (default: `nothing`) - `tol`: error tolerance passed to `QuadGK` and `NLSolve` functions, Number (default: `1e-6`) Note: provide values of K₀ and a₀ for active layers ONLY. """ function CreateModonLQG(grid, M::Int=8, U::Number=1, ℓ::Number=1, R::Union{Number,Vector}=1, β::Union{Number,Vector}=0, - ActiveLayers::Union{Number,Vector}=1, x₀::Vector=[0, 0], α::Number=0; K₀=Nothing, a₀=Nothing, tol=1e-6) + ActiveLayers::Union{Number,Vector}=1, x₀::Vector=[0, 0], α::Number=0; K₀::Union{Number,Array,Nothing}=nothing, + a₀::Union{Array,Nothing}=nothing, tol=1e-6) # If ActiveLayers size does not match size of R, assume all layers are active @@ -485,7 +486,7 @@ function CreateModonLQG(grid, M::Int=8, U::Number=1, ℓ::Number=1, R::Union{Num end """ -Function: `CreateModonSQG(grid, M, U=1, ℓ=1, R=[Inf, Inf], β=0, x₀=[0, 0], α=0; K₀=Nothing, a₀=Nothing, tol=1e-6)` +Function: `CreateModonSQG(grid, M, U=1, ℓ=1, R=[Inf, Inf], β=0, x₀=[0, 0], α=0; K₀=nothing, a₀=nothing, tol=1e-6)` High level wrapper function for calculating ψ and b for the SQG model using given parameters @@ -497,14 +498,15 @@ Arguments: - `β`: beta-plane (y) PV gradient, Number (default: `0`) - `x₀`: position of vortex center, vector (default: `[0, 0]`) - `α`: initial angle of vortex, Number (default: `0`) - - `K₀`, `a₀`: initial guesses for K and a, Arrays or Nothings (default: `Nothing`) + - `K₀`, `a₀`: initial guesses for K and a, Arrays or nothings (default: `nothing`) - `tol`: error tolerance passed to `QuadGK` and `NLSolve` functions, Number (default: `1e-6`) Note: Here R is the baroclinic Rossby radius, R = NH/f, and R' = R₀²/R where R₀ is the barotropic Rossby radius, R₀ = √(gH)/f. For infinite depth, R' = g/(fN). """ function CreateModonSQG(grid, M::Int=12, U::Number=1, ℓ::Number=1, R::Vector=[Inf, Inf], β::Number=0, - x₀::Vector=[0, 0], α::Number=0; K₀=Nothing, a₀=Nothing, tol=1e-6) + x₀::Vector=[0, 0], α::Number=0; K₀::Union{Number,Array,Nothing}=nothing, + a₀::Union{Array,Nothing}=nothing, tol=1e-6) # Define intermediate variables @@ -900,7 +902,6 @@ end """ Base.summary function for custom type `GridStruct` - """ function Base.summary(g::GridStruct) @@ -917,7 +918,6 @@ end """ Base.show function for custom type `GridStruct` - """ function Base.show(io::IO, g::GridStruct) @@ -932,11 +932,11 @@ function Base.show(io::IO, g::GridStruct) end return print(io, "GridStruct\n", - " ├───────────────── Device: ", dev, "\n", - " ├────────── size (Lx, Ly): ", (Lx, Ly), "\n", - " ├──── resolution (Nx, Ny): ", (Nx, Ny), "\n", - " ├── grid spacing (Δx, Δy): ", (Δx, Δy), "\n", - " └───────────────── domain: x ∈ [$(g.x[1]), $(g.x[end])]", "\n", - " y ∈ [$(g.y[1]), $(g.y[end])]") + " ├────────────────────── device: ", dev, "\n", + " ├─────────────── size (Lx, Ly): ", (Lx, Ly), "\n", + " ├───────── resolution (Nx, Ny): ", (Nx, Ny), "\n", + " ├─────── grid spacing (Δx, Δy): ", (Δx, Δy), "\n", + " └────────────────────── domain: x ∈ [$(g.x[1]), $(g.x[end])]", "\n", + " y ∈ [$(g.y[1]), $(g.y[end])]") end diff --git a/src/lin_sys.jl b/src/lin_sys.jl index a60d82f..40b7fc4 100644 --- a/src/lin_sys.jl +++ b/src/lin_sys.jl @@ -240,13 +240,13 @@ function IncludePassiveLayers(K::Array, a::Array, ActiveLayers::Union{Number,Vec end """ -Function: `SolveInhomEVP(A, B, c, d; K₀=Nothing, a₀=Nothing, tol=1e-6, method=0, m=2, sqg=false, warn=true)` +Function: `SolveInhomEVP(A, B, c, d; K₀=nothing, a₀=nothing, tol=1e-6, method=0, m=2, sqg=false, warn=true)` Solves the inhomogeneous eigenvalue problem using nonlinear root finding Arguments: - `A`, `B`, `c`, `d`: inhomogeneous eigenvalue problem terms, Arrays - - `K₀`, `a₀`: initial guesses for K and a, Arrays or Nothings (default: `Nothing`) + - `K₀`, `a₀`: initial guesses for K and a, Arrays or nothings (default: `nothing`) - `tol`: error tolerance for `nlsolve`, Number (default: `1e-6`) - `method`: `0` - eigensolve for N = 1 and `nlsolve` for N > 1, `1` - `nlsolve` (default: `0`) - `m`: exponent of K in eignevalue problem (default: `2`) @@ -257,8 +257,9 @@ Note: setting `sqg=true` overwrites the value of `m` and is equivalent to settin The option to set both is included for consistency with `BuildLinSys` and more generality with the value of `m`. """ -function SolveInhomEVP(A::Array, B::Array, c::Array, d::Array; K₀=Nothing, a₀=Nothing, - tol::Number=1e-6, method::Int=0, m::Int=2, sqg::Bool=false, warn::Bool=true) +function SolveInhomEVP(A::Array, B::Array, c::Array, d::Array; K₀::Union{Number,Array,Nothing}=nothing, + a₀::Union{Array,Nothing}=nothing, tol::Number=1e-6, method::Int=0, m::Int=2, + sqg::Bool=false, warn::Bool=true) # Ensure that m is set correctly for SQG case @@ -295,7 +296,7 @@ function SolveInhomEVP(A::Array, B::Array, c::Array, d::Array; K₀=Nothing, a # Set K₀ value if none given - if K₀ == Nothing + if K₀ isa Nothing K₀ = [4] @@ -346,7 +347,7 @@ function SolveInhomEVP(A::Array, B::Array, c::Array, d::Array; K₀=Nothing, a # Define a₀ if none given and reshape if given - if a₀ == Nothing + if a₀ isa Nothing a₀ = vcat(-10*ones(N, 1), zeros(N*(M-1), 1)) @@ -358,7 +359,7 @@ function SolveInhomEVP(A::Array, B::Array, c::Array, d::Array; K₀=Nothing, a # Define K₀ if none given and reshape if given - if K₀ == Nothing + if K₀ isa Nothing K₀ = 5*ones(N, 1) diff --git a/src/vortex_types.jl b/src/vortex_types.jl index 9aaee0e..ede9a43 100644 --- a/src/vortex_types.jl +++ b/src/vortex_types.jl @@ -1,35 +1,521 @@ """ -This file contains functions which build vortices as a `VortexSolution` type. +This file contains functions which build vortices and vortex parameter sets as structures. +These functions are intended to allow all fields and variables associated with a given +solution to be included in the same structure and allow parameters to be checked. -Plan: +""" -Single type, `VortexSolution` which can be SQG or LQG (maybe Monopole?) +""" +Structure: `LQGParams` -show and summary functions to display properties +Stores the parameters for an LQG dipolar vortex solution -Maybe types for SQG and LQG parameter sets? +Arguments: + - `U`: Vortex speed + - `ℓ`: Vortex radius + - `R`: Rossby radius + - `β`: background PV gradient + - `ActiveLayers`: 1 => layer contains vortex region + - `H`: thickness of each layer + - `x₀`: Vortex position + - `α`: Direction of vortex propagation + - `M`: number of coefficients in Zernike expansion + - `tol`: maximum error in solution evaluation + - `K₀`: initial guess for eigenvalue + - `a₀`: initial guess for coefficients + - `UseAnalytic`: use analytic solution (1-layer only) + - `CalcVelocity`: flag to determine if velocity is calculated + - `CalcEnergy`: flag to determine if energy is calculated + - `CalcEnstrophy`: flag to determine if enstrophy is calculated +""" +struct LQGParams + U::Number + ℓ::Number + R::Union{Number,Vector} + β::Union{Number,Vector} + ActiveLayers::Union{Number,Vector} + H::Union{Number,Vector} + x₀::Vector + α::Number + M::Int + tol::Number + K₀::Union{Number,Array,Nothing} + a₀::Union{Array,Nothing} + UseAnalytic::Bool + CalcVelocity::Bool + CalcEnergy::Bool + CalcEnstrophy::Bool +end +""" +Structure: `SQGParams` +Stores the parameters for an SQG dipolar vortex solution +Arguments: + - `U`: Vortex speed + - `ℓ`: Vortex radius + - `R`: Rossby radius + - `β`: background PV gradient + - `x₀`: Vortex position + - `α`: Direction of vortex propagation + - `M`: number of coefficients in Zernike expansion + - `tol`: maximum error in solution evaluation + - `K₀`: initial guess for eigenvalue + - `a₀`: initial guess for coefficients + - `CalcVelocity`: flag to determine if velocity is calculated + - `CalcEnergy`: flag to determine if energy is calculated + """ +struct SQGParams + U::Number + ℓ::Number + R::Vector + β::Number + x₀::Vector + α::Number + M::Int + tol::Number + K₀::Union{Number,Array,Nothing} + a₀::Union{Array,Nothing} + CalcVelocity::Bool + CalcEnergy::Bool +end +""" +Structure: `LQGVortex` + +Stores fields and diagnostics for an LQG dipolar vortex solution +Arguments: + - `params`: Vortex params + - `ψ`: streamfunction + - `q`: potential vorticity anomaly + - `K`: eigenvalue + - `a`: coefficient matrix + - `u`: x velocity + - `v`: y velocity + - `KE`: kinetic energy + - `PE`: potential energy + - `EN`: enstrophy """ -Function: `...` +struct LQGVortex + params::LQGParams + ψ::Union{CuArray,Array} + q::Union{CuArray,Array} + K::Array + a::Union{Array,Nothing} + u::Union{CuArray,Array,Nothing} + v::Union{CuArray,Array,Nothing} + KE::Union{Vector,Nothing} + PE::Union{Vector,Nothing} + EN::Union{Vector,Nothing} +end -... +""" +Structure: `SQGVortex` + +Stores fields and diagnostics for an SQG dipolar vortex solution Arguments: - - `n`: order, Integer - - `x`: evaluation point, Number or Array + - `params`: Vortex params + - `ψ`: surface streamfunction + - `b`: surface buoyancy + - `K`: eigenvalue + - `a`: coefficient matrix + - `u`: x velocity + - `v`: y velocity + - `E`: domain integrated energy + - `SPE`: surface potential energy +""" +struct SQGVortex + params::SQGParams + ψ::Union{CuArray,Array} + b::Union{CuArray,Array} + K::Array + a::Array + u::Union{CuArray,Array,Nothing} + v::Union{CuArray,Array,Nothing} + E::Union{Vector, Nothing} + SPE::Union{Vector, Nothing} +end + +""" +Function: `DefLQGParams` + +Defines an LQGParams structure using the given inputs -Note: ... +Arguments: + - `U`: Vortex speed + - `ℓ`: Vortex radius + - `R`: Rossby radius + - `β`: background PV gradient + - `ActiveLayers`: 1 => layer contains vortex region + - `H`: thickness of each layer + - `x₀`: Vortex position + - `α`: Direction of vortex propagation + - `M`: number of coefficients in Zernike expansion + - `tol`: maximum error in solution evaluation + - `K₀`: initial guess for eigenvalue + - `a₀`: initial guess for coefficients + - `UseAnalytic`: use analytic solution (1-layer only) + - `CalcVelocity`: flag to determine if velocity is calculated + - `CalcEnergy`: flag to determine if energy is calculated + - `CalcEnstrophy`: flag to determine if enstrophy is calculated """ -function ... +function DefLQGParams(U::Number=1, + ℓ::Number=1, + R::Union{Number,Vector}=Inf, + β::Union{Number,Vector}=0, + ActiveLayers::Union{Number,Vector}=1, + H::Union{Number,Vector}=1, + x₀::Vector=[0, 0], + α::Number=0, + M::Int=8; + tol::Number=1e-6, + K₀::Union{Number,Array,Nothing}=nothing, + a₀::Union{Array,Nothing}=nothing, + UseAnalytic::Bool=false, + CalcVelocity::Bool=false, + CalcEnergy::Bool=false, + CalcEnstrophy::Bool=false) + return LQGParams(U, ℓ, R, β, ActiveLayers, H, x₀, α, M, + tol, K₀, a₀, UseAnalytic, CalcVelocity, CalcEnergy, CalcEnstrophy) +end + +""" +Function: `DefSQGParams` + +Defines an SQGParams structure using the given inputs + +Arguments: + - `U`: Vortex speed + - `ℓ`: Vortex radius + - `R`: Rossby radius + - `β`: background PV gradient + - `x₀`: Vortex position + - `α`: Direction of vortex propagation + - `M`: number of coefficients in Zernike expansion + - `tol`: maximum error in solution evaluation + - `K₀`: initial guess for eigenvalue + - `a₀`: initial guess for coefficients + - `CalcVelocity`: flag to determine if velocity is calculated + - `CalcEnergy`: flag to determine if energy is calculated +""" +function DefSQGParams(U::Number=1, + ℓ::Number=1, + R::Vector=[Inf, Inf], + β::Number=0, + x₀::Vector=[0, 0], + α::Number=0, + M::Int=12; + tol::Number=1e-6, + K₀::Union{Number,Array,Nothing}=nothing, + a₀::Union{Array,Nothing}=nothing, + CalcVelocity::Bool=false, + CalcEnergy::Bool=false) + + return SQGParams(U, ℓ, R, β, x₀, α, M, tol, K₀, a₀, CalcVelocity, CalcEnergy) +end + +""" +Function: `DefLQGVortex` + +Defines an LQGVortex solution structure using the given inputs + +Arguments: + - `grid`: grid structure + - `U`: Vortex speed + - `ℓ`: Vortex radius + - `R`: Rossby radius + - `β`: background PV gradient + - `ActiveLayers`: 1 => layer contains vortex region + - `H`: thickness of each layer + - `x₀`: Vortex position + - `α`: Direction of vortex propagation + - `M`: number of coefficients in Zernike expansion + - `tol`: maximum error in solution evaluation + - `K₀`: initial guess for eigenvalue + - `a₀`: initial guess for coefficients + - `UseAnalytic`: use analytic solution (1-layer only) + - `CalcVelocity`: flag to determine if velocity is calculated + - `CalcEnergy`: flag to determine if energy is calculated + - `CalcEnstrophy`: flag to determine if enstrophy is calculated +""" +function DefLQGVortex(grid, + U::Number=1, + ℓ::Number=1, + R::Union{Number,Vector}=Inf, + β::Union{Number,Vector}=0, + ActiveLayers::Union{Number,Vector}=1, + H::Union{Number,Vector}=1, + x₀::Vector=[0, 0], + α::Number=0, + M::Int=8; + tol::Number=1e-6, + K₀::Union{Number,Array,Nothing}=nothing, + a₀::Union{Array,Nothing}=nothing, + UseAnalytic::Bool=false, + CalcVelocity::Bool=false, + CalcEnergy::Bool=false, + CalcEnstrophy::Bool=false) + + params = DefLQGParams(U, ℓ, R, β, ActiveLayers, H, x₀, α, M; + tol, K₀, a₀, UseAnalytic, CalcVelocity, CalcEnergy, CalcEnstrophy) + + N = length(R) + + if UseAnalytic + if N == 1 + ψ, q, K = CreateLRD(grid, U, ℓ, R, β, x₀, α) + a = nothing + else + @error "UseAnalytic = true not supported for N > 1" + end + else + ψ, q, K, a = CreateModonLQG(grid, M, U, ℓ, R, β, ActiveLayers, x₀, α; K₀, a₀, tol) + end + + if CalcVelocity + u, v = Calc_uv(ψ, grid) + else + u, v = nothing, nothing + end + + if CalcEnergy + KE, PE = EnergyLQG(grid, ψ, R, H) + else + KE, PE = nothing, nothing + end + + if CalcEnstrophy + EN = EnstrophyLQG(grid, q, H) + else + EN = nothing + end + + return LQGVortex(params, ψ, q, K, a, u, v, KE, PE, EN) +end + +""" +Function: `DefSQGVortex` + +Defines an SQGVortex solution structure using the given inputs + +Arguments: + - `grid`: grid structure + - `U`: Vortex speed + - `ℓ`: Vortex radius + - `R`: Rossby radius + - `β`: background PV gradient + - `x₀`: Vortex position + - `α`: Direction of vortex propagation + - `M`: number of coefficients in Zernike expansion + - `tol`: maximum error in solution evaluation + - `K₀`: initial guess for eigenvalue + - `a₀`: initial guess for coefficients + - `CalcVelocity`: flag to determine if velocity is calculated + - `CalcEnergy`: flag to determine if energy is calculated +""" +function DefSQGVortex(grid, + U::Number=1, + ℓ::Number=1, + R::Vector=[Inf, Inf], + β::Number=0, + x₀::Vector=[0, 0], + α::Number=0, + M::Int=12; + tol::Number=1e-6, + K₀::Union{Number,Array,Nothing}=nothing, + a₀::Union{Number,Array,Nothing}=nothing, + CalcVelocity::Bool=false, + CalcEnergy::Bool=false) + + params = DefSQGParams(U, ℓ, R, β, x₀, α, M; tol, K₀, a₀, CalcVelocity, CalcEnergy) + + ψ, b, K, a = CreateModonSQG(grid, M, U, ℓ, R, β, x₀, α; K₀, a₀, tol) + + if CalcVelocity + u, v = Calc_uv(ψ, grid) + else + u, v = nothing, nothing + end + + if CalcEnergy + E, SPE = EnergySQG(grid, ψ, b, R[2]) + else + E, SPE = nothing, nothing + end + + return SQGVortex(params, ψ, b, K, a, u, v, E, SPE) +end + +""" +Function: `DefLQGVortex` + +Defines an LQGVortex solution structure using the given inputs + +Arguments: + - `grid`: grid structure + - `params`: vortex parameters, LQGParams structure +""" +function DefLQGVortex(grid, params::LQGParams) + + return DefLQGVortex(grid, params.U, params.ℓ, params.R, params.β, params.ActiveLayers, params.H, + params.x₀, params.α, params.M; params.tol, params.K₀, params.a₀, params.UseAnalytic, + params.CalcVelocity, params.CalcEnergy, params.CalcEnstrophy) +end + +""" +Function: `DefSQGVortex` + +Defines an SQGVortex solution structure using the given inputs + +Arguments: + - `grid`: grid structure + - `params`: vortex parameters, LQGParams structure +""" +function DefSQGVortex(grid, params::SQGParams) + + return DefSQGVortex(grid, params.U, params.ℓ, params.R, params.β, params.x₀, params.α, params.M; + params.tol, params.K₀, params.a₀, params.CalcVelocity, params.CalcEnergy) +end + +""" +Base.summary function for custom type `LQGParams` +""" +function Base.summary(g::LQGParams) + return string("Parameter set structure for an LQG vortex solution (LQGParams)") +end + + +""" +Base.summary function for custom type `SQGParams` +""" +function Base.summary(g::SQGParams) + return string("Parameter set structure for an SQG vortex solution (SQGParams)") +end + + +""" +Base.summary function for custom type `LQGVortex` +""" +function Base.summary(g::LQGVortex) + return string("Vortex solution structure for an LQG model (LQGVortex)") +end + + +""" +Base.summary function for custom type `SQGVortex` +""" +function Base.summary(g::SQGVortex) + return string("Vortex solution structure for an SQG model (SQGVortex)") +end + +""" +Base.show function for custom type `LQGParams` +""" +function Base.show(io::IO, p::LQGParams) + + N = length(p.R) + a₀_given = ~(p.a₀ isa Nothing) + + return print(io, "LQGParams\n", + " ├───────── number of layers (N): ", N, "\n", + " ├───────────── vortex speed (U): ", p.U, "\n", + " ├──────────── vortex radius (ℓ): ", p.ℓ, "\n", + " ├──────────── Rossby radius (R): ", p.R, "\n", + " ├───────── PV gradient in y (β): ", p.β, "\n", + " ├─ active layers (ActiveLayers): ", p.ActiveLayers, "\n", + " ├───────────── layer depths (H): ", p.H, "\n", + " ├───────── vortex position (x₀): ", p.x₀, "\n", + " ├───────────── vortex angle (α): ", p.α, "\n", + " ├─── number of coefficients (M): ", p.M, "\n", + " ├──────── error tolerance (tol): ", p.tol, "\n", + " ├──── guess for eigenvalue (K₀): ", p.K₀, "\n", + " ├── guess for coeffs (a₀) given: ", a₀_given, "\n", + " ├──────── use analytic solution: ", p.UseAnalytic, "\n", + " ├─────────── calculate velocity: ", p.CalcVelocity, "\n", + " ├───────────── calculate energy: ", p.CalcEnergy, "\n", + " └────────── calculate enstrophy: ", p.CalcEnstrophy) - return ... end +""" +Base.show function for custom type `SQGParams` +""" +function Base.show(io::IO, p::SQGParams) + + a₀_given = ~(p.a₀ isa Nothing) + + return print(io, "SQGParams\n", + " ├───────────── vortex speed (U): ", p.U, "\n", + " ├──────────── vortex radius (ℓ): ", p.ℓ, "\n", + " ├──────────── Rossby radius (R): ", p.R, "\n", + " ├───────── PV gradient in y (β): ", p.β, "\n", + " ├───────── vortex position (x₀): ", p.x₀, "\n", + " ├───────────── vortex angle (α): ", p.α, "\n", + " ├─── number of coefficients (M): ", p.M, "\n", + " ├──────── error tolerance (tol): ", p.tol, "\n", + " ├──── guess for eigenvalue (K₀): ", p.K₀, "\n", + " ├── guess for coeffs (a₀) given: ", a₀_given, "\n", + " ├─────────── calculate velocity: ", p.CalcVelocity, "\n", + " └───────────── calculate energy: ", p.CalcEnergy) + +end + +""" +Base.show function for custom type `LQGVortex` +""" +function Base.show(io::IO, p::LQGVortex) + + contains_a = ~(p.a isa Nothing) + contains_vel = ~(p.u isa Nothing) + contains_ener = ~(p.KE isa Nothing) + contains_enst = ~(p.EN isa Nothing) + + if p.ψ isa CuArray + dev = "GPU" + else + dev = "CPU" + end + + UseAnalytic = p.params.UseAnalytic + + return print(io, "LQGVortex\n", + " ├─ params structure (LQGParams): varname.params\n", + " ├─────────────────────── device: ", dev, "\n", + " ├──────── use analytic solution: ", UseAnalytic, "\n", + " ├────────── contains ψ, q and K: ", true, "\n", + " ├─────────────────── contains a: ", contains_a, "\n", + " ├────────── contains velocities: ", contains_vel, "\n", + " ├──────────── contains energies: ", contains_ener, "\n", + " └─────────── contains enstrophy: ", contains_enst) + +end + +""" +Base.show function for custom type `SQGVortex` +""" +function Base.show(io::IO, p::SQGVortex) + + contains_vel = ~(p.u isa Nothing) + contains_ener = ~(p.E isa Nothing) + + if p.ψ isa CuArray + dev = "GPU" + else + dev = "CPU" + end + + return print(io, "SQGVortex\n", + " ├─ params structure (SQGParams): varname.params\n", + " ├─────────────────────── device: ", dev, "\n", + " ├─────── contains ψ, b, K and a: ", true, "\n", + " ├────────── contains velocities: ", contains_vel, "\n", + " └──────────── contains energies: ", contains_ener) + +end \ No newline at end of file