Skip to content

Commit

Permalink
fix for bug Bug [# 1608]
Browse files Browse the repository at this point in the history
 - functions with inputs (parameters and discrete) have zero derivative
 - Derive, BackendDAEUtil, BackendVariable
- BackendDAETransform: update Debug code


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10866 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jan 7, 2012
1 parent 45b6ece commit e5bbbb1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
7 changes: 4 additions & 3 deletions Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -4727,7 +4727,7 @@ algorithm
eqns_1 = List.setDifferenceOnTrue(eqns, diff_eqns, intEq);
// print("differentiating equations: ");print(stringDelimitList(List.map(eqns_1,intString),","));
// print("\n");
// print(BackendDump.dumpMarkedEqns(dae, eqns_1));
// print(BackendDump.dumpMarkedEqns(syst, eqns_1));

// Collect the states in the equations that are singular, i.e. composing a constraint between states.
// Note that states are collected from -all- marked equations, not only the differentiated ones.
Expand All @@ -4749,10 +4749,11 @@ algorithm
syst = makeAlgebraic(syst, state);
syst = BackendDAEUtil.updateIncidenceMatrix(syst, shared, changedeqns);
// print("new DAE:");
// BackendDump.dump(dae);
// BackendDump.dump(BackendDAE.DAE({syst},shared));
// print("new IM:");
// (_,m,_) = BackendDAEUtil.getIncidenceMatrixfromOption(syst,shared);
// BackendDump.dumpIncidenceMatrix(m);
// BackendDump.dumpStateVariables(BackendVariable.daeVars(dae));
// BackendDump.dumpStateVariables(BackendVariable.daeVars(syst));
then
(syst,shared,ass1,ass2,derivedAlgs1,derivedMultiEqn1,inArg);

Expand Down
13 changes: 12 additions & 1 deletion Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -3016,6 +3016,17 @@ algorithm
end match;
end whenClauseAddDAE;

public function getStrongComponents
"function: getStrongComponents
autor: Frenkel TUD 2011-11
This function returns the strongComponents of a BackendDAE.
in BackendDAE.BackendDAE to get speed up"
input BackendDAE.EqSystem syst;
output BackendDAE.StrongComponents outComps;
algorithm
BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(comps=outComps)) := syst;
end getStrongComponents;

/**************************
BackendDAE.BinTree stuff
**************************/
Expand Down Expand Up @@ -5104,7 +5115,7 @@ algorithm
case (e,vars)
equation
crefs = Expression.extractCrefsFromExp(e);
b_lst = List.map1(crefs, BackendVariable.existsVar, vars);
b_lst = List.map2(crefs, BackendVariable.existsVar, vars, false);
res = Util.boolOrList(b_lst);
res_1 = boolNot(res);
then
Expand Down
19 changes: 15 additions & 4 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -3186,10 +3186,11 @@ public function existsVar
Return true if a variable exists in the vector"
input DAE.ComponentRef inComponentRef;
input BackendDAE.Variables inVariables;
input Boolean skipDiscrete;
output Boolean outBoolean;
algorithm
outBoolean:=
matchcontinue (inComponentRef,inVariables)
matchcontinue (inComponentRef,inVariables,skipDiscrete)
local
BackendDAE.Value hval,hashindx,indx,bsize,n;
list<BackendDAE.CrefIndex> indexes;
Expand All @@ -3198,7 +3199,7 @@ algorithm
array<list<BackendDAE.CrefIndex>> hashvec;
BackendDAE.VariableArray varr;
String str;
case (cr,BackendDAE.VARIABLES(crefIdxLstArr = hashvec,varArr = varr,bucketSize = bsize,numberOfVars = n))
case (cr,BackendDAE.VARIABLES(crefIdxLstArr = hashvec,varArr = varr,bucketSize = bsize,numberOfVars = n),false)
equation
hashindx = HashTable2.hashFunc(cr, bsize);
indexes = hashvec[hashindx + 1];
Expand All @@ -3207,7 +3208,17 @@ algorithm
true = ComponentReference.crefEqualNoStringCompare(cr, cr2);
then
true;
case (cr,BackendDAE.VARIABLES(crefIdxLstArr = hashvec,varArr = varr,bucketSize = bsize,numberOfVars = n))
case (cr,BackendDAE.VARIABLES(crefIdxLstArr = hashvec,varArr = varr,bucketSize = bsize,numberOfVars = n),true)
equation
hashindx = HashTable2.hashFunc(cr, bsize);
indexes = hashvec[hashindx + 1];
indx = getVar3(cr, indexes, getVar4(cr, indexes));
((v as BackendDAE.VAR(varName = cr2))) = vararrayNth(varr, indx);
true = ComponentReference.crefEqualNoStringCompare(cr, cr2);
false = isVarDiscrete(v);
then
true;
case (cr,BackendDAE.VARIABLES(crefIdxLstArr = hashvec,varArr = varr,bucketSize = bsize,numberOfVars = n),_)
equation
hashindx = HashTable2.hashFunc(cr, bsize);
indexes = hashvec[hashindx + 1];
Expand All @@ -3219,7 +3230,7 @@ algorithm
print("\n");
then
false;
case (_,_) then false;
case (_,_,_) then false;
end matchcontinue;
end existsVar;

Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/Derive.mo
Expand Up @@ -608,10 +608,10 @@ algorithm

case (e as DAE.CALL(path = a,expLst = expl,attr=DAE.CALL_ATTR(ty=tp)),inVariables as (timevars,_,_))
equation
// if only parameters no derivative needed
// if only parameters or discrete no derivative needed
crefslstls = List.map(expl,Expression.extractCrefsFromExp);
crefs = List.flatten(crefslstls);
blst = List.map1(crefs,BackendVariable.existsVar,timevars);
blst = List.map2(crefs,BackendVariable.existsVar,timevars,true);
false = Util.boolOrList(blst);
(e1,_) = Expression.makeZeroExpression(Expression.arrayDimension(tp));
then
Expand Down

0 comments on commit e5bbbb1

Please sign in to comment.