Skip to content

Commit 0f93219

Browse files
authored
Use proper format specifiers (#14446)
- Use proper format specifiers - Remove some compiler warnings - Avoid unnecessary tuples
1 parent 063cb48 commit 0f93219

File tree

19 files changed

+154
-175
lines changed

19 files changed

+154
-175
lines changed

OMCompiler/Compiler/BackEnd/BackendDAE.mo

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,15 +441,15 @@ end WhenEquation;
441441
public
442442
uniontype WhenOperator
443443
record ASSIGN " left_cr = right_exp"
444-
.DAE.Exp left "left hand side of equation";
445-
.DAE.Exp right "right hand side of equation";
446-
.DAE.ElementSource source "origin of equation";
444+
.DAE.Exp left "left hand side of equation";
445+
.DAE.Exp right "right hand side of equation";
446+
.DAE.ElementSource source "origin of equation";
447447
end ASSIGN;
448448

449449
record REINIT "Reinit Statement"
450450
.DAE.ComponentRef stateVar "State variable to reinit";
451-
.DAE.Exp value "Value after reinit";
452-
.DAE.ElementSource source "origin of equation";
451+
.DAE.Exp value "Value after reinit";
452+
.DAE.ElementSource source "origin of equation";
453453
end REINIT;
454454

455455
record ASSERT

OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5777,21 +5777,20 @@ end getEqnAndVarsFromInnerEquation;
57775777

57785778
public function getEqnAndVarsFromInnerEquationLst
57795779
input BackendDAE.InnerEquations innerEquations;
5780-
output tuple<list<Integer>,list<list<Integer>>,list<BackendDAE.Constraints>> eqnVarConstTpl;
5780+
output list<Integer> eqns = {};
5781+
output list<list<Integer>> allVars = {};
5782+
output list<BackendDAE.Constraints> allConstraints = {};
57815783
protected
57825784
Integer eqn;
5783-
list<Integer> eqns = {}, vars;
5784-
list<list<Integer>> allVars = {};
5785+
list<Integer> vars;
57855786
BackendDAE.Constraints constraints;
5786-
list<BackendDAE.Constraints> allConstraints = {};
57875787
algorithm
57885788
for innerEq in innerEquations loop
57895789
(eqn,vars,constraints) := getEqnAndVarsFromInnerEquation(innerEq);
57905790
eqns := eqn::eqns;
5791-
allVars := vars::allVars;
5792-
allConstraints := constraints::allConstraints;
5791+
if isPresent(allVars) then allVars := vars::allVars; end if;
5792+
if isPresent(allConstraints) then allConstraints := constraints::allConstraints; end if;
57935793
end for;
5794-
eqnVarConstTpl := (eqns,allVars,allConstraints);
57955794
end getEqnAndVarsFromInnerEquationLst;
57965795

57975796
protected function transformSolvabilityForCasualTearingSet

OMCompiler/Compiler/BackEnd/DataReconciliation.mo

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ protected
10501050
list<tuple<Integer, BackendDAE.Equation, list<Integer>>> unMeasuredVariablesAndEquations;
10511051
algorithm
10521052
for eq in unMeasuredEqsLst loop
1053-
(_, varIndex) := getSolvedVariableNumber(eq, solvedEqsAndVarsInfo);
1053+
varIndex := getSolvedVariableNumber(eq, solvedEqsAndVarsInfo);
10541054
intermediateVars := getVariablesAfterExtraction({eq}, {}, sBltAdjacencyMatrix);
10551055
intermediateVars := listReverse(List.setDifferenceOnTrue(intermediateVars, knownVars, intEq));
10561056
//print("\n equation No: " + anyString(eq) + "==>" + anyString(varIndex));
@@ -1224,7 +1224,7 @@ algorithm
12241224

12251225
// if status == false, prepare setB = {(var, equation to be removed)}
12261226
if not status then
1227-
(_, varnumber) := getSolvedVariableNumber(eq, solvedEqsAndVarsInfo);
1227+
varnumber := getSolvedVariableNumber(eq, solvedEqsAndVarsInfo);
12281228
if listEmpty(minimalSetS) then
12291229
minimalSetS := {eq}; // first equation is detected as boundary condition equation
12301230
end if;
@@ -1389,7 +1389,7 @@ algorithm
13891389
break;
13901390
end if;
13911391

1392-
(mappedEq, _) := getSolvedEquationNumber(varIndex, solvedEqsAndVarsInfo);
1392+
mappedEq := getSolvedEquationNumber(varIndex, solvedEqsAndVarsInfo);
13931393

13941394
if not listMember(mappedEq, bindingEquations) then
13951395
minimalSetS := mappedEq :: minimalSetS;
@@ -2134,7 +2134,7 @@ protected
21342134
Integer varNumber;
21352135
algorithm
21362136
for eq in constantEquations loop
2137-
(_, varNumber) := getSolvedVariableNumber(eq, solvedEqsVarInfo);
2137+
varNumber := getSolvedVariableNumber(eq, solvedEqsVarInfo);
21382138
constantVariables := varNumber :: constantVariables;
21392139
end for;
21402140
end getExactConstantVariables;
@@ -2148,7 +2148,7 @@ protected
21482148
Integer varNumber;
21492149
algorithm
21502150
for eq in boundaryConditionEquations loop
2151-
(_, varNumber) := getSolvedVariableNumber(eq, solvedEqsVarInfo);
2151+
varNumber := getSolvedVariableNumber(eq, solvedEqsVarInfo);
21522152
boundaryConditionVariables := varNumber :: boundaryConditionVariables;
21532153
end for;
21542154
end getBoundaryConditionVariables;
@@ -2219,7 +2219,7 @@ protected
22192219
BackendDAE.Var var;
22202220
BackendDAE.Equation tmpEq;
22212221
algorithm
2222-
(_, varNumber) := getSolvedVariableNumber(eq, solvedEqsVarInfo);
2222+
varNumber := getSolvedVariableNumber(eq, solvedEqsVarInfo);
22232223
var := BackendVariable.getVarAt(orderedVars, varNumber);
22242224
mappedEq := mapIncRowEqn[eq];
22252225
tmpEq := BackendEquation.get(orderedEqs, mappedEq);
@@ -2244,7 +2244,7 @@ algorithm
22442244
print("\n" + heading + ":" + "(" + intString(listLength(tempSetS)) + ")" + "\n============================================================\n");
22452245
end if;
22462246
for eq in tempSetS loop
2247-
(_, varNumber) := getSolvedVariableNumber(eq, solvedEqsVarInfo);
2247+
varNumber := getSolvedVariableNumber(eq, solvedEqsVarInfo);
22482248
var := BackendVariable.getVarAt(orderedVars, varNumber);
22492249
mappedEq := mapIncRowEqn[eq];
22502250
tmpEq := BackendEquation.get(orderedEqs, mappedEq);
@@ -2564,10 +2564,10 @@ public function checkBlueOrRedOrBrownBlocks
25642564
output list<Integer> outIntegerList = {};
25652565
output list<String> outStringList = {};
25662566
protected
2567-
Integer eqNumber, varNumber;
2567+
Integer varNumber;
25682568
algorithm
25692569
for i in inlist loop
2570-
(eqNumber, varNumber) := getSolvedVariableNumber(i, solvedVar);
2570+
varNumber := getSolvedVariableNumber(i, solvedVar);
25712571
// knownVars are named as knowns and belong to Blue Blocks
25722572
if listMember(varNumber, knowns) then
25732573
outStringList := "knowns" :: outStringList;
@@ -2590,14 +2590,13 @@ public function getSolvedVariableNumber
25902590
"returns solvedvars based on the equation "
25912591
input Integer eqnumber;
25922592
input list<tuple<Integer, Integer>> inlist;
2593-
output tuple<Integer, Integer> mappedEqVar;
2593+
output Integer solvedvar;
25942594
protected
2595-
Integer eq, solvedvar;
2595+
Integer solvedeq;
25962596
algorithm
25972597
for var in inlist loop
2598-
(eq, solvedvar):=var;
2599-
if intEq(eqnumber, eq) then
2600-
mappedEqVar := (eqnumber, solvedvar);
2598+
(solvedeq, solvedvar):=var;
2599+
if intEq(eqnumber, solvedeq) then
26012600
return;
26022601
end if;
26032602
end for;
@@ -2607,14 +2606,13 @@ public function getSolvedEquationNumber
26072606
"returns solvedeqs based on the variables "
26082607
input Integer varnumber;
26092608
input list<tuple<Integer, Integer>> inlist;
2610-
output tuple<Integer, Integer> mappedEqVar;
2609+
output Integer solvedeq;
26112610
protected
2612-
Integer eq, solvedvar;
2611+
Integer solvedvar;
26132612
algorithm
26142613
for var in inlist loop
2615-
(eq, solvedvar) := var;
2614+
(solvedeq, solvedvar) := var;
26162615
if intEq(varnumber, solvedvar) then
2617-
mappedEqVar := (eq, solvedvar);
26182616
return;
26192617
end if;
26202618
end for;
@@ -2925,8 +2923,8 @@ protected
29252923
list<Integer> t={}, nonsq, e_BltList;
29262924
Integer eqnumber, varnumber;
29272925
algorithm
2928-
for i in inlist loop
2929-
(eqnumber,varnumber) := getSolvedVariableNumber(i, solvedvariables);
2926+
for eqnumber in inlist loop
2927+
varnumber := getSolvedVariableNumber(eqnumber, solvedvariables);
29302928
(nonsq, outEBLT) := getdirectOccurrencesinEquation(m, eqnumber, varnumber);
29312929
//print(anyString(nonsq));
29322930
for lst in nonsq loop

OMCompiler/Compiler/BackEnd/ExpressionSolve.mo

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,6 @@ algorithm
11951195
(x, y, new_x, eqnForNewVars, newVarsCrefs, odepth) := matchcontinue inExp1
11961196
local
11971197
DAE.Exp arg, e1, e_1, e, e2, exP, lhs, e3, e4, e5, e6, rhs, a1,x1, a2,x2, ee1, ee2;
1198-
tuple<DAE.Exp, DAE.Exp> a, c;
11991198
list<DAE.Exp> z1, z2, z3, z4;
12001199
DAE.ComponentRef cr;
12011200
DAE.Type tp;
@@ -1256,10 +1255,8 @@ algorithm
12561255

12571256
x2 := makeProductLstSort(z3);
12581257
a2 := if Expression.isAdd(op1) then makeProductLstSort(z4) else Expression.negate(makeProductLstSort(z4));
1259-
a := simplifyBinaryMulCoeff(x1);
1260-
c := simplifyBinaryMulCoeff(x2);
1261-
(e2, e3) := a;
1262-
(e5, e6) := c;
1258+
(e2, e3) := simplifyBinaryMulCoeff(x1);
1259+
(e5, e6) := simplifyBinaryMulCoeff(x2);
12631260
(lhs, rhs, eqnForNewVars_, newVarsCrefs_) := solveQE(a1,e2,e3,a2,e5,e6,inExp2,inExp3,ieqnForNewVars,inewVarsCrefs,uniqueEqIndex,idepth);
12641261
then(lhs, rhs, true, eqnForNewVars_, newVarsCrefs_, idepth + 1);
12651262

@@ -1501,9 +1498,10 @@ end preprocessingSolveFunctionCall;
15011498
protected function simplifyBinaryMulCoeff
15021499
"generalization of ExpressionSimplify.simplifyBinaryMulCoeff2"
15031500
input DAE.Exp inExp;
1504-
output tuple<DAE.Exp, DAE.Exp> outRes;
1501+
output DAE.Exp exp1;
1502+
output DAE.Exp exp2;
15051503
algorithm
1506-
outRes := match(inExp)
1504+
(exp1, exp2) := match(inExp)
15071505
local
15081506
DAE.Exp e,e1,e2;
15091507
DAE.Exp coeff;

OMCompiler/Compiler/BackEnd/HpcOmScheduler.mo

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5206,7 +5206,7 @@ protected function quicksortWithOrder1
52065206
algorithm
52075207
(lstOut,orderOut) := match(lstIn,orderIn,pivotIdx,markedIn,size)
52085208
local
5209-
Boolean b1,b2,b3;
5209+
Boolean b1,b2;
52105210
Integer lIdx,rIdx,pivot;
52115211
Real e,p,l,r,b;
52125212
list<Integer> orderTmp;
@@ -5233,8 +5233,13 @@ algorithm
52335233
lstTmp = if b2 then swapEntriesInList(pivotIdx,rIdx,lstTmp) else lstTmp;
52345234
orderTmp = if b1 then swapEntriesInList(pivotIdx,lIdx,orderIn) else orderIn;
52355235
orderTmp = if b2 then swapEntriesInList(pivotIdx,rIdx,orderTmp) else orderTmp;
5236-
b3 = boolAnd(boolNot(b1),boolNot(b2)); // if both are false(no member left or rigth found) than the pivot has the right place
5237-
((marked,pivot)) = if b3 then getNextPivot(lstTmp,markedIn,pivotIdx) else ((markedIn,pivotIdx));
5236+
// if both are false(no member left or rigth found) than the pivot has the right place
5237+
if not b1 and not b2 then
5238+
(marked, pivot) = getNextPivot(lstTmp,markedIn,pivotIdx);
5239+
else
5240+
marked = markedIn;
5241+
pivot = pivotIdx;
5242+
end if;
52385243

52395244
(lstTmp,orderTmp) = quicksortWithOrder1(lstTmp,orderTmp,pivot,marked,size);
52405245
then
@@ -5247,13 +5252,14 @@ protected function getNextPivot "author:Waurich TUD 2013-11
52475252
input list<Real> lstIn;
52485253
input list<Real> markedLstIn;
52495254
input Integer pivotIdx;
5250-
output tuple<list<Real>,Integer> tplOut;
5255+
output list<Real> marked;
5256+
output Integer newIdx;
52515257
algorithm
5252-
tplOut := match(lstIn,markedLstIn,pivotIdx)
5258+
(marked, newIdx) := match(lstIn,markedLstIn,pivotIdx)
52535259
local
5254-
Integer newIdx,midIdx;
5260+
Integer midIdx;
52555261
Real pivotElement,r1,r2,r3,e;
5256-
list<Real> marked,rest;
5262+
list<Real> rest;
52575263
case(_,{_},_)
52585264
then
52595265
(({},0));

OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4643,7 +4643,7 @@ uniontype LinearJacobian
46434643
// ToDo: updating the pivot row would also need an update for the rhs!
46444644

46454645
for j in i+1:arrayLength(linJac.rows) loop
4646-
row_value := getElementValue(linJac.rows[j], col_index);
4646+
row_value := UnorderedMap.getOrDefault(col_index, linJac.rows[j], 0.0);
46474647
if not realEq(row_value, 0.0) then
46484648
// set row to processed and perform pivot step
46494649
linJac.eq_marks[j] := true;
@@ -4721,7 +4721,7 @@ uniontype LinearJacobian
47214721
algorithm
47224722
if not realEq(piv_value, 1.0) then
47234723
for idx in UnorderedMap.keyList(pivot_row) loop
4724-
SOME(value) := UnorderedMap.get(idx, pivot_row);
4724+
value := UnorderedMap.getOrFail(idx, pivot_row);
47254725
UnorderedMap.add(idx, value/piv_value, pivot_row);
47264726
end for;
47274727
end if;
@@ -4731,32 +4731,18 @@ uniontype LinearJacobian
47314731
"author: kabdelhak FHB 03-2021
47324732
Returns the first element that can be chosen as pivot, fails if none can be chosen."
47334733
input LinearJacobianRow pivot_row;
4734-
output tuple<Integer, Real> pivot_elem;
4735-
protected
4736-
Integer idx;
4734+
output Integer idx;
4735+
output Real value;
47374736
algorithm
47384737
if Vector.isEmpty(pivot_row.keys) then
47394738
/* singular row */
47404739
fail();
47414740
else
47424741
idx := UnorderedMap.firstKey(pivot_row);
4743-
pivot_elem := (idx, Util.getOption(UnorderedMap.get(idx, pivot_row)));
4742+
value := UnorderedMap.getOrFail(idx, pivot_row);
47444743
end if;
47454744
end getPivot;
47464745

4747-
protected function getElementValue
4748-
"author: kabdelhak FHB 03-2021
4749-
Returns the value at given column and zero if it does not exist in sparse structure."
4750-
input LinearJacobianRow row;
4751-
input Integer col_index;
4752-
output Real value;
4753-
algorithm
4754-
value := match UnorderedMap.get(col_index, row)
4755-
case SOME(value) then value;
4756-
else 0.0;
4757-
end match;
4758-
end getElementValue;
4759-
47604746
public function resolveASSC
47614747
"author: kabdelhak FHB 03-2021
47624748
Resolves analytical singularities by replacing the equations with

0 commit comments

Comments
 (0)