I have some ModelingToolkit model that works when importing via using. Because of a name conflict, I need to import MTK as import ModelingToolkit as mtk instead. The following code works with using.... What modifications do I need to do if I use import...?
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using OrdinaryDiffEq
#
@mtkmodel Model begin
@structural_parameters begin
nonlinear = true
end
#
@parameters begin
a = 2
b = 3
end
#
@variables begin
x(t) = 1
end
@equations begin
if nonlinear
D(x) ~ -a*x -b*x^3
else
D(x) ~ -a*x
end
end
end
#
@mtkcompile m_n = Model()
@mtkcompile m_L = Model(;nonlinear=false)
This works.
When I change using ModelingToolkit to import ModelingToolkit as mtk, do I also need to do something with the import of time and derivative?
What about the macros? Do I need to change @mtkmodel to @mtk.mtkmodel? What about @parameters, etc.?
using ModelingToolkit: @mtkmodel, @structural_parameters, @parameters, @variables, @equations, @mtkcompile
using ModelingToolkit: t_nounits as t, D_nounits as D
using OrdinaryDiffEq
and get warnings:
WARNING: Imported binding ModelingToolkit.@structural_parameters was undeclared at import time during import to Main.
WARNING: Imported binding ModelingToolkit.@equations was undeclared at import time during import to Main.
UndefVarError: `ModelingToolkit` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Hint: ModelingToolkit is loaded but not imported in the active module Main.
Stacktrace:
[1] __Model__(; name::Symbol, nonlinear::Bool, a::ModelingToolkit.NoValue, b::ModelingToolkit.NoValue, x::ModelingToolkit.NoValue)
@ Main C:\Users\Bernt\.julia\packages\ModelingToolkit\b28X4\src\systems\model_parsing.jl:159
[2] __Model__
@ C:\Users\Bernt\.julia\packages\ModelingToolkit\b28X4\src\systems\model_parsing.jl:159 [inlined]
[3] #_#432
@ C:\Users\Bernt\.julia\packages\ModelingToolkit\b28X4\src\systems\model_parsing.jl:25 [inlined]
[4] top-level scope
@ C:\Users\Bernt\.julia\packages\ModelingToolkit\b28X4\src\systems\abstractsystem.jl:2152
Hm. I decided it was probably simpler to do using ModelingToolkit and instead import the other package as import Molly as mly. The conflict between these is that both appear to expose a System constructor.