-
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
structural_simplify
cannot deal with algebraic equations of array variables
#3292
Comments
This is not a bug with |
I thought about that and tried to add a |
It works the same way for all array variables: |
Oops, I misunderstood: you meant setting the default inside @mtkmodel Foo begin
@variables begin
arr(t)[1:4] = ones(4)
end
end You just need to set the value to an array of the appropriate size. |
But in that way it won't work, since those values are also considered initial conditions and then the problem will become overdetermined and will error... is there any way to give those value in the |
Even for julia> @mtkmodel CST begin
@structural_parameters begin
NC = 1
end
@parameters begin
Q = 2.0
V = 1.0
c_in[1:NC] = [1.0 for i in 1:NC]
end
@variables begin
cin(t)[1:NC] = nothing
cout(t)[1:NC] = zeros(NC)
end
@equations begin
[D(cout)[i] ~ Q/V * (cin[i] - cout[i]) for i in 1:NC]
cin ~ c_in
end
end
julia> @mtkbuild m = CST()
julia> prob = ODEProblem(m, [], (0.0, 5.0))
ODEProblem with uType Vector{Float64} and tType Float64. In-place: true
timespan: (0.0, 5.0)
u0: 1-element Vector{Float64}:
0.0 |
Perfection, it worked like a charm. Thank you. Is there any plan to change this behaviour or should this approach be standard? |
The incorrect default is a bug and will be fixed. You shouldn't have to specify a default of |
I see. Interestingly, it only affects array variables, scalar variables have no issue |
I'm trying to implement a model of a Continuously Stirred Tank with multiple components. I first started assuming there was only one component:
This one works perfectly. Afterwards I wanted to add multiple components by using array variables:
However, running this example:
I get the error:
I can circumvent it by:
However this is not ideal. I want to escale this to second order PDEs where the space discretization is by Orthogonal Collocation, which has algebraic equations in the boundary conditions and in the nodes between the collocation elements, where I can't use this workaround.
To note that by transforming this to a DAE form:
And then using
complete
:Works fine. However this is not ideal because
structural_simplify
eliminates a lot of equations from the system and I would prefer to use it. Can it be done usingstructural_simplify
?using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
Additional context
I know sometimes the problem might be in the WSL environment, by I also reproduced the error in Windows 11.
The text was updated successfully, but these errors were encountered: