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