Closed baggepinnen closed 1 year ago
@ven-k is it possible to define components with @mtkmodel
and make the constructor take input arguments without making those arguments a parameter of the system?
I can confirm that the error goes away with the old implementation of MatrixGain
RN, any input to the component will have to be either a parameter or a variable.
We can have constructor take in an input, here K
, and get the nout = size(K, 2)
and nin = size(K, 1)
and pass them to the component. But nout
and nin
will be the parameters of the component.
But nout and nin will be the parameters of the component.
This would be confusing since they cannot be modified the same way as standard parameters. In general, it would be good to let the @mtkmodel
macro accept arguments like standard functions, the multibody library uses this a lot to select things like how to initialize variables, which orientation representation to use etc.
The issue isn't because of MatrixGain; but it triggers it.
The error stems from the fact that the vs
has array and hence the C is promoted to Union{Float64, Int64, Matrix{Float64}}
. RN it doesn't handle when Boolean values are present.
In the above example, use_support
from Torque
adds the boolean parameter in the vs
.
[ Info: vs = Any[false, 1, 1, 1000, 0.0, 10, [0.12043084138093132 -1.1140463077640161 0.5778026986504824 0.07683217428721806], 1, 1, 0, 1, 1, 2]
In all other cases so far convert(vs
; thus C is promoted to Union{Float64, Int64, Matrix{Float64}}
- here^1.
This isn't an issue with MSL@1, as use_support wasn't a parameter.
Ideally, use_support
should not be included as a parameter. If I after the creation of the model change use_support
before calling solve
, will I get the other branch in this code?
https://github.com/SciML/ModelingToolkitStandardLibrary.jl/blob/main/src/Mechanical/Rotational/utils.jl#L142C1-L149C8
If not, I have now introduced a silent bug where I think that I'm running with support, but the model was created without and is thus incorrect.
If I indeed do get the other branch, then I'm fine with this, but since the other branch changes the number of equations and variables I'm not sure how that would work
This is fixed on the latest MTK and MTKStdlib.
The example below used to work fine (MTKstdlib v1), but now errors with
The problem is related to the parameter
MatrixGain.K
, which in MTKstdlib v1 was a hard-coded constant, while in v2 it's a parameter