Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)
include("pages.jl")

makedocs(sitename = "ModelOrderReduction.jl",
authors = "Bowen S. Zhu",
modules = [ModelOrderReduction],
clean = true, doctest = false, linkcheck = true,
warnonly = [:missing_docs, :example_block],
format = Documenter.HTML(assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/ModelOrderReduction/stable/"),
pages = pages)
authors = "Bowen S. Zhu",
modules = [ModelOrderReduction],
clean = true, doctest = false, linkcheck = true,
warnonly = [:missing_docs, :example_block],
format = Documenter.HTML(assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/ModelOrderReduction/stable/"),
pages = pages)

deploydocs(repo = "github.com/SciML/ModelOrderReduction.jl.git")
2 changes: 1 addition & 1 deletion docs/pages.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pages = [
"Home" => "index.md",
"Functions" => "functions.md",
"Tutorials" => Any["tutorials/deim_FitzHugh-Nagumo.md"],
"Tutorials" => Any["tutorials/deim_FitzHugh-Nagumo.md"]
]
22 changes: 11 additions & 11 deletions docs/src/tutorials/deim_FitzHugh-Nagumo.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ svdval_w = svdvals(snapshot_w)
svdval_fv = svdvals(snapshot_fv)
using Plots, LaTeXStrings
svd_plt = plot(yscale = :log10, xticks = eachindex(svdval_v), titlefont = 11,
legendfont = 10, title = "Singular values of the snapshots")
legendfont = 10, title = "Singular values of the snapshots")
plot!(svd_plt, svdval_v, markershape = :circle, label = L"Singular Val of $v$")
plot!(svd_plt, svdval_w, markershape = :circle, label = L"Singular Val of $w$")
plot!(svd_plt, svdval_fv, markershape = :circle, label = L"Singular Val of $f(v)$")
Expand All @@ -118,9 +118,9 @@ points ``x`` from the full-order system.

```@example deim_FitzHugh_Nagumo
full_plt = plot(xlabel = L"v(x,t)", ylabel = L"x", zlabel = L"w(x,t)", xlims = (-0.5, 2.0),
ylims = (0.0, L), zlims = (0.0, 0.25), legend = false, xflip = true,
camera = (50, 30), titlefont = 10,
title = "Phase−Space diagram of full $(nameof(pde_sys)) system")
ylims = (0.0, L), zlims = (0.0, 0.25), legend = false, xflip = true,
camera = (50, 30), titlefont = 10,
title = "Phase−Space diagram of full $(nameof(pde_sys)) system")
@views for i in 1:nₓ
plot!(full_plt, snapshot_v[i, :], _ -> sol_x[i], snapshot_w[i, :])
end
Expand Down Expand Up @@ -149,9 +149,9 @@ And plot the result from the POD-DEIM reduced system.

```@example deim_FitzHugh_Nagumo
deim_plt = plot(xlabel = L"v(x,t)", ylabel = L"x", zlabel = L"w(x,t)", xlims = (-0.5, 2.0),
ylims = (0.0, L), zlims = (0.0, 0.25), legend = false, xflip = true,
camera = (50, 30), titlefont = 10,
title = "Phase−Space diagram of reduced $(nameof(pde_sys)) system")
ylims = (0.0, L), zlims = (0.0, 0.25), legend = false, xflip = true,
camera = (50, 30), titlefont = 10,
title = "Phase−Space diagram of reduced $(nameof(pde_sys)) system")
@views for i in 1:nₓ
plot!(deim_plt, sol_deim_v[i, :], _ -> sol_deim_x[i], sol_deim_w[i, :])
end
Expand All @@ -178,12 +178,12 @@ function unconnected(v::AbstractVector, nₜ::Integer)
vec(data)
end
plt_2 = plot(xlabel = L"v(x,t)", ylabel = L"x", zlabel = L"w(x,t)", xlims = (-0.5, 2.0),
ylims = (0.0, L), zlims = (0.0, 0.25), xflip = true, camera = (50, 30),
titlefont = 10, title = "Comparison of full and reduced systems")
ylims = (0.0, L), zlims = (0.0, 0.25), xflip = true, camera = (50, 30),
titlefont = 10, title = "Comparison of full and reduced systems")
plot!(plt_2, unconnected(snapshot_v), unconnected(sol_x, nₜ), unconnected(snapshot_w),
label = "Full$(length(ode_sys.eqs))")
label = "Full$(length(ode_sys.eqs))")
plot!(plt_2, unconnected(sol_deim_v), unconnected(sol_deim_x, nₜ_deim),
unconnected(sol_deim_w), label = "POD$(pod_dim)/DEIM$(deim_dim)")
unconnected(sol_deim_w), label = "POD$(pod_dim)/DEIM$(deim_dim)")
```

As we can see, the reduced-order system captures the limit cycle of the original full-order
Expand Down
10 changes: 5 additions & 5 deletions src/DataReduction/POD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ mutable struct POD <: AbstractDRProblem
spectrum::Any
# constructors
function POD(snaps;
min_renergy = 1.0,
min_nmodes::Int = 1,
max_nmodes::Int = length(snaps[1]))
min_renergy = 1.0,
min_nmodes::Int = 1,
max_nmodes::Int = length(snaps[1]))
nmodes = min_nmodes
errorhandle(snaps, nmodes, min_renergy, min_nmodes, max_nmodes)
new(snaps, min_renergy, min_nmodes, max_nmodes, nmodes, missing, 1.0, missing)
Expand All @@ -66,7 +66,7 @@ end
function reduce!(pod::POD, alg::SVD)
u, s, v = _svd(pod.snapshots; alg.kwargs...)
pod.nmodes, pod.renergy = determine_truncation(s, pod.min_nmodes, pod.max_nmodes,
pod.min_renergy)
pod.min_renergy)
pod.rbasis = u[:, 1:(pod.nmodes)]
pod.spectrum = s
nothing
Expand Down Expand Up @@ -94,6 +94,6 @@ function Base.show(io::IO, pod::POD)
print(io, "POD \n")
print(io, "Reduction Order = ", pod.nmodes, "\n")
print(io, "Snapshot size = (", size(pod.snapshots, 1), ",", size(pod.snapshots[1], 2),
")\n")
")\n")
print(io, "Relative Energy = ", pod.renergy, "\n")
end
2 changes: 1 addition & 1 deletion src/ErrorHandle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function errorhandle(data::AbstractMatrix, nmodes::Int, max_energy, min_nmodes,
end

function errorhandle(data::AbstractVector{T}, nmodes::Int, max_energy, min_nmodes,
max_nmodes) where {T <: AbstractVector}
max_nmodes) where {T <: AbstractVector}
@assert size(data[1], 1)>1 "State vector is expected to be vector valued."
s = min(size(data, 1), size(data[1], 1))
@assert 0<nmodes<=s "Number of modes should be in {1,2,...,$s}."
Expand Down
12 changes: 6 additions & 6 deletions src/deim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ the ``\\rho_i``-th column of the identity matrix ``I_n\\in\\mathbb R^{n\\times n
- `linear_projection_eqs`: the linear projection mapping ``\\mathbf y=V\\hat{\\mathbf y}``.
"""
function deim(full_vars::AbstractVector, linear_coeffs::AbstractMatrix,
constant_part::AbstractVector, nonlinear_part::AbstractVector,
reduced_vars::AbstractVector, linear_projection_matrix::AbstractMatrix,
nonlinear_projection_matrix::AbstractMatrix; kwargs...)
constant_part::AbstractVector, nonlinear_part::AbstractVector,
reduced_vars::AbstractVector, linear_projection_matrix::AbstractMatrix,
nonlinear_projection_matrix::AbstractMatrix; kwargs...)
# rename variables for convenience
y = full_vars
A = linear_coeffs
Expand Down Expand Up @@ -119,8 +119,8 @@ nonlinear terms, which is computed by executing the runtime-generated function f
nonlinear expressions.
"""
function deim(sys::ODESystem, snapshot::AbstractMatrix, pod_dim::Integer;
deim_dim::Integer = pod_dim, name::Symbol = Symbol(nameof(sys), :_deim),
kwargs...)::ODESystem
deim_dim::Integer = pod_dim, name::Symbol = Symbol(nameof(sys), :_deim),
kwargs...)::ODESystem
sys = deepcopy(sys)
@set! sys.name = name

Expand Down Expand Up @@ -167,7 +167,7 @@ function deim(sys::ODESystem, snapshot::AbstractMatrix, pod_dim::Integer;
fullstates = [map(eq -> eq.lhs, old_observed); dvs; ModelingToolkit.get_states(sys)]
new_observed = [old_observed; linear_projection_eqs]
new_sorted_observed = ModelingToolkit.topsort_equations(new_observed, fullstates;
kwargs...)
kwargs...)
@set! sys.observed = new_sorted_observed

inv_dict = Dict(Symbolics.scalarize(ŷ .=> V' * dvs)) # reduced vars to original vars
Expand Down
16 changes: 12 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
using SafeTestsets

@safetestset "Quality Assurance" begin include("qa.jl") end
@safetestset "POD" begin include("DataReduction.jl") end
@safetestset "utils" begin include("utils.jl") end
@safetestset "DEIM" begin include("deim.jl") end
@safetestset "Quality Assurance" begin
include("qa.jl")
end
@safetestset "POD" begin
include("DataReduction.jl")
end
@safetestset "utils" begin
include("utils.jl")
end
@safetestset "DEIM" begin
include("deim.jl")
end
Loading