Skip to content

Commit

Permalink
Don't add a dummy state to generate symbolic Jacobians
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel committed May 19, 2015
1 parent 27df1e5 commit 8b2edc7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 86 deletions.
85 changes: 0 additions & 85 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -654,91 +654,6 @@ algorithm
osyst := BackendDAE.EQSYSTEM(vars, eqs, m, mT, matching, stateSets, partitionKind);
end addVarsToEqSystem;

public function addDummyStateIfNeeded
"author: Frenkel TUD 2012-09
adds a dummy state if dae contains no states"
input BackendDAE.BackendDAE inBackendDAE;
output BackendDAE.BackendDAE outBackendDAE;
protected
BackendDAE.EqSystems systs;
BackendDAE.Shared shared;
Boolean daeContainsNoStates;
algorithm
BackendDAE.DAE(eqs=systs,shared=shared) := inBackendDAE;
// check if the DAE has states
daeContainsNoStates := addDummyStateIfNeeded1(systs);
// adrpo: add the dummy derivative state ONLY IF the DAE contains no states
systs := if daeContainsNoStates then addDummyState(systs) else systs;
outBackendDAE := if daeContainsNoStates then BackendDAE.DAE(systs,shared) else inBackendDAE;
end addDummyStateIfNeeded;

protected function addDummyStateIfNeeded1
input BackendDAE.EqSystems iSysts;
output Boolean oContainsNoStates;
algorithm
oContainsNoStates := match(iSysts)
local
BackendDAE.EqSystems systs;
BackendDAE.Variables vars;
Boolean containsNoStates;
case ({}) then true;
case (BackendDAE.EQSYSTEM(orderedVars = vars)::systs)
equation
containsNoStates = BackendVariable.traverseBackendDAEVarsWithStop(vars, traverserVaraddDummyStateIfNeeded, true);
containsNoStates = if containsNoStates then addDummyStateIfNeeded1(systs) else containsNoStates;
then
containsNoStates;
end match;
end addDummyStateIfNeeded1;

protected function traverserVaraddDummyStateIfNeeded
input BackendDAE.Var v;
input Boolean b;
output BackendDAE.Var ov;
output Boolean cont;
output Boolean ob;
algorithm
(ov,cont,ob) := match (v,b)
case (BackendDAE.VAR(varKind=BackendDAE.STATE()),_)
then (v,false,false);
case (_,_) then (v,b,b);
end match;
end traverserVaraddDummyStateIfNeeded;

protected function addDummyState
"In order for the solver to work correctly at least one state variable
must exist in the equation system. This function therefore adds a
dummy state variable and an equation for that variable."
input BackendDAE.EqSystems isysts;
output BackendDAE.EqSystems osysts;
protected
DAE.ComponentRef cr;
BackendDAE.Var v;
BackendDAE.Variables vars;
DAE.Exp exp;
BackendDAE.Equation eqn;
BackendDAE.EquationArray eqns;
array<Integer> ass;
BackendDAE.EqSystem syst;
algorithm
// generate dummy state
(v,cr) := BackendVariable.createDummyVar();

// generate vars
vars := BackendVariable.listVar({v});
/*
* adrpo: after a bit of talk with Francesco Casella & Peter Aronsson we will add der($dummy) = 0;
*/
exp := Expression.crefExp(cr);
eqn := BackendDAE.EQUATION(DAE.CALL(Absyn.IDENT("der"),{exp},DAE.callAttrBuiltinReal),DAE.RCONST(0.0), DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN);
eqns := BackendEquation.listEquation({eqn});
// generate equationsystem
ass := arrayCreate(1, 1);
syst := BackendDAE.EQSYSTEM(vars,eqns,NONE(),NONE(),BackendDAE.MATCHING(ass,ass,{BackendDAE.SINGLEEQUATION(1,1)}),{},BackendDAE.UNSPECIFIED_PARTITION());
// add system to list of systems
osysts := syst::isysts;
end addDummyState;

public function numberOfZeroCrossings "author: lochel"
input BackendDAE.BackendDAE inBackendDAE;
output Integer outNumZeroCrossings "number of ordinary zerocrossings" ;
Expand Down
1 change: 0 additions & 1 deletion Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -149,7 +149,6 @@ algorithm

// prepare a DAE
DAE := BackendDAEUtil.copyBackendDAE(inBackendDAE);
DAE := BackendDAEUtil.addDummyStateIfNeeded(DAE);
DAE := BackendDAEOptimize.collapseIndependentBlocks(DAE);
DAE := BackendDAEUtil.transformBackendDAE(DAE, SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.EXACT())), NONE(), NONE());

Expand Down

0 comments on commit 8b2edc7

Please sign in to comment.