Skip to content

Commit 5188268

Browse files
committed
Add kwargs... in deim signature
1 parent 3464581 commit 5188268

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/deim.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ the ``\\rho_i``-th column of the identity matrix ``I_n\\in\\mathbb R^{n\\times n
6767
function deim(full_vars::AbstractVector, linear_coeffs::AbstractMatrix,
6868
constant_part::AbstractVector, nonlinear_part::AbstractVector,
6969
reduced_vars::AbstractVector, linear_projection_matrix::AbstractMatrix,
70-
nonlinear_projection_matrix::AbstractMatrix)
70+
nonlinear_projection_matrix::AbstractMatrix; kwargs...)
7171
# rename variables for convenience
7272
y = full_vars
7373
A = linear_coeffs
@@ -85,7 +85,7 @@ function deim(full_vars::AbstractVector, linear_coeffs::AbstractMatrix,
8585
# the DEIM projector (not DEIM basis) satisfies
8686
# F(original_vars) ≈ projector * F(pod_basis * reduced_vars)[indices]
8787
projector = ((@view U[indices, :])' \ (U' * V))'
88-
temp = substitute.(F[indices], (linear_projection_dict,))
88+
temp = substitute.(F[indices], (linear_projection_dict,); kwargs...)
8989
= projector * temp # DEIM approximation for nonlinear func F
9090

9191
= V' * A * V
@@ -112,13 +112,13 @@ nonlinear terms, which is computed by executing the runtime-generated function f
112112
nonlinear expressions.
113113
"""
114114
function deim(sys::ODESystem, snapshot::AbstractMatrix, pod_dim::Integer;
115-
deim_dim::Integer = pod_dim,
116-
name::Symbol = Symbol(nameof(sys), :_deim))::ODESystem
115+
deim_dim::Integer = pod_dim, name::Symbol = Symbol(nameof(sys), :_deim),
116+
kwargs...)::ODESystem
117117
@set! sys.name = name
118118

119119
# handle ODESystem.substitutions
120120
# https://github.com/SciML/ModelingToolkit.jl/issues/1754
121-
sys = tearing_substitution(sys)
121+
sys = tearing_substitution(sys; kwargs...)
122122

123123
iv = ModelingToolkit.get_iv(sys) # the single independent variable
124124
D = Differential(iv)
@@ -140,7 +140,7 @@ function deim(sys::ODESystem, snapshot::AbstractMatrix, pod_dim::Integer;
140140
A, g, F = linear_terms(rhs, dvs)
141141

142142
# generate an in-place function from the symbolic expression of the nonlinear functions
143-
F_func! = build_function(F, dvs; expression = Val{false})[2]
143+
F_func! = build_function(F, dvs; expression = Val{false}, kwargs...)[2]
144144
nonlinear_snapshot = similar(snapshot) # snapshot matrix of nonlinear terms
145145
for i in 1:size(snapshot, 2) # iterate through time instances
146146
F_func!(view(nonlinear_snapshot, :, i), view(snapshot, :, i))
@@ -150,15 +150,16 @@ function deim(sys::ODESystem, snapshot::AbstractMatrix, pod_dim::Integer;
150150
reduce!(deim_reducer, TSVD())
151151
U = deim_reducer.rbasis # DEIM projection basis
152152

153-
reduced_rhss, linear_projection_eqs = deim(dvs, A, g, F, ŷ, V, U)
153+
reduced_rhss, linear_projection_eqs = deim(dvs, A, g, F, ŷ, V, U; kwargs...)
154154

155155
reduced_deqs = D.(ŷ) ~ reduced_rhss
156156
@set! sys.eqs = [Symbolics.scalarize(reduced_deqs); eqs]
157157

158158
old_observed = ModelingToolkit.get_observed(sys)
159159
fullstates = [map(eq -> eq.lhs, old_observed); dvs; ModelingToolkit.get_states(sys)]
160160
new_observed = [old_observed; linear_projection_eqs]
161-
new_sorted_observed = ModelingToolkit.topsort_equations(new_observed, fullstates)
161+
new_sorted_observed = ModelingToolkit.topsort_equations(new_observed, fullstates;
162+
kwargs...)
162163
@set! sys.observed = new_sorted_observed
163164

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

0 commit comments

Comments
 (0)