Skip to content

Commit

Permalink
Fixed Timetable-bug
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2748 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Håkan Lundvall committed Mar 13, 2007
1 parent ab19942 commit 70d9df0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
7 changes: 5 additions & 2 deletions Compiler/SimCodegen.mo
Expand Up @@ -3363,7 +3363,7 @@ algorithm
equation
vLst = DAELow.varList(v);
vLst = Util.listSelect(vLst,DAELow.isVarDiscrete); // select all discrete vars.
outString = Util.stringDelimitList(Util.listMap2(vLst, buildDiscreteVarChangesVar,daelow,mT),"\n");
outString = Util.stringDelimitList(Util.listMap2(vLst, buildDiscreteVarChangesVar,daelow,mT),"\n ");
then outString;
case(_,_,_,_,_,_) equation
print("buildDiscreteVarChanges failed\n");
Expand Down Expand Up @@ -3568,7 +3568,10 @@ algorithm
res = Util.stringAppendList(
{"int checkForDiscreteVarChanges()\n{\n",
" int needToIterate=0;\n",
check_code_1,check_code2_1,"\n return needToIterate;\n","}\n"});
check_code_1," ",check_code2_1,
"\n for (long i = 0; i < localData->nHelpVars; i++) {\n",
" if (change(localData->helpVars[i])) { needToIterate=1; }\n }",
"\n return needToIterate;\n","}\n"});
then
(res,helpVarInfo);
case (_,_,_,_,_,_,_)
Expand Down
25 changes: 20 additions & 5 deletions c_runtime/simulation_events.cpp
Expand Up @@ -178,17 +178,24 @@ void CheckForInitialEvents(double *t)

void CheckForNewEvents(double *t)
{
int discVarChange=0;
// int discVarChange=0;
// Check for changes in discrete variables
globalData->timeValue = *t;
// if discrete variable not in when equation has changed, saveall and solve equations again.
/*
while(checkForDiscreteVarChanges()) {
discVarChange=1;
saveall();
function_updateDependents(); }
function_updateDependents();
}
if(!discVarChange) function_updateDependents();
*/

if (checkForDiscreteVarChanges()) {
AddEvent(-1);
}

function_zeroCrossing(&globalData->nStates,
&globalData->timeValue,
globalData->states,
Expand Down Expand Up @@ -216,11 +223,14 @@ ExecuteNextEvent(double *t)
{
if (EventQueue.begin() != EventQueue.end()) {
long nextEvent = EventQueue.front();
if (nextEvent >= globalData->nZeroCrossing) {
if (sim_verbose) {
printf("Executing event id:%d\n",nextEvent);
}
if (nextEvent >= globalData->nZeroCrossing) {
globalData->timeValue = *t;
function_when(nextEvent-globalData->nZeroCrossing);
}
else {
else if (nextEvent >= 0) {
globalData->timeValue = *t;
handleZeroCrossing(nextEvent);
function_updateDependents();
Expand All @@ -240,11 +250,16 @@ StartEventIteration(double *t)
while (EventQueue.begin() != EventQueue.end()) {
calcEnabledZeroCrossings();
while (ExecuteNextEvent(t)) { }
for (long i = 0; i < globalData->nHelpVars; i++) save(globalData->helpVars[i]);
// for (long i = 0; i < globalData->nHelpVars; i++) save(globalData->helpVars[i]);
saveall();
globalData->timeValue = *t;
function_updateDependents();
CheckForNewEvents(t);
}
for (long i = 0; i < globalData->nHelpVars; i++) {
// globalData->helpVars[i] = 0;
// save(globalData->helpVars[i]);
}
// cout << "EventIteration done" << endl;
}

Expand Down
3 changes: 3 additions & 0 deletions c_runtime/simulation_runtime.cpp
Expand Up @@ -108,6 +108,9 @@ double newTime(double t, double step,double stop)
*/
void storeExtrapolationData()
{
if (globalData->timeValue == globalData->oldTime)
return;

int i;
for(i=0;i<globalData->nStates;i++) {
globalData->oldStates2[i]=globalData->oldStates[i];
Expand Down

0 comments on commit 70d9df0

Please sign in to comment.