|
1 | 1 | function matricize(VoV::Vector{Vector{FT}}) where {FT} |
2 | | - Matrix(reduce(hcat,VoV)') |
| 2 | + Matrix(reduce(hcat,VoV)) |
3 | 3 | end |
4 | 4 |
|
5 | | -mutable struct POD{FT,IT} <: AbstractDRProblem |
| 5 | +mutable struct POD{FT} <: AbstractDRProblem |
6 | 6 | snapshots::Union{Vector{Vector{FT}},Matrix{FT}} |
7 | | - nmodes::IT |
| 7 | + nmodes::Int |
8 | 8 | rbasis::Matrix{FT} |
9 | | - energy::FT |
| 9 | + renergy::FT |
10 | 10 |
|
11 | | - function POD(snaps::Vector{Vector{FT}},nmodes::IT) where {FT,IT} |
| 11 | + function POD(snaps::Vector{Vector{FT}},nmodes::Int) where {FT} |
12 | 12 | errorhandle(matricize(snaps),nmodes) |
13 | | - new{eltype(snaps[1]),typeof(nmodes)}(snaps,nmodes,Array{FT,2}(undef,size(snaps,1),nmodes),FT(0)) |
| 13 | + new{eltype(snaps[1])}(snaps,nmodes,Array{FT,2}(undef,size(snaps,1),nmodes),FT(0)) |
14 | 14 | end |
15 | 15 |
|
16 | | - function POD(snaps::Matrix{FT},nmodes::IT) where {FT,IT} |
| 16 | + function POD(snaps::Matrix{FT},nmodes::Int) where {FT} |
17 | 17 | errorhandle(snaps,nmodes) |
18 | | - new{eltype(snaps),typeof(nmodes)}(snaps,nmodes,Array{FT,2}(undef,size(snaps,1),nmodes),FT(0)) |
| 18 | + new{eltype(snaps)}(snaps,nmodes,Array{FT,2}(undef,size(snaps,1),nmodes),FT(0)) |
19 | 19 | end |
20 | 20 |
|
21 | | - function POD(snaps::Adjoint{FT,Matrix{FT}},nmodes::IT) where {FT,IT} |
| 21 | + function POD(snaps::Adjoint{FT,Matrix{FT}},nmodes::Int) where {FT} |
22 | 22 | POD(Matrix(snaps),nmodes,Array{FT,2}(undef,size(snaps,1),nmodes),FT(0)) |
23 | 23 | end |
24 | 24 | end |
25 | 25 |
|
26 | | -function reduce!(pod::POD{FT,IT},::SVD) where {FT,IT} |
| 26 | +function reduce!(pod::POD{FT},::SVD) where {FT} |
27 | 27 | op_matrix = pod.snapshots |
28 | 28 | if typeof(pod.snapshots) == Vector{Vector{FT}} |
29 | 29 | op_matrix = matricize(pod.snapshots) |
30 | 30 | end |
31 | 31 | u,s,v = svd(op_matrix) |
32 | 32 | pod.rbasis .= u[:,1:pod.nmodes] |
33 | 33 | sr = s[1:pod.nmodes] |
34 | | - pod.energy = sum(sr)/sum(s) |
| 34 | + pod.renergy = sum(s)/(sum(s) + (size(op_matrix,1)-pod.nmodes)*s[end]) |
35 | 35 | nothing |
36 | 36 | end |
37 | 37 |
|
38 | | -function reduce!(pod::POD{FT,IT},::TSVD) where {FT,IT} |
| 38 | +function reduce!(pod::POD{FT},::TSVD) where {FT} |
39 | 39 | op_matrix = pod.snapshots |
40 | 40 | if typeof(pod.snapshots) == Vector{Vector{FT}} |
41 | 41 | op_matrix = matricize(pod.snapshots) |
42 | 42 | end |
43 | 43 | u,s,v = tsvd(op_matrix,pod.nmodes) |
44 | | - pod.energy = NaN |
| 44 | + pod.renergy = sum(s)/(sum(s) + (size(op_matrix,1)-pod.nmodes)*s[end]) |
45 | 45 | pod.rbasis .= u |
46 | 46 | nothing |
47 | 47 | end |
48 | 48 |
|
49 | | -function reduce!(pod::POD{FT,IT},::RSVD) where {FT,IT} |
| 49 | +function reduce!(pod::POD{FT},::RSVD) where {FT} |
50 | 50 | op_matrix = pod.snapshots |
51 | 51 | if typeof(pod.snapshots) == Vector{Vector{FT}} |
52 | 52 | op_matrix = matricize(pod.snapshots) |
53 | 53 | end |
54 | 54 | u,s,v = rsvd(op_matrix,pod.nmodes) |
55 | | - pod.energy = NaN |
| 55 | + pod.renergy = sum(s)/(sum(s) + (size(op_matrix,1)-pod.nmodes)*s[end]) |
56 | 56 | pod.rbasis .= u |
57 | 57 | nothing |
58 | 58 | end |
59 | 59 |
|
60 | 60 | function Base.show(io::IO,pod::POD) |
61 | 61 | print(io,"POD \n") |
62 | 62 | print(io,"Reduction Order = ",pod.nmodes,"\n") |
63 | | - print(io,"Snapshot size = (", length(pod.snapshots),",",length(pod.snapshots[1]),")\n") |
64 | | - print(io,"Energy = ", pod.energy,"\n") |
| 63 | + print(io,"Snapshot size = (", size(pod.snapshots,1),",",size(pod.snapshots[1],2),")\n") |
| 64 | + print(io,"Relative Energy = ", pod.renergy,"\n") |
65 | 65 | end |
0 commit comments