From c2604cdecfb3b0ea4d5ceb69391a6e741398fd48 Mon Sep 17 00:00:00 2001 From: phannebohm Date: Thu, 31 Aug 2023 22:39:43 +0200 Subject: [PATCH] [janitor] Cleanup (#10954) --- .../Compiler/BackEnd/BackendDAEOptimize.mo | 48 +++++-------------- OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo | 9 ++-- .../Compiler/BackEnd/EvaluateFunctions.mo | 12 ++--- OMCompiler/Compiler/FrontEnd/Expression.mo | 46 +++++++++++------- .../Compiler/NBackEnd/Classes/NBEquation.mo | 6 +-- OMCompiler/Compiler/SimCode/SimCodeMain.mo | 7 ++- OMCompiler/Compiler/SimCode/SimCodeUtil.mo | 7 --- OMCompiler/Compiler/Template/CodegenC.tpl | 2 +- OMCompiler/Compiler/Template/SimCodeTV.mo | 6 --- OMCompiler/Compiler/Util/Util.mo | 3 -- .../c/simulation/solver/cvode_solver.c | 2 +- 11 files changed, 55 insertions(+), 93 deletions(-) diff --git a/OMCompiler/Compiler/BackEnd/BackendDAEOptimize.mo b/OMCompiler/Compiler/BackEnd/BackendDAEOptimize.mo index 9a83ee610d6..9c53ab9742f 100644 --- a/OMCompiler/Compiler/BackEnd/BackendDAEOptimize.mo +++ b/OMCompiler/Compiler/BackEnd/BackendDAEOptimize.mo @@ -5350,15 +5350,13 @@ protected function replaceDerCallWork input BackendDAE.Shared shared; output BackendDAE.EqSystem osyst; output BackendDAE.Shared oshared = shared; -protected - BackendDAE.Variables vars; - BackendDAE.EquationArray eqns; - list eqnsList; algorithm osyst := match inSyst local BackendDAE.EqSystem syst; BackendDAE.Variables localKnowns; + BackendDAE.Variables vars; + BackendDAE.EquationArray eqns; case syst as BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns) algorithm (eqns, vars) := @@ -5366,7 +5364,8 @@ algorithm (localKnowns, vars) := BackendVariable.traverseBackendDAEVars(vars, moveStatesVariables, (oshared.localKnownVars, vars)); oshared.localKnownVars := localKnowns; - syst.orderedEqs := eqns; syst.orderedVars := vars; + syst.orderedEqs := eqns; + syst.orderedVars := vars; then syst; end match; end replaceDerCallWork; @@ -5379,7 +5378,6 @@ protected function traverserreplaceDerCall " output BackendDAE.Variables outVars = inVars; protected BackendDAE.Equation e; - BackendDAE.Variables vars; list ops; algorithm (e, ops) := BackendEquation.traverseExpsOfEquation(inEq, traverserreplaceDerCallExp, {}); @@ -5394,20 +5392,12 @@ protected function traverserreplaceDerCallExp " output list outTpl; protected DAE.Exp e, e1; - tuple ext_arg; - BackendDAE.Variables vars; - list ops; - DAE.FunctionTree funcs; - Boolean b, addVars; - BackendDAE.Shared shared; - list eqnLst; + Boolean b; algorithm e := inExp; - ops := tpl; (e1, b) := Expression.traverseExpBottomUp(e, replaceDerCall, false); - ops := List.consOnTrue(b, DAE.SUBSTITUTION({e1}, e), ops); + outTpl := List.consOnTrue(b, DAE.SUBSTITUTION({e1}, e), tpl); outExp := e1; - outTpl := ops; end traverserreplaceDerCallExp; protected function replaceDerCall " @@ -5419,19 +5409,8 @@ protected function replaceDerCall " algorithm (outExp,tpl) := matchcontinue (inExp, itpl) local - BackendDAE.Variables vars; DAE.ComponentRef cr,cref; DAE.Type ty; - String str; - BackendDAE.Shared shared; - list varlst; - BackendDAE.Var v, v1; - Boolean b, addVar; - DAE.FunctionTree funcs; - list eqnLst; - Integer numVars; - list expLst; - String str; case (DAE.CALL(path=Absyn.IDENT(name="der"), expLst={DAE.CREF(componentRef=cr, ty=ty)}), _) equation cref = ComponentReference.crefPrefixDer(cr); @@ -5439,8 +5418,7 @@ algorithm then (outExp, true); case (DAE.CALL(path=Absyn.IDENT(name="der")), _) equation - str = "BackendDAEOptimize.replaceDerCall failed for: " + ExpressionDump.printExpStr(inExp) + "\n"; - Error.addMessage(Error.INTERNAL_ERROR, {str}); + Error.addMessage(Error.INTERNAL_ERROR, {getInstanceName() + " failed for: " + ExpressionDump.printExpStr(inExp) + "\n"}); then fail(); else (inExp, itpl); @@ -5453,11 +5431,11 @@ protected function moveStatesVariables output BackendDAE.Var outVar = inVar; output tuple outTpl = inTpl; algorithm - _ := match(inVar) - local - DAE.ComponentRef cref; - BackendDAE.Var newVar; - BackendDAE.Variables localKnowns, newVars; + () := match(inVar) + local + DAE.ComponentRef cref; + BackendDAE.Var newVar; + BackendDAE.Variables localKnowns, newVars; case(BackendDAE.VAR(varKind = BackendDAE.STATE(), varName=cref)) algorithm (localKnowns, newVars) := inTpl; // remove the state from variables @@ -5472,7 +5450,7 @@ algorithm newVars := BackendVariable.addVar(newVar, newVars); outTpl := (localKnowns, newVars); then (); - else then(); + else (); end match; end moveStatesVariables; diff --git a/OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo b/OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo index 5ed3d9b50ac..8830c43e052 100644 --- a/OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo +++ b/OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo @@ -5468,22 +5468,19 @@ algorithm local DAE.ComponentRef cr; DAE.Type ty; - String str; BackendDAE.Var v; - list expLst; case (DAE.CALL(path=Absyn.IDENT(name="der"), expLst={DAE.CREF(componentRef=cr, ty=ty)})) equation v = BackendVariable.createAliasDerVar(cr); cr = BackendVariable.varCref(v); outExp = DAE.CREF(cr,ty); - then (outExp); + then (outExp); case (DAE.CALL(path=Absyn.IDENT(name="der"))) equation - str = "BackendDAEUtil.replaceDerCall failed for: " + ExpressionDump.printExpStr(inExp) + "\n"; - Error.addMessage(Error.INTERNAL_ERROR, {str}); - then fail(); + Error.addMessage(Error.INTERNAL_ERROR, {getInstanceName() + " failed for: " + ExpressionDump.printExpStr(inExp) + "\n"}); + then fail(); else (inExp); end matchcontinue; diff --git a/OMCompiler/Compiler/BackEnd/EvaluateFunctions.mo b/OMCompiler/Compiler/BackEnd/EvaluateFunctions.mo index b8c8187b6d1..08239fda1a7 100644 --- a/OMCompiler/Compiler/BackEnd/EvaluateFunctions.mo +++ b/OMCompiler/Compiler/BackEnd/EvaluateFunctions.mo @@ -3444,18 +3444,16 @@ algorithm end setVarKindForStates; protected function findDerVarCrefs "traverses all the sub expressions and searches for der(var)" - input DAE.Exp inExp; + input output DAE.Exp exp; input list inCrefs; - output DAE.Exp outExp; output list outCrefs; algorithm - (outExp,outCrefs) := match(inExp,inCrefs) + outCrefs := match exp local DAE.ComponentRef cr; - tuple> tpl; - case (DAE.CALL(path = Absyn.IDENT(name = "der"),expLst = {DAE.CREF(componentRef = cr)}),_) - then (inExp,cr::inCrefs); - else (inExp,inCrefs); + case DAE.CALL(path = Absyn.IDENT(name = "der"), expLst = {DAE.CREF(componentRef = cr)}) + then cr :: inCrefs; + else inCrefs; end match; end findDerVarCrefs; diff --git a/OMCompiler/Compiler/FrontEnd/Expression.mo b/OMCompiler/Compiler/FrontEnd/Expression.mo index e67ae7a5f79..73d0d4e1767 100644 --- a/OMCompiler/Compiler/FrontEnd/Expression.mo +++ b/OMCompiler/Compiler/FrontEnd/Expression.mo @@ -917,7 +917,8 @@ public function prependSubscriptExp algorithm outExp := match(exp,subscr) local - Type t; ComponentRef cr,cr1,cr2; + Type t; + ComponentRef cr, cr1, cr2; list subs; DAE.Exp e; @@ -7718,43 +7719,39 @@ public function isPositiveOrZero input DAE.Exp inExp; output Boolean outBoolean; algorithm - - outBoolean := match (inExp) local Boolean b,b1,b2,b3; DAE.Exp e1,e2; Integer i; Real r; - /* abs(e) */ - case DAE.CALL(path = Absyn.IDENT("abs")) then true; - // exp(x) - case DAE.CALL(path = Absyn.IDENT("exp")) then true; - // cosh(x) - case DAE.CALL(path = Absyn.IDENT("cosh")) then true; - /* literals */ + + /* literals */ case DAE.ICONST(i) then i >= 0; case DAE.RCONST(r) then r >= 0.0; - /* e1 + e2 */ + + /* e1 + e2 */ case DAE.BINARY(e1,DAE.ADD(),e2) then isPositiveOrZero(e1) and isPositiveOrZero(e2); - /* e1 - e2 */ + /* e1 - e2 */ case DAE.BINARY(e1,DAE.SUB(),e2) then isPositiveOrZero(e1) and isNegativeOrZero(e2); - /* e1 * e2 , -e1 * -e2, e ^ 2.0 */ + + /* e1 * e2 , -e1 * -e2, e ^ 2.0 */ case DAE.BINARY(e1,DAE.MUL(),e2) equation b1 = (isPositiveOrZero(e1) and isPositiveOrZero(e2)); b2 = (isNegativeOrZero(e1) and isNegativeOrZero(e2)); b3 = expEqual(e1,e2); then b1 or b2 or b3; - /* e1 / e2, -e1 / -e2 */ + /* e1 / e2, -e1 / -e2 */ case DAE.BINARY(e1,DAE.DIV(),e2) equation b1 = (isPositiveOrZero(e1) and isPositiveOrZero(e2)); b2 = (isNegativeOrZero(e1) and isNegativeOrZero(e2)); then b1 or b2; - /* Integer power we can say something good about */ + + /* Integer power we can say something good about */ case DAE.BINARY(e1,DAE.POW(),DAE.RCONST(r)) equation i = realInt(r); @@ -7764,10 +7761,24 @@ algorithm b = b2 or b3; then b1 and b; case DAE.BINARY(_,DAE.POW(),e2) then isEven(e2); - // -(x) + + /* -(x) */ case DAE.UNARY(DAE.UMINUS(), e1) then isNegativeOrZero(e1); - else isZero(inExp); + /* builtin calls */ + case DAE.CALL(path = Absyn.IDENT("abs")) then true; + case DAE.CALL(path = Absyn.IDENT("cosh")) then true; + case DAE.CALL(path = Absyn.IDENT("exp")) then true; + case DAE.CALL(path = Absyn.IDENT("sign"), expLst = {e1}) then isPositiveOrZero(e1); + case DAE.CALL(path = Absyn.IDENT("sinh"), expLst = {e1}) then isPositiveOrZero(e1); + case DAE.CALL(path = Absyn.IDENT("tanh"), expLst = {e1}) then isPositiveOrZero(e1); + case DAE.CALL(path = Absyn.IDENT("ceil"), expLst = {e1}) then isPositiveOrZero(e1); + case DAE.CALL(path = Absyn.IDENT("floor"), expLst = {e1}) then isPositiveOrZero(e1); + case DAE.CALL(path = Absyn.IDENT("integer"), expLst = {e1}) then isPositiveOrZero(e1); + + // TODO div, mod, rem, ... + + else isZero(inExp); end match; end isPositiveOrZero; @@ -7787,7 +7798,6 @@ algorithm case DAE.BINARY(_,DAE.POW(),e2) guard(isOdd(e2)) then isNegativeOrZero(e2); else isZero(inExp); - end match; end isNegativeOrZero; diff --git a/OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo b/OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo index 032a752fbd3..5263f3a28e4 100644 --- a/OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo +++ b/OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo @@ -351,11 +351,7 @@ public function size input Iterator iter; - output Integer size = 1; - algorithm - for i in sizes(iter) loop - size := size * i; - end for; + output Integer size = product(i for i in sizes(iter)); end size; function createLocationReplacements diff --git a/OMCompiler/Compiler/SimCode/SimCodeMain.mo b/OMCompiler/Compiler/SimCode/SimCodeMain.mo index 28ee9937f85..976dfa52b13 100644 --- a/OMCompiler/Compiler/SimCode/SimCodeMain.mo +++ b/OMCompiler/Compiler/SimCode/SimCodeMain.mo @@ -1,7 +1,7 @@ /* * This file is part of OpenModelica. * - * Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC), + * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), * c/o Linköpings universitet, Department of Computer and Information Science, * SE-58183 Linköping, Sweden. * @@ -108,7 +108,6 @@ import Util; import SerializeTaskSystemInfo; public -constant Boolean debug=true; uniontype TranslateModelKind record NORMAL end NORMAL; @@ -310,7 +309,7 @@ algorithm else setGlobalRoot(Global.stackoverFlowIndex, NONE()); ErrorExt.rollbackNumCheckpoints(ErrorExt.getNumCheckpoints()-numCheckpoints); - Error.addInternalError("Stack overflow in "+getInstanceName()+"...\n"+stringDelimitList(StackOverflow.readableStacktraceMessages(), "\n"), sourceInfo()); + Error.addInternalError("Stack overflow in " + getInstanceName() + "...\n" + stringDelimitList(StackOverflow.readableStacktraceMessages(), "\n"), sourceInfo()); /* Do not fail or we can loop too much */ StackOverflow.clearStacktraceMessages(); end try annotation(__OpenModelica_stackOverflowCheckpoint=true); @@ -428,7 +427,7 @@ algorithm else setGlobalRoot(Global.stackoverFlowIndex, NONE()); ErrorExt.rollbackNumCheckpoints(ErrorExt.getNumCheckpoints()-numCheckpoints); - Error.addInternalError("Stack overflow in "+getInstanceName()+"...\n"+stringDelimitList(StackOverflow.readableStacktraceMessages(), "\n"), sourceInfo()); + Error.addInternalError("Stack overflow in " + getInstanceName() + "...\n" + stringDelimitList(StackOverflow.readableStacktraceMessages(), "\n"), sourceInfo()); /* Do not fail or we can loop too much */ StackOverflow.clearStacktraceMessages(); fail(); diff --git a/OMCompiler/Compiler/SimCode/SimCodeUtil.mo b/OMCompiler/Compiler/SimCode/SimCodeUtil.mo index f611f8f8cf7..979c54dc906 100644 --- a/OMCompiler/Compiler/SimCode/SimCodeUtil.mo +++ b/OMCompiler/Compiler/SimCode/SimCodeUtil.mo @@ -15419,13 +15419,6 @@ algorithm end match; end getNumContinuousEquationsSingleEq; -public function sortCrefBasedOnSimCodeIndex - input output list crs; - input SimCode.SimCode simCode; -algorithm - crs := List.sort(crs, function crefSimCodeIndexGreaterThan(simCode=simCode)); -end sortCrefBasedOnSimCodeIndex; - protected function crefSimCodeIndexGreaterThan input DAE.ComponentRef cr1, cr2; input SimCode.SimCode simCode; diff --git a/OMCompiler/Compiler/Template/CodegenC.tpl b/OMCompiler/Compiler/Template/CodegenC.tpl index 5576875a6a2..984b7b48df9 100644 --- a/OMCompiler/Compiler/Template/CodegenC.tpl +++ b/OMCompiler/Compiler/Template/CodegenC.tpl @@ -330,7 +330,7 @@ template functionInitSynchronous(list clockedPartitions, Strin void <%symbolName(modelNamePrefix,"function_initSynchronous")%>(DATA *data, threadData_t *threadData) { TRACE_PUSH - assertStreamPrint(threadData, data->modelData->nBaseClocks==<%listLength(clockedPartitions)%>, "Number of base clocks doens't match numer of clocks that are initialized! Code generation error!"); + assertStreamPrint(threadData, data->modelData->nBaseClocks==<%listLength(clockedPartitions)%>, "Number of base clocks doesn't match number of clocks that are initialized! Code generation error!"); data->simulationInfo->baseClocks = calloc(<%listLength(clockedPartitions)%>, sizeof(BASECLOCK_DATA)); <%body%> diff --git a/OMCompiler/Compiler/Template/SimCodeTV.mo b/OMCompiler/Compiler/Template/SimCodeTV.mo index 5b1e5e7026e..a91d7323c8f 100644 --- a/OMCompiler/Compiler/Template/SimCodeTV.mo +++ b/OMCompiler/Compiler/Template/SimCodeTV.mo @@ -1383,12 +1383,6 @@ package SimCodeUtil output list eqs; end sortSimpleAssignmentBasedOnLhs; - function sortCrefBasedOnSimCodeIndex - input list inCrefs; - input SimCode.SimCode simCode; - output list crs; - end sortCrefBasedOnSimCodeIndex; - function getNumContinuousEquations input list eqs; input Integer numStates; diff --git a/OMCompiler/Compiler/Util/Util.mo b/OMCompiler/Compiler/Util/Util.mo index c916e421c5e..3557686b011 100644 --- a/OMCompiler/Compiler/Util/Util.mo +++ b/OMCompiler/Compiler/Util/Util.mo @@ -602,7 +602,6 @@ algorithm outValue := match(inValue) local TI value; - TO res; case SOME(value) then inFunc(value); else inDefaultValue; @@ -628,7 +627,6 @@ algorithm outValue := match(inValue) local TI value; - TO res; case SOME(value) then inFunc(value, inArg); else inDefaultValue; @@ -656,7 +654,6 @@ algorithm outValue := match(inValue) local TI value; - TO res; case SOME(value) then inFunc(value, inArg1, inArg2); else inDefaultValue; diff --git a/OMCompiler/SimulationRuntime/c/simulation/solver/cvode_solver.c b/OMCompiler/SimulationRuntime/c/simulation/solver/cvode_solver.c index e667904331d..3e096f2e833 100644 --- a/OMCompiler/SimulationRuntime/c/simulation/solver/cvode_solver.c +++ b/OMCompiler/SimulationRuntime/c/simulation/solver/cvode_solver.c @@ -583,7 +583,7 @@ int cvode_solver_initial(DATA *data, threadData_t *threadData, SOLVER_INFO *solv flag = CVodeSetErrHandlerFn(cvodeData->cvode_mem, cvodeErrorHandlerFunction, cvodeData); checkReturnFlag_SUNDIALS(flag, SUNDIALS_CV_FLAG, "CVodeSetErrHandlerFn"); - /* Set linear solver useb by CVODE */ + /* Set linear solver used by CVODE */ cvodeData->y_linSol = N_VNew_Serial(cvodeData->N); switch (cvodeData->config.jacobianMethod) {