Opened 17 years ago
Last modified 17 years ago
#144 closed defect (fixed)
improper event interferrence of trapezoid blocks
Reported by: | Pavol Privitzer | Owned by: | Pavol Privitzer |
---|---|---|---|
Priority: | blocker | Milestone: | |
Component: | Version: | ||
Keywords: | Cc: | Pavol Privitzer, Adrian Pop |
Description
see the comments.
Attachments (1)
Change History (6)
by , 17 years ago
Attachment: | bugTrapez.onb added |
---|
comment:1 by , 17 years ago
Created an attachment (id=25)
OMNotebook file to reproduce the bug.
I am using the OpenModelica-NIGHTLY-BUILD-2008_01_14-02_53.msi
This is probably bug similar or the same as bug 157 - "Pulse + Trapezoid Blocks fail", but I have found another example, probably simpler to debug.
Model to reproduce the bug consist of just two Trapeziod blocks:
model bugTrapez
Modelica.Blocks.Sources.Trapezoid trap1( startTime=0.1, rising=0.45);
Modelica.Blocks.Sources.Trapezoid trap2( startTime=0.5, rising=0.5);
end bugTrapez;
The end of rising of the trap1.y resets the rising of the trap2.y.
The value of parameter trap1.rising=0.45 is important to cause the bug,
e.g. with trap1.rising=0.5, the bug will not occur.
See attached bugTrapez.onb for detail.
comment:2 by , 17 years ago
Well, I tried to find the bug in the code myself,
and here is my first look at it:
The sample() function in simulation_events.cpp causes the problem:
double sample(double start ,double interval)
{
double sloop = 4.0/interval;
if (inSample == 0) return 0;
double tmp = ((globalData->timeValue - start)/interval);
tmp-= floor(tmp);
if (tmp >= 0 && tmp < 0.1)
return 1;
else
return 0;
}
When another event occurs during the 0.1 interval, the sample is still active,
... that is the sample event has 0.1 long "duration",
but it should have 0 duration. It should be an instant,
just be active when corresponding Sample() crosses zero.
Maybe there was an intent to solve this with the inSample variable,
but it's not working.
I am new here, please respond to me,
if you are reading this and if you are working on the bug.
I will be trying on to fix it,
one idea is to implement the sampling through time scheduling,
when the solver is stopped always "on time".
Best regards
Pavol
comment:3 by , 17 years ago
Hi,
I have a fix for this, I looked into it too.
I still have to test it a bit more thou' as
some of the tests are failing.
I will push the changes in the subversion and
in a new nightly-build as soon as I can.
This is my temporary fix for the sample function.
Of course as you say, the event should be generated
exactly as that time, not checked like this.
We'll change the code to generate the event directly,
but it will take some time.
/*
- Returns true and triggers time events at time instants
- start + i*interval (i=0,1,...).
- During continuous integration the operator returns always false.
- The starting time start and the sample interval interval need to
- be parameter expressions and need to be a subtype of Real or Integer. */
double sample(double start, double interval)
{
double sloop = 4.0/interval;
if (inSample == 0) return 0;
double tmp = ((globalData->timeValue - start)/interval);
tmp-= floor(tmp);
if (tmp >= 0 && tmp < 0.05)
{
if (sim_verbose)
cout << "Calling sample(" << start << ", " << interval << ")\n"
<< "+generating an event at time:" << globalData->timeValue << " tmp: " << tmp << endl;
return 1;
}
else
{
if (sim_verbose)
cout << "Calling sample(" << start << ", " << interval << ")\n"
<< "-NO an event at time:" << globalData->timeValue << " tmp: " << tmp << endl;
return 0;
}
}
Do you want me to build a nightly-build with this fix?
Cheers,
Adrian Pop/
comment:4 by , 17 years ago
Hi,
I see, you are not sleeping yet ... ok, ok, I did't mean the bug that serious ;)
I can build the sim.lib myself, thanks a lot.
Where can I find, what are you working on these days ?
Have you a project plan ?
I would like to join your development team :)
Then, specially, I would like to make a port of OpenModelica to the .NET platform or generally to another target platform/language (C#, Java, ActionScript),
are there some similar plans about it?
I've already started with some little experiments and it's promising.
Say hallo to Håkan, Peter and Jan, it was nice to meet them at Eurosim in Ljublana :)
Cheers
Pavol
PS: maybe, if you use Skype, my account name is PavolPr,
we can talk ...
OMNotebook file to reproduce the bug.