@@ -468,7 +468,9 @@ protected
468468 BackendDAE . SubClock subClock;
469469 BackendDAE . StrongComponent comp;
470470 Integer eqIdx, varIdx, parentIdx;
471+ MMath . Rational clockFactor;
471472algorithm
473+ clockFactor := MMath . RAT1 ;
472474 outSubClocks := arrayCreate(BackendVariable . varsSize(inVars), (BackendDAE . DEFAULT_SUBCLOCK , 0 ));
473475 for comp in inComps loop
474476 outClockKind := matchcontinue comp
@@ -482,9 +484,7 @@ algorithm
482484 case BackendDAE . SOLVED_EQUATION (exp = e) then e;
483485 end match;
484486 (clockKind, (subClock, parentIdx)) := getSubClock(exp, inVars, outSubClocks);
485- if parentIdx <> varIdx then
486- arrayUpdate(outSubClocks, varIdx, (subClock, parentIdx));
487- else
487+ if parentIdx == varIdx then
488488 // can't determine clock from var itself;
489489 // use alternative exp of unsolved equation instead
490490 exp := match eq
@@ -494,16 +494,21 @@ algorithm
494494 else exp;
495495 end match;
496496 (clockKind, (subClock, parentIdx)) := getSubClock(exp, inVars, outSubClocks);
497- arrayUpdate(outSubClocks, varIdx, (subClock, parentIdx));
498497 end if ;
498+ (clockKind, clockFactor) := setClockKind(outClockKind, clockKind, clockFactor);
499+ if parentIdx == 0 then
500+ // adapt uppermost subClock in the tree
501+ subClock. factor := MMath . multRational(subClock. factor, clockFactor);
502+ end if ;
503+ arrayUpdate(outSubClocks, varIdx, (subClock, parentIdx));
499504 /*
500505 print("var " + intString(varIdx) + ": " +
501506 BackendDump.equationString(eq) + " ->\n " +
502507 ExpressionDump.printExpStr(exp) + ": " +
503508 BackendDump.subClockString(subClock) +
504509 " with parent " + intString(parentIdx) + ".\n");
505510 */
506- then setClockKind(outClockKind, clockKind) ;
511+ then clockKind;
507512 else
508513 algorithm
509514 print("internal error -- SynchronousFeatures.resolveClocks failure \r\n " );
@@ -617,39 +622,48 @@ end getSubClock1;
617622protected function setClockKind
618623 input DAE . ClockKind inOldClockKind;
619624 input DAE . ClockKind inClockKind;
625+ input MMath . Rational inClockFactor;
620626 output DAE . ClockKind outClockKind;
627+ output MMath . Rational outClockFactor;
621628algorithm
622- outClockKind := match (inOldClockKind, inClockKind)
629+ ( outClockKind, outClockFactor) := match (inOldClockKind, inClockKind)
623630 local
624631 DAE . Exp e1, e2;
625- Integer i1, i2;
632+ Integer i1, i2, ie1, ie2 ;
626633 Real r1, r2;
627634 String s1, s2;
628- case (DAE . INFERRED_CLOCK (), _) then inClockKind;
629- case (_, DAE . INFERRED_CLOCK ()) then inOldClockKind;
635+ case (DAE . INFERRED_CLOCK (), _) then ( inClockKind, inClockFactor) ;
636+ case (_, DAE . INFERRED_CLOCK ()) then ( inOldClockKind, inClockFactor) ;
630637 case (DAE . INTEGER_CLOCK (intervalCounter = e1, resolution = i1),
631638 DAE . INTEGER_CLOCK (intervalCounter = e2, resolution = i2))
632639 guard
633640 Expression . expEqual(e1, e2) and
634641 (i1 == i2)
635- then inClockKind;
642+ then (inClockKind, inClockFactor);
643+ case (DAE . INTEGER_CLOCK (intervalCounter = e1, resolution = i1),
644+ DAE . INTEGER_CLOCK (intervalCounter = e2, resolution = i2))
645+ // stay with old clock and adapt clock factor to new clock
646+ algorithm
647+ DAE . ICONST (ie1) := e1;
648+ DAE . ICONST (ie2) := e2;
649+ then (inOldClockKind, MMath . divRational(MMath . multRational(inClockFactor, MMath . RATIONAL (ie2, i2)), MMath . RATIONAL (ie1, i1)));
636650 case (DAE . REAL_CLOCK (interval = e1),
637651 DAE . REAL_CLOCK (interval = e2))
638652 guard
639653 Expression . expEqual(e1, e2)
640- then inClockKind;
654+ then ( inClockKind, inClockFactor) ;
641655 case (DAE . BOOLEAN_CLOCK (condition = e1, startInterval = r1),
642656 DAE . BOOLEAN_CLOCK (condition = e2, startInterval = r2))
643657 guard
644658 Expression . expEqual(e1, e2) and
645659 (r1 == r2)
646- then inClockKind;
660+ then ( inClockKind, inClockFactor) ;
647661 case (DAE . SOLVER_CLOCK (c = e1, solverMethod = s1),
648662 DAE . SOLVER_CLOCK (c = e2, solverMethod = s2))
649663 guard
650664 Expression . expEqual(e1, e2) and
651665 stringEqual(s1, s2)
652- then inClockKind;
666+ then ( inClockKind, inClockFactor) ;
653667 else
654668 equation Error . addMessage(Error . CLOCK_CONFLICT , {});
655669 then fail();
0 commit comments