-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “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? Sign in to your account
Evaluate parameters with intended structural impact in Mechanics #3113
Evaluate parameters with intended structural impact in Mechanics #3113
Conversation
I'm unsure what this intends to say: I don't see that having the same equation systems is a goal for portability. Obviously we want different tools to generate the same solution, but that doesn't imply that we need the same equation systems. However, many of them influence state-selection and in those cases I agree that at least having the same number of states is a really good idea. I also note that this PR creates two kinds of issues:
If we compare with the introduction of "const functions" in C++ we notice that this ripple effect can be a major concern, especially since we don't have any standard way of circumventing this. |
While the implication same solution ⇒ same equation systems isn't true at all (we can easily process equation systems to take different forms, use other variables to express them, etc), it should also be clear that solving different equation systems will lead to different solutions in general. This is of particular importance for non-linear systems at initialization and events, since how to best provide guess values ( With all the trickiness involved in mixed systems, it should also be clear that getting fundamentally different mixed systems in different tools is a very likely cause for finding different solutions. With this in mind, I think that doing what can be done to allow different tools to end up with equivalent equation systems should be a clear prerequisite for portability of simulation results.
Yes, then the simulations at least belong to the same universe. |
We are talking about
Yes, at least it seems right that they shouldn't appear as parameters. For now, they are given a |
The current solution is:
All this looks fine to me. Your proposed solution
would be an alternative to the current pattern with Your argument is:
But this is also clear with the current solution, so it seems to be no argument at all to change the current solution. Note, "Evaluate=true" is only a suggestion and a tool can ignore it, but if a tool is ignoring it, it should cope with the variable structure (e.g. automatically re-compile the model when the parameter is changed). I checked with Dymola and in Dymola constants with a Dialog annotation do not appear in a parameter menu. I did not check what the specification says here. The effect is that changing This means, it is not possible to accept this pull request now. Instead a longer process is needed, by which Modelica specification and tools agree. But as I clearly wrote: The current solution and pattern looks good, so why changing it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me some time to figure out the solution - and then @MartinOtter had already described it.
However, I also noticed that the parameters in question differ slightly, which is part of the problem as these different categories are not obvious.
For useQuaternions
and enforceStates
it seems quite "challenging" for a tool to not evaluate them.
For exact
it seems entirely possible to not evaluate, but Dymola has long had the heuristic that the conditions of if-then-else equations are evaluated, if possible.
I believe that evaluate exact=false
is the fast variant, and evaluated exact=true
and unevaluated exact gives the same performance. Following Martin's statements we should ensure that exact-parameters have Evaluate=true.
There are reasons for using
|
Having a logic that relies on what is challenging and what is not is also a problem for tools, as one may not know from the beginning what will be considered challenging enough to evaluate parameters in the end. If all things that are allowed to be evaluated during translation were declared This is why I want to make it explicit that |
OK, I wasn't expecting any tool to ignore a |
I checked with SimulationX 4.0.2 and in SimulationX constants with a Dialog annotation do not appear in a properties window. Of course, this can be adapted if there is agreement to change this behaviour. |
Thanks for checking this. I've now opened modelica/ModelicaSpecification#2413 for this specific question. |
Just to make this clear: The Modelica Language group should clarify the recommended implementation of this feature, then the tools should support it and then something can be changed in MSL. I still think that the current pattern is fine. |
The very similar #3119 was just resolved by setting If I see support for doing this with |
@MartinOtter When accepting the suggestion |
I agree that with that proposed change it would be ok. These parameters are such that they basically have to be structural parameters, in contrast to e.g., axis n for Revolute joint which may have Evaluate=true to optionally evaluate it for performance. |
@henrikt-ma Please go ahead with the proposed changes. Thanks. |
There are if-equations that would be unbalanced unless useQuaternions is evaluated during translation; using Evaluate=true makes this evaluation somewhat more transparent to users, and tools don't have to go all the way to determining equation sizes in order to see that useQuaternions must be evaluated. This is the fallback solution that is applied because turning useQuaternions into 'constant' was rejected in modelica#3113. There was one case of useQuaternions with Evaluate=true before this change, so this also fixes a consistency issue.
State selection happens during translation, so it makes no sense to pretend that these are normal parameters that might not require evaluation during translation. This is the fallback solution that is applied because turning enforceStates into 'constant' was rejected in modelica#3113. There was one case of enforceStates with Evaluate=true before this change, so this also fixes a consistency issue.
This is the fallback solution that is applied because turning 'exact' into 'constant' was rejected in modelica#3113. As noted in the affected MultiBody parts, the 'exact' variable has impact on the structure of the equations. In order to get the desired performance benefit, the tool needs to know that it is allowed and expected to use the value of 'exact' during translation. For the Rotational and Translational parts, there are initial if-equations that become unbalanced unless 'exact' is evaluated during translation. This is made clear to the user by setting the variability to constant just like in MultiBody.
faff696
to
961fb22
Compare
Done. The old commits with |
There are merge conflicts. Did you rebase on current HEAD? |
Sorry, failed to do that. Will be fixed right away. |
There are if-equations that would be unbalanced unless useQuaternions is evaluated during translation; using Evaluate=true makes this evaluation somewhat more transparent to users, and tools don't have to go all the way to determining equation sizes in order to see that useQuaternions must be evaluated. This is the fallback solution that is applied because turning useQuaternions into 'constant' was rejected in modelica#3113.
State selection happens during translation, so it makes no sense to pretend that these are normal parameters that might not require evaluation during translation. This is the fallback solution that is applied because turning enforceStates into 'constant' was rejected in modelica#3113. There was one case of enforceStates with Evaluate=true before this change, so this also fixes a consistency issue.
This is the fallback solution that is applied because turning 'exact' into 'constant' was rejected in modelica#3113. As noted in the affected MultiBody parts, the 'exact' variable has impact on the structure of the equations. In order to get the desired performance benefit, the tool needs to know that it is allowed and expected to use the value of 'exact' during translation. For the Rotational and Translational parts, there are initial if-equations that become unbalanced unless 'exact' is evaluated during translation. This is made more transparent to the user by setting the Evaluate=true just like in MultiBody.
961fb22
to
eff6e78
Compare
Fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now.
The PR is limited to
Modelica.Mechanics
. It changes some components declaredparameter
to beconstant
instead in order to make clear to both users and tools that they can and are expected to be evaluated during translation.This kind of change is an important part of making a library portable between tools, since differences in which parameters that are turned into constants during translation will lead to different equation systems in different tools.
By trying to do this systematically instead of case by case when needed, we get a consistent and predictable user experience when dealing with these variables. Also, when all existing, say,
enforceStates
have the same variability, there is little risk of getting the wrong variability when creating a new component with anenforceStates
variable.That said, the variables affected by this PR have been selected based on improved compatibility with Wolfram SystemModeler.