ModelicaSpecification icon indicating copy to clipboard operation
ModelicaSpecification copied to clipboard

Clarification on shiftSample with changing intervalCounter of base clock

Open AnHeuermann opened this issue 2 years ago • 3 comments

I'm not sure if I got the definition of shiftSample (16.11 in the Specification) right.

For the following model the intervalCounter of u will change after the second tick. The shiftSample then moves these ticks 3/2, relative to the interval, to the right.

model breakSynchronous
  Integer intervalCnt(start=2);
  Integer cnt(start=0);
  Clock u = Clock(intervalCnt,1);
  Clock s1 = shiftSample(u, 3, 2);
  Real x1(start=0);
  Real x2(start=0);
equation 
   when u then
     cnt = previous(cnt) + 1;
     intervalCnt = if (cnt>=2) then 1 else previous(intervalCnt);
   end when;

   when s1 then
     x2 = previous(x2) + 0.1;
   end when;

   when u then
     x1 = previous(x1) + 0.1;
   end when;
  annotation (experiment(StopTime=6));
end breakSynchronous;

I would expect to get ticks of clock u at times 0.0, 2.0, 3.0, 4.0, 5.0, 6.0 and of sub-clock s1 at times 3.0, 3.5, 4.5, 5.5. Is this the correct interpretation?

Currently neither Dymola or OpenModelica produce these results.

AnHeuermann avatar Nov 19 '21 14:11 AnHeuermann

The text describing the operator may be hard to interpret - or possibly incorrect. The result in Dymola (s1 at 2.5, 3.5, 4.5, 5.5) is consistent with the formula:

You start with: 0.0, 2.0, 3.0, 4.0, 5.0, 6.0 Then you superSample, i.e., you split each sampling interval in 2 parts generating the points superSample(u resolution): 0.0, 1.0, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0 then you remove the first 3 points shiftSample(..., k): 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0 then you remove every other point subSample(..., resolution): 2.5, 3.5, 4.5, 5.5

The other alternative would be problematic and could not work for event clocks.

HansOlsson avatar Nov 19 '21 15:11 HansOlsson

My initial idea for the shiftOperator was, that I need to shift every tick of u by k/resolution * interval(u). So for the first tick of u at time=0.0 I need to shift it by 3/2 * 2. And that would work for the provided examples.

I can follow the resoning behind

You start with: 0.0, 2.0, 3.0, 4.0, 5.0, 6.0 Then you superSample, i.e., you split each sampling interval in 2 parts generating the points superSample(u resolution): 0.0, 1.0, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0 then you remove the first 3 points shiftSample(..., k): 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0 then you remove every other point subSample(..., resolution): 2.5, 3.5, 4.5, 5.5

and that works for me.

But I think what stopped me from trying the formua was, that it is trying to explain shiftSample(u, k, resolution) by using shiftSample(u, k, 1). After thinking a bit about it, it is clear what shiftSample(u, k, 1) should do. But it was not that clear to me at the first time reading it.

Maybe a third example using a base clock with a changing intervalCounter could improve the operator definition?

AnHeuermann avatar Nov 19 '21 15:11 AnHeuermann

Ok, seems like a good idea to add an example.

HansOlsson avatar Dec 07 '21 13:12 HansOlsson