Hello,
I am trying to move my models to the new ModelingToolkit framework and so far everything works nicely and it creates the models nicely.
For simplicity I refer here to the example as outlined in Acausal Component-Based Modeling the RC Circuit · ModelingToolkit.jl - my model is similar enough (more complex network, and a driving function), but the issue arises in the tutorial case as well.
Obviously the first run takes longer due to compile time, and the second run will be blisteringly fast.
However, I have not found a way yet to change the parameters (R, C) and rerun the model without incurring a recompilation.
My optimisation problem will need to change the model parameters (R and C) and rerun the model many times, so I need to find a way to make these parameters act in a similar way than when I define the ODEs manually.
I hope that it’s just my lack of understanding of how the model generation works and it is a rather simple solution.
The driving function is defined as:
systcos(t) = sin(2pi * t) < 0 ? 0 : 1 - cos(2pi * t)^2
@register systcos(t)
and has a similar problem. If I change the function or one of the parameters, then I need to go through the compose
, structural_simplify
, and ODAEProblem
steps, which means it will recompile the solve
step.
Edit:
The driving function component looks like this:
function DrivenCurrent(;name, I=1.0, fun)
@named oneport = OnePort()
@unpack i = oneport
ps = @parameters I = I
eqs = [
i ~ - I * fun(t)
]
extend(ODESystem(eqs, t, [], ps; name=name), oneport)
end
@named source = DrivenCurrent(I=I, fun=systcos)