Skip to content

Commit

Permalink
Merge pull request #14 from mncrowe/main
Browse files Browse the repository at this point in the history
Merge recent docs updates, fixes and additions
  • Loading branch information
mncrowe authored Nov 15, 2024
2 parents c85d4bd + 49ddcdf commit cba4233
Show file tree
Hide file tree
Showing 6 changed files with 554 additions and 38 deletions.
4 changes: 2 additions & 2 deletions docs/src/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 20 additions & 2 deletions docs/src/Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ Eval_w_SQG
Calc_∇
CartesianGrid
PolarGrid
Base.summary
Base.show
```

## `energetics.jl`
Expand All @@ -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
```
13 changes: 12 additions & 1 deletion src/QGDipoles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ export
EnstrophyLQG,
EnergySQG,
AreaInteg2,


# vortex_types.jl
LQGParams,
SQGParams,
LQGVortex,
SQGVortex,
DefLQGParams,
DefSQGParams,
DefLQGVortex,
DefSQGVortex,

# monopoles.jl
CreateRankine,
CreateMonopole,
Expand All @@ -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
28 changes: 14 additions & 14 deletions src/create_modon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -900,7 +902,6 @@ end

"""
Base.summary function for custom type `GridStruct`
"""
function Base.summary(g::GridStruct)

Expand All @@ -917,7 +918,6 @@ end

"""
Base.show function for custom type `GridStruct`
"""
function Base.show(io::IO, g::GridStruct)

Expand All @@ -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
15 changes: 8 additions & 7 deletions src/lin_sys.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand All @@ -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

Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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))

Expand All @@ -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)

Expand Down
Loading

0 comments on commit cba4233

Please sign in to comment.