Skip to content

Commit

Permalink
verbose output for spod algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
tb6g16 committed May 2, 2023
1 parent 9a45032 commit a41a93b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.2.0"
[deps]
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
13 changes: 10 additions & 3 deletions src/SPOD.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module SPOD

using LinearAlgebra, FFTW
using LinearAlgebra, FFTW, Printf

export spod!
export spod

# ! Ways to improve the code:
# ! - include windowing;
Expand All @@ -28,20 +28,24 @@ include("window.jl")
currently supported. The decomposition can be truncated by passing a unit
range to eigrange.
"""
function spod!(Q::M, quad_weights::AbstractVector, dt::Float64, Nf::Int, No::Int=0; window::WindowMethod=NoWindow(), eigrange::Union{Nothing, Int, UnitRange}=nothing) where {M <: AbstractMatrix}
function spod(Q::M, quad_weights::AbstractVector, dt::Float64, Nf::Int, No::Int=0; verbose::Bool=false, window::WindowMethod=NoWindow(), eigrange::Union{Nothing, Int, UnitRange}=nothing) where {M <: AbstractMatrix}
# get size of snapshot vectors
N = size(Q, 1)

# split Q into blocks with overlap
verbose && print("Splitting snapshot matrix into blocks...")
Q_blocks, Nb = split_into_blocks(Q, Nf, No)
verbose && println("Done!")

# initialise matrix to hold FFT of snapshot matrix blocks
Q̂_blocks = Vector{typeof(Q)}(undef, length(Q_blocks))

# loop over blocks and perform the time-wise FFT
verbose && print("Fourier transforming snapshot blocks... ")
for (i, block) in enumerate(Q_blocks)
Q̂_blocks[i] = fft_time(apply_window!(block, window))
end
verbose && println("Done!")
= size(Q̂_blocks[1], 2)

# initialise useful arrays
Expand All @@ -63,6 +67,8 @@ function spod!(Q::M, quad_weights::AbstractVector, dt::Float64, Nf::Int, No::Int

# loop over the frequencies of all the blocks
for fk in 1:
sleep(0.25)
verbose && @printf("Solving Eigenproblem for every frequency... fk = %i/%i\r", fk, Nω)
# construct fourier realisation matrices for each block
for nb in 1:Nb
Qfk[:, nb] .= sqrt_κ.*@view(Q̂_blocks[nb][:, fk])
Expand All @@ -81,6 +87,7 @@ function spod!(Q::M, quad_weights::AbstractVector, dt::Float64, Nf::Int, No::Int
# convert the eivenvectors to the correct SPOD modes
spod_modes[:, :, fk] .= Qfk*eigvecs*Diagonal(@view(eigvals[:, fk]).^-0.5)
end
verbose && print("Solving Eigenproblem for every frequency... Done! ")

return eigvals, spod_modes
end
Expand Down

0 comments on commit a41a93b

Please sign in to comment.