Skip to content

Commit 504e140

Browse files
Merge pull request #112 from ChrisRackauckas/fix-formatting
Apply JuliaFormatter to fix code formatting
2 parents 6ea2f9e + 3fc24e6 commit 504e140

7 files changed

Lines changed: 45 additions & 36 deletions

File tree

docs/make.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)
66
include("pages.jl")
77

88
makedocs(sitename = "ModelOrderReduction.jl",
9-
authors = "Bowen S. Zhu",
10-
modules = [ModelOrderReduction],
11-
clean = true, doctest = false, linkcheck = true,
12-
warnonly = [:missing_docs, :example_block],
13-
format = Documenter.HTML(assets = ["assets/favicon.ico"],
14-
canonical = "https://docs.sciml.ai/ModelOrderReduction/stable/"),
15-
pages = pages)
9+
authors = "Bowen S. Zhu",
10+
modules = [ModelOrderReduction],
11+
clean = true, doctest = false, linkcheck = true,
12+
warnonly = [:missing_docs, :example_block],
13+
format = Documenter.HTML(assets = ["assets/favicon.ico"],
14+
canonical = "https://docs.sciml.ai/ModelOrderReduction/stable/"),
15+
pages = pages)
1616

1717
deploydocs(repo = "github.com/SciML/ModelOrderReduction.jl.git")

docs/pages.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pages = [
22
"Home" => "index.md",
33
"Functions" => "functions.md",
4-
"Tutorials" => Any["tutorials/deim_FitzHugh-Nagumo.md"],
4+
"Tutorials" => Any["tutorials/deim_FitzHugh-Nagumo.md"]
55
]

docs/src/tutorials/deim_FitzHugh-Nagumo.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ svdval_w = svdvals(snapshot_w)
107107
svdval_fv = svdvals(snapshot_fv)
108108
using Plots, LaTeXStrings
109109
svd_plt = plot(yscale = :log10, xticks = eachindex(svdval_v), titlefont = 11,
110-
legendfont = 10, title = "Singular values of the snapshots")
110+
legendfont = 10, title = "Singular values of the snapshots")
111111
plot!(svd_plt, svdval_v, markershape = :circle, label = L"Singular Val of $v$")
112112
plot!(svd_plt, svdval_w, markershape = :circle, label = L"Singular Val of $w$")
113113
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.
118118

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

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

189189
As we can see, the reduced-order system captures the limit cycle of the original full-order

src/DataReduction/POD.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ mutable struct POD <: AbstractDRProblem
3939
spectrum::Any
4040
# constructors
4141
function POD(snaps;
42-
min_renergy = 1.0,
43-
min_nmodes::Int = 1,
44-
max_nmodes::Int = length(snaps[1]))
42+
min_renergy = 1.0,
43+
min_nmodes::Int = 1,
44+
max_nmodes::Int = length(snaps[1]))
4545
nmodes = min_nmodes
4646
errorhandle(snaps, nmodes, min_renergy, min_nmodes, max_nmodes)
4747
new(snaps, min_renergy, min_nmodes, max_nmodes, nmodes, missing, 1.0, missing)
@@ -65,8 +65,9 @@ end
6565

6666
function reduce!(pod::POD, alg::SVD)
6767
u, s, v = _svd(pod.snapshots; alg.kwargs...)
68-
pod.nmodes, pod.renergy = determine_truncation(s, pod.min_nmodes, pod.max_nmodes,
69-
pod.min_renergy)
68+
pod.nmodes,
69+
pod.renergy = determine_truncation(s, pod.min_nmodes, pod.max_nmodes,
70+
pod.min_renergy)
7071
pod.rbasis = u[:, 1:(pod.nmodes)]
7172
pod.spectrum = s
7273
nothing
@@ -94,6 +95,6 @@ function Base.show(io::IO, pod::POD)
9495
print(io, "POD \n")
9596
print(io, "Reduction Order = ", pod.nmodes, "\n")
9697
print(io, "Snapshot size = (", size(pod.snapshots, 1), ",", size(pod.snapshots[1], 2),
97-
")\n")
98+
")\n")
9899
print(io, "Relative Energy = ", pod.renergy, "\n")
99100
end

src/ErrorHandle.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function errorhandle(data::AbstractMatrix, nmodes::Int, max_energy, min_nmodes,
77
end
88

99
function errorhandle(data::AbstractVector{T}, nmodes::Int, max_energy, min_nmodes,
10-
max_nmodes) where {T <: AbstractVector}
10+
max_nmodes) where {T <: AbstractVector}
1111
@assert size(data[1], 1)>1 "State vector is expected to be vector valued."
1212
s = min(size(data, 1), size(data[1], 1))
1313
@assert 0<nmodes<=s "Number of modes should be in {1,2,...,$s}."

src/deim.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ the ``\\rho_i``-th column of the identity matrix ``I_n\\in\\mathbb R^{n\\times n
6565
- `linear_projection_eqs`: the linear projection mapping ``\\mathbf y=V\\hat{\\mathbf y}``.
6666
"""
6767
function deim(full_vars::AbstractVector, linear_coeffs::AbstractMatrix,
68-
constant_part::AbstractVector, nonlinear_part::AbstractVector,
69-
reduced_vars::AbstractVector, linear_projection_matrix::AbstractMatrix,
70-
nonlinear_projection_matrix::AbstractMatrix; kwargs...)
68+
constant_part::AbstractVector, nonlinear_part::AbstractVector,
69+
reduced_vars::AbstractVector, linear_projection_matrix::AbstractMatrix,
70+
nonlinear_projection_matrix::AbstractMatrix; kwargs...)
7171
# rename variables for convenience
7272
y = full_vars
7373
A = linear_coeffs
@@ -119,8 +119,8 @@ nonlinear terms, which is computed by executing the runtime-generated function f
119119
nonlinear expressions.
120120
"""
121121
function deim(sys::ODESystem, snapshot::AbstractMatrix, pod_dim::Integer;
122-
deim_dim::Integer = pod_dim, name::Symbol = Symbol(nameof(sys), :_deim),
123-
kwargs...)::ODESystem
122+
deim_dim::Integer = pod_dim, name::Symbol = Symbol(nameof(sys), :_deim),
123+
kwargs...)::ODESystem
124124
sys = deepcopy(sys)
125125
@set! sys.name = name
126126

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

173173
inv_dict = Dict(Symbolics.scalarize(ŷ .=> V' * dvs)) # reduced vars to original vars

test/runtests.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
using SafeTestsets
22

3-
@safetestset "Quality Assurance" begin include("qa.jl") end
4-
@safetestset "POD" begin include("DataReduction.jl") end
5-
@safetestset "utils" begin include("utils.jl") end
6-
@safetestset "DEIM" begin include("deim.jl") end
3+
@safetestset "Quality Assurance" begin
4+
include("qa.jl")
5+
end
6+
@safetestset "POD" begin
7+
include("DataReduction.jl")
8+
end
9+
@safetestset "utils" begin
10+
include("utils.jl")
11+
end
12+
@safetestset "DEIM" begin
13+
include("deim.jl")
14+
end

0 commit comments

Comments
 (0)