Skip to content

Commit

Permalink
- bugfix for singulare sytems, add test SingularePlanarLoop, Ticket #…
Browse files Browse the repository at this point in the history
…1948

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14028 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Nov 23, 2012
1 parent 9119907 commit 3b0a97b
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 136 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEEXT.mo
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function getEqnsforIndexReduction
"function: getEqnsforIndexReduction
author: Frenkel TUD 2012-04
"
output list<Integer> eqns;
output list<list<Integer>> eqns;
external "C" eqns = BackendDAEEXT_getEqnsforIndexReduction() annotation(Library = "omcruntime");
end getEqnsforIndexReduction;

Expand Down
20 changes: 11 additions & 9 deletions Compiler/BackEnd/BackendDAETransform.mo
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function matchingAlgorithm
output BackendDAE.Shared oshared;
output BackendDAE.StructurallySingularSystemHandlerArg outArg;
partial function StructurallySingularSystemHandlerFunc
input list<Integer> eqns;
input list<list<Integer>> eqns;
input Integer actualEqn;
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared ishared;
Expand Down Expand Up @@ -407,7 +407,7 @@ public function matchingAlgorithm2
output BackendDAE.Shared oshared;
output BackendDAE.StructurallySingularSystemHandlerArg outArg;
partial function StructurallySingularSystemHandlerFunc
input list<Integer> eqns;
input list<list<Integer>> eqns;
input Integer actualEqn;
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared ishared;
Expand Down Expand Up @@ -462,7 +462,7 @@ algorithm
case (_,_,_,_,_,BackendDAE.ASSIGNMENTS(an1,am1,vec1),BackendDAE.ASSIGNMENTS(an2,am2,vec2),match_opts as (BackendDAE.INDEX_REDUCTION(),eq_cons),_,_)
equation
meqns = BackendDAEEXT.getMarkedEqns();
(_,i_1,syst,shared,vec1,vec2,arg) = sssHandler(meqns,i,isyst,ishared,vec1,vec2,inArg)
(_,i_1,syst,shared,vec1,vec2,arg) = sssHandler({meqns},i,isyst,ishared,vec1,vec2,inArg)
"path_found failed, Try index reduction using dummy derivatives.
When a constraint exist between states and index reduction is needed
the dummy derivative will select one of the states as a dummy state
Expand Down Expand Up @@ -2663,7 +2663,7 @@ public function reduceIndexDummyDer
inputs: (BackendDAE, BackendDAE.IncidenceMatrix, BackendDAE.IncidenceMatrixT,
int /* number of vars */, int /* number of eqns */, int /* i */)
outputs: (BackendDAE, BackendDAE.IncidenceMatrix, IncidenceMatrixT)"
input list<Integer> eqns;
input list<list<Integer>> eqns;
input Integer actualEqn;
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared ishared;
Expand All @@ -2681,7 +2681,7 @@ algorithm
(changedEqns,continueEqn,osyst,oshared,outAssignments1,outAssignments2,outArg):=
matchcontinue (eqns,actualEqn,isyst,ishared,inAssignments1,inAssignments2,inArg)
local
list<Integer> eqns1,diff_eqns,eqns_1,stateindx,deqns,reqns,changedeqns;
list<Integer> eqnsf,eqns1,diff_eqns,eqns_1,stateindx,deqns,reqns,changedeqns;
list<DAE.ComponentRef> states;
array<list<Integer>> mt;
Integer stateno,noofeqns;
Expand All @@ -2699,8 +2699,9 @@ algorithm

case (_,_,syst as BackendDAE.EQSYSTEM(mT=SOME(mt)),shared,ass1,ass2,(so,orgEqnsLst,mapEqnIncRow,mapIncRowEqn,noofeqns))
equation
eqnsf = List.flatten(eqns);
// get from scalar eqns indexes the indexes in the equation array
eqns1 = List.map1r(eqns,arrayGet,mapIncRowEqn);
eqns1 = List.map1r(eqnsf,arrayGet,mapIncRowEqn);
eqns1 = List.unique(eqns1);
// BackendDump.dumpStateVariables(BackendVariable.daeVars(syst));
// print("marked equations:");print(stringDelimitList(List.map(eqns,intString),","));print("\n");
Expand All @@ -2711,7 +2712,7 @@ algorithm

// 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.
(states,stateindx) = statesInEqns(eqns, syst,{},{});
(states,stateindx) = statesInEqns(eqnsf, syst,{},{});
(syst,shared,deqns,so1,orgEqnsLst1) = differentiateEqns(syst,shared,eqns_1,so,orgEqnsLst);
(state,stateno) = selectDummyState(states, stateindx, syst, mapIncRowEqn, so);
// print("Selected ");print(ComponentReference.printComponentRefStr(state));print(" as dummy state\n");
Expand Down Expand Up @@ -2742,15 +2743,16 @@ algorithm

case (_,_,syst,shared,_,_,(_,_,_,mapIncRowEqn,_))
equation
eqnsf = List.flatten(eqns);
// get from scalar eqns indexes the indexes in the equation array
eqns1 = List.map1r(eqns,arrayGet,mapIncRowEqn);
eqns1 = List.map1r(eqnsf,arrayGet,mapIncRowEqn);
eqns1 = List.unique(eqns1);
diff_eqns = BackendDAEEXT.getDifferentiatedEqns();
eqns_1 = List.setDifferenceOnTrue(eqns1, diff_eqns, intEq);
es = List.map(eqns_1, intString);
es_1 = stringDelimitList(es, ", ");
print("eqns =");print(es_1);print("\n");
({},_) = statesInEqns(eqns, syst,{},{});
({},_) = statesInEqns(eqnsf, syst,{},{});
print("no states found in equations:");
BackendDump.printEquations(eqns_1, syst);
print("differentiated equations:");
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -8005,7 +8005,7 @@ partial function pastoptimiseDAEModule
end pastoptimiseDAEModule;

partial function StructurallySingularSystemHandlerFunc
input list<Integer> eqns;
input list<list<Integer>> eqns;
input Integer actualEqn;
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared ishared;
Expand Down

0 comments on commit 3b0a97b

Please sign in to comment.