@@ -126,8 +126,8 @@ algorithm
126126 size = BackendDAEUtil . systemSize(isyst);
127127 ErrorExt . setCheckpoint("Pantelites" );
128128 Debug . fcall(Flags . BLT_DUMP , print, "Reduce Index \n " );
129- (syst,shared ,ass1,ass2,arg) =
130- pantelidesIndexReduction1(b,unassignedStates,unassignedEqns,eqns,eqns_1,actualEqn,isyst,ishared,inAssignments1,inAssignments2,inArg);
129+ (syst,shared ,ass1,ass2,arg,_ ) =
130+ pantelidesIndexReduction1(b,unassignedStates,unassignedEqns,eqns,eqns_1,actualEqn,isyst,ishared,inAssignments1,inAssignments2,inArg,{} );
131131 ErrorExt . rollBack("Pantelites" );
132132 // get from eqns indexes the scalar indexes
133133 newsize = BackendDAEUtil . systemSize(syst);
@@ -195,33 +195,36 @@ public function pantelidesIndexReduction1
195195 input array< Integer > inAssignments1;
196196 input array< Integer > inAssignments2;
197197 input BackendDAE . StructurallySingularSystemHandlerArg inArg;
198+ input list< tuple< list< BackendDAE . Equation > ,list< BackendDAE . Equation > ,list< BackendDAE . Equation >>> iNotDiffableMSS;
198199 output BackendDAE . EqSystem osyst;
199200 output BackendDAE . Shared oshared;
200201 output array< Integer > outAssignments1;
201202 output array< Integer > outAssignments2;
202203 output BackendDAE . StructurallySingularSystemHandlerArg outArg;
204+ output list< tuple< list< BackendDAE . Equation > ,list< BackendDAE . Equation > ,list< BackendDAE . Equation >>> oNotDiffableMSS;
203205algorithm
204- (osyst,oshared,outAssignments1,outAssignments2,outArg):=
205- matchcontinue (b,unassignedStates,unassignedEqns,alleqns,iEqns,actualEqn,isyst,ishared,inAssignments1,inAssignments2,inArg)
206+ (osyst,oshared,outAssignments1,outAssignments2,outArg,oNotDiffableMSS ):=
207+ matchcontinue (b,unassignedStates,unassignedEqns,alleqns,iEqns,actualEqn,isyst,ishared,inAssignments1,inAssignments2,inArg,iNotDiffableMSS )
206208 local
207209 list< Integer > states,eqns,eqns_1,ueqns;
208210 list< list< Integer >> statelst,eqnsrest,eqnsrest_1,ueqnsrest;
209211 array< Integer > ass1,ass2;
210212 BackendDAE . EqSystem syst;
211213 BackendDAE . Shared shared ;
212214 BackendDAE . StructurallySingularSystemHandlerArg arg;
213- case (_,_,_,_,{},_,_,_,_,_,_)
215+ list< tuple< list< BackendDAE . Equation > ,list< BackendDAE . Equation > ,list< BackendDAE . Equation >>> notDiffableMSS;
216+ case (_,_,_,_,{},_,_,_,_,_,_,_)
214217 then
215- (isyst,ishared,inAssignments1,inAssignments2,inArg);
216- case (_,states::statelst,ueqns::ueqnsrest,eqns::eqnsrest,eqns_1::eqnsrest_1,_,_,_,_,_,_)
218+ (isyst,ishared,inAssignments1,inAssignments2,inArg,iNotDiffableMSS );
219+ case (_,states::statelst,ueqns::ueqnsrest,eqns::eqnsrest,eqns_1::eqnsrest_1,_,_,_,_,_,_,_ )
217220 equation
218- (syst,shared ,ass1,ass2,arg) =
219- pantelidesIndexReductionMSS(b,states,ueqns,eqns,eqns_1,actualEqn,isyst,ishared,inAssignments1,inAssignments2,inArg);
221+ (syst,shared ,ass1,ass2,arg,notDiffableMSS ) =
222+ pantelidesIndexReductionMSS(b,states,ueqns,eqns,eqns_1,actualEqn,isyst,ishared,inAssignments1,inAssignments2,inArg,iNotDiffableMSS );
220223 // next MSS
221- (syst,shared ,ass1,ass2,arg) =
222- pantelidesIndexReduction1(b,statelst,ueqnsrest,eqnsrest,eqnsrest_1,actualEqn,syst,shared ,ass1,ass2,arg);
224+ (syst,shared ,ass1,ass2,arg,notDiffableMSS ) =
225+ pantelidesIndexReduction1(b,statelst,ueqnsrest,eqnsrest,eqnsrest_1,actualEqn,syst,shared ,ass1,ass2,arg,notDiffableMSS );
223226 then
224- (syst,shared ,ass1,ass2,arg);
227+ (syst,shared ,ass1,ass2,arg,notDiffableMSS );
225228 else
226229 equation
227230 Error . addMessage(Error . INTERNAL_ERROR , {"- IndexReduction.pantelidesIndexReduction1 failed! Use +d=bltdump to get more information." });
@@ -245,14 +248,16 @@ public function pantelidesIndexReductionMSS
245248 input array< Integer > inAssignments1;
246249 input array< Integer > inAssignments2;
247250 input BackendDAE . StructurallySingularSystemHandlerArg inArg;
251+ input list< tuple< list< BackendDAE . Equation > ,list< BackendDAE . Equation > ,list< BackendDAE . Equation >>> iNotDiffableMSS;
248252 output BackendDAE . EqSystem osyst;
249253 output BackendDAE . Shared oshared;
250254 output array< Integer > outAssignments1;
251255 output array< Integer > outAssignments2;
252256 output BackendDAE . StructurallySingularSystemHandlerArg outArg;
257+ output list< tuple< list< BackendDAE . Equation > ,list< BackendDAE . Equation > ,list< BackendDAE . Equation >>> oNotDiffableMSS;
253258algorithm
254- (osyst,oshared,outAssignments1,outAssignments2,outArg):=
255- matchcontinue (b,unassignedStates,unassignedEqns,alleqns,eqns,actualEqn,isyst,ishared,inAssignments1,inAssignments2,inArg)
259+ (osyst,oshared,outAssignments1,outAssignments2,outArg,oNotDiffableMSS ):=
260+ matchcontinue (b,unassignedStates,unassignedEqns,alleqns,eqns,actualEqn,isyst,ishared,inAssignments1,inAssignments2,inArg,iNotDiffableMSS )
256261 local
257262 list< BackendDAE . Var > varlst;
258263 list< Integer > changedeqns,eqns1;
@@ -268,8 +273,8 @@ algorithm
268273 BackendDAE . EquationArray eqnsarray;
269274 BackendDAE . Variables vars;
270275 list< BackendDAE . Equation > notdiffedEqns,diffedEqns,orgeqns;
271-
272- case (true ,_,_,_,_::_,_,BackendDAE . EQSYSTEM (orderedVars= vars,orderedEqs= eqnsarray),_,_,_,(so,orgEqnsLst,mapEqnIncRow,mapIncRowEqn,noofeqns))
276+ list < tuple < list < BackendDAE . Equation > ,list < BackendDAE . Equation > ,list < BackendDAE . Equation >>> notDiffableMSS;
277+ case (true ,_,_,_,_::_,_,BackendDAE . EQSYSTEM (orderedVars= vars,orderedEqs= eqnsarray),_,_,_,(so,orgEqnsLst,mapEqnIncRow,mapIncRowEqn,noofeqns),_ )
273278 equation
274279 // get from scalar eqns indexes the indexes in the equation array
275280 eqns1 = List . map1r(eqns,arrayGet,mapIncRowEqn);
@@ -285,11 +290,11 @@ algorithm
285290 // (syst,shared,ass1,ass2,so1,orgEqnsLst1,mapEqnIncRow,mapIncRowEqn,changedeqns) = differentiateEqns(syst,shared,eqns1,ass1,ass2,so1,orgEqnsLst,mapEqnIncRow,mapIncRowEqn,changedeqns);
286291 // For unrolling errors
287292 (notdiffedEqns,diffedEqns,orgeqns) = differentiateEqnsLst(eqns1,vars,eqnsarray,ishared,{},{},{});
288- (syst,shared ,ass1,ass2,so1,orgEqnsLst1,mapEqnIncRow,mapIncRowEqn) = differentiateEqns(notdiffedEqns,diffedEqns,orgeqns,eqns1,unassignedStates,unassignedEqns,isyst,ishared,inAssignments1,inAssignments2,so,orgEqnsLst,mapEqnIncRow,mapIncRowEqn);
293+ (syst,shared ,ass1,ass2,so1,orgEqnsLst1,mapEqnIncRow,mapIncRowEqn,notDiffableMSS ) = differentiateEqns(notdiffedEqns,diffedEqns,orgeqns,eqns1,unassignedStates,unassignedEqns,isyst,ishared,inAssignments1,inAssignments2,so,orgEqnsLst,mapEqnIncRow,mapIncRowEqn,iNotDiffableMSS );
289294 then
290- (syst,shared ,ass1,ass2,(so1,orgEqnsLst1,mapEqnIncRow,mapIncRowEqn,noofeqns));
295+ (syst,shared ,ass1,ass2,(so1,orgEqnsLst1,mapEqnIncRow,mapIncRowEqn,noofeqns),notDiffableMSS );
291296
292- case (_,_,_,_,{},_,_,_,_,_,(_,_,_,mapIncRowEqn,_))
297+ case (_,_,_,_,{},_,_,_,_,_,(_,_,_,mapIncRowEqn,_),_ )
293298 equation
294299 Debug . fcall(Flags . BLT_DUMP , print, "Reduce Index failed! Found empty set of continues equations. \n marked equations: \n " );
295300 // get from scalar eqns indexes the indexes in the equation array
@@ -302,7 +307,7 @@ algorithm
302307 then
303308 fail();
304309
305- case (false ,_,_,_,_::_,_,_,_,_,_,(_,_,_,mapIncRowEqn,_))
310+ case (false ,_,_,_,_::_,_,_,_,_,_,(_,_,_,mapIncRowEqn,_),_ )
306311 equation
307312 Debug . fcall(Flags . BLT_DUMP , print, "Reduce Index failed! System is structurally singulare and cannot handled because number of unassigned equations is larger than number of states. \n marked equations: \n " );
308313 // get from scalar eqns indexes the indexes in the equation array
@@ -318,7 +323,7 @@ algorithm
318323 Error . addMessage(Error . INTERNAL_ERROR , {"IndexReduction.pantelidesIndexReduction1 failed! System is structurally singulare and cannot handled because number of unassigned equations is larger than number of states. Use +d=bltdump to get more information." });
319324 then
320325 fail();
321- case (_,_,_,_,_,_,_,_,_,_,(_,_,_,mapIncRowEqn,_))
326+ case (_,_,_,_,_,_,_,_,_,_,(_,_,_,mapIncRowEqn,_),_ )
322327 equation
323328 syst = BackendDAEUtil . setEqSystemMatching(isyst,BackendDAE . MATCHING (inAssignments1,inAssignments2,{}));
324329 Debug . fcall(Flags . BLT_DUMP , BackendDump . dumpBackendDAE, BackendDAE . DAE ({syst},ishared));
@@ -717,6 +722,7 @@ protected function differentiateEqns
717722 input BackendDAE . ConstraintEquations inOrgEqnsLst;
718723 input array< list< Integer >> imapEqnIncRow;
719724 input array< Integer > imapIncRowEqn;
725+ input list< tuple< list< BackendDAE . Equation > ,list< BackendDAE . Equation > ,list< BackendDAE . Equation >>> iNotDiffableMSS;
720726 output BackendDAE . EqSystem osyst;
721727 output BackendDAE . Shared oshared;
722728 output array< Integer > outAss1;
@@ -725,9 +731,10 @@ protected function differentiateEqns
725731 output BackendDAE . ConstraintEquations outOrgEqnsLst;
726732 output array< list< Integer >> omapEqnIncRow;
727733 output array< Integer > omapIncRowEqn;
734+ output list< tuple< list< BackendDAE . Equation > ,list< BackendDAE . Equation > ,list< BackendDAE . Equation >>> oNotDiffableMSS;
728735algorithm
729- (osyst,oshared,outAss1,outAss2,outStateOrd,outOrgEqnsLst,omapEqnIncRow,omapIncRowEqn):=
730- matchcontinue (notDiffedEquations,inDiffEqns,inOrgEqns,inEqns,unassignedStates,unassignedEqns,isyst,ishared,inAss1,inAss2,inStateOrd,inOrgEqnsLst,imapEqnIncRow,imapIncRowEqn)
736+ (osyst,oshared,outAss1,outAss2,outStateOrd,outOrgEqnsLst,omapEqnIncRow,omapIncRowEqn,oNotDiffableMSS ):=
737+ match (notDiffedEquations,inDiffEqns,inOrgEqns,inEqns,unassignedStates,unassignedEqns,isyst,ishared,inAss1,inAss2,inStateOrd,inOrgEqnsLst,imapEqnIncRow,imapIncRowEqn,iNotDiffableMSS )
731738 local
732739 Integer eqnss,eqnss1;
733740 BackendDAE . EquationArray eqns_1,eqns;
@@ -743,7 +750,7 @@ algorithm
743750 array< Integer > ass1,ass2,mapIncRowEqn;
744751 array< list< Integer >> mapEqnIncRow;
745752 // all equations are differentiated
746- case ({},_,_,_,_,_,BackendDAE . EQSYSTEM (v,eqns,SOME (m),SOME (mt),matching),_,_,_,_,_,_,_)
753+ case ({},_,_,_,_,_,BackendDAE . EQSYSTEM (v,eqns,SOME (m),SOME (mt),matching),_,_,_,_,_,_,_,_ )
747754 equation
748755 eqnss = BackendDAEUtil . equationArraySize(eqns);
749756 (v1,eqns_1,so,ilst,orgEqnsLst) = replaceDifferentiatedEqns(listReverse(inEqns),inDiffEqns,inOrgEqns,v,eqns,inStateOrd,mt,imapIncRowEqn,{},inOrgEqnsLst);
@@ -764,9 +771,13 @@ algorithm
764771 Debug . fcall(Flags . BLT_DUMP , BackendDump . debuglst,(eqnslst1,intString," " ," \n " ));
765772 (syst,mapEqnIncRow,mapIncRowEqn) = BackendDAEUtil . updateIncidenceMatrixScalar(syst,BackendDAE . SOLVABLE (), eqnslst1, imapEqnIncRow, imapIncRowEqn);
766773 then
767- (syst,ishared,ass1,ass2,so,orgEqnsLst,mapEqnIncRow,mapIncRowEqn);
774+ (syst,ishared,ass1,ass2,so,orgEqnsLst,mapEqnIncRow,mapIncRowEqn,iNotDiffableMSS );
768775 // not all equations are differentiated
769- case (_::_,_,_,_,_,_,BackendDAE . EQSYSTEM (orderedVars= v,mT = SOME (mt)),_,_,_,_,_,_,_)
776+ /* case (_::_,_,_,_,_,_,BackendDAE.EQSYSTEM(orderedVars=v,mT = SOME(mt)),_,_,_,_,_,_,_,_)
777+ then
778+ (isyst,ishared,inAss1,inAss2,inStateOrd,inOrgEqnsLst,imapEqnIncRow,imapIncRowEqn,(notDiffedEquations,inDiffEqns,inOrgEqns)::iNotDiffableMSS);
779+ */ // not all equations are differentiated
780+ case (_::_,_,_,_,_,_,BackendDAE . EQSYSTEM (orderedVars= v,mT = SOME (mt)),_,_,_,_,_,_,_,_)
770781 equation
771782 Debug . fcall(Flags . BLT_DUMP ,print,"notDiffedEquations: \n " );
772783 Debug . fcall(Flags . BLT_DUMP ,BackendDump . dumpEqns,notDiffedEquations);
@@ -787,8 +798,8 @@ algorithm
787798 (syst,shared ,ass1,ass2,so,orgEqnsLst,mapEqnIncRow,mapIncRowEqn) =
788799 handleundifferntiableMSS(intEq(listLength(ilst),listLength(unassignedEqns)),ilst,notDiffedEquations,inDiffEqns,inOrgEqns,inEqns,unassignedStates,unassignedEqns,isyst,ishared,inAss1,inAss2,inStateOrd,inOrgEqnsLst,imapEqnIncRow,imapIncRowEqn);
789800 then
790- (syst,shared ,ass1,ass2,so,orgEqnsLst,mapEqnIncRow,mapIncRowEqn);
791- end matchcontinue ;
801+ (syst,shared ,ass1,ass2,so,orgEqnsLst,mapEqnIncRow,mapIncRowEqn,iNotDiffableMSS );
802+ end match ;
792803end differentiateEqns;
793804
794805protected function searchDerivativesEqn "function searchDerivativesEqn
@@ -1049,7 +1060,7 @@ algorithm
10491060 then
10501061 fail();
10511062*/
1052-
1063+
10531064 // if size of unmatched eqns is not equal to size of states without used derivative change first to algebraic
10541065 // until I have a better sulution
10551066 case (false ,i::ilst,_,_,_,_,_,_,BackendDAE . EQSYSTEM (v,eqns,SOME (m),SOME (mt),matching),_,_,_,_,_,_,_)
@@ -1072,12 +1083,14 @@ algorithm
10721083 (syst,mapEqnIncRow,mapIncRowEqn) = BackendDAEUtil . updateIncidenceMatrixScalar(syst,BackendDAE . SOLVABLE (), eqnslst1, imapEqnIncRow, imapIncRowEqn);
10731084 then
10741085 (syst,ishared,inAss1,inAss2,inStateOrd,inOrgEqnsLst,mapEqnIncRow,mapIncRowEqn);
1075-
1076- case (false ,_,_,_,_,_,_,_,BackendDAE . EQSYSTEM (v,eqns,SOME (m),SOME (mt),matching),_,_,_,_,_,_,_)
1086+
1087+ case (_ ,_,_,_,_,_,_,_,BackendDAE . EQSYSTEM (v,eqns,SOME (m),SOME (mt),matching),_,_,_,_,_,_,_)
10771088 equation
10781089 varlst = List . map1r(unassignedStates,BackendVariable . getVarAt,v);
10791090 Debug . fcall(Flags . BLT_DUMP , print, "unassignedStates \n " );
10801091 Debug . fcall(Flags . BLT_DUMP , BackendDump . printVarList, varlst);
1092+ // syst = BackendDAEUtil.setEqSystemMatching(isyst,BackendDAE.MATCHING(inAss1,inAss2,{}));
1093+ // dumpSystemGraphML(syst,ishared,NONE(),"IndexReductionFailed.graphml");
10811094 then
10821095 fail();
10831096 end matchcontinue;
@@ -3843,13 +3856,15 @@ algorithm
38433856 list< BackendDAE . WhenClause > wclst;
38443857 list< BackendDAE . Var > varlst,varlst1;
38453858 BackendDAE . Var var ;
3859+ DAE . Type tp;
38463860 case ({},_,_,_,_,_,_,_,_,_,_,_,_)
38473861 equation
38483862 crconexppre = DAE . CALL (Absyn . IDENT ("pre" ), {contexp}, DAE . callAttrBuiltinReal);
38493863 e1 = generateSetExpressions(ifexplst,index- 1 ,crconexppre);
38503864 e2 = generateSetExpressions(ifdexplst,index- 1 ,crconexppre);
38513865 eqn = Util . if_(intGt(rang,1 ),BackendDAE . ARRAY_EQUATION ({rang},crsetexp,e1,DAE . emptyElementSource),BackendDAE . EQUATION (crsetexp,e1,DAE . emptyElementSource));
3852- deqn = Util . if_(intGt(rang,1 ),BackendDAE . ARRAY_EQUATION ({rang},DAE . CALL (Absyn . IDENT ("der" ),{crsetexp},DAE . callAttrBuiltinReal),e2,DAE . emptyElementSource),BackendDAE . EQUATION (DAE . CALL (Absyn . IDENT ("der" ),{crsetexp},DAE . callAttrBuiltinReal),e2,DAE . emptyElementSource));
3866+ tp = Expression . typeof(crsetexp);
3867+ deqn = Util . if_(intGt(rang,1 ),BackendDAE . ARRAY_EQUATION ({rang},DAE . CALL (Absyn . IDENT ("der" ),{crsetexp},DAE . CALL_ATTR (tp,false ,true ,DAE . NO_INLINE (),DAE . NO_TAIL ())),e2,DAE . emptyElementSource),BackendDAE . EQUATION (DAE . CALL (Absyn . IDENT ("der" ),{crsetexp},DAE . callAttrBuiltinReal),e2,DAE . emptyElementSource));
38533868 startvalues = generateStartExpressions(istartvalues,index- 1 ,contstartExp);
38543869 varlst = setVarLstStartValue(isetvarlst,startvalues,{});
38553870 then
@@ -3878,8 +3893,11 @@ protected function makeder
38783893Author: Frenkel TUD 2012-09"
38793894 input DAE . Exp inExp;
38803895 output DAE . Exp outExp;
3896+ protected
3897+ DAE . Type tp;
38813898algorithm
3882- outExp := DAE . CALL (Absyn . IDENT ("der" ),{inExp},DAE . callAttrBuiltinReal);
3899+ tp := Expression . typeof(inExp);
3900+ outExp := DAE . CALL (Absyn . IDENT ("der" ),{inExp},DAE . CALL_ATTR (tp,false ,true ,DAE . NO_INLINE (),DAE . NO_TAIL ()));
38833901end makeder;
38843902
38853903protected function changeVarToStartValue "
@@ -5244,7 +5262,8 @@ algorithm
52445262 eqns = BackendEquation . daeEqns(isyst);
52455263 // (_,m,mt) = BackendDAEUtil.getIncidenceMatrix(isyst,BackendDAE.NORMAL());
52465264 // mapIncRowEqn = listArray(List.intRange(arrayLength(m)));
5247- (_,m,mt,_,mapIncRowEqn) = BackendDAEUtil . getIncidenceMatrixScalar(isyst,BackendDAE . SOLVABLE ());
5265+ // (_,m,mt,_,mapIncRowEqn) = BackendDAEUtil.getIncidenceMatrixScalar(isyst,BackendDAE.SOLVABLE());
5266+ (_,m,mt,_,mapIncRowEqn) = BackendDAEUtil . getIncidenceMatrixScalar(isyst,BackendDAE . NORMAL ());
52485267 graph = GraphML . getGraph("G" ,false );
52495268 ((_,_,graph)) = BackendVariable . traverseBackendDAEVars(vars,addVarGraphMatch,(1 ,vec1,graph));
52505269 // neqns = BackendDAEUtil.equationArraySize(eqns);
0 commit comments