Skip to content
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

Derivative of step signal by CombiTimeTable #3115

Closed
beutlich opened this issue Sep 10, 2019 · 3 comments · Fixed by #3370
Closed

Derivative of step signal by CombiTimeTable #3115

beutlich opened this issue Sep 10, 2019 · 3 comments · Fixed by #3370
Assignees
Labels
discussion Discussion issue that it not necessarily related to a concrete bug or feature L: Blocks Issue addresses Modelica.Blocks
Milestone

Comments

@beutlich
Copy link
Member

Discontinous signals can/should not be differentiated:

model M1
  Real y=if time <= 0.5 then 0 else 1;
  Real yd=der(y);
end M1;

This has been considered in #1147 when implementing the constant interpolation of CombiTimeTable:

model M2
  Real yd=der(combiTimeTable.y[1]);
  Modelica.Blocks.Sources.CombiTimeTable combiTimeTable(
    table=[0,0;0.5,1;1,1],
    smoothness=Modelica.Blocks.Types.Smoothness.ConstantSegments);
end M2;

However, using linear interpolation of CombiTimeTable and duplicated sample points we successfully can model a discontinuous signal and get its derivative.

model M3
  Real yd=der(combiTimeTable.y[1]);
  Modelica.Blocks.Sources.CombiTimeTable combiTimeTable(
    table=[0,0;0.5,0;0.5,1;1,1]);
end M3;

This seems inconsistent, if not even wrong. Since linear interpolation with duplicated sample points was one of the designed features of the CombiTimeTable it would be a major loss if we'd deprecate it. I have no good idea how to solve this inconsistency and would like to get @HansOlsson's and @MartinOtter's feedback,

@beutlich beutlich added L: Blocks Issue addresses Modelica.Blocks discussion Discussion issue that it not necessarily related to a concrete bug or feature labels Sep 10, 2019
beutlich added a commit to beutlich/ModelicaStandardLibrary that referenced this issue Sep 10, 2019
@MartinOtter
Copy link
Member

In Modelica it is possible to model a discontinuous signal and then differentiate it as shown in your example M1. The differentiation of a table is in a similar spirit. In general, it seems hard (impossible) to detect such issues at compile time and therefore this needs to be detected during simulation. This in turn means that this is a tool issue (if a differentiation would lead to a Dirac impulse, and this is not supported by the tool, then at least a warning message needs to be printed). As I recall, in fact Dymola can detect some cases of this kind during run-time.

@beutlich
Copy link
Member Author

beutlich commented Sep 11, 2019

Yes, Dymola simulation fails for models M1 and M2 at time 0.5s. With the knowledge of #1147 this is as expected. However, M3 models the same step signal using the same block (CombiTimeTable) but shows different behaviour when differentiating. I'd like to fix it (or at least document it) if @HansOlsson and @MartinOtter also think that it is misuse of the linear interpolation with duplicated sample points.

@HansOlsson
Copy link
Contributor

The only possibility would be to add another Boolean flag, or interpolation-variant indicating whether duplicated are allowed or not.

If duplicated points are allowed we, similarly as for constant-segments, forbid differentiation.
If duplicated points are not allowed we allow differentiation; and generate a diagnostic in case of duplicated points.

I don't know how impactful this will be - but I guess it depends on the severity of the diagnostics, and how easy it is to set the flag.

It seems problematic in general to skip the flag and generate the diagnostics when differentiated during simulation, as the derivative is also used in systems of equations, and sometimes dynamic state-selection will cause additional differentiation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Discussion issue that it not necessarily related to a concrete bug or feature L: Blocks Issue addresses Modelica.Blocks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants