#3675 closed enhancement (fixed)
Add interactive simulation support (e.g., DynamicSelect display)
Reported by: | Dietmar Winkler | Owned by: | Adeel Asghar |
---|---|---|---|
Priority: | high | Milestone: | 1.18.1 |
Component: | OMEdit | Version: | v1.9.4-dev-nightly |
Keywords: | DynamicSelect iPSL | Cc: |
Description
OMEdit is missing one nice feature that allows to make models more expressive: interactive simulation support and with this the support of the DynamicSelect
annotation.
One typical user case can be found in the iPSL library where it is used to visualise power flows. Something that is really nice to have.
Change History (21)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Just to increase the pressure: http://www.claytex.com/blog/using-dynamicselect-in-icons/ (via today's twitter message)
;-)
comment:3 by , 8 years ago
PR41 starts by replacing %par
macros with simulation results. This is particularly useful for steady-state models.
Support for DynamicSelect
would require, besides a time slider, the evaluation of expressions with variables from the model. Meaning we would need a small Modelica interpreter supporting a subset of the language. This appears also needed to eventually adapt the GUI to model values, e.g. for conditional connectors #2081.
A good thing with the "light" version in PR41 is that one can have multiple models active at the same time without messing up values of variables between them in the GUI.
comment:4 by , 8 years ago
How could DynamicSelect be implemented rigorously?
Currently OMC passes annotation strings to OMEdit and OMEdit parses them. This is duplicate work because OMC parses them as well. This is why OMC might pass two parsed expressions to OMEdit:
- an expression with constant values for the static case
- an (otional) expression with variables for the dynamic case, accomplished with a list of variables used in the expression
OMEdit first uses the static expression. After simulation it passes the dynamic expression along with a list of instantiated variables to OMC for evaluation. The result of the evaluation is used to update the graphics.
This new API can be prototyped with dynamic texts provided by PR41 and then extended to other annotations.
comment:5 by , 8 years ago
A new version of the pull request implements DynamicSelect rigorously -- as much as missing expression evaluation on OMEdit side permits. See https://github.com/OpenModelica/OMEdit/pull/45
comment:6 by , 8 years ago
OMEdit PR 46 introduces DynamicSelect for visible
attributes. This is a quite universal and powerful feature (anything that changes conditionally).
From my side I'm satisfied for now with dynamic texts and dynamic visibility.
comment:7 by , 8 years ago
Is there any documentation on how to perform interactive simulation (or animation) in OMEdit?
comment:8 by , 8 years ago
It's just being built. First, there is a new menu "Simulate with Animation". This opens a 3D animation window in the plotting perspective after simulation. Useful for MultiBody examples.
This ticket is about animating the Model diagram with DynamicSelect
annotations. Since this week this works for textString
and visible
. The former can be seen e.g. with Modelica.Fluid.Examples.Tanks.ThreeTanks
-- you see the numerical values of the tank levels in the model diagram after simulation.
You may uncheck
Tools->Options->Simulation->Switch to plotting perspective after simulation
to stay in the modeling pane.
The major limitation is lacking evaluation of expressions on OMEdit side, meaning that the DynamicSelect statements must contain variables of the model, no expressions with variables.
The visible
attribute isn't used by MSL to my knowledge, but very powerful to implement any kind of conditional changes with just one attribute. Something like interactive simulation in the Modelica.StateGraph library could be implemented with visible
. Modelica.StateGraph uses if statements for multiple graphical attributes instead. Support for this should also be easy to implement -- provided someone fixes the wrong annotations in Modelica.Stategraph
from:
model Foo Boolean active = true; annotation(... if active > 0.5 then ...); end Foo;
(Compare Boolean with Real??) to
annotation(... if active then ...);
It would become correct and the expression would be lost.
A second limitation is a missing slider to replay simulation results, see #4108.
comment:9 by , 8 years ago
I played a bit with the DynamicSelect
and there seems to be a bug with string concatenation.
Example
textString=DynamicSelect("0.0", String(V, significantDigits=3))
works but
textString=DynamicSelect("0.0", String(V, significantDigits=3))+" Volts"
does break the display (works in Dymola is probably needless to say ;-) )
And yes my thumbs up on the need for expression evaluation(e.g., visible=DisplayValues
) and the slider.
comment:10 by , 8 years ago
visible=DisplayValues
should work if DisplayValues
is a variable available for plotting. visible=not DisplayValues
should not work, because evaluation of expressions is not supported -- except for String conversion. The same holds for string concatenation. It's not a bug. The current implementation could either be extended gradually, to support e.g. boolean negation and string concatenation -- makes sense if many examples would benefit from it -- you might just do it and issue a pull request.
Alternatively / eventually some rigorous evaluation of expressions should be introduced.
comment:11 by , 8 years ago
So in this case DisplayValues
is a parameter one sets in order to either display or not.
Here the actual code from OpenIPSL:
Definition of Boolean parameter: https://github.com/SmarTS-Lab/OpenIPSL/blob/master/OpenIPSL/Electrical/Branches/PwLine.mo#L22
Usage:
https://github.com/SmarTS-Lab/OpenIPSL/blob/master/OpenIPSL/Electrical/Branches/PwLine.mo#L73
and OMEdit does not display the DynamicSelect part at all.
comment:13 by , 8 years ago
So I created a minimal example. First of all I thought simply testing it out on the Diagram layer. Turns out Dynamic select does not work for the diagram layer of a model itself:
model TestDynamicSelect parameter Boolean displayValue = true; Real x; equation x=10*time; annotation( Diagram(graphics = {Text(origin = {0, 0}, extent = {{-20, 20}, {20, -20}}, visible=displayValue, textString = DynamicSelect("0.0", String(x, significantDigits = 2)))})); end TestDynamicSelect;
You will notice that it will not work.
So I added the same to the Icon layer and put it in a model:
model TestDynamicSelect parameter Boolean displayValue = true; Real x; equation x=10*time; annotation( Diagram(graphics = {Text(origin = {0, 0}, extent = {{-20, 20}, {20, -20}}, visible=displayValue, textString = DynamicSelect("0.0", String(x, significantDigits = 2)))}), Icon(graphics = {Text(origin = {-40, 40}, extent = {{-20, 20}, {20, -20}}, visible=displayValue, textString = DynamicSelect("0.0", String(x, significantDigits = 2)))})); end TestDynamicSelect;
Now this would work when used in a model like:
model test TestDynamicSelect testDynamicSelect1 annotation( Placement(transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); end test;
But set displayValue = false
in TestDynamicSelect
and then use it via modification:
model test TestDynamicSelect testDynamicSelect1(displayValue = true) annotation( Placement(transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); end test;
The dynamic select type is still set to false anyway.
comment:14 by , 6 years ago
DynamicSelect support is slightly improved in OMEdit in b3569f0/OpenModelica. Now there is a new Diagram window in the plotting perspective which shows the animation of the model based on the result file. There are controls in the Variables Browser e.g., slider to move back and forth in the animation.
However, we still only support visible and textString graphical attributes. There is still no way to evaluate the expressions.
Both the examples by Dietmar works now i.e., DynamicSelect on the diagram layer and on the icon layer inside a component.
comment:15 by , 6 years ago
As far as I can tell from playing with this. DynamicSelect for now only can display the initial value and only in the modelling pane. The new diagram window in the simulation pane stays blank. Is that observation correct?
comment:16 by , 6 years ago
With
OMEdit 1.11.0~1-gf048cec Connected to OpenModelica 1.14.0~dev-5914-g99eb5ee
It now shows the described behaviour. Despite crashing a bit ;-)
comment:17 by , 5 years ago
Can someone clarify what is the current status of Diagram Animation feature?
UserGuide said
The browser also contains the slider and animation buttons. These controls are used for variable graphics and schematic animation of models i.e., DynamicSelect annotation. They are also used for debugging of state machines. Open the Diagram Window for animation.
but when I try to get this, for example for Modelica.Fluid.Examples.Tanks.EmptyTanks I get a static diagram - no animation.
Windows 7 SP1 64-bit
OMEdit v1.13.2 (64-bit) Connected to v1.13.2 (64-bit) Connected to OMSimulator v2.0.1-mingw
comment:18 by , 5 years ago
This is still WIP.
However, you should read the documentation provided with your installation instead of the latest one.
comment:20 by , 3 years ago
Milestone: | 2.0.0 → 1.18.1 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
For this we would need:
See section *Variable Graphics and Schematic Animation* in the spec.