diff --git a/Compiler/BackEnd/HpcOmScheduler.mo b/Compiler/BackEnd/HpcOmScheduler.mo index d098390f213..515b9753ac0 100644 --- a/Compiler/BackEnd/HpcOmScheduler.mo +++ b/Compiler/BackEnd/HpcOmScheduler.mo @@ -3443,42 +3443,40 @@ protected function TDS_replaceSimEqSysIndex "author: Waurich TUD 2014-07 input array assIn; output SimCode.SimEqSystem simEqOut; algorithm - simEqOut := matchcontinue(simEqIn,assIn) + simEqOut := matchcontinue(simEqIn) local - Boolean partOfMixed; - Integer newIdx, oldIdx, indexNonLinearSystem, indexLinearSystem, nUnknowns; - array ass; - SimCode.SimEqSystem simEqSys; - list eqs; - list vars; - list crefs; - list beqs; - list> simJac; - Option jacobianMatrix; - list sources; - Boolean homotopySupport; - Boolean mixedSystem, tornSystem; - BackendDAE.EquationAttributes eqAttr; - case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(eqs=eqs,crefs=crefs,indexNonLinearSystem=indexNonLinearSystem,nUnknowns=nUnknowns,jacobianMatrix=jacobianMatrix,homotopySupport=homotopySupport,mixedSystem=mixedSystem, tornSystem=tornSystem), eqAttr=eqAttr),_) + Integer newIdx, oldIdx; + list eqs; + Option jacobianMatrix; + SimCode.SimEqSystem simEqSys; + SimCode.NonlinearSystem nlSystem; + SimCode.LinearSystem lSystem; + case (simEqSys as SimCode.SES_NONLINEAR(nlSystem=nlSystem as SimCode.NONLINEARSYSTEM(eqs=eqs,jacobianMatrix=jacobianMatrix))) equation eqs = List.map1(eqs,TDS_replaceSimEqSysIndex,assIn); oldIdx = SimCodeUtil.simEqSystemIndex(simEqIn); newIdx = arrayGet(assIn,oldIdx); jacobianMatrix = TDS_replaceSimEqSysIdxInJacobianMatrix(jacobianMatrix,assIn); - simEqSys = SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(newIdx,eqs,crefs,indexNonLinearSystem,nUnknowns,jacobianMatrix,homotopySupport,mixedSystem,tornSystem), NONE(), eqAttr); - then simEqSys; - case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(partOfMixed=partOfMixed,tornSystem=tornSystem,vars=vars,beqs=beqs,simJac=simJac,residual=eqs,jacobianMatrix=jacobianMatrix,sources=sources,indexLinearSystem=indexLinearSystem,nUnknowns=nUnknowns), eqAttr=eqAttr),ass) + nlSystem.jacobianMatrix = jacobianMatrix; + nlSystem.index = newIdx; + nlSystem.eqs = eqs; + simEqSys.nlSystem = nlSystem; + then simEqSys; + case (simEqSys as SimCode.SES_LINEAR(lSystem=lSystem as SimCode.LINEARSYSTEM(residual=eqs,jacobianMatrix=jacobianMatrix))) equation - eqs = List.map1(eqs,TDS_replaceSimEqSysIndex,ass); + eqs = List.map1(eqs,TDS_replaceSimEqSysIndex,assIn); oldIdx = SimCodeUtil.simEqSystemIndex(simEqIn); - newIdx = arrayGet(ass,oldIdx); - jacobianMatrix = TDS_replaceSimEqSysIdxInJacobianMatrix(jacobianMatrix,ass); - simEqSys = SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(newIdx,partOfMixed,tornSystem,vars,beqs,simJac,eqs,jacobianMatrix,sources,indexLinearSystem,nUnknowns), NONE(), eqAttr); + newIdx = arrayGet(assIn,oldIdx); + jacobianMatrix = TDS_replaceSimEqSysIdxInJacobianMatrix(jacobianMatrix,assIn); + lSystem.jacobianMatrix = jacobianMatrix; + lSystem.index = newIdx; + lSystem.residual = eqs; + simEqSys.lSystem = lSystem; then simEqSys; - case(_,ass) + case(_) equation oldIdx = SimCodeUtil.simEqSystemIndex(simEqIn); - newIdx = arrayGet(ass,oldIdx); + newIdx = arrayGet(assIn,oldIdx); simEqSys = SimCodeUtil.replaceSimEqSysIndex(simEqIn,newIdx); then simEqSys; end matchcontinue; @@ -3493,40 +3491,38 @@ protected function TDS_replaceSimEqSysIndexWithUpdate "author: Waurich TUD 2014- algorithm (simEqOut,tplOut) := matchcontinue(simEqIn,tplIn) local - Boolean partOfMixed; - Integer newIdx, oldIdx, indexNonLinearSystem, indexLinearSystem, indexMixedSystem, nUnknowns; - array ass; - SimCode.SimEqSystem simEqSys,cont; - list eqs; - list vars, discVars; - list crefs; - list beqs; - list> simJac; - Option jacobianMatrix; - list sources; - Boolean homotopySupport; - Boolean mixedSystem, tornSystem; - BackendDAE.EquationAttributes eqAttr; - case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=oldIdx,eqs=eqs,crefs=crefs,indexNonLinearSystem=indexNonLinearSystem,nUnknowns=nUnknowns,jacobianMatrix=jacobianMatrix,homotopySupport=homotopySupport,mixedSystem=mixedSystem,tornSystem=tornSystem), _, eqAttr=eqAttr),(newIdx,ass)) + Integer newIdx, oldIdx; + array ass; + SimCode.SimEqSystem simEqSys,cont; + list eqs; + list crefs; + Option jacobianMatrix; + SimCode.NonlinearSystem nlSystem; + SimCode.LinearSystem lSystem; + case (simEqSys as SimCode.SES_NONLINEAR(nlSystem=nlSystem as SimCode.NONLINEARSYSTEM(index=oldIdx,eqs=eqs,crefs=crefs,jacobianMatrix=jacobianMatrix)),(newIdx,ass)) equation (eqs,(newIdx,ass)) = List.mapFold(eqs,TDS_replaceSimEqSysIndexWithUpdate,(newIdx,ass)); (jacobianMatrix,(newIdx,ass)) = TDS_replaceSimEqSysIdxInJacobianMatrixWithUpdate(jacobianMatrix,(newIdx,ass)); ass = arrayUpdate(ass,oldIdx,newIdx); - simEqSys = SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(newIdx,eqs,crefs,indexNonLinearSystem,nUnknowns,jacobianMatrix,homotopySupport,mixedSystem,tornSystem), NONE(), eqAttr); - then (simEqSys,(newIdx+1,ass)); - case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index=oldIdx,partOfMixed=partOfMixed,tornSystem=tornSystem,vars=vars,beqs=beqs,simJac=simJac,residual=eqs,jacobianMatrix=jacobianMatrix,sources=sources,indexLinearSystem=indexLinearSystem,nUnknowns=nUnknowns), _, eqAttr=eqAttr),(newIdx,ass)) + nlSystem.jacobianMatrix = jacobianMatrix; + nlSystem.index = newIdx; nlSystem.eqs = eqs; + simEqSys.nlSystem = nlSystem; + then (simEqSys,(newIdx+1,ass)); + case (simEqSys as SimCode.SES_LINEAR(lSystem=lSystem as SimCode.LINEARSYSTEM(index=oldIdx,residual=eqs,jacobianMatrix=jacobianMatrix)),(newIdx,ass)) equation (eqs,(newIdx,ass)) = List.mapFold(eqs,TDS_replaceSimEqSysIndexWithUpdate,(newIdx,ass)); (jacobianMatrix,(newIdx,ass)) = TDS_replaceSimEqSysIdxInJacobianMatrixWithUpdate(jacobianMatrix,(newIdx,ass)); ass = arrayUpdate(ass,oldIdx,newIdx); - simEqSys = SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(newIdx,partOfMixed,tornSystem,vars,beqs,simJac,eqs,jacobianMatrix,sources,indexLinearSystem,nUnknowns), NONE(), eqAttr); - then (simEqSys,(newIdx+1,ass)); - case(SimCode.SES_MIXED(index=oldIdx,cont=cont,discVars=discVars,discEqs=eqs,indexMixedSystem=indexMixedSystem, eqAttr=eqAttr),(newIdx,ass)) + lSystem.jacobianMatrix = jacobianMatrix; + lSystem.index = newIdx; lSystem.residual = eqs; + simEqSys.lSystem = lSystem; + then (simEqSys,(newIdx+1,ass)); + case (simEqSys as SimCode.SES_MIXED(index=oldIdx,cont=cont,discEqs=eqs),(newIdx,ass)) equation (cont,(newIdx,ass)) = TDS_replaceSimEqSysIndexWithUpdate(cont,(newIdx,ass)); (eqs,(newIdx,ass)) = List.mapFold(eqs,TDS_replaceSimEqSysIndexWithUpdate,(newIdx,ass)); ass = arrayUpdate(ass,oldIdx,newIdx); - simEqSys = SimCode.SES_MIXED(newIdx,cont,discVars,eqs,indexMixedSystem,eqAttr); + simEqSys.cont = cont; simEqSys.discEqs = eqs; then (simEqSys,(newIdx+1,ass)); case(_,(newIdx,ass)) equation @@ -3970,21 +3966,14 @@ protected function TDS_duplicateSystemOfEquations algorithm (simEqsOut,simEqSysIdxOut) := matchcontinue(simEqsIn,simEqSysIdxIn,repl,simEqsFold) local - Integer simEqSysIdx, index, numEqs, nUnknowns; - Boolean partOfMixed,tornSystem; + Integer simEqSysIdx, numEqs; list systSimEqSysIdcs2; SimCode.SimEqSystem simEqSys; list rest,duplicated,residual; - list vars; - list beqs; - list> simJac; - Option jacobianMatrix; - list sources; - Integer indexLinearSystem; - BackendDAE.EquationAttributes eqAttr; + SimCode.LinearSystem lSystem; case({},_,_,_) then (listReverse(simEqsFold),simEqSysIdxIn); - case((simEqSys as SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index=index,partOfMixed=partOfMixed,tornSystem=tornSystem,vars=vars,beqs=beqs,simJac=simJac,jacobianMatrix=jacobianMatrix, residual=residual,sources=sources,indexLinearSystem=indexLinearSystem,nUnknowns=nUnknowns), eqAttr=eqAttr))::rest,_,_,_) + case((simEqSys as SimCode.SES_LINEAR(lSystem=lSystem as SimCode.LINEARSYSTEM(residual=residual)))::rest,_,_,_) equation //print("the systemSimEqSys "+SimCodeUtil.dumpSimEqSystemLst(residual)+"\n"); numEqs = listLength(residual); @@ -3992,8 +3981,9 @@ algorithm //print("systSimEqSysIdcs2 :"+intListString(systSimEqSysIdcs2)+"\n"); (duplicated,_) = List.map1_2(residual,replaceExpsInSimEqSystem,repl);// replace the exps and crefs duplicated = List.threadMap(duplicated,systSimEqSysIdcs2,SimCodeUtil.replaceSimEqSysIndex); + lSystem.residual = duplicated; + simEqSys.lSystem = lSystem; //print("the systemSimEqSysDupl "+SimCodeUtil.dumpSimEqSystemLst(duplicated)+"\n"); - simEqSys = SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index,partOfMixed,tornSystem,vars,beqs,simJac,duplicated,jacobianMatrix,sources,indexLinearSystem,nUnknowns), NONE(), eqAttr); simEqSysIdx = simEqSysIdxIn + numEqs; (duplicated,simEqSysIdx) = TDS_duplicateSystemOfEquations(rest,simEqSysIdx,repl,simEqSys::simEqsFold); then (duplicated,simEqSysIdx); @@ -4052,35 +4042,30 @@ protected function replaceSystemIndex "author: Waurich TUD 2014-04 output SimCode.SimEqSystem simEqSysOut; output tuple idcsOut;// lsIdx,nlsIdx,mIdx algorithm - (simEqSysOut,idcsOut) := match(simEqSysIn,idcsIn) + (simEqSysOut,idcsOut) := match(simEqSysIn) local - Boolean pom; - Integer idx,lsIdx,nlsIdx,mIdx,nUnknowns; - SimCode.SimEqSystem simEqSys,cont; - list simVars; - list simEqSysLst; - list crefs; - list expLst; - list sources; - list> simJac; - Option jac; - Boolean homotopySupport; - Boolean mixedSystem,tornSystem; - BackendDAE.EquationAttributes eqAttr; - case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index=idx,partOfMixed=pom,tornSystem=tornSystem,vars=simVars,beqs=expLst,sources=sources,simJac=simJac,residual=simEqSysLst,jacobianMatrix=jac,nUnknowns=nUnknowns), eqAttr=eqAttr),_) + Integer lsIdx,nlsIdx,mIdx; + SimCode.SimEqSystem simEqSys; + SimCode.LinearSystem lSystem; + SimCode.NonlinearSystem nlSystem; + case (simEqSys as SimCode.SES_LINEAR(lSystem=lSystem)) equation (lsIdx,nlsIdx,mIdx) = idcsIn; - simEqSys = SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(idx,pom,tornSystem,simVars,expLst,simJac,simEqSysLst,jac,sources,lsIdx,nUnknowns), NONE(), eqAttr); + lSystem.indexLinearSystem = lsIdx; + simEqSys.lSystem = lSystem; then (simEqSys,(lsIdx+1,nlsIdx,mIdx)); - case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=idx,eqs=simEqSysLst,crefs=crefs,nUnknowns=nUnknowns,jacobianMatrix=jac,homotopySupport=homotopySupport,mixedSystem=mixedSystem,tornSystem=tornSystem), eqAttr=eqAttr),_) + + case (simEqSys as SimCode.SES_NONLINEAR(nlSystem=nlSystem)) equation (lsIdx,nlsIdx,mIdx) = idcsIn; - simEqSys = SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(idx,simEqSysLst,crefs,nlsIdx,nUnknowns,jac,homotopySupport,mixedSystem,tornSystem), NONE(), eqAttr); + nlSystem.indexNonLinearSystem = nlsIdx; + simEqSys.nlSystem = nlSystem; then (simEqSys,(lsIdx,nlsIdx+1,mIdx)); - case(SimCode.SES_MIXED(index=idx,cont=cont,discVars=simVars,discEqs=simEqSysLst, eqAttr=eqAttr),_) + + case (simEqSys as SimCode.SES_MIXED()) equation (lsIdx,nlsIdx,mIdx) = idcsIn; - simEqSys = SimCode.SES_MIXED(idx,cont,simVars,simEqSysLst,mIdx, eqAttr); + simEqSys.indexMixedSystem = mIdx; then (simEqSys,(lsIdx,nlsIdx,mIdx+1)); else (simEqSysIn,idcsIn); end match; @@ -4103,18 +4088,17 @@ protected function replaceExpsInSimEqSystem "author: Waurich TUD 2014-06 output SimCode.SimEqSystem simEqSysOut; output Boolean changedOut; algorithm - (simEqSysOut,changedOut) := matchcontinue(simEqSysIn,replIn) + (simEqSysOut,changedOut) := matchcontinue(simEqSysIn) local - Boolean pom,changed,changed1,hasRepl,ic; - Integer idx,idxLS,idxNLS,idxMS,nUnknowns; + Boolean changed,changed1,hasRepl; list bLst; DAE.ComponentRef cref; DAE.ElementSource source; DAE.Exp exp,lhs; SimCode.SimEqSystem simEqSys; + SimCode.SimEqSystem cont; list expLst, crefExps; list crefs; - list sources; list stmts; list simEqSysLst; list simVars; @@ -4122,40 +4106,37 @@ algorithm list> simJac; list>> ifs; list elsebranch; - Option jac; - Boolean homotopySupport; - Boolean mixedSystem, tornSystem; - list whenStmtLst; - BackendDAE.Constraints cons; - BackendDAE.EquationAttributes eqAttr; - case(SimCode.SES_RESIDUAL(index=idx,exp=exp,source=source,eqAttr=eqAttr),_) + SimCode.LinearSystem lSystem; + SimCode.NonlinearSystem nlSystem; + SimCode.SimEqSystem elseWhen; + case (simEqSys as SimCode.SES_RESIDUAL()) equation - (exp,changed) = BackendVarTransform.replaceExp(exp,replIn,NONE()); - simEqSys = SimCode.SES_RESIDUAL(idx,exp,source,eqAttr); + (exp,changed) = BackendVarTransform.replaceExp(simEqSys.exp,replIn,NONE()); + simEqSys.exp = exp; then (simEqSys,changed); - case(SimCode.SES_SIMPLE_ASSIGN(index=idx,cref=cref,exp=exp,source=source,eqAttr=eqAttr),_) + case (simEqSys as SimCode.SES_SIMPLE_ASSIGN(cref=cref,exp=exp)) equation hasRepl = BackendVarTransform.hasReplacement(replIn,cref); DAE.CREF(componentRef=cref) = if hasRepl then BackendVarTransform.getReplacement(replIn,cref) else DAE.CREF(cref,DAE.T_UNKNOWN_DEFAULT); (exp,changed) = BackendVarTransform.replaceExp(exp,replIn,NONE()); - simEqSys = SimCode.SES_SIMPLE_ASSIGN(idx,cref,exp,source,eqAttr); + simEqSys.cref = cref; simEqSys.exp = exp; then (simEqSys,changed or hasRepl); - case(SimCode.SES_SIMPLE_ASSIGN_CONSTRAINTS(index=idx,cref=cref,exp=exp,source=source,cons=cons,eqAttr=eqAttr),_) + case (simEqSys as SimCode.SES_SIMPLE_ASSIGN_CONSTRAINTS(cref=cref,exp=exp)) equation hasRepl = BackendVarTransform.hasReplacement(replIn,cref); DAE.CREF(componentRef=cref) = if hasRepl then BackendVarTransform.getReplacement(replIn,cref) else DAE.CREF(cref,DAE.T_UNKNOWN_DEFAULT); (exp,changed) = BackendVarTransform.replaceExp(exp,replIn,NONE()); - simEqSys = SimCode.SES_SIMPLE_ASSIGN_CONSTRAINTS(idx,cref,exp,source,cons,eqAttr); + simEqSys.cref = cref; simEqSys.exp = exp; then (simEqSys,changed or hasRepl); - case(SimCode.SES_ARRAY_CALL_ASSIGN(index=idx,lhs=lhs,exp=exp,source=source,eqAttr=eqAttr),_) + case (simEqSys as SimCode.SES_ARRAY_CALL_ASSIGN(lhs=lhs,exp=exp)) equation cref = Expression.expCref(lhs); hasRepl = BackendVarTransform.hasReplacement(replIn,cref); lhs = if hasRepl then BackendVarTransform.getReplacement(replIn,cref) else DAE.CREF(cref,DAE.T_UNKNOWN_DEFAULT); (exp,changed) = BackendVarTransform.replaceExp(exp,replIn,NONE()); - simEqSys = SimCode.SES_ARRAY_CALL_ASSIGN(idx,lhs,exp,source,eqAttr); + simEqSys.lhs = lhs; simEqSys.exp = exp; then (simEqSys,changed or hasRepl); - case(SimCode.SES_IFEQUATION(index=idx,ifbranches=ifs,elsebranch=elsebranch,source=source,eqAttr=eqAttr),_) + case (simEqSys as SimCode.SES_IFEQUATION(ifbranches=ifs,elsebranch=elsebranch)) equation expLst = List.map(ifs,Util.tuple21); (expLst,changed) = BackendVarTransform.replaceExpList(expLst,replIn,NONE()); @@ -4164,41 +4145,43 @@ algorithm ifs = List.threadMap(expLst,simEqSysLstLst,Util.makeTuple); (elsebranch,bLst) = List.map1_2(elsebranch,replaceExpsInSimEqSystem,replIn); changed = List.fold(bLst,boolOr,changed); - simEqSys = SimCode.SES_IFEQUATION(idx,ifs,elsebranch,source,eqAttr); + simEqSys.ifbranches = ifs; simEqSys.elsebranch = elsebranch; then (simEqSys,changed); - case(SimCode.SES_ALGORITHM(index=idx,statements=stmts,eqAttr=eqAttr),_) + case (simEqSys as SimCode.SES_ALGORITHM(statements=stmts)) equation (stmts,changed) = BackendVarTransform.replaceStatementLst(stmts,replIn,NONE(),{},false); - simEqSys = SimCode.SES_ALGORITHM(idx,stmts,eqAttr); + simEqSys.statements = stmts; then (simEqSys,changed); - case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index=idx,partOfMixed=pom,tornSystem=tornSystem,vars=simVars,beqs=expLst,sources=sources,simJac=simJac,residual=simEqSysLst,jacobianMatrix=jac,indexLinearSystem=idxLS,nUnknowns=nUnknowns),eqAttr=eqAttr),_) + case (simEqSys as SimCode.SES_LINEAR(lSystem=lSystem)) equation - (simVars,bLst) = List.map1_2(simVars,replaceCrefInSimVar,replIn); - (expLst,changed) = BackendVarTransform.replaceExpList(expLst,replIn,NONE()); + (simVars,bLst) = List.map1_2(lSystem.vars,replaceCrefInSimVar,replIn); + (expLst,changed) = BackendVarTransform.replaceExpList(lSystem.beqs,replIn,NONE()); changed = List.fold(bLst,boolOr,changed); - simJac = List.map1(simJac,replaceInSimJac,replIn); - simEqSys = SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(idx,pom,tornSystem,simVars,expLst,simJac,simEqSysLst,jac,sources,idxLS,nUnknowns), NONE(), eqAttr); + simJac = List.map1(lSystem.simJac,replaceInSimJac,replIn); + lSystem.vars = simVars; lSystem.beqs = expLst; lSystem.simJac = simJac; + simEqSys.lSystem = lSystem; then (simEqSys,changed); - case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=idx,eqs=simEqSysLst,crefs=crefs,indexNonLinearSystem=idxNLS,nUnknowns=nUnknowns,homotopySupport=homotopySupport,mixedSystem=mixedSystem,tornSystem=tornSystem),eqAttr=eqAttr),_) + case (simEqSys as SimCode.SES_NONLINEAR(nlSystem=nlSystem)) equation - expLst = List.map(crefs,Expression.crefExp); + expLst = List.map(nlSystem.crefs,Expression.crefExp); (expLst,changed) = BackendVarTransform.replaceExpList(expLst,replIn,NONE()); crefs = List.map(expLst,Expression.expCref); - (simEqSysLst,bLst) = List.map1_2(simEqSysLst,replaceExpsInSimEqSystem,replIn); + (simEqSysLst,bLst) = List.map1_2(nlSystem.eqs,replaceExpsInSimEqSystem,replIn); changed = changed or List.fold(bLst,boolOr,false); print("implement Jacobian replacement for SES_NONLINEAR in HpcOmScheduler.replaceExpsInSimEqSystems!\n"); - simEqSys = SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(idx,simEqSysLst,crefs,idxNLS,nUnknowns,NONE(),homotopySupport,mixedSystem,tornSystem), NONE(), eqAttr); + nlSystem.crefs = crefs; nlSystem.eqs = simEqSysLst; + simEqSys.nlSystem = nlSystem; then (simEqSys,changed); - case(SimCode.SES_MIXED(index=idx,cont=simEqSys,discVars=simVars,discEqs=simEqSysLst,indexMixedSystem=idxMS,eqAttr=eqAttr),_) + case (simEqSys as SimCode.SES_MIXED(cont=cont,discVars=simVars,discEqs=simEqSysLst)) equation - (simEqSys,changed) = replaceExpsInSimEqSystem(simEqSys,replIn); + (cont,changed) = replaceExpsInSimEqSystem(cont,replIn); (simVars,bLst) = List.map1_2(simVars,replaceCrefInSimVar,replIn); changed = List.fold(bLst,boolOr,changed); (simEqSysLst,bLst) = List.map1_2(simEqSysLst,replaceExpsInSimEqSystem,replIn); changed = List.fold(bLst,boolOr,changed); - simEqSys = SimCode.SES_MIXED(idx,simEqSys,simVars,simEqSysLst,idxMS,eqAttr); + simEqSys.discVars = simVars; simEqSys.discEqs=simEqSysLst; simEqSys.cont = cont; then (simEqSys,changed); - case(SimCode.SES_WHEN(index=idx,conditions=crefs,initialCall=ic,whenStmtLst={BackendDAE.ASSIGN(left=lhs,right=exp)},elseWhen=NONE(),source=source,eqAttr=eqAttr),_) + case (simEqSys as SimCode.SES_WHEN(conditions=crefs,whenStmtLst={BackendDAE.ASSIGN(left=lhs,right=exp,source=source)},elseWhen=NONE())) equation (crefExps,bLst) = List.map1_2(crefs,BackendVarTransform.replaceCref,replIn); crefs = List.map(crefExps,Expression.expCref); @@ -4206,9 +4189,9 @@ algorithm changed = List.fold(bLst,boolOr,changed); (exp,changed1) = BackendVarTransform.replaceExp(exp,replIn,NONE()); changed = boolOr(changed,changed1); - simEqSys = SimCode.SES_WHEN(idx,crefs,ic,{BackendDAE.ASSIGN(lhs, exp, source)},NONE(),source, eqAttr); + simEqSys.conditions = crefs; simEqSys.whenStmtLst = {BackendDAE.ASSIGN(lhs, exp, source)}; then (simEqSys,changed); - case(SimCode.SES_WHEN(index=idx,conditions=crefs,initialCall=ic,whenStmtLst={BackendDAE.ASSIGN(left=lhs,right=exp)},elseWhen=SOME(simEqSys),source=source,eqAttr=eqAttr),_) + case (simEqSys as SimCode.SES_WHEN(conditions=crefs,whenStmtLst={BackendDAE.ASSIGN(left=lhs,right=exp,source=source)},elseWhen=SOME(elseWhen))) equation (crefExps,bLst) = List.map1_2(crefs,BackendVarTransform.replaceCref,replIn); crefs = List.map(crefExps,Expression.expCref); @@ -4218,7 +4201,8 @@ algorithm changed = boolOr(changed,changed1); (simEqSys,changed1) = replaceExpsInSimEqSystem(simEqSys,replIn); changed = boolOr(changed,changed1); - simEqSys = SimCode.SES_WHEN(idx,crefs,ic,{BackendDAE.ASSIGN(lhs, exp, source)},SOME(simEqSys),source, eqAttr); + simEqSys.conditions = crefs; simEqSys.whenStmtLst = {BackendDAE.ASSIGN(lhs, exp, source)}; + simEqSys.elseWhen = SOME(elseWhen); then (simEqSys,changed); else equation diff --git a/Compiler/SimCode/SimCodeUtil.mo b/Compiler/SimCode/SimCodeUtil.mo index 18ccd122bfb..25974699dda 100644 --- a/Compiler/SimCode/SimCodeUtil.mo +++ b/Compiler/SimCode/SimCodeUtil.mo @@ -1011,51 +1011,50 @@ protected function setSystemIndexMap " input array inSysIndexMap; output SimCode.SimEqSystem outEqn; algorithm - outEqn := match(inEqn, inSysIndexMap) + outEqn := match(inEqn) local - Integer index, index2, sysIndex, sysIndex2, nUnknowns, nUnknowns2; - list eqs, eqs2; - list crefs, crefs2; + Integer index, sysIndex; + SimCode.LinearSystem lSystem; + SimCode.NonlinearSystem nlSystem; + Option alternativeTearingL; + Option alternativeTearingNL; + SimCode.SimEqSystem simEq; SimCode.SimEqSystem cont; - list discVars; - list discEqs; - Option optSymJac, optSymJac2; - Boolean partOfMixed,partOfMixed2; - list vars,vars2; - list beqs,beqs2; - list> simJac,simJac2; - list sources,sources2; - Boolean homotopySupport, homotopySupport2; - Boolean mixedSystem, mixedSystem2, tornSystem, tornSystem2; - BackendDAE.EquationAttributes eqAttr; - - // no dynamic tearing - case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index, partOfMixed, tornSystem, vars, beqs, simJac, eqs, optSymJac, sources, _, nUnknowns), NONE(), eqAttr), _) equation - sysIndex = inSysIndexMap[index]; - then SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index, partOfMixed, tornSystem, vars, beqs, simJac, eqs, optSymJac, sources, sysIndex, nUnknowns), NONE(), eqAttr); - case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index, eqs, crefs, _, nUnknowns, optSymJac, homotopySupport, mixedSystem, tornSystem), NONE(), eqAttr), _) equation - eqs = List.map1(eqs, setSystemIndexMap, inSysIndexMap); - sysIndex = inSysIndexMap[index]; - then SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index, eqs, crefs, sysIndex, nUnknowns, optSymJac, homotopySupport, mixedSystem, tornSystem), NONE(), eqAttr); + case (simEq as SimCode.SES_LINEAR(lSystem=lSystem, alternativeTearing=alternativeTearingL)) equation + sysIndex = inSysIndexMap[lSystem.index]; + lSystem.indexLinearSystem = sysIndex; + simEq.lSystem = lSystem; + // dynamic tearing + if isSome(alternativeTearingL) then + lSystem = Util.getOption(alternativeTearingL); + sysIndex = inSysIndexMap[lSystem.index]; + lSystem.indexLinearSystem = sysIndex; + alternativeTearingL = SOME(lSystem); + simEq.alternativeTearing = alternativeTearingL; + end if; + then simEq; + + case (simEq as SimCode.SES_NONLINEAR(nlSystem=nlSystem, alternativeTearing=alternativeTearingNL)) equation + sysIndex = inSysIndexMap[nlSystem.index]; + nlSystem.indexNonLinearSystem = sysIndex; + simEq.nlSystem = nlSystem; + // dynamic tearing + if isSome(alternativeTearingNL) then + nlSystem = Util.getOption(alternativeTearingNL); + sysIndex = inSysIndexMap[nlSystem.index]; + nlSystem.indexNonLinearSystem = sysIndex; + alternativeTearingNL = SOME(nlSystem); + simEq.alternativeTearing = alternativeTearingNL; + end if; + then simEq; - // dynamic tearing - case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index, partOfMixed, tornSystem, vars, beqs, simJac, eqs, optSymJac, sources, _, nUnknowns), SOME(SimCode.LINEARSYSTEM(index2, partOfMixed2, _, vars2, beqs2, simJac2, eqs2, optSymJac2, sources2, _, nUnknowns2)), eqAttr), _) equation - sysIndex = inSysIndexMap[index]; - sysIndex2 = inSysIndexMap[index2]; - then SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(index, partOfMixed, tornSystem, vars, beqs, simJac, eqs, optSymJac, sources, sysIndex, nUnknowns), SOME(SimCode.LINEARSYSTEM(index2, partOfMixed2, tornSystem, vars2, beqs2, simJac2, eqs2, optSymJac2, sources2, sysIndex2, nUnknowns2)), eqAttr); - - case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=index, eqs=eqs, crefs=crefs, nUnknowns=nUnknowns, jacobianMatrix=optSymJac, homotopySupport=homotopySupport, mixedSystem=mixedSystem, tornSystem=tornSystem), SOME(SimCode.NONLINEARSYSTEM(index=index2, eqs=eqs2, crefs=crefs2, nUnknowns=nUnknowns2, jacobianMatrix=optSymJac2, homotopySupport=homotopySupport2, mixedSystem=mixedSystem2, tornSystem=tornSystem2)), eqAttr=eqAttr), _) equation - eqs = List.map1(eqs, setSystemIndexMap, inSysIndexMap); - sysIndex = inSysIndexMap[index]; - eqs2 = List.map1(eqs2, setSystemIndexMap, inSysIndexMap); - sysIndex2 = inSysIndexMap[index2]; - then SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index, eqs, crefs, sysIndex, nUnknowns, optSymJac, homotopySupport, mixedSystem, tornSystem), SOME(SimCode.NONLINEARSYSTEM(index2, eqs2, crefs2, sysIndex2, nUnknowns2, optSymJac2, homotopySupport2, mixedSystem2, tornSystem2)), eqAttr); - - case(SimCode.SES_MIXED(index, cont, discVars, discEqs, _, eqAttr), _) equation - sysIndex = inSysIndexMap[index]; + case (simEq as SimCode.SES_MIXED(cont=cont)) equation + sysIndex = inSysIndexMap[simEq.index]; cont = setSystemIndexMap(cont, inSysIndexMap); - then SimCode.SES_MIXED(index, cont, discVars, discEqs, sysIndex, eqAttr); + simEq.cont = cont; + simEq.indexMixedSystem = sysIndex; + then simEq; else then inEqn; @@ -11557,74 +11556,77 @@ end replaceModelInfo; public function replaceSimEqSysIndex "updated the index of the given SimEqSysIn. author:Waurich TUD 2014-05" input SimCode.SimEqSystem simEqSysIn; - input Integer idx; + input Integer inputIndex; output SimCode.SimEqSystem simEqSysOut; algorithm - simEqSysOut := match(simEqSysIn,idx) + simEqSysOut := match(simEqSysIn) local - Boolean pom,changed,ic, inls; - Integer idxLS,idxNLS,idxMX,nUnknowns; - list bLst; - DAE.ComponentRef cref; - DAE.ElementSource source; - DAE.Exp exp,lhs; + SimCode.LinearSystem lSystem; + SimCode.NonlinearSystem nlSystem; SimCode.SimEqSystem simEqSys; - list expLst; - list stmts; - list crefs; - list sources; - list simEqSysLst,elsebranch; - list simVars; - list> simJac; - list>> ifbranches; - Option jac; - Option elseWhen; - Boolean homotopySupport; - Boolean mixedSystem, tornSystem; - list whenStmtLst; - BackendDAE.Constraints cons; - BackendDAE.EquationAttributes eqAttr; - case(SimCode.SES_RESIDUAL(exp=exp,source=source,eqAttr=eqAttr),_) + + case (simEqSys as SimCode.SES_RESIDUAL()) equation - simEqSys = SimCode.SES_RESIDUAL(idx,exp,source, eqAttr); + simEqSys.index = inputIndex; then simEqSys; - case(SimCode.SES_SIMPLE_ASSIGN(cref=cref,exp=exp,source=source,eqAttr=eqAttr),_) + + case (simEqSys as SimCode.SES_SIMPLE_ASSIGN()) + equation + simEqSys.index = inputIndex; + then simEqSys; + + case (simEqSys as SimCode.SES_SIMPLE_ASSIGN_CONSTRAINTS()) equation - simEqSys = SimCode.SES_SIMPLE_ASSIGN(idx,cref,exp,source, eqAttr); + simEqSys.index = inputIndex; then simEqSys; - case(SimCode.SES_SIMPLE_ASSIGN_CONSTRAINTS(cref=cref,exp=exp,source=source,cons=cons,eqAttr=eqAttr),_) + + case (simEqSys as SimCode.SES_ARRAY_CALL_ASSIGN()) equation - simEqSys = SimCode.SES_SIMPLE_ASSIGN_CONSTRAINTS(idx,cref,exp,source,cons, eqAttr); + simEqSys.index = inputIndex; then simEqSys; - case(SimCode.SES_ARRAY_CALL_ASSIGN(lhs=lhs,exp=exp,source=source,eqAttr=eqAttr),_) + + case (simEqSys as SimCode.SES_IFEQUATION()) equation - simEqSys = SimCode.SES_ARRAY_CALL_ASSIGN(idx,lhs,exp,source, eqAttr); + simEqSys.index = inputIndex; then simEqSys; - case(SimCode.SES_IFEQUATION(ifbranches=ifbranches,elsebranch=elsebranch,source=source,eqAttr=eqAttr),_) + + case (simEqSys as SimCode.SES_ALGORITHM()) equation - simEqSys = SimCode.SES_IFEQUATION(idx,ifbranches,elsebranch,source,eqAttr); + simEqSys.index = inputIndex; then simEqSys; - case(SimCode.SES_ALGORITHM(statements=stmts,eqAttr=eqAttr), _) equation - simEqSys = SimCode.SES_ALGORITHM(idx,stmts, eqAttr); + + case (simEqSys as SimCode.SES_INVERSE_ALGORITHM()) + equation + simEqSys.index = inputIndex; then simEqSys; - case(SimCode.SES_INVERSE_ALGORITHM(statements=stmts, knownOutputCrefs=crefs,insideNonLinearSystem=inls,eqAttr=eqAttr), _) equation - simEqSys = SimCode.SES_INVERSE_ALGORITHM(idx, stmts, crefs, inls, eqAttr); + + // WARNING: dynamic tearing not handled + case (simEqSys as SimCode.SES_LINEAR(lSystem=lSystem)) + equation + lSystem.index = inputIndex; + simEqSys.lSystem = lSystem; then simEqSys; - case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(partOfMixed=pom,tornSystem=tornSystem,vars=simVars,beqs=expLst,sources=sources,simJac=simJac,residual=simEqSysLst,jacobianMatrix=jac,indexLinearSystem=idxLS,nUnknowns=nUnknowns),eqAttr=eqAttr),_) + + // WARNING: dynamic tearing not handled + case (simEqSys as SimCode.SES_NONLINEAR(nlSystem=nlSystem)) equation - simEqSys = SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(idx,pom,tornSystem,simVars,expLst,simJac,simEqSysLst,jac,sources,idxLS,nUnknowns), NONE(),eqAttr); + nlSystem.index = inputIndex; + simEqSys.nlSystem = nlSystem; then simEqSys; - case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(eqs=simEqSysLst,crefs=crefs,indexNonLinearSystem=idxNLS,nUnknowns=nUnknowns,jacobianMatrix=jac,homotopySupport=homotopySupport,mixedSystem=mixedSystem, tornSystem=tornSystem),eqAttr=eqAttr),_) + + case (simEqSys as SimCode.SES_MIXED()) equation - simEqSys = SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(idx,simEqSysLst,crefs,idxNLS,nUnknowns,jac,homotopySupport,mixedSystem,tornSystem), NONE(),eqAttr); + simEqSys.index = inputIndex; then simEqSys; - case(SimCode.SES_MIXED(cont=simEqSys,discVars=simVars,discEqs=simEqSysLst,indexMixedSystem=idxMX,eqAttr=eqAttr),_) + + case (simEqSys as SimCode.SES_WHEN()) equation - simEqSys = SimCode.SES_MIXED(idx,simEqSys,simVars,simEqSysLst,idxMX,eqAttr); + simEqSys.index = inputIndex; then simEqSys; - case(SimCode.SES_WHEN(conditions=crefs,initialCall=ic,whenStmtLst=whenStmtLst,elseWhen=elseWhen,source=source,eqAttr=eqAttr),_) + + case (simEqSys as SimCode.SES_FOR_LOOP()) equation - simEqSys = SimCode.SES_WHEN(idx,crefs,ic,whenStmtLst,elseWhen,source,eqAttr); + simEqSys.index = inputIndex; then simEqSys; end match; end replaceSimEqSysIndex;