diff --git a/Compiler/BackEnd/BackendDAEOptimize.mo b/Compiler/BackEnd/BackendDAEOptimize.mo index 148e826de32..fa48e341cbc 100644 --- a/Compiler/BackEnd/BackendDAEOptimize.mo +++ b/Compiler/BackEnd/BackendDAEOptimize.mo @@ -1965,7 +1965,7 @@ protected BackendDAE.EquationArray eqs; algorithm BackendDAE.EQSYSTEM(orderedEqs=eqs) := syst; - (_,_) := BackendEquation.traverseEquationArrayWithUpdate(eqs, residualForm2, 1); + (_,_) := BackendEquation.traverseEquationArray_WithUpdate(eqs, residualForm2, 1); osyst := syst; oshared := shared; end residualForm1; @@ -2060,7 +2060,7 @@ algorithm equation eqns = BackendEquation.getEqnsFromEqSystem(isyst); eqn = BackendEquation.equationNth1(eqns, e); - (_,tpl) = BackendEquation.traverseBackendDAEExpsEqn(eqn,countOperationsExp,inTpl); + (_,tpl) = BackendEquation.traverseExpsOfEquation(eqn,countOperationsExp,inTpl); then countOperationstraverseComps(rest,isyst,ishared,tpl); case ((comp as BackendDAE.EQUATIONSYSTEM(jac=jac,jacType=BackendDAE.JAC_LINEAR()))::rest,_,BackendDAE.SHARED(functionTree=funcs),_) @@ -2081,31 +2081,31 @@ algorithm case (BackendDAE.SINGLEARRAY(eqn=e)::rest,_,_,_) equation eqn = BackendEquation.equationNth1(BackendEquation.getEqnsFromEqSystem(isyst), e); - (_,tpl) = BackendEquation.traverseBackendDAEExpsEqn(eqn,countOperationsExp,inTpl); + (_,tpl) = BackendEquation.traverseExpsOfEquation(eqn,countOperationsExp,inTpl); then countOperationstraverseComps(rest,isyst,ishared,tpl); case (BackendDAE.SINGLEIFEQUATION(eqn=e)::rest,_,_,_) equation eqn = BackendEquation.equationNth1(BackendEquation.getEqnsFromEqSystem(isyst), e); - (_,tpl) = BackendEquation.traverseBackendDAEExpsEqn(eqn,countOperationsExp,inTpl); + (_,tpl) = BackendEquation.traverseExpsOfEquation(eqn,countOperationsExp,inTpl); then countOperationstraverseComps(rest,isyst,ishared,tpl); case (BackendDAE.SINGLEALGORITHM(eqn=e)::rest,_,_,_) equation eqn = BackendEquation.equationNth1(BackendEquation.getEqnsFromEqSystem(isyst), e); - (_,tpl) = BackendEquation.traverseBackendDAEExpsEqn(eqn,countOperationsExp,inTpl); + (_,tpl) = BackendEquation.traverseExpsOfEquation(eqn,countOperationsExp,inTpl); then countOperationstraverseComps(rest,isyst,ishared,tpl); case (BackendDAE.SINGLECOMPLEXEQUATION(eqn=e)::rest,_,_,_) equation eqn = BackendEquation.equationNth1(BackendEquation.getEqnsFromEqSystem(isyst), e); - (_,tpl) = BackendEquation.traverseBackendDAEExpsEqn(eqn,countOperationsExp,inTpl); + (_,tpl) = BackendEquation.traverseExpsOfEquation(eqn,countOperationsExp,inTpl); then countOperationstraverseComps(rest,isyst,ishared,tpl); case (BackendDAE.SINGLEWHENEQUATION(eqn=e)::rest,_,_,_) equation eqn = BackendEquation.equationNth1(BackendEquation.getEqnsFromEqSystem(isyst), e); - (_,tpl) = BackendEquation.traverseBackendDAEExpsEqn(eqn,countOperationsExp,inTpl); + (_,tpl) = BackendEquation.traverseExpsOfEquation(eqn,countOperationsExp,inTpl); then countOperationstraverseComps(rest,isyst,ishared,tpl); case ((comp as BackendDAE.TORNSYSTEM(tearingvars=vlst, linear=true))::rest,_,BackendDAE.SHARED(functionTree=funcs),_) @@ -2161,7 +2161,7 @@ protected function countOperationsJac1 input tuple inTpl; output tuple outTpl; algorithm - (_,outTpl) := BackendEquation.traverseBackendDAEExpsEqn(Util.tuple33(inJac),countOperationsExp,inTpl); + (_,outTpl) := BackendEquation.traverseExpsOfEquation(Util.tuple33(inJac),countOperationsExp,inTpl); end countOperationsJac1; protected function addJacSpecificOperations @@ -2392,7 +2392,7 @@ algorithm case (eqn,knvars,(acc,asserts,b)) equation - (eqn,(_,b)) = BackendEquation.traverseBackendDAEExpsEqn(eqn, simplifyIfExpevaluatedParamter, (knvars,b)); + (eqn,(_,b)) = BackendEquation.traverseExpsOfEquation(eqn, simplifyIfExpevaluatedParamter, (knvars,b)); then ((eqn::acc,asserts,b)); end matchcontinue; @@ -3055,7 +3055,7 @@ algorithm case (BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,stateSets=stateSets,partitionKind=partitionKind),shared) equation // traverse the equations and collect all semiLinear calls y=semiLinear(x,sa,sb) - (eqns,(eqnslst,_,true)) = BackendEquation.traverseEquationArrayWithUpdate(eqns,simplifysemiLinearFinder,({},0,false)); + (eqns,(eqnslst,_,true)) = BackendEquation.traverseEquationArray_WithUpdate(eqns,simplifysemiLinearFinder,({},0,false)); // sort for (y,x) pairs eqnsarray = arrayCreate(5,{}); ht = HashTableExpToIndex.emptyHashTable(); @@ -3728,7 +3728,7 @@ algorithm BackendDAE.EqSystem eqs; case(eqs as BackendDAE.EQSYSTEM(orderedVars=ordvars, orderedEqs=ordeqns), _) equation - (ordeqns, _) = BackendEquation.traverseEquationArrayWithUpdate(ordeqns, eaddInitialStmtsToAlgorithms1Helper, ordvars); + (ordeqns, _) = BackendEquation.traverseEquationArray_WithUpdate(ordeqns, eaddInitialStmtsToAlgorithms1Helper, ordvars); then(eqs, shared); end match; end addInitialStmtsToAlgorithms1; @@ -3841,8 +3841,8 @@ algorithm case (BackendDAE.EQSYSTEM(vars, eqns, m, mT, matching, stateSets, partitionKind), BackendDAE.SHARED(knvars, exobj, av, inieqns, remeqns, constrs, clsAttrs, cache, graph, funcs, einfo, eoc, btp, symjacs,ei)) equation - (eqns1, (vars1, _)) = BackendEquation.traverseEquationArrayWithUpdate(eqns, traverserexpandDerEquation, (vars, shared)); - (inieqns1, (vars2, _)) = BackendEquation.traverseEquationArrayWithUpdate(inieqns, traverserexpandDerEquation, (vars1, shared)); + (eqns1, (vars1, _)) = BackendEquation.traverseEquationArray_WithUpdate(eqns, traverserexpandDerEquation, (vars, shared)); + (inieqns1, (vars2, _)) = BackendEquation.traverseEquationArray_WithUpdate(inieqns, traverserexpandDerEquation, (vars1, shared)); then (BackendDAE.EQSYSTEM(vars2, eqns1, m, mT, matching, stateSets, partitionKind), BackendDAE.SHARED(knvars, exobj, av, inieqns1, remeqns, constrs, clsAttrs, cache, graph, funcs, einfo, eoc, btp, symjacs,ei)); end match; @@ -3865,7 +3865,7 @@ protected algorithm e := inEq; (vars, shared) := tpl; - (e1, (vars, shared, ops)) := BackendEquation.traverseBackendDAEExpsEqn(e, traverserexpandDerExp, (vars, shared, {})); + (e1, (vars, shared, ops)) := BackendEquation.traverseExpsOfEquation(e, traverserexpandDerExp, (vars, shared, {})); e1 := List.foldr(ops, BackendEquation.addOperation, e1); outEq := e1; outTpl := (vars, shared); diff --git a/Compiler/BackEnd/BackendDAETransform.mo b/Compiler/BackEnd/BackendDAETransform.mo index 664715fac8c..9c820e774ec 100644 --- a/Compiler/BackEnd/BackendDAETransform.mo +++ b/Compiler/BackEnd/BackendDAETransform.mo @@ -1106,7 +1106,7 @@ end checkStack; traverseBackendDAEExps stuff *****************************************/ -public function traverseBackendDAEExpsEqn +public function traverseExpsOfEquation "author: Frenkel TUD 2010-11 Traverse all expressions of a list of Equations. It is possible to change the equations and the multidim equations and the algorithms." @@ -1124,7 +1124,7 @@ public function traverseBackendDAEExpsEqn end FuncExpType; algorithm (outEquation,(_,outTypeA)) := traverseBackendDAEExpsEqnWithSymbolicOperation(inEquation,traverseBackendDAEExpsEqnWithoutSymbolicOperationHelper,(func,inTypeA)); -end traverseBackendDAEExpsEqn; +end traverseExpsOfEquation; protected function traverseBackendDAEExpsEqnWithoutSymbolicOperationHelper replaceable type Type_a subtypeof Any; @@ -1471,7 +1471,7 @@ public function traverseExpsOfEquationList "author: Frenkel TUD 2010-11 end FuncExpType; algorithm for eq in inEquations loop - (eq, outArg) := traverseBackendDAEExpsEqn(eq, func, outArg); + (eq, outArg) := traverseExpsOfEquation(eq, func, outArg); outEquations := eq :: outEquations; end for; diff --git a/Compiler/BackEnd/BackendDAEUtil.mo b/Compiler/BackEnd/BackendDAEUtil.mo index 50031edbc38..02c4a0d6c87 100644 --- a/Compiler/BackEnd/BackendDAEUtil.mo +++ b/Compiler/BackEnd/BackendDAEUtil.mo @@ -6043,7 +6043,7 @@ algorithm end matchcontinue; end traverseStrongComponentsJacobiansExp; -protected function traverseBackendDAEExpsJacobianEqn "Helper for traverseBackendDAEExpsEqn." +protected function traverseBackendDAEExpsJacobianEqn "Helper for traverseExpsOfEquation." replaceable type Type_a subtypeof Any; input list> inJacEntry; input FuncExpType func; @@ -6631,7 +6631,7 @@ algorithm end traverseBackendDAEExpsEqnsWithUpdate; public function traverseBackendDAEExpsOptEqn "author: Frenkel TUD 2010-11 - Helper for traverseBackendDAEExpsEqn." + Helper for traverseExpsOfEquation." replaceable type Type_a subtypeof Any; input Option inEquation; input FuncExpType func; @@ -6671,14 +6671,14 @@ algorithm case (NONE(),_,_) then (true,inTypeA); case (SOME(eqn),_,_) equation - (b,ext_arg_1) = BackendEquation.traverseBackendDAEExpsEqnWithStop(eqn,func,inTypeA); + (b,ext_arg_1) = BackendEquation.traverseExpsOfEquation_WithStop(eqn,func,inTypeA); then (b,ext_arg_1); end match; end traverseBackendDAEExpsOptEqnWithStop; protected function traverseBackendDAEExpsOptEqnWithUpdate "author: Frenkel TUD 2010-11 - Helper for traverseBackendDAEExpsEqn." + Helper for traverseExpsOfEquation." replaceable type Type_a subtypeof Any; input Option inEquation; input FuncExpType func; @@ -6699,7 +6699,7 @@ algorithm case (NONE(),_,_) then (NONE(),inTypeA); case (SOME(eqn),_,_) equation - (eqn,ext_arg_1) = BackendEquation.traverseBackendDAEExpsEqn(eqn,func,inTypeA); + (eqn,ext_arg_1) = BackendEquation.traverseExpsOfEquation(eqn,func,inTypeA); then (SOME(eqn),ext_arg_1); end match; diff --git a/Compiler/BackEnd/BackendEquation.mo b/Compiler/BackEnd/BackendEquation.mo index 11647027aba..6fc46f9cae7 100644 --- a/Compiler/BackEnd/BackendEquation.mo +++ b/Compiler/BackEnd/BackendEquation.mo @@ -288,7 +288,7 @@ protected list keys; algorithm bt := BinaryTreeInt.emptyBinTree; - (_, (_, (_, bt))) := traverseBackendDAEExpsEqn(inEquation, Expression.traverseSubexpressionsHelper, (checkEquationsVarsExp, (inVars, bt))); + (_, (_, (_, bt))) := traverseExpsOfEquation(inEquation, Expression.traverseSubexpressionsHelper, (checkEquationsVarsExp, (inVars, bt))); (keys, _) := BinaryTreeInt.bintreeToList(bt); outVars := List.map1r(keys, BackendVariable.getVarAt, inVars); end equationVars; @@ -443,7 +443,7 @@ protected function traversingEquationCrefFinder "author: Frenkel TUD 2010-11" algorithm e := inEq; cr_lst := inCrefs; - (_, (_,cr_lst)) := traverseBackendDAEExpsEqn(e, Expression.traverseSubexpressionsHelper, (Expression.traversingComponentRefFinder, cr_lst)); + (_, (_,cr_lst)) := traverseExpsOfEquation(e, Expression.traverseSubexpressionsHelper, (Expression.traversingComponentRefFinder, cr_lst)); end traversingEquationCrefFinder; public function equationUnknownCrefs "author: Frenkel TUD 2012-05 @@ -542,14 +542,14 @@ public function traverseExpsOfEquationList "author: Frenkel TUD 2010-11 end FuncExpType; algorithm for eq in inEquations loop - (eq, outArg) := traverseBackendDAEExpsEqn(eq, func, outArg); + (eq, outArg) := traverseExpsOfEquation(eq, func, outArg); outEquations := eq::outEquations; end for; outEquations := listReverse(outEquations); end traverseExpsOfEquationList; -protected function traverseBackendDAEExpsEqnListWithStop "author: Frenkel TUD 2012-09 +protected function traverseExpsOfEquationList_WithStop "author: Frenkel TUD 2012-09 Traverses all expressions of a list of equations. It is possible to change the equations." replaceable type Type_a subtypeof Any; @@ -577,34 +577,34 @@ algorithm then (true, inTypeA); case (eqn::eqns, _, _) equation - (b, arg) = traverseBackendDAEExpsEqnWithStop(eqn, inFunc, inTypeA); + (b, arg) = traverseExpsOfEquation_WithStop(eqn, inFunc, inTypeA); if b then - (b, arg) = traverseBackendDAEExpsEqnListWithStop(eqns, inFunc, arg); + (b, arg) = traverseExpsOfEquationList_WithStop(eqns, inFunc, arg); end if; then (b, arg); end match; -end traverseBackendDAEExpsEqnListWithStop; +end traverseExpsOfEquationList_WithStop; -protected function traverseBackendDAEExpsEqnListListWithStop "author: Frenkel TUD 2012-09 +protected function traverseExpsOfEquationListList_WithStop "author: Frenkel TUD 2012-09 Traverses all expressions of a list of equations. It is possible to change the equations." - replaceable type Type_a subtypeof Any; input list> inEquations; input FuncExpType func; - input Type_a inTypeA; + input T inTypeA; output Boolean outBoolean; - output Type_a outTypeA; + output T outTypeA; + partial function FuncExpType input DAE.Exp inExp; - input Type_a inTypeA; + input T inTypeA; output DAE.Exp outExp; output Boolean cont; - output Type_a outA; + output T outA; end FuncExpType; algorithm (outBoolean, outTypeA) := match (inEquations, func, inTypeA) local - Type_a arg; + T arg; list eqn; list> eqns; Boolean b; @@ -613,31 +613,31 @@ algorithm then (true, inTypeA); case (eqn::eqns, _, _) equation - (b, arg) = traverseBackendDAEExpsEqnListWithStop(eqn, func, inTypeA); + (b, arg) = traverseExpsOfEquationList_WithStop(eqn, func, inTypeA); if b then - (b, arg) = traverseBackendDAEExpsEqnListListWithStop(eqns, func, arg); + (b, arg) = traverseExpsOfEquationListList_WithStop(eqns, func, arg); end if; then (b, arg); end match; -end traverseBackendDAEExpsEqnListListWithStop; +end traverseExpsOfEquationListList_WithStop; -public function traverseBackendDAEExpsEqn "author: Frenkel TUD 2010-11 +public function traverseExpsOfEquation "author: Frenkel TUD 2010-11 Traverses all expressions of a equation. It is possible to change the equation." - replaceable type Type_a subtypeof Any; input BackendDAE.Equation inEquation; input FuncExpType inFunc; - input Type_a inTypeA; + input T inTypeA; output BackendDAE.Equation outEquation; - output Type_a outTypeA; + output T outTypeA; + partial function FuncExpType input DAE.Exp inExp; - input Type_a inTypeA; + input T inTypeA; output DAE.Exp outExp; - output Type_a outA; + output T outTypeA; end FuncExpType; algorithm - (outEquation, outTypeA) := match (inEquation, inFunc, inTypeA) + (outEquation, outTypeA) := match(inEquation) local DAE.Exp e1, e2, e_1, e_2, cond; list expl; @@ -646,7 +646,7 @@ algorithm BackendDAE.WhenEquation elsePart, elsePart1; DAE.ElementSource source; Integer size; - Type_a ext_arg_1, ext_arg_2, ext_arg_3; + T extArg; list dimSize; DAE.Algorithm alg; list stmts, stmts1; @@ -655,77 +655,77 @@ algorithm DAE.Expand crefExpand; BackendDAE.EquationAttributes attr; - case (BackendDAE.EQUATION(exp=e1, scalar=e2, source=source, attr=attr), _, _) equation - (e_1, ext_arg_1) = inFunc(e1, inTypeA); - (e_2, ext_arg_2) = inFunc(e2, ext_arg_1); - then (BackendDAE.EQUATION(e_1, e_2, source, attr), ext_arg_2); + case BackendDAE.EQUATION(exp=e1, scalar=e2, source=source, attr=attr) equation + (e_1, extArg) = inFunc(e1, inTypeA); + (e_2, extArg) = inFunc(e2, extArg); + then (BackendDAE.EQUATION(e_1, e_2, source, attr), extArg); - case (BackendDAE.ARRAY_EQUATION(dimSize=dimSize, left=e1, right=e2, source=source, attr=attr), _, _) equation - (e_1, ext_arg_1) = inFunc(e1, inTypeA); - (e_2, ext_arg_2) = inFunc(e2, ext_arg_1); - then (BackendDAE.ARRAY_EQUATION(dimSize, e_1, e_2, source, attr), ext_arg_2); + case BackendDAE.ARRAY_EQUATION(dimSize=dimSize, left=e1, right=e2, source=source, attr=attr) equation + (e_1, extArg) = inFunc(e1, inTypeA); + (e_2, extArg) = inFunc(e2, extArg); + then (BackendDAE.ARRAY_EQUATION(dimSize, e_1, e_2, source, attr), extArg); - case (BackendDAE.SOLVED_EQUATION(componentRef=cr, exp=e2, source=source, attr=attr), _, _) equation + case BackendDAE.SOLVED_EQUATION(componentRef=cr, exp=e2, source=source, attr=attr) equation tp = Expression.typeof(e2); e1 = Expression.makeCrefExp(cr, tp); - (DAE.CREF(cr1, _), ext_arg_1) = inFunc(e1, inTypeA); - (e_2, ext_arg_2) = inFunc(e2, ext_arg_1); - then (BackendDAE.SOLVED_EQUATION(cr1, e_2, source, attr), ext_arg_2); + (DAE.CREF(cr1, _), extArg) = inFunc(e1, inTypeA); + (e_2, extArg) = inFunc(e2, extArg); + then (BackendDAE.SOLVED_EQUATION(cr1, e_2, source, attr), extArg); - case (BackendDAE.RESIDUAL_EQUATION(exp=e1, source=source, attr=attr), _, _) equation - (e_1, ext_arg_1) = inFunc(e1, inTypeA); - then (BackendDAE.RESIDUAL_EQUATION(e_1, source, attr), ext_arg_1); + case BackendDAE.RESIDUAL_EQUATION(exp=e1, source=source, attr=attr) equation + (e_1, extArg) = inFunc(e1, inTypeA); + then (BackendDAE.RESIDUAL_EQUATION(e_1, source, attr), extArg); - case (BackendDAE.WHEN_EQUATION(size=size, whenEquation=BackendDAE.WHEN_EQ(condition=cond, left=cr, right=e2, elsewhenPart=NONE()), source=source, attr=attr), _, _) equation + case BackendDAE.WHEN_EQUATION(size=size, whenEquation=BackendDAE.WHEN_EQ(condition=cond, left=cr, right=e2, elsewhenPart=NONE()), source=source, attr=attr) equation tp = Expression.typeof(e2); e1 = Expression.makeCrefExp(cr, tp); - (DAE.CREF(cr1, _), ext_arg_1) = inFunc(e1, inTypeA); - (e_2, ext_arg_2) = inFunc(e2, ext_arg_1); - (cond, ext_arg_2) = inFunc(cond, ext_arg_2); - then (BackendDAE.WHEN_EQUATION(size, BackendDAE.WHEN_EQ(cond, cr1, e_2, NONE()), source, attr), ext_arg_2); + (DAE.CREF(cr1, _), extArg) = inFunc(e1, inTypeA); + (e_2, extArg) = inFunc(e2, extArg); + (cond, extArg) = inFunc(cond, extArg); + then (BackendDAE.WHEN_EQUATION(size, BackendDAE.WHEN_EQ(cond, cr1, e_2, NONE()), source, attr), extArg); - case (BackendDAE.WHEN_EQUATION(size=size, whenEquation=BackendDAE.WHEN_EQ(condition=cond, left=cr, right=e2, elsewhenPart=SOME(elsePart)), source=source, attr=attr), _, _) equation + case BackendDAE.WHEN_EQUATION(size=size, whenEquation=BackendDAE.WHEN_EQ(condition=cond, left=cr, right=e2, elsewhenPart=SOME(elsePart)), source=source, attr=attr) equation tp = Expression.typeof(e2); e1 = Expression.makeCrefExp(cr, tp); - (DAE.CREF(cr1, _), ext_arg_1) = inFunc(e1, inTypeA); - (e_2, ext_arg_2) = inFunc(e2, ext_arg_1); - (cond, ext_arg_2) = inFunc(cond, ext_arg_2); - (BackendDAE.WHEN_EQUATION(whenEquation=elsePart1), ext_arg_3) = traverseBackendDAEExpsEqn(BackendDAE.WHEN_EQUATION(size, elsePart, source, attr), inFunc, ext_arg_2); - then (BackendDAE.WHEN_EQUATION(size, BackendDAE.WHEN_EQ(cond, cr1, e_2, SOME(elsePart1)), source, attr), ext_arg_3); - - case (BackendDAE.ALGORITHM(size=size, alg=alg as DAE.ALGORITHM_STMTS(statementLst = stmts), source=source, expand=crefExpand, attr=attr), _, _) equation - (stmts1, ext_arg_1) = DAEUtil.traverseDAEEquationsStmts(stmts, inFunc, inTypeA); + (DAE.CREF(cr1, _), extArg) = inFunc(e1, inTypeA); + (e_2, extArg) = inFunc(e2, extArg); + (cond, extArg) = inFunc(cond, extArg); + (BackendDAE.WHEN_EQUATION(whenEquation=elsePart1), extArg) = traverseExpsOfEquation(BackendDAE.WHEN_EQUATION(size, elsePart, source, attr), inFunc, extArg); + then (BackendDAE.WHEN_EQUATION(size, BackendDAE.WHEN_EQ(cond, cr1, e_2, SOME(elsePart1)), source, attr), extArg); + + case BackendDAE.ALGORITHM(size=size, alg=alg as DAE.ALGORITHM_STMTS(statementLst = stmts), source=source, expand=crefExpand, attr=attr) equation + (stmts1, extArg) = DAEUtil.traverseDAEEquationsStmts(stmts, inFunc, inTypeA); alg = if referenceEq(stmts, stmts1) then alg else DAE.ALGORITHM_STMTS(stmts1); - then (BackendDAE.ALGORITHM(size, alg, source, crefExpand, attr), ext_arg_1); - - case (BackendDAE.COMPLEX_EQUATION(size=size, left=e1, right=e2, source=source, attr=attr), _, _) equation - (e_1, ext_arg_1) = inFunc(e1, inTypeA); - (e_2, ext_arg_2) = inFunc(e2, ext_arg_1); - then (BackendDAE.COMPLEX_EQUATION(size, e_1, e_2, source, attr), ext_arg_2); - - case (BackendDAE.IF_EQUATION(conditions=expl, eqnstrue=eqnslst, eqnsfalse=eqns, source=source, attr=attr), _, _) equation - (expl, ext_arg_1) = traverseBackendDAEExpList(expl, inFunc, inTypeA); - (eqnslst, ext_arg_2) = List.map1Fold(eqnslst, traverseExpsOfEquationList, inFunc, ext_arg_1); - (eqns, ext_arg_2) = List.map1Fold(eqns, traverseBackendDAEExpsEqn, inFunc, ext_arg_2); - then (BackendDAE.IF_EQUATION(expl, eqnslst, eqns, source, attr), ext_arg_2); + then (BackendDAE.ALGORITHM(size, alg, source, crefExpand, attr), extArg); + + case BackendDAE.COMPLEX_EQUATION(size=size, left=e1, right=e2, source=source, attr=attr) equation + (e_1, extArg) = inFunc(e1, inTypeA); + (e_2, extArg) = inFunc(e2, extArg); + then (BackendDAE.COMPLEX_EQUATION(size, e_1, e_2, source, attr), extArg); + + case BackendDAE.IF_EQUATION(conditions=expl, eqnstrue=eqnslst, eqnsfalse=eqns, source=source, attr=attr) equation + (expl, extArg) = traverseExpsOfExpList(expl, inFunc, inTypeA); + (eqnslst, extArg) = List.map1Fold(eqnslst, traverseExpsOfEquationList, inFunc, extArg); + (eqns, extArg) = List.map1Fold(eqns, traverseExpsOfEquation, inFunc, extArg); + then (BackendDAE.IF_EQUATION(expl, eqnslst, eqns, source, attr), extArg); end match; -end traverseBackendDAEExpsEqn; +end traverseExpsOfEquation; -public function traverseBackendDAEExpsEqnWithStop "author: Frenkel TUD 2010-11 +public function traverseExpsOfEquation_WithStop "author: Frenkel TUD 2010-11 Traverses all expressions of a equation. It is possible to change the equation." - replaceable type Type_a subtypeof Any; input BackendDAE.Equation inEquation; input FuncExpType func; - input Type_a inTypeA; + input T inTypeA; output Boolean outBoolean; - output Type_a outTypeA; + output T outTypeA; + partial function FuncExpType input DAE.Exp inExp; - input Type_a inTypeA; + input T inTypeA; output DAE.Exp outExp; output Boolean cont; - output Type_a outA; + output T outA; end FuncExpType; algorithm (outBoolean, outTypeA) := match (inEquation, func, inTypeA) @@ -737,7 +737,7 @@ algorithm BackendDAE.WhenEquation elsePart; DAE.ElementSource source; Integer size; - Type_a ext_arg, ext_arg_1, ext_arg_2, ext_arg_3; + T ext_arg, ext_arg_1, ext_arg_2, ext_arg_3; list dimSize; DAE.Algorithm alg; list stmts; @@ -802,13 +802,13 @@ algorithm (_, b, ext_arg) = func(cond, ext_arg); end if; if b then - (b, ext_arg) = traverseBackendDAEExpsEqnWithStop(BackendDAE.WHEN_EQUATION(size, elsePart, source, eqAttr), func, ext_arg); + (b, ext_arg) = traverseExpsOfEquation_WithStop(BackendDAE.WHEN_EQUATION(size, elsePart, source, eqAttr), func, ext_arg); end if; then (b, ext_arg); case (BackendDAE.ALGORITHM(alg=DAE.ALGORITHM_STMTS()), _, _) equation - print("not implemented error - BackendDAE.ALGORITHM - BackendEquation.traverseBackendDAEExpsEqnWithStop\n"); + print("not implemented error - BackendDAE.ALGORITHM - BackendEquation.traverseExpsOfEquation_WithStop\n"); // (stmts1, ext_arg_1) = DAEUtil.traverseDAEEquationsStmts(stmts, func, inTypeA); then fail(); @@ -823,82 +823,80 @@ algorithm case (BackendDAE.IF_EQUATION(conditions=expl, eqnstrue=eqnslst, eqnsfalse=eqns), _, _) equation - (b, ext_arg) = traverseBackendDAEExpListWithStop(expl, func, inTypeA); + (b, ext_arg) = traverseExpsOfExpList_WithStop(expl, func, inTypeA); if b then - (b, ext_arg) = traverseBackendDAEExpsEqnListListWithStop(eqnslst, func, ext_arg); + (b, ext_arg) = traverseExpsOfEquationListList_WithStop(eqnslst, func, ext_arg); end if; if b then - (b, ext_arg) = traverseBackendDAEExpsEqnListWithStop(eqns, func, ext_arg); + (b, ext_arg) = traverseExpsOfEquationList_WithStop(eqns, func, ext_arg); end if; then (b, ext_arg); end match; -end traverseBackendDAEExpsEqnWithStop; +end traverseExpsOfEquation_WithStop; -protected function traverseBackendDAEExpList "author Frenkel TUD: +protected function traverseExpsOfExpList "author Frenkel TUD: Calls user function for each element of list." - replaceable type Type_a subtypeof Any; input list inExpl; input FuncExpType rel; - input Type_a ext_arg; + input T inExtArg; output list outExpl; - output Type_a outTypeA; + output T outTypeA; + partial function FuncExpType input DAE.Exp inExp; - input Type_a inTypeA; + input T inTypeA; output DAE.Exp outExp; - output Type_a outA; + output T outA; end FuncExpType; algorithm - (outExpl, outTypeA) := match (inExpl, rel, ext_arg) + (outExpl, outTypeA) := match (inExpl) local DAE.Exp e, e1; list expl1, res; - Type_a ext_arg_1, ext_arg_2, ext_arg_3; + T extArg; - case ({}, _, ext_arg_1) - then ({}, ext_arg_1); + case {} + then ({}, inExtArg); - case (e::res, _, ext_arg_1) equation - (e1, ext_arg_2) = rel(e, ext_arg_1); - (expl1, ext_arg_3) = traverseBackendDAEExpList(res, rel, ext_arg_2); - then (e1::expl1, ext_arg_3); + case e::res equation + (e1, extArg) = rel(e, inExtArg); + (expl1, extArg) = traverseExpsOfExpList(res, rel, extArg); + then (e1::expl1, extArg); end match; -end traverseBackendDAEExpList; +end traverseExpsOfExpList; -protected function traverseBackendDAEExpListWithStop "author Frenkel TUD +protected function traverseExpsOfExpList_WithStop "author Frenkel TUD Calls user function for each element of list." - replaceable type Type_a subtypeof Any; input list inExpl; input FuncExpType rel; - input Type_a ext_arg; + input T inExtArg; output Boolean outBoolean; - output Type_a outTypeA; + output T outTypeA; partial function FuncExpType input DAE.Exp inExp; - input Type_a inTypeA; + input T inTypeA; output DAE.Exp outExp; output Boolean cont; - output Type_a outA; + output T outA; end FuncExpType;algorithm - (outBoolean, outTypeA) := match (inExpl, rel, ext_arg) + (outBoolean, outTypeA) := match(inExpl) local DAE.Exp e; list res; - Type_a ext_arg_1, ext_arg_2, ext_arg_3; + T extArg; Boolean b; - case ({}, _, ext_arg_1) - then (true, ext_arg_1); + case {} + then (true, inExtArg); - case (e::res, _, ext_arg_1) - equation - (_, b, ext_arg_2) = rel(e, ext_arg_1); - if b then - (b, ext_arg_2) = traverseBackendDAEExpListWithStop(res, rel, ext_arg_2); - end if; - then (b, ext_arg_2); + case e::res equation + (_, b, extArg) = rel(e, inExtArg); + if b then + (b, extArg) = traverseExpsOfExpList_WithStop(res, rel, extArg); + end if; + then (b, extArg); end match; -end traverseBackendDAEExpListWithStop; +end traverseExpsOfExpList_WithStop; public function traverseEquationArray "author: Frenkel TUD Traverses all equations of a BackendDAE.EquationArray." @@ -927,7 +925,7 @@ algorithm //end try; end traverseEquationArray; -public function traverseEquationArrayWithStop "author: Frenkel TUD +public function traverseEquationArray_WithStop "author: Frenkel TUD Traverses all equations of a BackendDAE.EquationArray." replaceable type Type_a subtypeof Any; input BackendDAE.EquationArray inEquationArray; @@ -947,14 +945,14 @@ protected algorithm //try BackendDAE.EQUATION_ARRAY(equOptArr=equOptArr) := inEquationArray; - outTypeA := BackendDAEUtil.traverseArrayNoCopyWithStop(equOptArr, inFuncWithStop, traverseOptEquationWithStop, inTypeA); + outTypeA := BackendDAEUtil.traverseArrayNoCopyWithStop(equOptArr, inFuncWithStop, traverseOptEquation_WithStop, inTypeA); //else // if Flags.isSet(Flags.FAILTRACE) then - // Debug.trace("- BackendEquation.traverseEquationArrayWithStop failed\n"); + // Debug.trace("- BackendEquation.traverseEquationArray_WithStop failed\n"); // end if; // fail(); //end try; -end traverseEquationArrayWithStop; +end traverseEquationArray_WithStop; protected function traverseOptEquation input Option inEquation; @@ -983,7 +981,7 @@ algorithm end match; end traverseOptEquation; -protected function traverseOptEquationWithStop +protected function traverseOptEquation_WithStop input Option inEquation; input FuncWithStop inFuncWithStop; input T inTypeA; @@ -1011,9 +1009,9 @@ algorithm (_, b, ext_arg) = inFuncWithStop(eqn, inTypeA); then (b, ext_arg); end match; -end traverseOptEquationWithStop; +end traverseOptEquation_WithStop; -public function traverseEquationArrayWithUpdate "author: Frenkel TUD +public function traverseEquationArray_WithUpdate "author: Frenkel TUD Traverses all equations of a BackendDAE.EquationArray." input BackendDAE.EquationArray inEquationArray; input FuncWithUpdate inFuncWithUpdate; @@ -1032,11 +1030,11 @@ protected array> equOptArr; algorithm BackendDAE.EQUATION_ARRAY(size=size, numberOfElement=numberOfElement, arrSize=arrSize, equOptArr=equOptArr) := inEquationArray; - (equOptArr, outTypeA) := BackendDAEUtil.traverseArrayNoCopyWithUpdate(equOptArr, inFuncWithUpdate, traverseOptEquationWithUpdate, inTypeA); + (equOptArr, outTypeA) := BackendDAEUtil.traverseArrayNoCopyWithUpdate(equOptArr, inFuncWithUpdate, traverseOptEquation_WithUpdate, inTypeA); outEquationArray := BackendDAE.EQUATION_ARRAY(size, numberOfElement, arrSize, equOptArr); -end traverseEquationArrayWithUpdate; +end traverseEquationArray_WithUpdate; -protected function traverseOptEquationWithUpdate "author: Frenkel TUD 2010-11 +protected function traverseOptEquation_WithUpdate "author: Frenkel TUD 2010-11 Helper for traverseBackendDAEExpsEqnsWithUpdate." input Option inEquation; input FuncWithUpdate inFuncWithUpdate; @@ -1065,7 +1063,7 @@ algorithm oeqn = if referenceEq(eqn, eqn1) then inEquation else SOME(eqn1); then (oeqn, ext_arg); end match; -end traverseOptEquationWithUpdate; +end traverseOptEquation_WithUpdate; public function equationEqual " Returns true if two equations are equal" @@ -1689,24 +1687,6 @@ algorithm end matchcontinue; end equationToResidualForm; -public function traverseequationToResidualForm -"author: Frenkel TUD 2010-11" - input tuple> inTpl; - output tuple> outTpl; -algorithm - outTpl := matchcontinue (inTpl) - local - list eqns; - BackendDAE.Equation eqn,reqn; - case ((eqn,eqns)) - equation - reqn = equationToResidualForm(eqn); - then - ((eqn,reqn::eqns)); - else inTpl; - end matchcontinue; -end traverseequationToResidualForm; - public function traverseEquationToScalarResidualForm "author: Frenkel TUD 2010-11" input BackendDAE.Equation inEq; diff --git a/Compiler/BackEnd/HpcOmMemory.mo b/Compiler/BackEnd/HpcOmMemory.mo index d95f0ce24ed..63993b5a92b 100644 --- a/Compiler/BackEnd/HpcOmMemory.mo +++ b/Compiler/BackEnd/HpcOmMemory.mo @@ -1365,7 +1365,7 @@ encapsulated package HpcOmMemory list varIdcList; algorithm //print("getEqSCVarMapping0: Handling equation:\n" + BackendDump.equationString(iEquation) + "\n"); - (_,(_,(_,oMapping))) := BackendEquation.traverseBackendDAEExpsEqn(iEquation,Expression.traverseSubexpressionsHelper, (createMemoryMapTraverse0, (iHt,{}))); + (_,(_,(_,oMapping))) := BackendEquation.traverseExpsOfEquation(iEquation,Expression.traverseSubexpressionsHelper, (createMemoryMapTraverse0, (iHt,{}))); //((_,(_,oMapping))) := Expression.traverseExp(exp,createMemoryMapTraverse, (iHt,{})); end getEqSCVarMapping0; diff --git a/Compiler/BackEnd/IndexReduction.mo b/Compiler/BackEnd/IndexReduction.mo index 6effa51c3c1..8b80400b8c5 100644 --- a/Compiler/BackEnd/IndexReduction.mo +++ b/Compiler/BackEnd/IndexReduction.mo @@ -767,7 +767,7 @@ algorithm //fcall(Flags.BLT_DUMP, print, "differentiated equation " + intString(e) + " " + BackendDump.equationString(eqn_1) + "\n"); eqn = BackendEquation.markDifferentiated(eqn); // get needed der(variables) from equation - (_,(_,(_,_,elst))) = BackendEquation.traverseBackendDAEExpsEqn(eqn_1, Expression.traverseSubexpressionsHelper, (getDerVarsExp, (vars,ass1,{}))); + (_,(_,(_,_,elst))) = BackendEquation.traverseExpsOfEquation(eqn_1, Expression.traverseSubexpressionsHelper, (getDerVarsExp, (vars,ass1,{}))); elst = List.map1r(elst,arrayGet,mapIncRowEqn); elst = List.fold2(elst, addUnMarked, mark, markarr, inNextEqns); (eqntpl, shared) = differentiateSetEqns(es,inNextEqns,vars,eqns,ass1,mapIncRowEqn,mark,markarr,shared,(e,SOME(eqn_1),eqn)::inEqnTpl); @@ -905,8 +905,8 @@ algorithm case ({},_,_,_,_,_,_,_) then (vars,eqns,inStateOrd,inChangedVars,inOrgEqnsLst); case ((e,SOME(eqn_1),eqn)::rest,_,_,_,_,_,_,_) equation - (eqn_1,_) = BackendDAETransform.traverseBackendDAEExpsEqn(eqn_1, replaceStateOrderExp, vars); - (eqn_1,(_,(vars1,eqns1,_,changedVars,_,_,_))) = BackendDAETransform.traverseBackendDAEExpsEqn(eqn_1,Expression.traverseSubexpressionsHelper,(changeDerVariablestoStatesFinderNew,(vars,eqns,inStateOrd,inChangedVars,e,imapIncRowEqn,mt))); + (eqn_1,_) = BackendDAETransform.traverseExpsOfEquation(eqn_1, replaceStateOrderExp, vars); + (eqn_1,(_,(vars1,eqns1,_,changedVars,_,_,_))) = BackendDAETransform.traverseExpsOfEquation(eqn_1,Expression.traverseSubexpressionsHelper,(changeDerVariablestoStatesFinderNew,(vars,eqns,inStateOrd,inChangedVars,e,imapIncRowEqn,mt))); if Flags.isSet(Flags.BLT_DUMP) then debugdifferentiateEqns((eqn,eqn_1)); end if; @@ -1253,7 +1253,7 @@ algorithm // get the equation eqn := BackendEquation.equationNth1(eqns, e); // reaplace final vars - (eqn, (_, b, repl)) := BackendEquation.traverseBackendDAEExpsEqn(eqn, replaceFinalVarsEqn, (vars, false, repl)); + (eqn, (_, b, repl)) := BackendEquation.traverseExpsOfEquation(eqn, replaceFinalVarsEqn, (vars, false, repl)); // if replaced set eqn eqns := if b then BackendEquation.setAtIndex(eqns, e, eqn) else eqns; changedEqns := List.consOnTrue(b, e, changedEqns); @@ -1359,7 +1359,7 @@ algorithm case (pos::rest, _, _, _, _) equation // replace in eqn eqn = BackendEquation.equationNth1(inEqns, pos); - (eqn1, _) = BackendDAETransform.traverseBackendDAEExpsEqn(eqn, replaceAliasStateExp, (inACr, inCrExp, indCrExp)); + (eqn1, _) = BackendDAETransform.traverseExpsOfEquation(eqn, replaceAliasStateExp, (inACr, inCrExp, indCrExp)); eqns = BackendEquation.setAtIndex(inEqns, pos, eqn1); // print("Replace in Eqn:\n" + BackendDump.equationString(eqn) + "\nto\n" + BackendDump.equationString(eqn1) + "\n"); then replaceAliasState(rest, inCrExp, indCrExp, inACr, eqns); diff --git a/Compiler/BackEnd/Initialization.mo b/Compiler/BackEnd/Initialization.mo index 988b2a63123..9c105bc4b3a 100644 --- a/Compiler/BackEnd/Initialization.mo +++ b/Compiler/BackEnd/Initialization.mo @@ -2298,7 +2298,7 @@ algorithm (eqns, reeqns) := inTpl; // replace der(x) with $DER.x and replace pre(x) with $PRE.x - (eqn1, _) := BackendEquation.traverseBackendDAEExpsEqn(eqn, Expression.traverseSubexpressionsDummyHelper, replaceDerPreCref); + (eqn1, _) := BackendEquation.traverseExpsOfEquation(eqn, Expression.traverseSubexpressionsDummyHelper, replaceDerPreCref); // add it, if size is zero (terminate, assert, noretcall) move to removed equations size := BackendEquation.equationSize(eqn1); diff --git a/Compiler/BackEnd/ResolveLoops.mo b/Compiler/BackEnd/ResolveLoops.mo index 90473082453..77e18cc535f 100644 --- a/Compiler/BackEnd/ResolveLoops.mo +++ b/Compiler/BackEnd/ResolveLoops.mo @@ -307,7 +307,7 @@ protected algorithm outEq := inEq; eqLst := inEqs; - (eq,isSimple) := BackendEquation.traverseBackendDAEExpsEqn(inEq,isAddOrSubExp,true); + (eq,isSimple) := BackendEquation.traverseExpsOfEquation(inEq,isAddOrSubExp,true); eqLst := if isSimple then eq::eqLst else eqLst; end getSimpleEquations; diff --git a/Compiler/BackEnd/SymbolicJacobian.mo b/Compiler/BackEnd/SymbolicJacobian.mo index 554626ba684..ef734ee94c2 100644 --- a/Compiler/BackEnd/SymbolicJacobian.mo +++ b/Compiler/BackEnd/SymbolicJacobian.mo @@ -3023,7 +3023,7 @@ algorithm case (_,_) equation repl = BackendDAEUtil.makeZeroReplacements(vars); - ((_,res,_)) = BackendEquation.traverseEquationArrayWithStop(eqns,rhsConstant2,(vars,true,repl)); + ((_,res,_)) = BackendEquation.traverseEquationArray_WithStop(eqns,rhsConstant2,(vars,true,repl)); then res; end matchcontinue; diff --git a/Compiler/BackEnd/SynchronousFeatures.mo b/Compiler/BackEnd/SynchronousFeatures.mo index 7e3b4bc7b05..73b980bef2b 100644 --- a/Compiler/BackEnd/SynchronousFeatures.mo +++ b/Compiler/BackEnd/SynchronousFeatures.mo @@ -470,7 +470,7 @@ algorithm else algorithm (_, (outContinuousTimeVars, outClockedVars)) := - BackendEquation.traverseBackendDAEExpsEqn(eq, getVariableLists, + BackendEquation.traverseExpsOfEquation(eq, getVariableLists, (outContinuousTimeVars, outClockedVars)); then (); diff --git a/Compiler/SimCode/SimCodeUtil.mo b/Compiler/SimCode/SimCodeUtil.mo index 02b9ec37ce4..a2a40e52d49 100644 --- a/Compiler/SimCode/SimCodeUtil.mo +++ b/Compiler/SimCode/SimCodeUtil.mo @@ -3008,7 +3008,7 @@ algorithm eqn = BackendDAE.EQUATION(e1, e2, source, BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN); (resEqs, uniqueEqIndex, tempvars) = createNonlinearResidualEquations({eqn}, iuniqueEqIndex, itempvars); cr = if BackendVariable.isStateVar(v) then ComponentReference.crefPrefixDer(cr) else cr; - (_, homotopySupport) = BackendDAETransform.traverseBackendDAEExpsEqn(eqn, containsHomotopyCall, false); + (_, homotopySupport) = BackendDAETransform.traverseExpsOfEquation(eqn, containsHomotopyCall, false); then ({SimCode.SES_NONLINEAR(uniqueEqIndex, resEqs, {cr}, 0, NONE(), false, homotopySupport, false)}, uniqueEqIndex+1, tempvars); @@ -3023,7 +3023,7 @@ algorithm // index = System.tmpTick(); (resEqs, uniqueEqIndex, tempvars) = createNonlinearResidualEquations({eqn}, iuniqueEqIndex, itempvars); cr = if BackendVariable.isStateVar(v) then ComponentReference.crefPrefixDer(cr) else cr; - (_, homotopySupport) = BackendDAETransform.traverseBackendDAEExpsEqn(eqn, containsHomotopyCall, false); + (_, homotopySupport) = BackendDAETransform.traverseExpsOfEquation(eqn, containsHomotopyCall, false); then ({SimCode.SES_NONLINEAR(uniqueEqIndex, resEqs, {cr}, 0, NONE(), false, homotopySupport, false)}, uniqueEqIndex+1, tempvars); @@ -5751,7 +5751,7 @@ algorithm // solved variables are on rhs and also lhs. This is not // cosidered yet there. (resEqs, uniqueEqIndex, tempvars) = createNonlinearResidualEquations({inEquation}, iuniqueEqIndex, itempvars); - (_, homotopySupport) = BackendDAETransform.traverseBackendDAEExpsEqn(inEquation, containsHomotopyCall, false); + (_, homotopySupport) = BackendDAETransform.traverseExpsOfEquation(inEquation, containsHomotopyCall, false); then ({SimCode.SES_NONLINEAR(uniqueEqIndex, resEqs, crefs, 0, NONE(), false, homotopySupport, false)}, uniqueEqIndex+1, tempvars); // failure