-
-
Notifications
You must be signed in to change notification settings - Fork 217
could the @structure_parameters of descendant models the main model calls be assigned simultaneously during @mtkbuild? Add the global variable feature? #2848
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? No Sign in to your account
Comments
@AayushSabharwal or @ven-k just handled something of the sort? |
This feature is great, but will take time to implement. If it had been handled, how to use, where is the code modification in the corresponding section of
|
Maybe, like: |
I can see this being possible, but specifically only for
What if you have two resistors in a model, one of which has a heat port and one doesn't? Or if you have two child components which just so happen to have identically named structural parameters (think something trivial like
I'm not aware of any such syntax 😅
Interesting concept. Assuming we propagate structural parameters up this would lower to something like Rc(; ConditionalHeatPort__useHeatPort = true) |
Rc model call Resistor, Resistor call ConditionalHeatPort, and ConditionalHeatPort has a structural parameter of useHeatPort. They are all
that is, when @mtkbuild, MTK already allows assigning parameters and structural parameters to child models, but not to grandchild models. If support many levels like "resistor__conditionalHeatPort__ ... __useHeatPort", it would be very nice. @AayushSabharwal |
Because MTK does not support argument "resistor__conditionalHeatPort__useHeatPort" now, In fact, the three structural parameters mean the same thing, but in the current MTK version, they cannot use the same variable name, so I need to think about how to name them using different strings (
|
Yes, these are also possible application scenarios. I don't know whether MTK needs the keywords Thank you very much @AayushSabharwal |
Yeah. The macro doesn't propagate down multiple levels of the hierarchy yet.
That's interesting. What happens when you give all of them the same name? |
It's OK now @AayushSabharwal .
Now, the same string "useHeatPort" as following is OK.
|
propagating down multiple levels, is a required feature. |
The MTK modeling process seems to be as follows:
@structural_parameters determine the model structure. Only after the model structure is determined can a specific ODESystem be obtained, so structural parameters can not be assined by
@parameters
. The@parameter
assignment of ODEsystem is very easy and can be done after@mtkbuild
, but structural parameters should be assigned during@mtkbuild
.Is your feature request related to a problem? Please describe.
For the case of a hierarchical ModelingToolkit.model, that is, model A calls B, B calls C, @structural_parameters assignent is a bit difficult. Take the RC system code of Issue #2758 as example, The current solution is as follows.
resistorUseHeatPort
,use_Heat_Port
,useHeatPort
are the structural parameter of modelRc
,Resistor
,ConditionalHeatPort
, respectively. In fact, these three structural parameters mean the same thing. In the current MTK version, they cannot use the same variable name, so I need to think about how to name them using different strings.For this hierarchical model
Rc
, I must pass the structural_parameters step by step, likeResistor(; use_Heat_Port=resistorUseHeatPort)
, andConditionalHeatPort(; useHeatPort=use_Heat_Port)
inResistor
again, and then I can bulid ODESystem using@mtkbuild sys = Rc(; resistorUseHeatPort=true)
Describe the solution you’d like
For the
@mtkmodel
style, not@component function
style:(1) Is there a better way to pass @structural_parameters in hierarchical models? When the main model is instantiated using
@mtkbuild
, could the structure parameters of its child, grandchild, descendant models it calls be assigned simultaneously? like@mtkbuild sys = Rc(; structural_param=..., child's_structural_param=..., grandchild's__structural_param=...)
, assigning all stucture parameters of the called descendant models at one time.In current MTK version, it seems that:
the
@parameters
of child model the main model calls could be assigned by double _ , like@mtkbuild sys = Rc(; resistor__R=100)
, but it doesn't work for grandchild models and structure parameters, that is,resistor__conditionalHeatPort__T=300
Error,resistor__use_Heat_Port=true
Error.(2) Is it possible to add global variable features? If the structure parameter could be declared as a global variable,
resistorUseHeatPort
,use_Heat_Port
,useHeatPort
could use the same name such asuse_heat_port
, and we don't need to pass the structural parameter step by step, we could do it as follows:@mtkbuild sys = Rc(; use_head_port=true)
, theuse_heat_port
value inResistor()
ConditionalHeatPort()
is automatically that ofuse_heat_port
inRc
, becauseuse_heat_port
is a global variable. ---- other related keywords: protected, private, public, ...@structural_parameters
is useful. Sometimes, we can use the Juliafunction ifelse()
, but sometimesif... else... statement
is necessary for the model construction by @mtkmodel.Thanks a lot for you all @ChrisRackauckas
The text was updated successfully, but these errors were encountered: