Hi all, this should be really easy but I can’t quite figure it out.
When you create an MTK system, and want to solve it as a NonlinearProblem, ODEProblem, or whatever, you often need provide an initial guess or initial conditions.
Not a MWE here, just some generic whiteboard code
sys = mtkcompile(_sys)
guess = [ pump.port_b.m_dot => -100.0, pipe.port_a.p => 10.0, some_valve.port_a.m_dot => 1.0]
# and so on with more guess values
prob = NonlinearProblem(sys, guess)
sol = solve(prob)
what I’d like to do is be able to iterate in a loop building the guess vector from strings, as I know what is in the system. Something like this:
for i in N_valves
push!(guesses, Pair(Symbol("valve_$i.port_a.m_dot"), 33))
push!(guesses, Pair(Symbol("valve_$i.port_a.p"), 42))
# exact guess values don't matter here
end
However, the type of the guess array is
typeof(guesses)
Vector{Pair{Num, Float64}}
The type of the guess pair vectors doesn’t say anything about a Symbol, and the above for loop doesn’t work. Num is supposed to be an abstract type, although displaying the guess vector shows the names and guess value
julia> guesses
3-element Vector{Pair{Num, Float64}}:
pump₊port_b₊m_dot(t) => -100.0
pipe₊port_a₊p(t) => 10.0
some_valve₊port_a₊m_dot(t) => 1.0
So that is puzzling.