Hi all,
In the past day, I have been reading the documentation on efficiently simulating ModelingToolkit models with different parameters. However, I find the documentation somewhat complex, especially for new users. In my case, I have a very simple system, which consists of a constant input and an integrator:
using ModelingToolkit, Plots, OrdinaryDiffEq
using ModelingToolkit: t_nounits as t, D_nounits as D
using ModelingToolkitStandardLibrary.Blocks
@mtkmodel TestModel begin
@parameters begin
value=3
end
@components begin
InputBlock = Constant(k=value)
IntegratorBlock = Integrator(k=1.0,x=0.0)
end
@equations begin
connect(InputBlock.output,IntegratorBlock.input)
end
end
@mtkbuild system = TestModel()
prob = ODEProblem(system,Pair[],(0,10.0))
sol = solve(prob,Tsit5(), dt=0.001, adaptive=false)
Suppose I want to re-simulate the system by changing the parameter of the constant value that serves as the input, without having to recompile the system. In this case, when I query the parameters, I get the following:
prob.p
First, I noticed that the initial value (in this case, 3) appears twice: once as a constant and once as the input value of the constant block. When trying to re-simulate the system by changing this parameter (for example, to 5), I implemented the following code. However, the solution of the system does not change at all.
p_new = copy(prob.p)
p_new[1][4] = 5
prob2 = remake(prob; p = p_new)
sol2 = solve(prob2,Tsit5(), dt=0.001, adaptive=false)
For this reason, I wonder if this process is incorrect. If it is, I think it would be helpful to have a simple example to understand how remake works. Thanks in advance.
