Skip to content

Commit bb2eb3f

Browse files
committed
Experimental variable filtering in dummy derivative
1 parent 47aa59d commit bb2eb3f

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

docs/src/basics/InputOutput.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ This function takes a vector of variables that are to be considered inputs, i.e.
3434

3535
### Example:
3636

37-
3837
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.
3938

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

53-
5451
We can inspect the state realization chosen by MTK
5552

56-
5753
```@example inputoutput
5854
x_sym
5955
```
@@ -70,7 +66,6 @@ nothing # hide
7066

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

73-
7469
```@example inputoutput
7570
p = [1]
7671
x = [rand()]

src/structural_transformation/partial_state_selection.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,23 @@ function dummy_derivative_graph!(
208208
col_order = Int[]
209209
nvars = ndsts(graph)
210210
eqs = Int[]
211+
vars = Int[]
211212
next_eq_idxs = Int[]
212213
next_var_idxs = Int[]
213214
new_eqs = Int[]
214215
new_vars = Int[]
215216
eqs_set = BitSet()
216-
for vars in var_sccs
217+
for vars in var_sccs
217218
empty!(eqs)
218-
for var in vars
219+
empty!(vars)
220+
for var in vars′
219221
eq = var_eq_matching[var]
220222
eq isa Int || continue
221-
diff_to_eq[eq] === nothing && continue
222-
push!(eqs, eq)
223+
diff_to_eq[eq] === nothing || push!(eqs, eq)
224+
if var_to_diff[var] !== nothing
225+
error("Invalid SCC")
226+
end
227+
(diff_to_var[var] !== nothing && is_present(structure, var)) && push!(vars, var)
223228
end
224229
isempty(eqs) && continue
225230

@@ -304,6 +309,8 @@ function dummy_derivative_graph!(
304309
for (i, var) in enumerate(vars)
305310
∫var = diff_to_var[var]
306311
∫var === nothing && continue
312+
∫∫var = diff_to_var[∫var]
313+
∫∫var === nothing && continue
307314
if J !== nothing
308315
push!(next_var_idxs, i)
309316
end

0 commit comments

Comments
 (0)