Opened 8 years ago

Closed 8 years ago

#4312 closed defect (invalid)

Discrete event example does not work

Reported by: janK Owned by: somebody
Priority: normal Milestone: Future
Component: *unknown* Version:
Keywords: Discrete event example Cc:

Description

Hi, I'm struggeling with an example from the Modelica Tutorial (https://www.modelica.org/documents/ModelicaRationale13norev.pdf) on page 29:

block DiscreteStateSpace2 
parameter Real a, b, c, d;
parameter Real Period=1;
input Real u;
discrete output Real y;
discrete Real x, NextSampling(start=0); 

equation
when time >= pre(NextSampling) then 
  x = a*pre(x) + b*u;
  y = c*pre(x) + d*u;
  NextSampling = time + Period;
end when;
end DiscreteStateSpace2;

NextSampling will be zero for all times. Is this a bug or is the code wrong? Replacing equation with algorithm didn't change the behavior.

Change History (5)

comment:1 Changed 8 years ago by janK

Well... Changing line 9 to
when {time >= pre(NextSampling), initial()} then
will solve the problem... Is this normal or is this a bug?

comment:2 Changed 8 years ago by lochel

This is just a rather bad model. If the when clause should be evaluated at the beginning, then it would be reasonable to add initial() to the condition. If the first evaluation of the when clause should be performed after the first period, then one could either change the when condition to time > pre(NextSampling) or, even better, change the definition of NextSampling to discrete Real x, NextSampling(start=Period, fixed=true).

comment:3 Changed 8 years ago by lochel

Or you could take the model as it is and start the simulation before time=0, e.g. at startTime = -0.1.

comment:4 Changed 8 years ago by janK

Thank you for your fast response! So it is not a bug but the model is just really bad? - I mean this is an example code from an official tutorial (well a rather old one from 1999...). If it is not a bug, you can close the ticket of course.

comment:5 Changed 8 years ago by lochel

  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.