Skip to content

Commit

Permalink
- put parameter dependent asserts in the paramEquation section and no…
Browse files Browse the repository at this point in the history
…t in all-equations

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25684 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Volker Waurich committed Apr 22, 2015
1 parent 2d01a1a commit d62f8e8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
19 changes: 19 additions & 0 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -6978,5 +6978,24 @@ algorithm
end match;
end toDAEInnerOuter;

public function getAssertConditionCrefs"gets the crefs of the assert condition.
author:Waurich 2015-04"
input DAE.Statement stmt;
input list<DAE.ComponentRef> crefsIn;
output list<DAE.ComponentRef> crefsOut;
algorithm
crefsOut := match(stmt,crefsIn)
local
DAE.Exp cond;
list<DAE.ComponentRef> crefs;
case(DAE.STMT_ASSERT(cond=cond),_)
algorithm
crefs := Expression.extractCrefsFromExp(cond);
then (listAppend(crefsIn,crefs));
else
then crefsIn;
end match;
end getAssertConditionCrefs;

annotation(__OpenModelica_Interface="frontend");
end DAEUtil;
40 changes: 37 additions & 3 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -1535,7 +1535,9 @@ algorithm
BackendDAE.EqSystems systs;
BackendDAE.Shared shared;
BackendDAE.EquationArray removedEqs;
list<BackendDAE.Equation> removedInitialEquationLst;
BackendDAE.Variables knownVars;
list<BackendDAE.Equation> removedInitialEquationLst, paramAsserts, remEqLst;
list<SimCode.SimEqSystem> paramAssertSimEqs;

list<DAE.Exp> lits;
list<SimCodeVar.SimVar> tempvars, jacobianSimvars;
Expand Down Expand Up @@ -1584,7 +1586,8 @@ algorithm
// addInitialStmtsToAlgorithms
dlow = BackendDAEOptimize.addInitialStmtsToAlgorithms(dlow);

BackendDAE.DAE(systs, shared as BackendDAE.SHARED(removedEqs=removedEqs,
BackendDAE.DAE(systs, shared as BackendDAE.SHARED(knownVars=knownVars,
removedEqs=removedEqs,
constraints=constraints,
classAttrs=classAttributes,
symjacs=symJacs,
Expand All @@ -1602,7 +1605,8 @@ algorithm
(uniqueEqIndex, odeEquations, algebraicEquations, allEquations, equationsForZeroCrossings, tempvars, equationSccMapping, eqBackendSimCodeMapping,backendMapping) = createEquationsForSystems(systs, shared, uniqueEqIndex, {}, {}, {}, {}, zeroCrossings, tempvars, 1, {}, {},backendMapping);
highestSimEqIndex = uniqueEqIndex;

((uniqueEqIndex, removedEquations)) = BackendEquation.traverseEquationArray(removedEqs, traversedlowEqToSimEqSystem, (uniqueEqIndex, {}));
(remEqLst,paramAsserts) = List.fold1(BackendEquation.equationList(removedEqs), getParamAsserts,knownVars,({},{}));
((uniqueEqIndex, removedEquations)) = BackendEquation.traverseEquationArray(BackendEquation.listEquation(remEqLst), traversedlowEqToSimEqSystem, (uniqueEqIndex, {}));

// Assertions and crap
// create parameter equations
Expand All @@ -1612,6 +1616,8 @@ algorithm
((uniqueEqIndex, maxValueEquations)) = BackendDAEUtil.foldEqSystem(dlow, createMaxValueEquations, (uniqueEqIndex, {}));
((uniqueEqIndex, parameterEquations)) = BackendDAEUtil.foldEqSystem(dlow, createVarNominalAssertFromVars, (uniqueEqIndex, {}));
(uniqueEqIndex, parameterEquations) = createParameterEquations(uniqueEqIndex, parameterEquations, primaryParameters, allPrimaryParameters);
((uniqueEqIndex, paramAssertSimEqs)) = BackendEquation.traverseEquationArray(BackendEquation.listEquation(paramAsserts), traversedlowEqToSimEqSystem, (uniqueEqIndex, {}));
parameterEquations = listAppend(parameterEquations,paramAssertSimEqs);

((uniqueEqIndex, algorithmAndEquationAsserts)) = BackendDAEUtil.foldEqSystem(dlow, createAlgorithmAndEquationAsserts, (uniqueEqIndex, {}));
discreteModelVars = BackendDAEUtil.foldEqSystem(dlow, extractDiscreteModelVars, {});
Expand Down Expand Up @@ -1766,6 +1772,34 @@ algorithm
end matchcontinue;
end createSimCode;

protected function getParamAsserts"splits the equationArray in variable-dependent and parameter-dependent equations.
author: Waurich TUD-2015-04"
input BackendDAE.Equation eqIn;
input BackendDAE.Variables vars;
input tuple<list<BackendDAE.Equation>, list<BackendDAE.Equation>> tplIn; //<var-dependent, param-dependent>
output tuple<list<BackendDAE.Equation>, list<BackendDAE.Equation>> tplOut;
algorithm
tplOut := matchcontinue(eqIn,vars,tplIn)
local
list<DAE.Statement> stmts;
list<DAE.ComponentRef> crefs;
list<BackendDAE.Var> varLst;
list<list<BackendDAE.Var>> varLstLst;
list<BackendDAE.Equation> varDep,paramDep;
case(BackendDAE.ALGORITHM(alg=DAE.ALGORITHM_STMTS(statementLst=stmts)),_,(varDep,paramDep))
algorithm
crefs := List.fold(stmts,DAEUtil.getAssertConditionCrefs,{});
(varLstLst,_) := List.map1_2(crefs,BackendVariable.getVar,vars);
varLst := List.flatten(varLstLst);
true := List.exist(varLst,BackendVariable.isParam);
then ((varDep,eqIn::paramDep));
else
algorithm
(varDep,paramDep) := tplIn;
then ((eqIn::varDep,paramDep));
end matchcontinue;
end getParamAsserts;

protected function addTempVars
input list<SimCodeVar.SimVar> tempVars;
input SimCode.ModelInfo modelInfo;
Expand Down

0 comments on commit d62f8e8

Please sign in to comment.