Skip to content

Commit

Permalink
Merge pull request #2944 from SciML/myb/exp
Browse files Browse the repository at this point in the history
Experimental variable filtering in dummy derivative
  • Loading branch information
YingboMa authored Aug 9, 2024
2 parents 0d962c4 + bb2eb3f commit 26b1d10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
5 changes: 0 additions & 5 deletions docs/src/basics/InputOutput.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ This function takes a vector of variables that are to be considered inputs, i.e.

### Example:


The following example implements a simple first-order system with an input `u` and state `x`. The function `f` is generated using `generate_control_function`, and the function `f` is then tested with random input and state values.


```@example inputoutput
import ModelingToolkit: t_nounits as t, D_nounits as D
@variables x(t)=0 u(t)=0 y(t)
Expand All @@ -50,10 +48,8 @@ f, x_sym, ps = ModelingToolkit.generate_control_function(sys, [u], simplify = tr
nothing # hide
```


We can inspect the state realization chosen by MTK


```@example inputoutput
x_sym
```
Expand All @@ -70,7 +66,6 @@ nothing # hide

Now we can test the generated function `f` with random input and state values


```@example inputoutput
p = [1]
x = [rand()]
Expand Down
15 changes: 11 additions & 4 deletions src/structural_transformation/partial_state_selection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,23 @@ function dummy_derivative_graph!(
col_order = Int[]
nvars = ndsts(graph)
eqs = Int[]
vars = Int[]
next_eq_idxs = Int[]
next_var_idxs = Int[]
new_eqs = Int[]
new_vars = Int[]
eqs_set = BitSet()
for vars in var_sccs
for vars in var_sccs
empty!(eqs)
for var in vars
empty!(vars)
for var in vars′
eq = var_eq_matching[var]
eq isa Int || continue
diff_to_eq[eq] === nothing && continue
push!(eqs, eq)
diff_to_eq[eq] === nothing || push!(eqs, eq)
if var_to_diff[var] !== nothing
error("Invalid SCC")
end
(diff_to_var[var] !== nothing && is_present(structure, var)) && push!(vars, var)
end
isempty(eqs) && continue

Expand Down Expand Up @@ -318,6 +323,8 @@ function dummy_derivative_graph!(
for (i, var) in enumerate(vars)
∫var = diff_to_var[var]
∫var === nothing && continue
∫∫var = diff_to_var[∫var]
∫∫var === nothing && continue
if J !== nothing
push!(next_var_idxs, i)
end
Expand Down

0 comments on commit 26b1d10

Please sign in to comment.