Skip to content

Commit 26b1d10

Browse files
authored
Merge pull request #2944 from SciML/myb/exp
Experimental variable filtering in dummy derivative
2 parents 0d962c4 + bb2eb3f commit 26b1d10

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

docs/src/basics/InputOutput.md

-5
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

+11-4
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,23 @@ function dummy_derivative_graph!(
216216
col_order = Int[]
217217
nvars = ndsts(graph)
218218
eqs = Int[]
219+
vars = Int[]
219220
next_eq_idxs = Int[]
220221
next_var_idxs = Int[]
221222
new_eqs = Int[]
222223
new_vars = Int[]
223224
eqs_set = BitSet()
224-
for vars in var_sccs
225+
for vars in var_sccs
225226
empty!(eqs)
226-
for var in vars
227+
empty!(vars)
228+
for var in vars′
227229
eq = var_eq_matching[var]
228230
eq isa Int || continue
229-
diff_to_eq[eq] === nothing && continue
230-
push!(eqs, eq)
231+
diff_to_eq[eq] === nothing || push!(eqs, eq)
232+
if var_to_diff[var] !== nothing
233+
error("Invalid SCC")
234+
end
235+
(diff_to_var[var] !== nothing && is_present(structure, var)) && push!(vars, var)
231236
end
232237
isempty(eqs) && continue
233238

@@ -318,6 +323,8 @@ function dummy_derivative_graph!(
318323
for (i, var) in enumerate(vars)
319324
∫var = diff_to_var[var]
320325
∫var === nothing && continue
326+
∫∫var = diff_to_var[∫var]
327+
∫∫var === nothing && continue
321328
if J !== nothing
322329
push!(next_var_idxs, i)
323330
end

0 commit comments

Comments
 (0)