ModelicaSpecification
ModelicaSpecification copied to clipboard
Default values of experiment annotations
Reported by christiankral on 12 Jun 2018 13:01 UTC In the experiment annotations of the MSL the start time is most of the time not explicitly set. In these cases
annotation(experiment(StartTime=0,...));
seems to be assumed. But this is not stated in writing somewhere -- at least I could not find it. In the MLS there are no default values specified for any experiment option. In order to improve the comparability of simulation results it would make sense to explicitly specify default values of the experiment options in the MLS.
StartTime = 0StopTime = 1Interval = 0.002(seems to be common sense in Dymola and OpenModelica)Tolerance = 1E-6(makes a lot more sense than 1E-4 for most simulations)
So if one of these options is not set explicitly, the default value should be used.
Migrated-From: https://trac.modelica.org/Modelica/ticket/2251
Comment by sjoelund.se on 12 Jun 2018 13:15 UTC Tolerance is not always used, and means slightly different things for different solvers (and needs to be specified if it is a tolerance for the integrator, non-linear solver, etc). So it is slightly difficult to specify this.
Interval = 0.002 only makes sense if roughly StopTime-StartTime = 1 (for sure not if StopTime-StartTime < 0.002). Perhaps it should be specified as a default 499 intervals instead?
Comment by jfrenkel on 12 Jun 2018 13:18 UTC
I agree to specify StartTime, StopTime and Interval. But Tolerance should be left out because it is related to the integration method and should be defined by the tool.
See Chapter 18.4
the default relative integration tolerance (Tolerance)
Comment by hansolsson on 12 Jun 2018 14:22 UTC
Perhaps it should be specified as a default 499 intervals instead?
I agree that number of intervals is more logical for a default (and we use 500 intervals leading to 501 output points in Dymola). However, it generates a dependency on StopTime-StartTime; whereas Interval should depend on some model characteristic time-scale - which makes it a more relevant setting, but trickier to have as default.
Thus I would only say that StartTime and StopTime have defaults.
Comment by stefanv on 12 Jun 2018 14:32 UTC
Didn't Dymola at one time have a NumIntervals setting?
Setting the default for Interval to (StopTime - StartTime) / 500 seems like a good idea for me. Since it just specifies the number of plot points, and screen sizes are pretty much all about the same (within less than an order of magnitude), a default of 500 (or 501) points makes sense.
It is only a default. A model for which it does not make sense is free to override it.
Comment by ottot on 12 Jun 2018 15:41 UTC
Specify StartTime and StopTime makes sense to me, but why specify Interval? If the model has a very specific demand it can specify it otherwise I think we can leave it to the tool to figure out a sensible default (which might not be the same for all models).
Comment by hansolsson on 12 Jun 2018 15:58 UTC
Didn't Dymola at one time have a NumIntervals setting?
It still does in the GUI; you either set that or interval - but:
- It seemed a bit excessive to describe that logic.
- It has the disadvantages I sketched above - and I view NumIntervals more linked to how you test the model whereas Interval is more linked to the time-scales of the model itself.
Comment by henrikt on 12 Jun 2018 20:04 UTC
For a user, thinking in terms of StopTime is probably easier than thinking in terms of Interval. Even though Interval is the property which is most related to the time scale of the model dynamics, also the simulation duration, StopTime - StartTime, typically says something about the time scale. Therefore, a fixed default for Interval would remove the possibility to make an intelligent choice based on the simulation duration. However, I agree with my colleague ottot above, in that we shouldn't prescribe exactly how a tool should compute the default Interval.
I also agree with Martin Sjölund in that specifying a default for Tolerance would be difficult. A suitable default for a solver with good step size control could be much bigger than a suitable default for a solver with poor step size control, and we don't even know what solvers to consider.
Regarding a default for StopTime, SystemModeler currently uses the presence of StopTime as an indication of a model meant for simulation. In addition, since Modelica is used in domains where time scale differs by many orders of magnitude, we really don't have any idea of what a good default would be, and it actually makes sense that at least this part of the experiment annotation is specified for a model meant for simulation. Therefore, I think specifying a default for StopTime would be counter-productive.
I don't have any objections to specifying 0 as a default for StartTime; it may not make sense for all StopTime settings (thinking of somehow specifying a date-time), but I can't see any other value that would make more sense as a default. More important than the default StartTime, however, is that no models in the MSL meant for simulation rely on a default for StopTime.
Comment by ahaumer on 14 Jun 2018 06:06 UTC I agree with Christian, it would make sense to set the experiment annotations explicitely. I'm not sure about the tolerance, it some (or a lot of?) experiments it makes sense. StartTime and StopTime are intuitive and necessary. I totally dislike the "Number of intervals" (unfortunately standard in OpenModelica), I prefer "Interval" (=[StopTime -StartTime]/NumberOfIntervals).
I should have some knowledge about the dynamics of my model, therefore I know about the needs of the Interval to avoid undersampling of the output. There's no general rule to set Interval (or NumberOfIntervals) without knowlede about the model's dynamic.
If I specify NumberOfIntervals and I choose to specify a larger StopTime, I have to adapt the NumberOfIntervals (which I forget to do so often) but I don't have to adapt Interval.
Modified by beutlich on 14 Jun 2018 07:43 UTC
Comment by otter on 14 Jun 2018 15:37 UTC It is clear that it would be best, if StartTime,StopTime,Interval,Tolerance would be explicitely defined for every simulation model. However, if a user would just like to build-up a model and simulate, it would be nice to have some meaningful defaults:
- StartTime is nearly always zero, besides some exceptional case. So StartTime=0 is a good default.
- There is no meaningful default for StopTime. Could be arbitrarily set to StopTime = 1.0 as assumed in the past in the MSL simulation models.
- There is no meaningful default for Interval. As pointed out previously, Interval > StopTime does not make sense. For this reason, Interval is not suited to be used as a default (if only the StopTime is changed, there are always cases where a default for the Interval is nonsense). Instead, NumberOfIntervals = 500 (or 1000), is a reasonable value that is often fine (independent of StopTime). If the dynamics is very fast, there would be also a small StopTime (say stopTime = 0.001) and the NumberOfIntervals might still be o.k. If it is not suited, then the relevant dynamics cannot be seen in a typical plot window and the modeler has to "zoom-in" to the plot. Of course, there are cases where a long simulation is needed, and then NumberOfIntervals=500 is not sufficient and has to be changed.
- The Tolerance depends not only on the variable-step integrator but also on the model (e.g. for mechanical models Tolerance=1e-4 is often sufficient, but for fluid models often Tolerance=1e-6 is needed). Probably, it is useful to use a conservative Tolerance since correctness of the result is more important as efficient simulation and therefore Tolerance=1e-6 might be a reasonable default.
Instead of closing without any action, I suppose that we make some polls on the things not requiring a difficult choice any numbers.
Poll on StartTime:
- Make
StartTimedefault to 0. - No default for
StartTime.
Poll on settings that may be omitted, with tool-dependent defaults:
IntervalToleranceStopTime
I am in favor of setting default StartTime to 0. Is there a way to organize the poll so it's easier to vote instead of adding a comment?
I am in favor of setting default
StartTimeto 0. Is there a way to organize the poll so it's easier to vote instead of adding a comment?
Yes, if we (@HansOlsson) decide to actually poll on this, we'll (he will) associate reactions to the different alternatives.