Skip to content

Commit

Permalink
search external alias in removed equations, fix init of external vars (
Browse files Browse the repository at this point in the history
…#831)

* search external alias in removed equations, fix init of external vars

* remove bindings of external objects if they are alias vars

* Removed matchcontinue. Fixed indention

Co-authored-by: John <JKRT@users.noreply.github.com>
  • Loading branch information
vwaurich and JKRT committed May 7, 2020
1 parent 37ce5aa commit 6257388
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 35 additions & 1 deletion OMCompiler/Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -142,7 +142,7 @@ algorithm
end if;
// handle alias equations
(vars, globalKnownVars, extVars, aliasVars, eqns, reqns, ieqns) := handleAliasEquations(aliaseqns, vars, globalKnownVars, extVars, aliasVars, eqns, reqns, ieqns);
(ieqns, eqns, extAliasVars, extVars) := getExternalObjectAlias(ieqns, eqns, extVars);
(ieqns, eqns, reqns, extAliasVars, extVars) := getExternalObjectAlias(ieqns, eqns, reqns, extVars);
aliasVars := BackendVariable.addVariables(extAliasVars,aliasVars);

vars_1 := detectImplicitDiscrete(vars, globalKnownVars, eqns);
Expand Down Expand Up @@ -194,9 +194,11 @@ If yes, assign alias var, replace equations, remove alias equation.
author: waurich TUD 2016-10"
input list<BackendDAE.Equation> inInitEqs;
input list<BackendDAE.Equation> inEqs;
input list<BackendDAE.Equation> inRemEqs;
input BackendDAE.Variables extVars;
output list<BackendDAE.Equation> oInitEqs;
output list<BackendDAE.Equation> oEqs;
output list<BackendDAE.Equation> oRemEqs;
output BackendDAE.Variables extAliasVars;
output BackendDAE.Variables extVarsOut;
protected
Expand All @@ -211,6 +213,7 @@ algorithm
// get alias equations for external objects
(oEqs,aliasEqs) := List.fold1(inEqs,getExternalObjectAlias2,extCrefs,({},{}));
(oInitEqs,aliasEqs) := List.fold1(inInitEqs,getExternalObjectAlias2,extCrefs,({},aliasEqs));
(oRemEqs,aliasEqs) := List.fold1(inRemEqs,getExternalObjectAlias2,extCrefs,({},aliasEqs));

if (not listEmpty(aliasEqs)) then
Error.addCompilerWarning("Alias equations of external objects are not Modelica compliant as in:\n "+stringDelimitList(List.map(aliasEqs,BackendDump.equationString),"\n ")+"\n");
Expand All @@ -223,14 +226,45 @@ algorithm

//remove alias from extVarArray
extVarsOut := BackendVariable.deleteVars(extAliasVars,extVars);
extVarsOut := removeExtAliasBinding(extVarsOut,repl);

//replace in equations
(oEqs,_) := BackendVarTransform.replaceEquations(oEqs,repl,NONE());
(oInitEqs,_) := BackendVarTransform.replaceEquations(oInitEqs,repl,NONE());
(oRemEqs,_) := BackendVarTransform.replaceEquations(oRemEqs,repl,NONE());

oEqs := listReverse(oEqs);
oInitEqs := listReverse(oInitEqs);
oRemEqs := listReverse(oRemEqs);
end getExternalObjectAlias;


protected function removeExtAliasBinding "Removes the binding of an external variable if the binding cref ist already detected as an alias variable.
author: Waurich TUD 2020-05"
input BackendDAE.Variables extVarsIn;
input BackendVarTransform.VariableReplacements repl;
output BackendDAE.Variables extVarsOut;
protected
list<BackendDAE.Var> varLst,extVarLst;
DAE.ComponentRef cref;
algorithm
varLst := BackendVariable.varList(extVarsIn);
extVarLst := {};
for var in varLst loop
var := match var
case BackendDAE.VAR(bindExp = SOME(DAE.CREF(componentRef=cref)))
algorithm
if BackendVarTransform.hasReplacement(repl,cref) then
var.bindExp := NONE();
end if;
then var;
else var;
end match;
extVarLst := var::extVarLst;
end for;
extVarsOut := BackendVariable.listVar(extVarLst);
end removeExtAliasBinding;

protected function getExternalObjectAlias3 "Gets the alias var and sim var for the given alias equation and adds a replacement rule
author: waurich TUD 2016-10"
input BackendDAE.Equation eqIn;
Expand Down
2 changes: 2 additions & 0 deletions OMCompiler/Compiler/BackEnd/Initialization.mo
Expand Up @@ -872,6 +872,8 @@ algorithm
var = BackendVariable.setVarFixed(extObj, true);
globalKnownVars = BackendVariable.addVar(var, globalKnownVars);
then (globalKnownVars);
else
then (globalKnownVars);
end match;
end addExtObjToGlobalKnownVars;

Expand Down

0 comments on commit 6257388

Please sign in to comment.