Hey,
I should have followed up. I figured out a workaround by declaring the same variables in the function and the executing script. Likely not ideal but works fine for now:
using ModelingToolkit, DifferentialEquations
function init_vars()
@parameters g
@variables t, x(t), y(t), c_gp(t)
@parameters r_g C_α C_φ g C_e
return t, x, y, c_gp, g
end
function init_ODE(u)
t, x, y, c_gp, g = init_vars()
D = Differential(t)
particle_equations = [
c_gp ~ - x./ g,
D(x) ~ c_gp ,
D(y) ~ x- u(t)
]
return particle_equations
end
u(t) = 7 + 2.0 .* sin.(t .* π ./(60*30))
t, x, y, c_gp, g = init_vars()
z0 = [ x => 0.0, y => 0.0]
params = [ g => 9 ]
@named particle_system0 = ODESystem( init_ODE(u) )
particle_system1 = structural_simplify(particle_system0)
problem = ODEProblem(particle_system1, z0, (0.0, 60*60) , params)
sol = solve(problem, saveat=60*5)
Both functions can then be put in a module and called from another script.