Skip to content

Commit

Permalink
- continue dynamic state selection, try to get symbolic jacobian
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14493 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Dec 20, 2012
1 parent c3cb7d0 commit b896161
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 840 deletions.
10 changes: 7 additions & 3 deletions Compiler/BackEnd/BackendDAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,13 @@ type StateSets = list<StateSet> "List of StateSets";
public
uniontype StateSet
record STATESET
list< .DAE.ComponentRef> states "the states of the set";
list<Equation> constraintEquations "the constrain equations of the set";
list< .DAE.ComponentRef> dummystates "the dummystates of the set";
Integer rang;
.DAE.ComponentRef crA "set.x=A*states";
list< Var> varA;
list< Var> states;
list< Var> ovars;
list< Equation> eqns;
list< Equation> oeqns;
end STATESET;
end StateSet;

Expand Down
30 changes: 4 additions & 26 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,6 @@ algorithm
lsteqns = BackendEquation.equationList(eqns);
(vars,_) = replaceFinalVars(1,vars,repl,false); // replacing variable attributes (e.g start) in unknown vars
(eqns_1,_) = BackendVarTransform.replaceEquations(lsteqns, repl,NONE());
((stateSets,_)) = List.fold1(stateSets,replaceEquationsStateSet,repl,({},false));
eqns1 = BackendEquation.listEquation(eqns_1);
then
BackendDAE.EQSYSTEM(vars,eqns1,NONE(),NONE(),matching,stateSets);
Expand Down Expand Up @@ -1564,15 +1563,14 @@ algorithm
BackendDAE.Variables vars;
BackendDAE.EquationArray eqns,eqns1;
list<BackendDAE.Equation> eqns_1,lsteqns;
Boolean b,b1;
Boolean b;
BackendDAE.StateSets stateSets;
case (BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,stateSets=stateSets),_)
equation
lsteqns = BackendEquation.equationList(eqns);
(eqns_1,b) = BackendVarTransform.replaceEquations(lsteqns, repl,NONE());
eqns1 = Debug.bcallret1(b, BackendEquation.listEquation,eqns_1,eqns);
((stateSets,b1)) = List.fold1(stateSets,replaceEquationsStateSet,repl,({},false));
syst = Util.if_(b or b1,BackendDAE.EQSYSTEM(vars,eqns1,NONE(),NONE(),BackendDAE.NO_MATCHING(),stateSets),isyst);
syst = Util.if_(b,BackendDAE.EQSYSTEM(vars,eqns1,NONE(),NONE(),BackendDAE.NO_MATCHING(),stateSets),isyst);
then
syst;
end match;
Expand Down Expand Up @@ -12107,7 +12105,7 @@ algorithm
BackendDAE.Variables vars;
BackendDAE.EquationArray eqns,eqns1;
list<BackendDAE.Equation> eqns_1,lsteqns;
Boolean b,b1;
Boolean b;
BackendDAE.EqSystem syst;
BackendDAE.StateSets stateSets;
case (BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,stateSets=stateSets),_)
Expand All @@ -12116,32 +12114,12 @@ algorithm
lsteqns = BackendEquation.equationList(eqns);
(eqns_1,b) = BackendVarTransform.replaceEquations(lsteqns, repl,NONE());
eqns1 = Debug.bcallret1(b,BackendEquation.listEquation,eqns_1,eqns);
((stateSets,b1)) = List.fold1(stateSets,replaceEquationsStateSet,repl,({},false));
syst = Util.if_(b or b1,BackendDAE.EQSYSTEM(vars,eqns1,NONE(),NONE(),BackendDAE.NO_MATCHING(),stateSets),isyst);
syst = Util.if_(b,BackendDAE.EQSYSTEM(vars,eqns1,NONE(),NONE(),BackendDAE.NO_MATCHING(),stateSets),isyst);
then
syst;
end match;
end removeConstantsWork;

protected function replaceEquationsStateSet
"author: Frenkel TUD 2012-12"
input BackendDAE.StateSet inSet;
input BackendVarTransform.VariableReplacements repl;
input tuple<BackendDAE.StateSets,Boolean> inTpl;
output tuple<BackendDAE.StateSets,Boolean> outTpl;
protected
list< .DAE.ComponentRef> states;
list<BackendDAE.Equation> ceqns;
list< .DAE.ComponentRef> dstates;
BackendDAE.StateSets sets;
Boolean b,b1;
algorithm
BackendDAE.STATESET(states,ceqns,dstates) := inSet;
(sets,b) := inTpl;
(ceqns,b1) := BackendVarTransform.replaceEquations(ceqns, repl,NONE());
outTpl := (BackendDAE.STATESET(states,ceqns,dstates)::sets,b or b1);
end replaceEquationsStateSet;

protected function removeConstantsFinder
"author: Frenkel TUD 2012-10"
input tuple<BackendDAE.Var, BackendVarTransform.VariableReplacements> inTpl;
Expand Down
25 changes: 10 additions & 15 deletions Compiler/BackEnd/BackendDump.mo
Original file line number Diff line number Diff line change
Expand Up @@ -255,29 +255,24 @@ algorithm
end printBackendDAEType;

public function printStateSets "function printStateSets
author: jfrenkel"
author: Frenkel TUD"
input BackendDAE.StateSets stateSets;
algorithm
List.map_0(stateSets, printStateSet);
end printStateSets;

protected function printStateSet "function printStateSet
author: jfrenkel
This is a helper for printStateSets."
author: Frenkel TUD"
input BackendDAE.StateSet statSet;
protected
list<DAE.ComponentRef> states;
list<BackendDAE.Equation> ceqns;
list<DAE.ComponentRef> dstates;
algorithm
BackendDAE.STATESET(states,ceqns,dstates) := statSet;
print("StateSet:\n");
print("States:\n");
debuglst((states,ComponentReference.printComponentRefStr,"\n","\n"));
print("ConstraintEquations:\n");
debuglst((ceqns,equationString,"\n","\n"));
print("Dummystates:\n");
debuglst((dstates,ComponentReference.printComponentRefStr,"\n","\n"));
Integer rang;
list<BackendDAE.Var> states;
list<DAE.ComponentRef> crstates;
algorithm
BackendDAE.STATESET(rang=rang,states=states) := statSet;
crstates := List.map(states,BackendVariable.varCref);
print("StateSet: select " +& intString(rang) +& " from\n");
debuglst((crstates,ComponentReference.printComponentRefStr,"\n","\n"));
end printStateSet;

public function printVar "function printVar
Expand Down
5 changes: 3 additions & 2 deletions Compiler/BackEnd/BackendQSS.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ algorithm
list<String> externalFunctionIncludes;
list<list<SimCode.SimEqSystem>> odeEquations;
list<SimCode.SimEqSystem> allEquations,algebraicEquations,residualEquations,startValueEquations,parameterEquations,inlineEquations,removedEquations,sampleEquations,algorithmAndEquationAsserts;
list<SimCode.StateSet> stateSets;
Boolean useSymbolicInitialization;
list<SimCode.SimEqSystem> initialEquations;
list<DAE.Constraint> constraints;
Expand All @@ -1033,7 +1034,7 @@ algorithm
list<SimCode.SimEqSystem> eqs;
case (SimCode.SIMCODE(modelInfo,literals,recordDecls,externalFunctionIncludes,allEquations,odeEquations,
algebraicEquations,residualEquations,useSymbolicInitialization,initialEquations,startValueEquations,
parameterEquations,inlineEquations,removedEquations,algorithmAndEquationAsserts,constraints,classAttributes,zeroCrossings,relations,
parameterEquations,inlineEquations,removedEquations,algorithmAndEquationAsserts,stateSets,constraints,classAttributes,zeroCrossings,relations,
sampleConditions,sampleEquations,helpVarInfo,whenClauses,discreteModelVars,extObjInfo,makefileParams,
delayedExps,jacobianMatrixes,simulationSettingsOpt,fileNamePrefix,crefToSimVarHT),_)
equation
Expand All @@ -1042,7 +1043,7 @@ algorithm
then SimCode.SIMCODE(modelInfo, literals, recordDecls, externalFunctionIncludes,
allEquations, {eqs}, algebraicEquations, residualEquations, useSymbolicInitialization,
initialEquations, startValueEquations, parameterEquations, inlineEquations,
removedEquations, algorithmAndEquationAsserts, constraints, classAttributes,
removedEquations, algorithmAndEquationAsserts, stateSets, constraints, classAttributes,
zeroCrossings, relations, sampleConditions, sampleEquations,
helpVarInfo, whenClauses, discreteModelVars, extObjInfo,
makefileParams, delayedExps, jacobianMatrixes,
Expand Down

0 comments on commit b896161

Please sign in to comment.