Working with Catalyst v15.0.8 and ModelingToolkit v9.80.5,
I found a strange and misleading behavior w.r.t. parameter declarations in reaction components: suppose I declare a parameter (k
) in two different components (n1
and n2
) with two different default values (say 1.0
in n1
and 2.0
in n2
), and in both components I also declare a variable x
with k
as initial condition. I would thus expect that the initial condition of n1.x
is 1.0
and n2.x
is 2.0
. This is not the case, both variable have the same initial value! More concretely:
n1 = @network_component n1 begin
@parameters k = 1.0
@variables x(t) = k
end
n2 = @network_component n2 begin
@parameters k = 2.0
@variables x(t) = k
end
@named sys1 = System([D(n2.x) ~ 0, D(n1.x) ~ 0], t)
prob1 = ODEProblem(complete(sys1))
I get:
ODEProblem with uType Vector{Float64} and tType Nothing. In-place: true
Initialization status: FULLY_DETERMINED
Non-trivial mass matrix: false
timespan: (nothing, nothing)
u0: 2-element Vector{Float64}:
1.0
1.0
So both n1.x
and n2.x
have 1.0
as initial condition. If I swap both equations:
@named sys2 = System([D(n1.x) ~ 0, D(n2.x) ~ 0], t)
prob2 = ODEProblem(complete(sys2))
I get:
ODEProblem with uType Vector{Float64} and tType Nothing. In-place: true
Initialization status: FULLY_DETERMINED
Non-trivial mass matrix: false
timespan: (nothing, nothing)
u0: 2-element Vector{Float64}:
2.0
2.0
both n1.x
and n2.x
have now 1.0
as initial condition.
If I translate this code in ModelingToolkit
as follows:
@mtkmodel Decl1 begin
@parameters begin
k = 1.0
end
@variables begin
x(t) = k
end
end
@mtkmodel Decl2 begin
@parameters begin
k = 2.0
end
@variables begin
x(t) = k
end
end
@mtkmodel Eq begin
@components begin
n1 = Decl1()
n2 = Decl2()
end
@equations begin
D(n2.x) ~ 0
D(n1.x) ~ 0
end
end
@mtkbuild sys3 = Eq()
prob3 = ODEProblem(sys3)
then I get the expected initial conditions:
ODEProblem with uType Vector{Float64} and tType Nothing. In-place: true
Initialization status: FULLY_DETERMINED
Non-trivial mass matrix: false
timespan: (nothing, nothing)
u0: 2-element Vector{Float64}:
1.0
2.0
Is it a bug or a feature of @reaction_component
?