diff --git a/Compiler/BackEnd/BackendDAEOptimize.mo b/Compiler/BackEnd/BackendDAEOptimize.mo index 47f08e65786..7c74b3f2e2a 100644 --- a/Compiler/BackEnd/BackendDAEOptimize.mo +++ b/Compiler/BackEnd/BackendDAEOptimize.mo @@ -7051,7 +7051,7 @@ algorithm // Debug dumping Debug.fcall(Flags.JAC_DUMP2, BackendDump.dumpFullMatching, bdaeMatching); - Debug.fcall(Flags.JAC_DUMP2,BackendDump.dumpVars,BackendVariable.varList(varswithDiffs)); + Debug.fcall(Flags.JAC_DUMP2,BackendDump.printVarList,BackendVariable.varList(varswithDiffs)); Debug.fcall(Flags.JAC_DUMP2,BackendDump.dumpEqns,BackendEquation.equationList(orderedEqns)); Debug.fcall(Flags.JAC_DUMP2,BackendDump.dumpIncidenceMatrix,adjMatrix); Debug.fcall(Flags.JAC_DUMP2,BackendDump.dumpIncidenceMatrixT,adjMatrixT); @@ -11965,7 +11965,7 @@ algorithm eqnmark = arrayCreate(arrayLength(ass2),false); (g0,othercomps1) = getOtherEquationsPointZero(othercomps,vars,eqns,repl,eqnmark,mapIncRowEqn,{},{}); Debug.fcall(Flags.TEARING_DUMP, print,"k0:\n"); - Debug.fcall(Flags.TEARING_DUMP, BackendDump.dumpVars,k0); + Debug.fcall(Flags.TEARING_DUMP, BackendDump.printVarList,k0); Debug.fcall(Flags.TEARING_DUMP, print,"g0:\n"); Debug.fcall(Flags.TEARING_DUMP, BackendDump.dumpEqns,g0); // replace tearing vars with zero and other wars with temp variables to get residual equations for point zero (h(z0,k0)=h0) @@ -12000,7 +12000,7 @@ algorithm pdcr_lst = BackendEquation.equationUnknownCrefs(g,BackendVariable.daeVars(isyst),kvars); pdvarlst = List.map(pdcr_lst,makePardialDerVar); Debug.fcall(Flags.TEARING_DUMP, print,"PartialDerivatives:\n"); - Debug.fcall(Flags.TEARING_DUMP, BackendDump.dumpVars,pdvarlst); + Debug.fcall(Flags.TEARING_DUMP, BackendDump.printVarList,pdvarlst); Debug.fcall(Flags.TEARING_DUMP, print,"dh/dz extra:\n"); Debug.fcall(Flags.TEARING_DUMP, BackendDump.dumpEqns,g); tvarexps = List.map2(tvars,getTVarCrefExps,vars,ishared); diff --git a/Compiler/BackEnd/BackendDAETransform.mo b/Compiler/BackEnd/BackendDAETransform.mo index 8a15ae395b5..4fd3f857b4f 100644 --- a/Compiler/BackEnd/BackendDAETransform.mo +++ b/Compiler/BackEnd/BackendDAETransform.mo @@ -1144,8 +1144,7 @@ algorithm fail(); else equation - msg = "BackendDAETransform.analyseStrongComponentBlock failed"; - Error.addMessage(Error.INTERNAL_ERROR, {msg}); + Error.addMessage(Error.INTERNAL_ERROR, {"./Compiler/BackEnd/BackendDAETransform.mo: function analyseStrongComponentBlock failed"}); then fail(); end matchcontinue; @@ -1494,7 +1493,7 @@ algorithm then (contEqnLst,contVarLst,discEqnLst,discVarLst,indxcontEqnLst,indxcontVarLst,indxdiscEqnLst,indxdiscVarLst); case (_,_,_,_) equation - BackendDump.dumpVars(varLst); + BackendDump.printVarList(varLst); BackendDump.dumpEqns(eqnLst); then fail(); end matchcontinue; diff --git a/Compiler/BackEnd/BackendDAEUtil.mo b/Compiler/BackEnd/BackendDAEUtil.mo index c5e030d025a..85426c54b08 100644 --- a/Compiler/BackEnd/BackendDAEUtil.mo +++ b/Compiler/BackEnd/BackendDAEUtil.mo @@ -1253,7 +1253,7 @@ algorithm case (var as BackendDAE.VAR(bindValue = SOME(_)), _, _, _) equation print("*** Not Ceval.eval var: "); - BackendDump.dumpVars({var}); + BackendDump.printVar(var); print("\n"); then var; @@ -3799,7 +3799,10 @@ algorithm res = incidenceRowExp1(varslst,p,pa,false); then ((e,false,(vars,res))); - + + // lochel: internally generated call start(v) depends not on v + case ((e as DAE.CALL(path = Absyn.IDENT(name = "$_start")), (vars, pa))) then ((e, false, (vars, pa))); + /* pre(v) is considered a known variable */ case (((e as DAE.CALL(path = Absyn.IDENT(name = "pre")),(vars,pa)))) then ((e,false,(vars,pa))); diff --git a/Compiler/BackEnd/BackendDump.mo b/Compiler/BackEnd/BackendDump.mo index f53c57d88be..bbdc022a414 100644 --- a/Compiler/BackEnd/BackendDump.mo +++ b/Compiler/BackEnd/BackendDump.mo @@ -77,6 +77,20 @@ protected import Util; // These are functions, that print directly to the standard-stream. // ============================================================================= +public function printVariables "function printVariables + Helper function to dump." + input BackendDAE.Variables vars; +algorithm + _ := List.fold(BackendVariable.varList(vars), printVars1, 1); +end printVariables; + +public function printVarList "function printVarList + Helper function to dump." + input list vars; +algorithm + _ := List.fold(vars, printVars1, 1); +end printVarList; + public function printVar "function printVar " input BackendDAE.Var inVar; @@ -84,6 +98,18 @@ algorithm print(varString(inVar) +& "\n"); end printVar; +protected function printVars1 "function printVars1 + Helper function to printVariables and printVarList" + input BackendDAE.Var inVar; + input Integer inVarNo; + output Integer outVarNo; +algorithm + print(intString(inVarNo)); + print(": "); + printVar(inVar); + outVarNo := inVarNo + 1; +end printVars1; + public function printEquation "function printEquation author: PA Helper function to print_equations" @@ -166,6 +192,15 @@ end printEquationNo; // there output (e.g. with some kind of headings). // ============================================================================= +public function dumpVariables "function dumpVariables" + input BackendDAE.Variables inVars; + input String heading; +algorithm + print("\n" +& heading +& "\n========================================\n"); + printVariables(inVars); + print("\n"); +end dumpVariables; + public function dumpBackendDAE "function dumpBackendDAE This function dumps the BackendDAE.BackendDAE representaton to stdout." input BackendDAE.BackendDAE inBackendDAE; @@ -220,7 +255,7 @@ algorithm print(varlen_str); print(")\n"); print("=========\n"); - dumpVars(vars); + printVarList(vars); print("\n"); print("\nEquations ("); eqnsl := BackendEquation.equationList(eqns); @@ -275,7 +310,7 @@ algorithm print(varlen_str); print(")\n"); print("=============================\n"); - dumpVars(knvars); + printVarList(knvars); print("External Objects ("); extvars = BackendVariable.varList(vars3); varlen = listLength(extvars); @@ -283,7 +318,7 @@ algorithm print(varlen_str); print(")\n"); print("=============================\n"); - dumpVars(extvars); + printVarList(extvars); print("Classes of External Objects ("); varlen = listLength(extObjCls); @@ -531,7 +566,7 @@ public function dumpBackendDAEVarList input String header; algorithm print(header +& "\n"); - dumpVars(inBackendDAEVarList); + printVarList(inBackendDAEVarList); print("===================\n"); end dumpBackendDAEVarList; @@ -604,7 +639,7 @@ algorithm equation print("SingleEquation: " +& intString(e) +& "\n"); var = BackendVariable.getVarAt(vars,v); - dumpVars({var}); + printVarList({var}); eqn = BackendDAEUtil.equationNth(eqns,e-1); dumpEqns({eqn}); dumpEqnsSolved2(rest,eqns,vars); @@ -614,7 +649,7 @@ algorithm equation print("Mixed EquationSystem:\n"); varlst = List.map1r(vlst, BackendVariable.getVarAt, vars); - dumpVars(varlst); + printVarList(varlst); eqnlst = BackendEquation.getEqns(elst,eqns); dumpEqns(eqnlst); dumpEqnsSolved2({comp},eqns,vars); @@ -625,7 +660,7 @@ algorithm equation print("Equationsystem " +& jacobianTypeStr(jacType) +& ":\n"); varlst = List.map1r(vlst, BackendVariable.getVarAt, vars); - dumpVars(varlst); + printVarList(varlst); eqnlst = BackendEquation.getEqns(elst,eqns); dumpEqns(eqnlst); dumpEqnsSolved2(rest,eqns,vars); @@ -635,7 +670,7 @@ algorithm equation print("ArrayEquation:\n"); varlst = List.map1r(vlst, BackendVariable.getVarAt, vars); - dumpVars(varlst); + printVarList(varlst); eqn = BackendDAEUtil.equationNth(eqns,e-1); dumpEqns({eqn}); dumpEqnsSolved2(rest,eqns,vars); @@ -645,7 +680,7 @@ algorithm equation print("Algorithm:\n"); varlst = List.map1r(vlst, BackendVariable.getVarAt, vars); - dumpVars(varlst); + printVarList(varlst); eqn = BackendDAEUtil.equationNth(eqns,e-1); dumpEqns({eqn}); dumpEqnsSolved2(rest,eqns,vars); @@ -655,7 +690,7 @@ algorithm equation print("ComplexEquation:\n"); varlst = List.map1r(vlst, BackendVariable.getVarAt, vars); - dumpVars(varlst); + printVarList(varlst); eqn = BackendDAEUtil.equationNth(eqns,e-1); dumpEqns({eqn}); dumpEqnsSolved2(rest,eqns,vars); @@ -665,7 +700,7 @@ algorithm equation print("WhenEquation:\n"); varlst = List.map1r(vlst, BackendVariable.getVarAt, vars); - dumpVars(varlst); + printVarList(varlst); eqn = BackendDAEUtil.equationNth(eqns,e-1); dumpEqns({eqn}); dumpEqnsSolved2(rest,eqns,vars); @@ -678,9 +713,9 @@ algorithm vlst1 = List.flatten(List.map(eqnsvartpllst,Util.tuple22)); elst1 = List.map(eqnsvartpllst,Util.tuple21); varlst = List.map1r(vlst1, BackendVariable.getVarAt, vars); - dumpVars(varlst); + printVarList(varlst); varlst = List.map1r(vlst, BackendVariable.getVarAt, vars); - dumpVars(varlst); + printVarList(varlst); eqnlst = BackendEquation.getEqns(elst1,eqns); dumpEqns(eqnlst); eqnlst = BackendEquation.getEqns(elst,eqns); @@ -1766,7 +1801,7 @@ algorithm vars := BackendVariable.varList(vars1); varlen_str := "Variables (" +& intString(listLength(vars)) +& ")"; tags := DumpHTML.addHeadingTag(2,varlen_str,{}); - tags := dumpVarsHTML(vars,prefixId,tags); + tags := printVarListHTML(vars,prefixId,tags); eqnsl := BackendEquation.equationList(eqns); eqnlen_str := "Equations (" +& intString(listLength(eqnsl)) +& "," +& intString(BackendDAEUtil.equationSize(eqns)) +& ")"; tags := DumpHTML.addHeadingTag(2,eqnlen_str,tags); @@ -1781,9 +1816,9 @@ algorithm outTpl := (doc,i+1); end dumpEqSystemHTML; -protected function dumpVarsHTML -"function: dumpVarsHTML - Helper function to dumpVars." +protected function printVarListHTML +"function: printVarListHTML + Helper function to printVarList." input list vars; input String prefixId; input DumpHTML.Tags inTags; @@ -1794,11 +1829,11 @@ algorithm ((tags,_)) := List.fold1(vars,dumpVarHTML,prefixId,({},1)); outTags := DumpHTML.addHyperLinkTag("javascript:toggle('" +& prefixId +& "variables')","Variablen einblenden","Variablen ein/ausblenden",inTags); outTags := DumpHTML.addDivisionTag(prefixId +& "variables",{("background","#FFFFCC"),("display","none")},tags,outTags); -end dumpVarsHTML; +end printVarListHTML; protected function dumpVarHTML "function: dumpVar - Helper function to dumpVars." + Helper function to printVarList." input BackendDAE.Var inVar; input String prefixId; input tuple inTpl; @@ -1818,8 +1853,8 @@ algorithm end dumpVarHTML; protected function dumpEqnsHTML -"function: dumpVarsHTML - Helper function to dumpVars." +"function: printVarListHTML + Helper function to printVarList." input list eqns; input String prefixId; input DumpHTML.Tags inTags; @@ -2196,36 +2231,8 @@ algorithm end match; end dumpExtObjCls; -public function dumpVarsArray "function dumpVarsArray - Helper function to dump." - input BackendDAE.Variables vars; -algorithm - _ := List.fold(BackendVariable.varList(vars), dumpVar, 1); -end dumpVarsArray; - -public function dumpVars -"function: dumpVars - Helper function to dump." - input list vars; -algorithm - _ := List.fold(vars,dumpVar,1); -end dumpVars; - -protected function dumpVar "function dumpVar - Helper function to dumpVars." - input BackendDAE.Var inVar; - input Integer inVarNo; - output Integer outVarNo; -algorithm - print(intString(inVarNo)); - print(": "); - print(varString(inVar)); - print("\n"); - outVarNo := inVarNo + 1; -end dumpVar; - public function varString "function varString - Helper function to dumpVars." + Helper function to printVarList." input BackendDAE.Var inVar; output String outStr; protected @@ -3049,7 +3056,7 @@ algorithm print("AliasVariables: "); print(sl); print("\n===============\n"); - dumpVars(vars); + printVarList(vars); print("\n"); end dumpAliasVariables; diff --git a/Compiler/BackEnd/IndexReduction.mo b/Compiler/BackEnd/IndexReduction.mo index ce8992aa1cb..df3f69083d5 100644 --- a/Compiler/BackEnd/IndexReduction.mo +++ b/Compiler/BackEnd/IndexReduction.mo @@ -312,7 +312,7 @@ algorithm Debug.fcall(Flags.BLT_DUMP, print, BackendDump.dumpMarkedEqns(isyst, eqns1)); Debug.fcall(Flags.BLT_DUMP, print, "unassgined states:\n"); varlst = List.map1r(unassignedStates,BackendVariable.getVarAt,BackendVariable.daeVars(isyst)); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVars,varlst); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVarList,varlst); syst = BackendDAEUtil.setEqSystemMatching(isyst,BackendDAE.MATCHING(inAssignments1,inAssignments2,{})); Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpBackendDAE, BackendDAE.DAE({syst},ishared)); 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."}); @@ -1024,7 +1024,7 @@ algorithm // change varKind varlst = List.map1r(statesWithUnusedDer,BackendVariable.getVarAt,v); Debug.fcall(Flags.BLT_DUMP, print, "Change varKind to algebraic for\n"); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVars, varlst); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVarList, varlst); varlst = BackendVariable.setVarsKind(varlst,BackendDAE.VARIABLE()); v1 = BackendVariable.addVars(varlst,v); // update IncidenceMatrix @@ -1042,7 +1042,7 @@ algorithm varlst = BackendEquation.equationsLstVars(notDiffedEquations,v); varlst = List.select(varlst,BackendVariable.isStateVar); Debug.fcall(Flags.BLT_DUMP, print, "state vars of undiffed Eqns\n"); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVars, varlst); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVarList, varlst); syst = BackendDAEUtil.setEqSystemMatching(isyst,BackendDAE.MATCHING(inAss1,inAss2,{})); dumpSystemGraphML(syst,ishared,NONE(),"test.graphml"); @@ -1058,12 +1058,12 @@ algorithm var = BackendVariable.getVarAt(v,i); varlst = {var}; Debug.fcall(Flags.BLT_DUMP, print, "Change varKind to algebraic for\n"); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVars, varlst); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVarList, varlst); varlst = BackendVariable.setVarsKind(varlst,BackendDAE.VARIABLE()); v1 = BackendVariable.addVars(varlst,v); varlst = List.map1r(ilst,BackendVariable.getVarAt,v); Debug.fcall(Flags.BLT_DUMP, print, "Other Candidates are\n"); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVars, varlst); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVarList, varlst); // update IncidenceMatrix eqnslst1 = BackendDAETransform.collectVarEqns({i},{},mt,arrayLength(mt)); syst = BackendDAE.EQSYSTEM(v1,eqns,SOME(m),SOME(mt),matching); @@ -1077,7 +1077,7 @@ algorithm equation varlst = List.map1r(unassignedStates,BackendVariable.getVarAt,v); Debug.fcall(Flags.BLT_DUMP, print, "unassignedStates\n"); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVars, varlst); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVarList, varlst); then fail(); end matchcontinue; @@ -1844,7 +1844,7 @@ algorithm // get highest order derivatives varlst = highestOrderDerivatives(BackendVariable.daeVars(isyst),so); Debug.fcall(Flags.BLT_DUMP, print, "highest Order Derivatives:\n"); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVars, varlst); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVarList, varlst); (dummystates,syst,shared) = processComps1New(inComps,isyst,ishared,vec2,inArg,varlst,inDummyStates); then (dummystates,syst,shared); @@ -1855,7 +1855,7 @@ algorithm varlst = highestOrderDerivatives(BackendVariable.daeVars(isyst),so); hov = BackendVariable.listVar1(varlst); Debug.fcall(Flags.BLT_DUMP, print, "highest Order Derivatives:\n"); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVarsArray, hov); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVariables, hov); (dummystates,syst,shared) = processComps1(inComps,isyst,ishared,vec2,inArg,hov,inDummyStates); then (dummystates,syst,shared); @@ -2401,14 +2401,14 @@ algorithm crlst = BackendVariable.getAllCrefFromVariables(vars); vars = BackendVariable.deleteCrefs(crlst,cvars); Debug.fcall(Flags.BLT_DUMP, print,"Vars:\n"); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVarsArray,vars); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVariables,vars); // select dummy derivatives eqns = BackendEquation.listEquation(eqnslst); (hov_1,dummyStates,lov,syst,shared) = selectDummyDerivatives(vars,BackendVariable.numVariables(vars),eqns,BackendDAEUtil.equationSize(eqns),eqnindxlst,hov_1,dummyStates,syst,shared,so,BackendVariable.emptyVars()); // get derivatives (lov,dummyStates) = higerOrderDerivatives(lov,BackendVariable.daeVars(isyst),so,dummyStates); Debug.fcall(Flags.BLT_DUMP, print,"HigerOrderVars:\n"); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVarsArray,lov); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVariables,lov); then (hov_1,dummyStates,lov,syst,shared); end matchcontinue; @@ -2496,7 +2496,7 @@ algorithm equation // if there is only one var select it because there is no choice Debug.fcall(Flags.BLT_DUMP, print, "single var and eqn\n"); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVarsArray, vars); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVariables, vars); Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpEqnsArray, eqns); v = BackendVariable.getVarAt(vars,1); cr = BackendVariable.varCref(v); @@ -2511,11 +2511,11 @@ algorithm true = intGt(varSize,1); true = intEq(eqnsSize,varSize); Debug.fcall(Flags.BLT_DUMP, print, "equal var and eqn size\n"); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVarsArray, vars); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVariables, vars); Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpEqnsArray, eqns); varlst = BackendVariable.varList(vars); Debug.fcall(Flags.BLT_DUMP, print, ("Select as dummyStates:\n")); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVars,varlst); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVarList,varlst); (hov1,lov,dummystates) = selectDummyStateVars(varlst,vars,hov,inLov,inDummyStates); then (hov1,dummystates,lov,isyst,ishared); @@ -2529,12 +2529,12 @@ algorithm dummyvarssize = listLength(varlst); true = intEq(eqnsSize,dummyvarssize); Debug.fcall(Flags.BLT_DUMP, print, "select dummy vars from stateselection\n"); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVarsArray, vars); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVariables, vars); Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpEqnsArray, eqns); crlst = List.map(varlst,BackendVariable.varCref); states = List.threadTuple(crlst,List.intRange2(1,dummyvarssize)); Debug.fcall(Flags.BLT_DUMP, print, ("Select as dummyStates:\n")); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVars,varlst); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVarList,varlst); (hov1,lov,dummystates) = selectDummyStateVars(varlst,vars,hov,inLov,inDummyStates); then (hov1,dummystates,lov,isyst,ishared); @@ -2582,7 +2582,7 @@ algorithm true = intGt(varSize,1); true = intGt(eqnsSize,varSize); print("Structural singular system:\n"); - Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpVarsArray, vars); + Debug.fcall(Flags.BLT_DUMP, BackendDump.printVariables, vars); Debug.fcall(Flags.BLT_DUMP, BackendDump.dumpEqnsArray, eqns); then fail(); @@ -2689,10 +2689,10 @@ algorithm prio4 := varStateSelectHeuristicPrio4(v,so,vars); prio5 := varStateSelectHeuristicPrio5(v); prio:= prio1 +. prio2 +. prio3 +. prio4 +. prio5; - dumpvarStateSelectHeuristicPrio(prio1,prio2,prio3,prio4,prio5); + printVarListtateSelectHeuristicPrio(prio1,prio2,prio3,prio4,prio5); end varStateSelectHeuristicPrio; -protected function dumpvarStateSelectHeuristicPrio +protected function printVarListtateSelectHeuristicPrio input Real Prio1; input Real Prio2; input Real Prio3; @@ -2712,7 +2712,7 @@ algorithm (); else then (); end matchcontinue; -end dumpvarStateSelectHeuristicPrio; +end printVarListtateSelectHeuristicPrio; protected function varStateSelectHeuristicPrio5 "function varStateSelectHeuristicPrio5 diff --git a/Compiler/BackEnd/Initialization.mo b/Compiler/BackEnd/Initialization.mo index 25afea4f267..f8efc6608a1 100644 --- a/Compiler/BackEnd/Initialization.mo +++ b/Compiler/BackEnd/Initialization.mo @@ -75,9 +75,7 @@ algorithm dae := inlineWhenForInitialization(inDAE); initVars := selectInitializationVariablesDAE(dae); - Debug.fcall(Flags.DUMP_INITIAL_SYSTEM, print, "\nselected initialization variables\n=================================\n"); - Debug.fcall(Flags.DUMP_INITIAL_SYSTEM, BackendDump.dumpVarsArray, initVars); - Debug.fcall(Flags.DUMP_INITIAL_SYSTEM, print, "\n"); + Debug.fcall2(Flags.DUMP_INITIAL_SYSTEM, BackendDump.dumpVariables, initVars, "selected initialization variables"); outInitDAE := solveInitialSystem1(dae, initVars); end solveInitialSystem; @@ -511,8 +509,7 @@ protected BackendDAE.IncidenceMatrix m, mt; algorithm (system, m, mt) := BackendDAEUtil.getIncidenceMatrix(inSystem, BackendDAE.NORMAL()); - // fallback - should be removed soon - system := analyzeInitialSystem1(system, mt, 1); // fix discrete vars to get rid of unneeded pre-vars + // system := analyzeInitialSystem1(system, mt, 1); // fix discrete vars to get rid of unneeded pre-vars system := analyzeInitialSystem2(system, inDAE, inInitVars); // fix unbalanced initial system if it is definite (outSystem, _, _) := BackendDAEUtil.getIncidenceMatrix(system, BackendDAE.NORMAL()); end analyzeInitialSystem; @@ -675,25 +672,6 @@ algorithm Debug.fcall(Flags.PEDANTIC, Error.addCompilerWarning, "Assuming fixed start value for the following " +& intString(nVars-nEqns) +& " variables:"); eqns = addStartValueEquations(states, eqns); then (true, inVars, eqns); - - // fallback - should be removed soon - // fix all states - case(_, _, eqns, _) equation - (dae, outputs) = BackendDAEOptimize.generateInitialMatricesDAE(inDAE); - - BackendDAE.DAE(eqs=systs) = inDAE; - ivars = BackendVariable.emptyVars(); - ivars = List.fold(systs, collectUnfixedStatesFromSystem, ivars); - states = BackendVariable.varList(ivars); - - nStates = BackendVariable.varsSize(ivars); - nVars = BackendVariable.varsSize(inVars); - nEqns = BackendDAEUtil.equationSize(eqns); - true = intEq(nVars, nEqns+nStates); - - Debug.fcall(Flags.PEDANTIC, Error.addCompilerWarning, "Assuming fixed start value for the following " +& intString(nVars-nEqns) +& " states:"); - eqns = addStartValueEquations(states, eqns); - then (true, inVars, eqns); // fix a subset of unfixed variables case(_, _, eqns, _) equation @@ -719,73 +697,12 @@ algorithm Debug.fcall(Flags.PEDANTIC, Error.addCompilerWarning, "Assuming fixed start value for the following " +& intString(nVars-nEqns) +& " variables:"); eqns = addStartValueEquations1(someStates, eqns); then (true, inVars, eqns); - - // fallback - should be removed soon - // fix a subset of unfixed states - case(_, _, eqns, _) equation - (dae, outputs) = BackendDAEOptimize.generateInitialMatricesDAE(inDAE); - - BackendDAE.DAE(eqs=systs) = inDAE; - ivars = BackendVariable.emptyVars(); - ivars = List.fold(systs, collectUnfixedStatesFromSystem, ivars); - states = BackendVariable.varList(ivars); - - nVars = BackendVariable.varsSize(inVars); - nEqns = BackendDAEUtil.equationSize(eqns); - true = intLt(nEqns, nVars); - - (sparsityPattern, _) = BackendDAEOptimize.generateSparsePattern(dae, states, outputs); - (dep, _) = sparsityPattern; - someStates = collectIndependentVars(dep, {}); - - Debug.fcall(Flags.DUMP_INITIAL_SYSTEM, print, "\ninitial equations ($res1 ... $resN) with respect to states\n"); - Debug.fcall(Flags.DUMP_INITIAL_SYSTEM, BackendDump.dumpSparsityPattern, sparsityPattern); - - true = intEq(nVars-nEqns, listLength(someStates)); // fix only if it is definite - - Debug.fcall(Flags.PEDANTIC, Error.addCompilerWarning, "Assuming fixed start value for the following " +& intString(nVars-nEqns) +& " variables:"); - eqns = addStartValueEquations1(someStates, eqns); - then (true, inVars, eqns); else equation - Error.addMessage(Error.INTERNAL_ERROR, {"It is not possible to determine unique which additional conditions can be added to the initial system by auto-fixed variables."}); + Error.addMessage(Error.INTERNAL_ERROR, {"It is not possible to determine unique which additional initial conditions should be added by auto-fixed variables."}); then (false, inVars, inEqns); end matchcontinue; end fixUnderDeterminedInitialSystem; - -// fallback - should be removed soon -protected function collectUnfixedStatesFromSystem - input BackendDAE.EqSystem isyst; - input BackendDAE.Variables inVars; - output BackendDAE.Variables outVars; -protected - BackendDAE.Variables vars; -algorithm - BackendDAE.EQSYSTEM(orderedVars=vars) := isyst; - outVars := BackendVariable.traverseBackendDAEVars(vars, collectUnfixedStates, inVars); -end collectUnfixedStatesFromSystem; - -// fallback - should be removed soon -protected function collectUnfixedStates - input tuple inTpl; - output tuple outTpl; -algorithm - outTpl := matchcontinue(inTpl) - local - BackendDAE.Var var; - BackendDAE.Variables vars; - DAE.ComponentRef cr, preCR; - - // state - case((var as BackendDAE.VAR(varKind=BackendDAE.STATE()), vars)) equation - false = BackendVariable.varFixed(var); - vars = BackendVariable.addVar(var, vars); - then ((var, vars)); - - else - then inTpl; - end matchcontinue; -end collectUnfixedStates; protected function collectIndependentVars "protected function collectIndependentVars author lochel" diff --git a/Compiler/BackEnd/SimCodeUtil.mo b/Compiler/BackEnd/SimCodeUtil.mo index ad39524a0cd..c2296c12b65 100644 --- a/Compiler/BackEnd/SimCodeUtil.mo +++ b/Compiler/BackEnd/SimCodeUtil.mo @@ -6456,7 +6456,7 @@ algorithm case (_, _, _, _, _) equation (initialEqs_lst, numberOfInitialEquations, numberOfInitialAlgorithms) = BackendDAEOptimize.collectInitialEquations(inDAE); (residual_equations, uniqueEqIndex, tempvars) = createNonlinearResidualEquations(initialEqs_lst, iuniqueEqIndex, itempvars); - Debug.fcall(Flags.SOLVE_INITIAL_SYSTEM, Error.addCompilerWarning, "No system for the symbolic initialization was generated. A method using numerical algorithms will be used instead.\n"); + Debug.fcall(Flags.SOLVE_INITIAL_SYSTEM, Error.addCompilerWarning, "No system for the symbolic initialization was generated. A method using numerical algorithms will be used instead."); then (residual_equations, {}, numberOfInitialEquations, numberOfInitialAlgorithms, uniqueEqIndex, tempvars, false); else equation @@ -7383,7 +7383,6 @@ algorithm BackendDAE.Variables extvars; BackendDAE.EquationArray ie; BackendDAE.Variables aliasVars; - list initCrefs; BackendDAE.EqSystems systs; case (BackendDAE.DAE(eqs=systs,shared=BackendDAE.SHARED( knownVars = knvars, initialEqs=ie, @@ -7403,9 +7402,6 @@ algorithm /* Index of algebraic and parameters need to fix due to separation of int Vars*/ varsOut = fixIndex(varsOut); - /* fix the initial thing */ - initCrefs = BackendEquation.getAllCrefFromEquations(ie); - varsOut = fixInitialThing(varsOut, initCrefs); then varsOut; @@ -8221,98 +8217,6 @@ algorithm end match; end varIndexComparer; -protected function fixInitialThing - input SimCode.SimVars simvarsIn; - input list initCrefs; - output SimCode.SimVars simvarsOut; -algorithm - simvarsOut := - matchcontinue (simvarsIn, initCrefs) - local - list stateVars; - list derivativeVars; - list algVars; - list intAlgVars; - list boolAlgVars; - list inputVars; - list outputVars; - list aliasVars; - list intAliasVars; - list boolAliasVars; - list paramVars; - list intParamVars; - list boolParamVars; - list stringAlgVars; - list stringParamVars; - list stringAliasVars; - list extObjVars; - list constVars; - list intConstVars; - list boolConstVars; - list stringConstVars; - /* no initial equations so nothing to do */ - case (_, {}) then simvarsIn; - case (SimCode.SIMVARS(stateVars, derivativeVars, algVars, intAlgVars, boolAlgVars, inputVars, - outputVars, aliasVars, intAliasVars, boolAliasVars, paramVars, intParamVars, boolParamVars, - stringAlgVars, stringParamVars, stringAliasVars, extObjVars, constVars, intConstVars, boolConstVars, stringConstVars), _) - equation - true = List.mapAllValueBool(stateVars, simvarFixed,true); - stateVars = List.map1(stateVars, nonFixifyIfHasInit, initCrefs); - then SimCode.SIMVARS(stateVars, derivativeVars, algVars, intAlgVars, boolAlgVars, inputVars, - outputVars, aliasVars, intAliasVars, boolAliasVars, paramVars, intParamVars, boolParamVars, - stringAlgVars, stringParamVars, stringAliasVars, extObjVars, constVars, intConstVars, boolConstVars, stringConstVars); - /* not all were fixed so nothing to do */ - else simvarsIn; - end matchcontinue; -end fixInitialThing; - -protected function simvarFixed - input SimCode.SimVar simvar; - output Boolean fixed_; -algorithm - fixed_ := - match (simvar) - case (SimCode.SIMVAR(isFixed=fixed_)) then fixed_; - case (_) then fail(); - end match; -end simvarFixed; - -protected function nonFixifyIfHasInit - input SimCode.SimVar simvarIn; - input list initCrefs; - output SimCode.SimVar simvarOut; -algorithm - simvarOut := - matchcontinue (simvarIn, initCrefs) - local - DAE.ComponentRef name; - BackendDAE.VarKind kind; - String comment, unit, displayUnit; - Integer index; - Option minVal, maxVal; - Option initVal, nomVal; - Boolean isFixed; - DAE.Type type_; - Boolean isDiscrete; - Option arrayCref; - SimCode.AliasVariable aliasvar; - String varNameStr; - DAE.ElementSource source; - Absyn.Info info; - SimCode.Causality causality; - list numArrayElement; - case (SimCode.SIMVAR(name, kind, comment, unit, displayUnit, index, minVal, maxVal, initVal, nomVal, isFixed, type_, isDiscrete, arrayCref, aliasvar, source, causality,NONE(),numArrayElement), _) - equation - (_ :: _) = List.select1(initCrefs, ComponentReference.crefEqualNoStringCompare, name); - varNameStr = ComponentReference.printComponentRefStr(name); - info = DAEUtil.getElementSourceFileInfo(source); - Error.addSourceMessage(Error.SETTING_FIXED_ATTRIBUTE, {varNameStr}, info); - then SimCode.SIMVAR(name, kind, comment, unit, displayUnit, index, minVal, maxVal, initVal, nomVal, false, type_, isDiscrete, arrayCref, aliasvar, source, causality,NONE(),numArrayElement); - case (_, _) then simvarIn; - end matchcontinue; -end nonFixifyIfHasInit; - - protected function createCrefToSimVarHT input SimCode.ModelInfo modelInfo; output SimCode.HashTableCrefToSimVar outHT;