ModelingToolkitStandardLibrary.jl icon indicating copy to clipboard operation
ModelingToolkitStandardLibrary.jl copied to clipboard

Let default constructor initialize the GUIMetadata type

Open zsoerenm opened this issue 2 years ago • 5 comments

Something like this would be helpful e.g.

function Resistor(; name, R)
    @named oneport = OnePort()
    @unpack v, i = oneport
    pars = @parameters R = R
    eqs = [
        v ~ i * R,
    ]
    extend(ODESystem(eqs, t, [], pars; name = name, gui_metadata = GUIMetadata("Resistor")), oneport)
end

Maybe a symbol would fit better than a string?

zsoerenm avatar Feb 10 '23 09:02 zsoerenm

This seems misguided. Will this just be the same as the type name that would then be used for better lowering. @YingboMa should we just add that first?

ChrisRackauckas avatar Feb 11 '23 14:02 ChrisRackauckas

Should we always instantiate a component like

@component function Resistor(; name, R)
    @named oneport = OnePort()
    @unpack v, i = oneport
    pars = @parameters R = R
    eqs = [
        v ~ i * R,
    ]
    extend(ODESystem(eqs, t, [], pars; name = name), oneport)
end

?

YingboMa avatar Feb 11 '23 16:02 YingboMa

I think so. And it would make a Val(:Resistor) type information or something?

ChrisRackauckas avatar Feb 11 '23 16:02 ChrisRackauckas

We then have to assume all the components are instantiated in the same world age, but I guess it's a fair assumption.

And it would make a Val(:Resistor) type information or something?

Since it would be a very simple type system within MTK, we would use some other encoding that's independent from Julia's so that we don't take unnecessary compile time hit.

YingboMa avatar Feb 11 '23 16:02 YingboMa

oh yes no val. But yeah, let's go this route.

ChrisRackauckas avatar Feb 11 '23 16:02 ChrisRackauckas