ModelingToolkitStandardLibrary.jl
ModelingToolkitStandardLibrary.jl copied to clipboard
Provide keyword-free constructors for single-arg components
It would be nice if we could provide a constructor that does not require a keyword argument for components that are typically associated with a single parameter. Some examples are
- Resistor
- Capacitor
- Inertia
- Spring
- Damper
Even if these component constructors do sometimes take more than one argument (initial state etc.) there is arguably one parameter that is going to be the only one provided most of the time.
This could be achieved with a macro applied to the constructor definitions, e.g.,
@positional C function Capacitor(;name, C, v_start=0.0)
...
end
where C
indicates the keyword argument that is to be provided as the single positional argument in the alternative constructor.
Alternatively, the positional constructor could be the default and the macro would add a method that takes the keyword arg instead of the positional:
@add_keyword function Capacitor(C; name, v_start=0.0)
...
end
This would remove the need to remember keywords in many common cases. For example, I always call spring constants k
, but the keyword in MTKSL is c
.