ModelingToolkit.jl
ModelingToolkit.jl copied to clipboard
Specify variable scope
Would it be possible to specify the variable scope in the @variables
macro?
Like:
@variables p [scope = ParentScope]
What is your use case? We have thought about this a bit, because it becomes useful if you want to have lambda expressions that one can pattern match, but still wondering if it's worth the increase in complexity of implementation.
In Modelica there is the notion of a medium. Which is propagated to the components of the model. Simscape has this too. My idea is to specify the properties of the medium via a component and lift the corresponding parameters in all other components into the parent scope.
The macro would just be for a nicer syntax.
See this PR for an implementieren of the idea: https://github.com/SciML/ModelingToolkitStandardLibrary.jl/pull/78/files#diff-eb1be027e9de472ab7ab428be392b14eeb634c9cad7df9309ebcc0025e6e175fR37-R50
I have an old branch that performs "clock inference", i.e., determines what clock partition a variable or equations belongs to. Clock partitions become relevant when you have both continuous and discrete systems, and potentially many different clocks for different discrete systems. This is quite similar in the sense that the clock partition for a variable is automatically inferred based on surrounding variables. The logic is quite complicated, so if the two problems are sufficiently similar, it'd be nice to have a good way of doing these kinds of things