Skip to content

Commit

Permalink
Fix generation of parameter equations
Browse files Browse the repository at this point in the history
- see second issue of ticket:4093
  • Loading branch information
lochel authored and OpenModelica-Hudson committed Oct 26, 2016
1 parent c8df1c5 commit 3fd4d4f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
19 changes: 18 additions & 1 deletion Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -350,7 +350,8 @@ algorithm
end varHasBindExp;

public function varBindExpStartValue "author: Frenkel TUD 2010-12
Returns the bindExp or the start value if no bind is there of a variable."
Returns the binding or the start value if no binding is available.
This function fails if there is neither a binding nor a start value."
input BackendDAE.Var v;
output DAE.Exp sv;
algorithm
Expand All @@ -365,6 +366,22 @@ algorithm
end match;
end varBindExpStartValue;

public function varBindExpStartValueNoFail
"Returns the binding or the start value if no binding is available."
input BackendDAE.Var v;
output DAE.Exp sv;
algorithm
sv := match(v)
local
DAE.Exp e;

case (BackendDAE.VAR(bindExp=SOME(e)))
then e;

else varStartValue(v);
end match;
end varBindExpStartValueNoFail;

public function varStateSelect "author: PA
Extracts the state select attribute of a variable. If no stateselect explicilty set, return
StateSelect.default"
Expand Down
11 changes: 4 additions & 7 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -846,13 +846,10 @@ algorithm
outVars := BackendVariable.addVar(p, outVars);
else
outAllPrimaryParameters := p::outAllPrimaryParameters;
try
bindExp := BackendVariable.varBindExpStartValue(p);
if not Expression.isConst(bindExp) then
outPrimaryParameters := p::outPrimaryParameters;
end if;
else
end try;
bindExp := BackendVariable.varBindExpStartValueNoFail(p);
if (not Expression.isConst(bindExp)) or BackendVariable.isFinalOrProtectedVar(p) then
outPrimaryParameters := p::outPrimaryParameters "this is used in SimCode to generate parameter equations";
end if;
end if;
end for;

Expand Down
16 changes: 6 additions & 10 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -6306,7 +6306,7 @@ protected
DAE.ElementSource source;
algorithm
cr := BackendVariable.varCref(inVar);
e := BackendVariable.varBindExpStartValue(inVar);
e := BackendVariable.varBindExpStartValueNoFail(inVar);
source := BackendVariable.getVarSource(inVar);
outSimEqn := SimCode.SES_SIMPLE_ASSIGN(inUniqueEqIndex, cr, e, source);
outUniqueEqIndex := inUniqueEqIndex+1;
Expand All @@ -6330,22 +6330,18 @@ algorithm
BackendDump.dumpVarList(inPrimaryParameters, "parameters in order");
end if;

for p in inPrimaryParameters loop
(simEq, outUniqueEqIndex) := makeSolved_SES_SIMPLE_ASSIGN_fromStartValue(p, outUniqueEqIndex);
outParameterEquations := simEq::outParameterEquations;
end for;

// get min/max and nominal asserts
varasserts := {};
for p in inAllPrimaryParameters loop
if BackendVariable.isFinalOrProtectedVar(p) and Expression.isConst(BackendVariable.varBindExpStartValue(p)) then
(simEq, outUniqueEqIndex) := makeSolved_SES_SIMPLE_ASSIGN_fromStartValue(p, outUniqueEqIndex);
outParameterEquations := simEq::outParameterEquations;
end if;
varasserts2 := createVarAsserts(p);
varasserts := List.append_reverse(varasserts2, varasserts);
end for;

for p in inPrimaryParameters loop
(simEq, outUniqueEqIndex) := makeSolved_SES_SIMPLE_ASSIGN_fromStartValue(p, outUniqueEqIndex);
outParameterEquations := simEq::outParameterEquations;
end for;

varasserts := MetaModelica.Dangerous.listReverseInPlace(varasserts);
(simvarasserts, outUniqueEqIndex) := List.mapFold(varasserts, dlowAlgToSimEqSystem, outUniqueEqIndex);

Expand Down

0 comments on commit 3fd4d4f

Please sign in to comment.