@@ -85,7 +85,7 @@ algorithm
8585 (outEqSys, outSysIdx) := matchcontinue(inEqSys)
8686 local
8787 Integer numSimpEqs, numVars, numSimpVars;
88- array< Integer > eqMapArr,varMapArr,nonLoopEqMark;
88+ array< Integer > eqMapArr,varMapArr,nonLoopEqMark,markLinEqVars ;
8989 list< Integer > eqMapping, varMapping, eqCrossLst, varCrossLst;
9090 list< list< Integer >> partitions, loops;
9191 list< tuple< Boolean ,String >> varAtts,eqAtts;
@@ -101,18 +101,19 @@ algorithm
101101
102102 case syst as BackendDAE . EQSYSTEM (orderedVars= vars, orderedEqs= eqs)
103103 equation
104+ (m,_) = BackendDAEUtil . incidenceMatrix(syst, BackendDAE . ABSOLUTE (), NONE ());
104105 if Flags . isSet(Flags . RESOLVE_LOOPS_DUMP ) then
105106 BackendDump . dumpBipartiteGraphEqSystem(syst,inShared, "whole System_" + intString(inSysIdx));
106107 end if ;
107108 // BackendDump.dumpEqSystem(syst,"the complete DAE");
108109
109110 // get the linear equations and their vars
110- (simpEqLst,eqMapping,_,_) = BackendEquation . traverseEquationArray(eqs, getSimpleEquations, ({},{},1 ,vars));
111+ markLinEqVars = arrayCreate(BackendVariable . varsSize(vars),-1 );
112+ (simpEqLst,eqMapping,_,_,markLinEqVars,_) = BackendEquation . traverseEquationArray(eqs, getSimpleEquations, ({},{},1 ,vars,markLinEqVars,m));
111113 eqMapArr = listArray(eqMapping);
114+ (simpVarLst,varMapArr) = getSimpleEquationVariables(markLinEqVars,vars);
115+
112116 simpEqs = BackendEquation . listEquation(simpEqLst);
113- crefs = BackendEquation . getAllCrefFromEquations(simpEqs);
114- (simpVarLst,varMapping) = BackendVariable . getVarLst(crefs,vars);
115- varMapArr = listArray(varMapping);
116117 simpVars = BackendVariable . listVar1(simpVarLst);
117118
118119 // build the incidence matrix for the linear equations
@@ -306,28 +307,54 @@ end arrayEntryLengthIs;
306307protected function getSimpleEquations
307308"if the linear equation contains only variables with factor 1 or -1 except for the states."
308309 input BackendDAE . Equation inEq;
309- input tuple< list< BackendDAE . Equation > , list< Integer > , Integer , BackendDAE . Variables > inTpl;
310+ input tuple< list< BackendDAE . Equation > , list< Integer > , Integer , BackendDAE . Variables , array < Integer > , BackendDAE . IncidenceMatrix > inTpl;
310311 output BackendDAE . Equation outEq = inEq;
311- output tuple< list< BackendDAE . Equation > , list< Integer > , Integer , BackendDAE . Variables > outTpl;
312+ output tuple< list< BackendDAE . Equation > , list< Integer > , Integer , BackendDAE . Variables , array < Integer > , BackendDAE . IncidenceMatrix > outTpl;
312313protected
313314 Boolean isSimple;
314315 Integer idx;
315316 BackendDAE . Equation eq;
317+ BackendDAE . IncidenceMatrix m;
316318 BackendDAE . Variables vars;
319+ array< Integer > markLinEqVars;
317320 list< BackendDAE . Equation > eqLst;
318321 list< Integer > idxMap;
319322algorithm
320- (eqLst, idxMap, idx, vars) := inTpl;
323+ (eqLst, idxMap, idx, vars, markLinEqVars, m ) := inTpl;
321324 if BackendEquation . isEquation(inEq) and not eqIsConst(inEq)/* simple assignments should not occur here, they cannot be improved any further*/ then
322325 (eq,(isSimple,_)) := BackendEquation . traverseExpsOfEquation(inEq,isAddOrSubExp,(true ,vars));
323326 if isSimple then
324327 eqLst := eq::eqLst;
325328 idxMap := idx::idxMap;
329+ for varIdx in m[idx] loop
330+ arrayUpdate(markLinEqVars,intAbs(varIdx),1 );
331+ end for ;
326332 end if ;
327333 end if ;
328- outTpl := (eqLst,idxMap,idx+ 1 ,vars);
334+ outTpl := (eqLst,idxMap,idx+ 1 ,vars,markLinEqVars,m );
329335end getSimpleEquations;
330336
337+ protected function getSimpleEquationVariables"
338+ Get the variables which occur in the linear equations and have been marked in the markLinEqVars array.
339+ author:Waurich 2017-07"
340+ input array< Integer > markLinEqVars;
341+ input BackendDAE . Variables vars;
342+ output list< BackendDAE . Var > simpVars= {};
343+ output array< Integer > varMapArr;
344+ protected
345+ Integer varIdx;
346+ list< Integer > varMap;
347+ algorithm
348+ varMap := {};
349+ for varIdx in List . intRange(arrayLength(markLinEqVars)) loop
350+ if markLinEqVars[varIdx] > 0 then
351+ varMap := varIdx::varMap;
352+ simpVars := BackendVariable . getVarAt(vars, varIdx)::simpVars;
353+ end if ;
354+ end for ;
355+ varMapArr := listArray(varMap);
356+ end getSimpleEquationVariables;
357+
331358public function resolveLoops_findLoops "author:Waurich TUD 2014-02
332359 gets the crossNodes for the partitions and searches for loops"
333360 input list< list< Integer >> partitionsIn;
0 commit comments