|
| 1 | +""" |
| 2 | +$(TYPEDSIGNATURES) |
| 3 | +
|
| 4 | +Get the set of independent variables for the given system. |
| 5 | +""" |
| 6 | +function independent_variables end |
| 7 | + |
| 8 | +""" |
| 9 | +$(TYPEDSIGNATURES) |
| 10 | +
|
| 11 | +Check if the given sym is an independent variable in the given system. |
| 12 | +""" |
| 13 | +function is_indep_sym end |
| 14 | + |
| 15 | +""" |
| 16 | +$(TYPEDSIGNATURES) |
| 17 | +
|
| 18 | +Get the set of states for the given system. |
| 19 | +""" |
| 20 | +function states end |
| 21 | + |
| 22 | +""" |
| 23 | +$(TYPEDSIGNATURES) |
| 24 | +
|
| 25 | +Find the index of the given sym in the given system. |
| 26 | +""" |
| 27 | +function state_sym_to_index end |
| 28 | + |
| 29 | +""" |
| 30 | +$(TYPEDSIGNATURES) |
| 31 | +
|
| 32 | +Check if the given sym is a state variable in the given system. |
| 33 | +""" |
| 34 | +function is_state_sym end |
| 35 | + |
| 36 | +""" |
| 37 | +$(TYPEDSIGNATURES) |
| 38 | +
|
| 39 | +Get the set of parameters variables for the given system. |
| 40 | +""" |
| 41 | +function parameters end |
| 42 | + |
| 43 | +""" |
| 44 | +$(TYPEDSIGNATURES) |
| 45 | +
|
| 46 | +Find the index of the given sym in the given system. |
| 47 | +""" |
| 48 | +function param_sym_to_index end |
| 49 | + |
| 50 | +""" |
| 51 | +$(TYPEDSIGNATURES) |
| 52 | +
|
| 53 | +Check if the given sym is a parameter variable in the given system. |
| 54 | +""" |
| 55 | +function is_param_sym end |
| 56 | + |
| 57 | +struct SymbolCache{S,T,U} |
| 58 | + syms::S |
| 59 | + indepsym::T |
| 60 | + paramsyms::U |
| 61 | +end |
| 62 | + |
| 63 | + |
| 64 | +independent_variables(sc::SymbolCache) = sc.indepsym |
| 65 | +independent_variables(::SymbolCache{S,Nothing}) where {S} = [] |
| 66 | +is_indep_sym(sc::SymbolCache, sym) = any(isequal(sym), sc.indepsym) |
| 67 | +is_indep_sym(::SymbolCache{S,Nothing}, _) where {S} = false |
| 68 | +states(sc::SymbolCache) = sc.syms |
| 69 | +states(::SymbolCache{Nothing}) = [] |
| 70 | +state_sym_to_index(sc::SymbolCache, sym) = findfirst(isequal(sym), sc.syms) |
| 71 | +state_sym_to_index(::SymbolCache{Nothing}, _) = nothing |
| 72 | +is_state_sym(sc::SymbolCache, sym) = !isnothing(state_sym_to_index(sc, sym)) |
| 73 | +parameters(sc::SymbolCache) = sc.paramsyms |
| 74 | +parameters(::SymbolCache{S,T,Nothing}) where {S,T} = [] |
| 75 | +param_sym_to_index(sc::SymbolCache, sym) = findfirst(isequal(sym), sc.paramsyms) |
| 76 | +param_sym_to_index(::SymbolCache{S,T,Nothing}, _) where {S,T} = nothing |
| 77 | +is_param_sym(sc::SymbolCache, sym) = !isnothing(param_sym_to_index(sc, sym)) |
| 78 | + |
| 79 | +Base.copy(VA::SymbolCache) = typeof(VA)( |
| 80 | + (VA.syms===nothing) ? nothing : copy(VA.syms), |
| 81 | + (VA.indepsym===nothing) ? nothing : copy(VA.indepsym), |
| 82 | + (VA.paramsyms===nothing) ? nothing : copy(VA.paramsyms), |
| 83 | +) |
| 84 | + |
0 commit comments