1+ function test_instantaneous (
2+ sys:: ModelingToolkit.AbstractSystem ,
3+ ic,
4+ checks:: Num ;
5+ t = nothing ) # todo: after porting to v9 use InitializationSystem to solve the checks system
6+ if ! SymbolicIndexingInterface. is_observed (checks)
7+ @assert false " The given check values are not observed values of the given system"
8+ end
9+ sv = ModelingToolkit. varmap_to_vars (ic, states (sys); defaults= ModelingToolkit. defaults (sys))
10+ pv = ModelingToolkit. varmap_to_vars (ic, parameters (sys); defaults= ModelingToolkit. defaults (sys))
11+
12+ obsfun = SymbolicIndexingInterface. observed (sys, checks)
13+ if SymbolicIndexingInterface. istimedependent (sys)
14+ @assert ! isnothing (t) " The kwarg t must be given (and be a non-nothing value) if the system is time dependent"
15+ return obsfun (sv, pv, t)
16+ elseif ! SymbolicIndexingInterface. constant_structure (sys)
17+ @assert false " The system's structure must be constant to use test_instantaneous; to be fixed" # TODO
18+ else
19+ return obsfun (sv, pv)
20+ end
21+ end
22+
23+ function test_instantaneous (
24+ sys:: ModelingToolkit.AbstractSystem ,
25+ ic,
26+ checks:: Array ;
27+ t = nothing ) # todo: after porting to v9 use InitializationSystem to solve the checks system
28+ if ! all (SymbolicIndexingInterface. is_observed .((sys, ), checks))
29+ @assert false " The given check values are not observed values of the given system"
30+ end
31+ sv = ModelingToolkit. varmap_to_vars (ic, states (sys); defaults= ModelingToolkit. defaults (sys))
32+ pv = ModelingToolkit. varmap_to_vars (ic, parameters (sys); defaults= ModelingToolkit. defaults (sys))
33+
34+ obsfuns = SymbolicIndexingInterface. observed .((ODEFunction (sys),), checks)
35+ if SymbolicIndexingInterface. is_time_dependent (sys)
36+ @assert ! isnothing (t) " The kwarg t must be given (and be a non-nothing value) if the system is time dependent"
37+ return map (fun -> fun (sv, pv, t), obsfuns)
38+ elseif ! SymbolicIndexingInterface. constant_structure (sys)
39+ @assert false " The system's structure must be constant to use test_instantaneous; to be fixed" # TODO
40+ else
41+ return map (fun -> fun (sv, pv), obsfuns)
42+ end
43+ end
44+
45+ export test_instantaneous
0 commit comments