Regarding your root comment using the explicit interpolation parameter:
Could you give an example for how you’re creating the model? The code snippet only includes the model definition. In addition, I would recommend specifying a more concrete type than Function
for type stability. If you want to swap out the function after building the model, you could go the FunctionWrapper
route and declare it as I_L(::Float64)::Float64
.
As for the second approach using ParametrizedInterpolation
:
I got rid of the explicit parameter method and replaced it by
ParametrizedInterpolation
:
There are two problems with this model:
ParametrizedInterpolation
is created outside the @mtkmodel
and used inside. This doesn’t include it as a subcomponent. It seems that the way ParametrizedInterpolation
is defined prevents it from being used inside @components
, which is something the standard library should probably fix. In the meantime, the last few lines of function SingleDiode
should be:
@named sys = Single_Diode()
sys = compose(sys, [I_L])
structural_simplify(sys)
The second problem is the reason your system is unbalanced. The ParametrizedInterpolation
needs an input, using which it samples the data. It does not sample with respect to time by default. If you wish to sample with respect to time, you can add I_L.input.u ~ t
to the equations.
An additional performance enhancement for this approach:
Judging from the root comment, it seems you do not need the interpolation data as a parameter. In such a case, you can replace ParametrizedInterpolation
with Interpolation
, which simply stores the interpolant as a callable symbolic.