diff --git a/docs/make.jl b/docs/make.jl index fc3171f..ecb4609 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -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") diff --git a/docs/pages.jl b/docs/pages.jl index 2a7c950..8ddcb50 100644 --- a/docs/pages.jl +++ b/docs/pages.jl @@ -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"] ] diff --git a/docs/src/tutorials/deim_FitzHugh-Nagumo.md b/docs/src/tutorials/deim_FitzHugh-Nagumo.md index 41e17cc..e53fef7 100644 --- a/docs/src/tutorials/deim_FitzHugh-Nagumo.md +++ b/docs/src/tutorials/deim_FitzHugh-Nagumo.md @@ -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)$") @@ -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 @@ -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 @@ -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 diff --git a/src/DataReduction/POD.jl b/src/DataReduction/POD.jl index 854b706..2abd01a 100644 --- a/src/DataReduction/POD.jl +++ b/src/DataReduction/POD.jl @@ -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) @@ -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 @@ -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 diff --git a/src/ErrorHandle.jl b/src/ErrorHandle.jl index 2994f42..a867ecb 100644 --- a/src/ErrorHandle.jl +++ b/src/ErrorHandle.jl @@ -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 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 diff --git a/test/runtests.jl b/test/runtests.jl index 821f7d6..4953946 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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