Skip to content

Commit

Permalink
- do not intruduce extra derivative variables while do index reduction
Browse files Browse the repository at this point in the history
- add information about derivative name to STATE
- replace state alias variables
- improve singular system check, use absoulte incidence matrix for check and not the one with extra information for states



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14861 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jan 21, 2013
1 parent 72beca4 commit de1f6a8
Show file tree
Hide file tree
Showing 26 changed files with 1,673 additions and 685 deletions.
1 change: 1 addition & 0 deletions Compiler/BackEnd/BackendDAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ uniontype VarKind "- Variabile kind"
record VARIABLE end VARIABLE;
record STATE
Integer index "how often this states was differentiated";
Option< .DAE.ComponentRef> derName "the name of the derivative";
end STATE;
record STATE_DER end STATE_DER;
record DUMMY_DER end DUMMY_DER;
Expand Down
12 changes: 6 additions & 6 deletions Compiler/BackEnd/BackendDAECreate.mo
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,10 @@ algorithm
(outVarKind) := matchcontinue (inVarKind, inType, inComponentRef, inVarDirection, inConnectorType, daeAttr)
// variable -> state if have stateSelect=StateSelect.always
case (DAE.VARIABLE(), _, _, _, _, SOME(DAE.VAR_ATTR_REAL(stateSelectOption = SOME(DAE.ALWAYS()))))
then (BackendDAE.STATE(1));
then (BackendDAE.STATE(1,NONE()));
// variable -> state if have stateSelect=StateSelect.prefer
case (DAE.VARIABLE(), _, _, _, _, SOME(DAE.VAR_ATTR_REAL(stateSelectOption = SOME(DAE.PREFER()))))
then (BackendDAE.STATE(1));
then (BackendDAE.STATE(1,NONE()));

case (DAE.VARIABLE(), DAE.T_BOOL(varLst = _), _, _, _, _)
equation
Expand Down Expand Up @@ -2631,7 +2631,7 @@ algorithm
Boolean b, b1, b2;
DAE.Exp e, ae;
// state variable
case (BackendDAE.VAR(varKind=BackendDAE.STATE(_)), _, 1, _,
case (BackendDAE.VAR(varKind=BackendDAE.STATE(index=_)), _, 1, _,
BackendDAE.VAR(varName=cr2), _, 1, _, _, _, _, _, _, _)
equation
// check if replacable
Expand All @@ -2656,7 +2656,7 @@ algorithm
(vars, iKnVars, iExtVars, avars, repl);
// state variable
case (BackendDAE.VAR(varName=cr1), _, 1, _,
BackendDAE.VAR(varKind=BackendDAE.STATE(_)), _, 1, _, _, _, _, _, _, _)
BackendDAE.VAR(varKind=BackendDAE.STATE(index=_)), _, 1, _, _, _, _, _, _, _)
equation
// check if replacable
false = BackendVariable.isStateVar(v1);
Expand Down Expand Up @@ -3300,7 +3300,7 @@ algorithm
equation
false = BackendVariable.isVarDiscrete(var) "do not change discrete vars to states, because they have no derivative" ;
false = BackendVariable.isStateVar(var);
var1 = BackendVariable.setVarKind(var, BackendDAE.STATE(1));
var1 = BackendVariable.setVarKind(var, BackendDAE.STATE(1,NONE()));
vars = BackendVariable.addVar(var1, inVars);
then (vars, iExp);
case(_, _, _)
Expand Down Expand Up @@ -3333,7 +3333,7 @@ algorithm
equation
false = BackendVariable.isVarDiscrete(var) "do not change discrete vars to states, because they have no derivative" ;
false = BackendVariable.isStateVar(var);
var = BackendVariable.setVarKind(var, BackendDAE.STATE(1));
var = BackendVariable.setVarKind(var, BackendDAE.STATE(1,NONE()));
vars = BackendVariable.addVar(var, inVars);
vars = updateStatesVars(vars, newStates, true);
then vars;
Expand Down
24 changes: 22 additions & 2 deletions Compiler/BackEnd/BackendDAEEXT.mo
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,27 @@ public function setIncidenceMatrix
external "C" BackendDAEEXT_setIncidenceMatrix(nv,ne,nz,m) annotation(Library = "omcruntime");
end setIncidenceMatrix;

public function cheapmatching
"function: cheapmatching
author: Frenkel TUD 2012-04
calls cheapmatching algorithms
cheapID: id of cheap algo (1-4)
1: Simple Greedy
2: Karp-Sipser
3: Random Karp-Sipser (DEFAULT)
4: Minimum Degree (two-sided)
Other than these two, non-positive values are not allowed.
"
input Integer nv;
input Integer ne;
input Integer cheapID;
input Integer clear_match;
external "C" BackendDAEEXT_cheapmatching(nv,ne,cheapID,clear_match) annotation(Library = "omcruntime");
end cheapmatching;

public function matching
"function: matchingExternal
"function: matching
author: Frenkel TUD 2012-04
calls matching algorithms
matchingID: id of match algo (1-9)
Expand All @@ -230,7 +249,8 @@ public function matching
9: ABMP-BFS (ABMP + BFS)
10: PR-FIFO-FAIR (DEFAULT)
cheapID: id of cheap algo (1-4)
cheapID: id of cheap algo (0-4)
0: No Cheap Matching
1: Simple Greedy
2: Karp-Sipser
3: Random Karp-Sipser (DEFAULT)
Expand Down
42 changes: 12 additions & 30 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2947,13 +2947,11 @@ algorithm
end matchcontinue;
end checkLinearSystem;




// =============================================================================
// tearing system of equations stuff
//
// =============================================================================

public function tearingSystem
" function: tearingSystem
author: Frenkel TUD
Expand Down Expand Up @@ -3309,7 +3307,6 @@ algorithm
end match;
end setDaeVarsAndEqs;


protected function printEquationArr
"prints an array of BackendDAE.Equations"
input array<Option<BackendDAE.Equation>> inArr;
Expand Down Expand Up @@ -6161,7 +6158,7 @@ algorithm
(r2,res) = generateJacobianVars2(var, restVar, inMatrixName);
then (r2,res);

case(var as BackendDAE.VAR(varName=cref,varKind=BackendDAE.STATE(_)), currVar::restVar, _) equation
case(var as BackendDAE.VAR(varName=cref,varKind=BackendDAE.STATE(index=_)), currVar::restVar, _) equation
cref = ComponentReference.crefPrefixDer(cref);
derivedCref = differentiateVarWithRespectToX(cref, currVar, inMatrixName);
r1 = BackendDAE.VAR(derivedCref, BackendDAE.STATE_DER(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.NON_CONNECTOR());
Expand Down Expand Up @@ -6209,7 +6206,7 @@ algorithm
then
creatallDiffedVars(restVar,cref,inAllVars,inIndex, inMatrixName,iVars);

case(BackendDAE.VAR(varName=currVar,varKind=BackendDAE.STATE(_))::restVar,cref,_,_, _, _) equation
case(BackendDAE.VAR(varName=currVar,varKind=BackendDAE.STATE(index=_))::restVar,cref,_,_, _, _) equation
({v1}, _) = BackendVariable.getVar(currVar, inAllVars);
currVar = ComponentReference.crefPrefixDer(currVar);
derivedCref = differentiateVarWithRespectToX(currVar, cref, inMatrixName);
Expand All @@ -6224,7 +6221,7 @@ algorithm
then
creatallDiffedVars(restVar, cref, inAllVars, inIndex+1, inMatrixName,r1::iVars);

case(BackendDAE.VAR(varName=currVar,varKind=BackendDAE.STATE(_))::restVar,cref,_,_, _, _) equation
case(BackendDAE.VAR(varName=currVar,varKind=BackendDAE.STATE(index=_))::restVar,cref,_,_, _, _) equation
currVar = ComponentReference.crefPrefixDer(currVar);
derivedCref = differentiateVarWithRespectToX(currVar, cref, inMatrixName);
r1 = BackendDAE.VAR(derivedCref, BackendDAE.VARIABLE(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), DAE.NON_CONNECTOR());
Expand Down Expand Up @@ -10482,6 +10479,10 @@ algorithm
case (condition as DAE.CALL(path = Absyn.IDENT(name = "initial")), _, index, ht)
then (condition, {}, {}, {}, index, ht);

// we do not replace symbols
case (condition as DAE.CREF(componentRef=_), _, index, ht)
then (condition, {}, {}, {}, index, ht);

// array-condition with dim = 1 [already in ht]
case (DAE.ARRAY(array={condition}), _, index, ht) equation
localIndex = BaseHashTable.get(condition, ht);
Expand Down Expand Up @@ -10731,6 +10732,10 @@ algorithm
case (condition as DAE.CALL(path = Absyn.IDENT(name = "initial")), _, index)
then (condition, {}, {}, {}, index);

// we do not replace symbols
case (condition as DAE.CREF(componentRef=_), _, index)
then (condition, {}, {}, {}, index);

// array-condition
case (DAE.ARRAY(array={condition}), _, index) equation
crStr = "$whenCondition" +& intString(index);
Expand Down Expand Up @@ -10873,29 +10878,6 @@ algorithm
end matchcontinue;
end getConditionList1;

// =============================================================================
// section for ???
//
// =============================================================================

public function solvabilityWights "function: solvabilityWights
author: Frenkel TUD 2012-05,
return a integer for the solvability, this function is used
to calculade wights for variables to select the tearing variable."
input BackendDAE.Solvability solva;
output Integer i;
algorithm
i := match(solva)
case BackendDAE.SOLVABILITY_SOLVED() then 0;
case BackendDAE.SOLVABILITY_CONSTONE() then 2;
case BackendDAE.SOLVABILITY_CONST() then 5;
case BackendDAE.SOLVABILITY_PARAMETER(b=false) then 0;
case BackendDAE.SOLVABILITY_PARAMETER(b=true) then 50;
case BackendDAE.SOLVABILITY_TIMEVARYING(b=false) then 0;
case BackendDAE.SOLVABILITY_TIMEVARYING(b=true) then 100;
case BackendDAE.SOLVABILITY_NONLINEAR() then 200;
case BackendDAE.SOLVABILITY_UNSOLVABLE() then 300;
end match;
end solvabilityWights;

end BackendDAEOptimize;
6 changes: 3 additions & 3 deletions Compiler/BackEnd/BackendDAETransform.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ algorithm
DAE.ElementSource source;

case (BackendDAE.VAR(varName = cr,
varKind = BackendDAE.STATE(_),
varKind = BackendDAE.STATE(index=_),
varDirection = dir,
varParallelism = prl,
varType = tp,
Expand Down Expand Up @@ -2991,7 +2991,7 @@ algorithm
case (_,(cr :: crs))
equation
((v :: _),_) = BackendVariable.getVar(cr, vars);
BackendDAE.STATE(_) = BackendVariable.varKind(v);
BackendDAE.STATE(index=_) = BackendVariable.varKind(v);
then
cr;
case (_,(cr :: crs))
Expand Down Expand Up @@ -3558,7 +3558,7 @@ algorithm

case ((DAE.CALL(path = Absyn.IDENT(name = "der"),expLst = {DAE.CALL(path = Absyn.IDENT(name = "der"),expLst = {DAE.CREF(componentRef = cr)})}),(vars,i)))
equation
((BackendDAE.VAR(cr,BackendDAE.STATE(_),a,prl,b,c,d,lstSubs,source,dae_var_attr,comment,ct) :: _),_) = BackendVariable.getVar(cr, vars) "der(der(s)) s is state => der_der_s" ;
((BackendDAE.VAR(cr,BackendDAE.STATE(index=_),a,prl,b,c,d,lstSubs,source,dae_var_attr,comment,ct) :: _),_) = BackendVariable.getVar(cr, vars) "der(der(s)) s is state => der_der_s" ;
dummyder = ComponentReference.crefPrefixDer(cr);
dummyder = ComponentReference.crefPrefixDer(dummyder);
vars_1 = BackendVariable.addVar(BackendDAE.VAR(dummyder, BackendDAE.DUMMY_DER(), a, prl, b, NONE(), NONE(), lstSubs, source, NONE(), comment, ct), vars);
Expand Down

0 comments on commit de1f6a8

Please sign in to comment.