Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit e36b947

Browse files
ptaeuberOpenModelica-Hudson
authored andcommitted
Use nominal value to define threshold for param division
1 parent 5351a6e commit e36b947

File tree

4 files changed

+134
-41
lines changed

4 files changed

+134
-41
lines changed

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5014,7 +5014,7 @@ protected function adjacencyRowEnhanced2
50145014
input BackendDAE.Variables globalKnownVars;
50155015
output BackendDAE.Solvability oSolvab;
50165016
algorithm
5017-
oSolvab := matchcontinue(cr,e,crlst,vars,globalKnownVars)
5017+
oSolvab := match(cr,e,crlst,vars,globalKnownVars)
50185018
local
50195019
Boolean b,b1,b2;
50205020
case(_,_,{},_,_)
@@ -5023,9 +5023,7 @@ algorithm
50235023
b2 = Expression.isConstOne(e) or Expression.isConstMinusOne(e);
50245024
then
50255025
if b2 then BackendDAE.SOLVABILITY_CONSTONE() else BackendDAE.SOLVABILITY_CONST(not b1);
5026-
case(_,_,_,_,_)
5027-
equation
5028-
true = List.isMemberOnTrue(cr,crlst,ComponentReference.crefEqualNoStringCompare);
5026+
case(_,_,_,_,_) guard List.isMemberOnTrue(cr,crlst,ComponentReference.crefEqualNoStringCompare)
50295027
then
50305028
BackendDAE.SOLVABILITY_NONLINEAR();
50315029
case(_,_,_,_,_)
@@ -5034,7 +5032,7 @@ algorithm
50345032
b2 = containAnyVar(crlst,vars);
50355033
then
50365034
adjacencyRowEnhanced3(b1,b2,cr,e,crlst,vars,globalKnownVars);
5037-
end matchcontinue;
5035+
end match;
50385036
end adjacencyRowEnhanced2;
50395037

50405038
protected function adjacencyRowEnhanced3
@@ -5050,13 +5048,13 @@ protected function adjacencyRowEnhanced3
50505048
input BackendDAE.Variables globalKnownVars;
50515049
output BackendDAE.Solvability oSolvab;
50525050
algorithm
5053-
oSolvab := matchcontinue(b1,b2,cr,e,crlst,vars,globalKnownVars)
5051+
oSolvab := match(b1,b2,cr,e,crlst,vars,globalKnownVars)
50545052
local
50555053
Boolean b,b_1;
5056-
DAE.Exp e1;
5054+
DAE.Exp e1, nominal;
50575055
case(true,true,_,_,_,_,_)
50585056
equation
5059-
(e1,_) = Expression.traverseExpBottomUp(e, replaceVartraverser, globalKnownVars);
5057+
(e1,_) = Expression.traverseExpBottomUp(e, replaceVarWithValue, globalKnownVars);
50605058
(e1,_) = ExpressionSimplify.simplify(e1);
50615059
b = not Expression.isZeroOrAlmostZero(e1);
50625060
then
@@ -5067,28 +5065,25 @@ algorithm
50675065
then
50685066
BackendDAE.SOLVABILITY_LINEAR(b);
50695067
case(true,_,_,_,_,_,_)
5070-
equation
5071-
(e1,_) = Expression.traverseExpBottomUp(e, replaceVartraverser, globalKnownVars);
5072-
(e1,_) = ExpressionSimplify.simplify(e1);
5073-
b = not Expression.isZeroOrAlmostZero(e1);
5074-
b_1 = Expression.isConst(e1);
5068+
algorithm
5069+
(nominal,_) := Expression.traverseExpBottomUp(e, replaceVarWithNominal, globalKnownVars);
5070+
(nominal,_) := ExpressionSimplify.simplify(nominal);
5071+
(e1,_) := Expression.traverseExpBottomUp(e, replaceVarWithValue, globalKnownVars);
5072+
(e1,_) := ExpressionSimplify.simplify(e1);
5073+
b := not Expression.isZeroOrAlmostZero(e1, nominal);
5074+
b_1 := Expression.isConst(e1);
50755075
then
50765076
if b_1 then BackendDAE.SOLVABILITY_PARAMETER(b) else BackendDAE.SOLVABILITY_LINEAR(b);
50775077
case(_,_,_,_,_,_,_)
50785078
equation
50795079
b = not Expression.isZeroOrAlmostZero(e);
50805080
then
50815081
BackendDAE.SOLVABILITY_LINEAR(b);
5082-
/* case(_,_,_,_,_,_,_)
5083-
equation
5084-
BackendDump.debugStrCrefStrExpStr(("Warning cannot calculate solvabilty for",cr," in ",e,"\n"));
5085-
then
5086-
BackendDAE.SOLVABILITY_LINEAR(true);
5087-
*/ end matchcontinue;
5082+
end match;
50885083
end adjacencyRowEnhanced3;
50895084

5090-
protected function replaceVartraverser
5091-
"Helper function to adjacencyRowEnhanced3. Traverser to replace variables(parameters) with there bind expression."
5085+
protected function replaceVarWithValue
5086+
"Helper function to adjacencyRowEnhanced3. Traverser to replace variables(parameters) with their bind expression."
50925087
input DAE.Exp inExp;
50935088
input BackendDAE.Variables inVars;
50945089
output DAE.Exp outExp;
@@ -5105,21 +5100,47 @@ algorithm
51055100
equation
51065101
(v::_,_) = BackendVariable.getVar(cr,vars);
51075102
e = BackendVariable.varBindExp(v);
5108-
(e,_) = Expression.traverseExpBottomUp(e, replaceVartraverser, vars);
5103+
(e,_) = Expression.traverseExpBottomUp(e, replaceVarWithValue, vars);
51095104
then (e, vars);
51105105

51115106
case (DAE.CREF(componentRef=cr),vars)
51125107
equation
51135108
(v::_,_) = BackendVariable.getVar(cr,vars);
51145109
true = BackendVariable.varFixed(v);
51155110
e = BackendVariable.varBindExpStartValue(v);
5116-
(e,_) = Expression.traverseExpBottomUp(e, replaceVartraverser, vars);
5111+
(e,_) = Expression.traverseExpBottomUp(e, replaceVarWithValue, vars);
51175112
then (e, vars);
51185113

51195114
else (inExp,inVars);
51205115

51215116
end matchcontinue;
5122-
end replaceVartraverser;
5117+
end replaceVarWithValue;
5118+
5119+
protected function replaceVarWithNominal
5120+
"Helper function to adjacencyRowEnhanced3. Traverser to replace variables(parameters) with their nominal values."
5121+
input DAE.Exp inExp;
5122+
input BackendDAE.Variables inVars;
5123+
output DAE.Exp outExp;
5124+
output BackendDAE.Variables outVars;
5125+
algorithm
5126+
(outExp,outVars) := matchcontinue (inExp,inVars)
5127+
local
5128+
DAE.ComponentRef cr;
5129+
BackendDAE.Variables vars;
5130+
BackendDAE.Var v;
5131+
DAE.Exp nom;
5132+
5133+
case (DAE.CREF(componentRef=cr),vars)
5134+
equation
5135+
(v::_,_) = BackendVariable.getVar(cr,vars);
5136+
nom = BackendVariable.getVarNominalValue(v);
5137+
(nom,_) = Expression.traverseExpBottomUp(nom, replaceVarWithNominal, vars);
5138+
then (nom, vars);
5139+
5140+
else (inExp,inVars);
5141+
5142+
end matchcontinue;
5143+
end replaceVarWithNominal;
51235144

51245145
protected function adjacencyRowExpEnhanced
51255146
"author: Frenkel TUD 2012-05

Compiler/BackEnd/Tearing.mo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ algorithm
185185
algorithm
186186
if Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE) then
187187
print("\nTearing type: heuristic\n");
188+
print("Tearing strictness: " + Flags.getConfigString(Flags.TEARING_STRICTNESS) + "\n");
188189
end if;
189190
(ocomp,outRunMatching) := omcTearing(isyst, ishared, eindex, vindx, ojac, jacType, mixedSystem);
190191
if debug then execStat("Tearing.omcTearing"); end if;
@@ -194,6 +195,7 @@ algorithm
194195
algorithm
195196
if Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE) then
196197
print("\nTearing type: heuristic\n");
198+
print("Tearing strictness: " + Flags.getConfigString(Flags.TEARING_STRICTNESS) + "\n");
197199
end if;
198200
(ocomp,outRunMatching) := CellierTearing(isyst, ishared, eindex, vindx, userTVars, ojac, jacType, mixedSystem, strongComponentIndex);
199201
if debug then execStat("Tearing.CellierTearing"); end if;
@@ -203,6 +205,7 @@ algorithm
203205
algorithm
204206
if Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE) then
205207
print("\nTearing type: total\n");
208+
print("Tearing strictness: " + Flags.getConfigString(Flags.TEARING_STRICTNESS) + "\n");
206209
end if;
207210
(ocomp,outRunMatching) := totalTearing(isyst, ishared, eindex, vindx, ojac, jacType, mixedSystem);
208211
if debug then execStat("Tearing.totalTearing"); end if;
@@ -212,6 +215,7 @@ algorithm
212215
algorithm
213216
if Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE) then
214217
print("\nTearing type: user defined\n");
218+
print("Tearing strictness: " + Flags.getConfigString(Flags.TEARING_STRICTNESS) + "\n");
215219
end if;
216220
(ocomp,outRunMatching) := userDefinedTearing(isyst, ishared, eindex, vindx, ojac, jacType, mixedSystem, userTVars, userResiduals);
217221
if debug then execStat("Tearing.userDefinedTearing"); end if;

Compiler/FrontEnd/Expression.mo

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7511,17 +7511,26 @@ algorithm
75117511
list<DAE.Exp> ae;
75127512
list<list<DAE.Exp>> matrix;
75137513

7514-
case (DAE.ICONST(integer = ival)) then intEq(ival,0);
7515-
case (DAE.RCONST(real = rval)) then realEq(rval,0.0);
7516-
case (DAE.CAST(exp = e)) then isZero(e);
7514+
case (DAE.ICONST(integer = ival))
7515+
then intEq(ival,0);
75177516

7518-
case(DAE.UNARY(DAE.UMINUS(_),e)) then isZero(e);
7519-
case(DAE.ARRAY(array = ae)) then List.mapAllValueBool(ae,isZero,true);
7517+
case (DAE.RCONST(real = rval))
7518+
then realEq(rval,0.0);
7519+
7520+
case (DAE.CAST(exp = e))
7521+
then isZero(e);
7522+
7523+
case (DAE.UNARY(DAE.UMINUS(_),e))
7524+
then isZero(e);
7525+
7526+
case (DAE.ARRAY(array = ae))
7527+
then List.mapAllValueBool(ae,isZero,true);
75207528

75217529
case (DAE.MATRIX(matrix = matrix))
7522-
then List.mapListAllValueBool(matrix,isZero,true);
7530+
then List.mapListAllValueBool(matrix,isZero,true);
75237531

7524-
case(DAE.UNARY(DAE.UMINUS_ARR(_),e)) then isZero(e);
7532+
case (DAE.UNARY(DAE.UMINUS_ARR(_),e))
7533+
then isZero(e);
75257534

75267535
else false;
75277536

@@ -7533,30 +7542,45 @@ public function isZeroOrAlmostZero
75337542
"Returns true if an expression is constant
75347543
and zero or near to zero, otherwise false"
75357544
input DAE.Exp inExp;
7545+
input DAE.Exp nominal = DAE.RCONST(1.0);
75367546
output Boolean outBoolean;
75377547
algorithm
7538-
outBoolean := match (inExp)
7548+
outBoolean := match (inExp, nominal)
75397549
local
75407550
Integer ival;
75417551
Real rval;
75427552
Type t;
75437553
DAE.Exp e,e1;
75447554
list<DAE.Exp> ae;
75457555
list<list<DAE.Exp>> matrix;
7556+
Real rNom;
75467557

7547-
case (DAE.ICONST(integer = ival)) then intEq(ival,0);
7548-
case (DAE.RCONST(real = rval)) then realLt(abs(rval),1e-15);
7549-
case (DAE.CAST(exp = e)) then isZeroOrAlmostZero(e);
7558+
case (DAE.ICONST(integer = ival),_)
7559+
then intEq(ival,0);
75507560

7551-
case(DAE.UNARY(DAE.UMINUS(_),e)) then isZeroOrAlmostZero(e);
7552-
case(DAE.ARRAY(array = ae)) then List.mapAllValueBool(ae,isZeroOrAlmostZero,true);
7561+
case (DAE.RCONST(real = rval), DAE.RCONST(real=rNom))
7562+
then realLt(abs(rval),1e-6*abs(rNom));
75537563

7554-
case (DAE.MATRIX(matrix = matrix))
7555-
then List.mapListAllValueBool(matrix,isZeroOrAlmostZero,true);
7564+
case (DAE.RCONST(real = rval),_)
7565+
then realLt(abs(rval),1e-6);
7566+
7567+
case (DAE.CAST(exp = e),_)
7568+
then isZeroOrAlmostZero(e, nominal);
7569+
7570+
case (DAE.UNARY(DAE.UMINUS(_),e),_)
7571+
then isZeroOrAlmostZero(e, nominal);
7572+
7573+
case (DAE.ARRAY(array = ae),_)
7574+
then List.map1AllValueBool(ae,isZeroOrAlmostZero,true,nominal);
7575+
7576+
case (DAE.MATRIX(matrix = matrix),_)
7577+
then List.map1ListAllValueBool(matrix,isZeroOrAlmostZero,true,nominal);
75567578

7557-
case(DAE.UNARY(DAE.UMINUS_ARR(_),e)) then isZeroOrAlmostZero(e);
7579+
case (DAE.UNARY(DAE.UMINUS_ARR(_),e),_)
7580+
then isZeroOrAlmostZero(e, nominal);
75587581

7559-
case(DAE.IFEXP(_,e,e1)) then (isZeroOrAlmostZero(e) or isZeroOrAlmostZero(e1));
7582+
case (DAE.IFEXP(_,e,e1),_)
7583+
then (isZeroOrAlmostZero(e, nominal) or isZeroOrAlmostZero(e1, nominal));
75607584

75617585
else false;
75627586

Compiler/Util/List.mo

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,6 +2948,28 @@ algorithm
29482948
end try;
29492949
end mapAllValueBool;
29502950

2951+
public function map1AllValueBool<TI, TO, VT, ArgT1>
2952+
"Same as mapAllValueBool, but takes one extra argument."
2953+
input list<TI> inList;
2954+
input MapFunc inMapFunc;
2955+
input VT inValue;
2956+
input ArgT1 inArg1;
2957+
output Boolean outAllValue;
2958+
2959+
partial function MapFunc
2960+
input TI inElement;
2961+
input ArgT1 inArg1;
2962+
output TO outElement;
2963+
end MapFunc;
2964+
algorithm
2965+
try
2966+
map1AllValue(inList, inMapFunc, inValue, inArg1);
2967+
outAllValue := true;
2968+
else
2969+
outAllValue := false;
2970+
end try;
2971+
end map1AllValueBool;
2972+
29512973
public function map1AllValue<TI, TO, VT, ArgT1>
29522974
"Applies a function to all elements in the lists, and fails if not all
29532975
elements are equal to the given value. This function also takes an extra
@@ -3040,6 +3062,28 @@ algorithm
30403062
end for;
30413063
end mapListAllValueBool;
30423064

3065+
public function map1ListAllValueBool<TI, TO, VT, ArgT1>
3066+
"Same as mapListAllValueBool, but takes one extra argument."
3067+
input list<list<TI>> inList;
3068+
input MapFunc inMapFunc;
3069+
input VT inValue;
3070+
input ArgT1 inArg1;
3071+
output Boolean outAllValue = true;
3072+
3073+
partial function MapFunc
3074+
input TI inElement;
3075+
input ArgT1 inArg1;
3076+
output TO outElement;
3077+
end MapFunc;
3078+
algorithm
3079+
for lst in inList loop
3080+
if not map1AllValueBool(lst, inMapFunc, inValue, inArg1) then
3081+
outAllValue := false;
3082+
return;
3083+
end if;
3084+
end for;
3085+
end map1ListAllValueBool;
3086+
30433087
public function foldAllValue<TI, TO, ArgT1>
30443088
"Applies a function to all elements in the lists, and fails if not all
30453089
elements are equal to the given value. This function also takes an extra

0 commit comments

Comments
 (0)