Skip to content

Commit

Permalink
- BackendDump: use capital letters for constants
Browse files Browse the repository at this point in the history
- RemoveSimpleEquations: do not replace discrete variables and do not merge fixed and start for discrete variables, fixes issues with symbolic initialization, (Modelica.Blocks.Exmaples.Interaktion1)
- Initialization: bugfix for inaktive when transformation to equations if only one assignment


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14549 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Dec 27, 2012
1 parent b3c3c19 commit 857e2dc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 32 deletions.
34 changes: 17 additions & 17 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -384,15 +384,15 @@ end printSparsityPattern;
// - dumpVarList
// =============================================================================

protected constant String border = "########################################";
protected constant String underline = "========================================";
protected constant String BORDER = "########################################";
protected constant String UNDERLINE = "========================================";

public function dumpBackendDAE "function dumpBackendDAE
This function dumps the BackendDAE.BackendDAE representaton to stdout."
input BackendDAE.BackendDAE inBackendDAE;
input String heading;
algorithm
print("\n" +& border +& "\n" +& heading +& "\n" +& border +& "\n\n");
print("\n" +& BORDER +& "\n" +& heading +& "\n" +& BORDER +& "\n\n");
printBackendDAE(inBackendDAE);
print("\n");
end dumpBackendDAE;
Expand All @@ -401,7 +401,7 @@ public function dumpEqSystem "function dumpEqSystem"
input BackendDAE.EqSystem inEqSystem;
input String heading;
algorithm
print("\n" +& heading +& "\n" +& underline +& "\n");
print("\n" +& heading +& "\n" +& UNDERLINE +& "\n");
printEqSystem(inEqSystem);
print("\n");
end dumpEqSystem;
Expand All @@ -410,7 +410,7 @@ public function dumpVariables "function dumpVariables"
input BackendDAE.Variables inVars;
input String heading;
algorithm
print("\n" +& heading +& " (" +& intString(BackendVariable.varsSize(inVars)) +& ")\n" +& underline +& "\n");
print("\n" +& heading +& " (" +& intString(BackendVariable.varsSize(inVars)) +& ")\n" +& UNDERLINE +& "\n");
printVariables(inVars);
print("\n");
end dumpVariables;
Expand All @@ -419,7 +419,7 @@ public function dumpVarList "function dumpVarList"
input list<BackendDAE.Var> inVars;
input String heading;
algorithm
print("\n" +& heading +& " (" +& intString(listLength(inVars)) +& ")\n" +& underline +& "\n");
print("\n" +& heading +& " (" +& intString(listLength(inVars)) +& ")\n" +& UNDERLINE +& "\n");
printVarList(inVars);
print("\n");
end dumpVarList;
Expand All @@ -428,7 +428,7 @@ public function dumpEquationArray "function dumpEquationArray"
input BackendDAE.EquationArray inEqns;
input String heading;
algorithm
print("\n" +& heading +& " (" +& intString(listLength(BackendEquation.equationList(inEqns))) +& ", " +& intString(BackendDAEUtil.equationSize(inEqns)) +& ")\n" +& underline +& "\n");
print("\n" +& heading +& " (" +& intString(listLength(BackendEquation.equationList(inEqns))) +& ", " +& intString(BackendDAEUtil.equationSize(inEqns)) +& ")\n" +& UNDERLINE +& "\n");
printEquationArray(inEqns);
print("\n");
end dumpEquationArray;
Expand All @@ -438,7 +438,7 @@ protected function dumpExternalObjectClasses "function dumpExternalObjectClasses
input BackendDAE.ExternalObjectClasses inEOC;
input String heading;
algorithm
print("\n" +& heading +& " (" +& intString(listLength(inEOC)) +& ")\n" +& underline +& "\n");
print("\n" +& heading +& " (" +& intString(listLength(inEOC)) +& ")\n" +& UNDERLINE +& "\n");
printExternalObjectClasses(inEOC);
print("\n");
end dumpExternalObjectClasses;
Expand All @@ -447,7 +447,7 @@ protected function dumpStateSets
input BackendDAE.StateSets stateSets;
input String heading;
algorithm
print("\n" +& heading +& "\n" +& underline +& "\n");
print("\n" +& heading +& "\n" +& UNDERLINE +& "\n");
printStateSets(stateSets);
print("\n");
end dumpStateSets;
Expand All @@ -456,7 +456,7 @@ protected function dumpZeroCrossingList "function dumpZeroCrossingList"
input list<BackendDAE.ZeroCrossing> inZeroCrossingList;
input String heading;
algorithm
print("\n" +& heading +& "\n" +& underline +& "\n");
print("\n" +& heading +& "\n" +& UNDERLINE +& "\n");
print(zeroCrossingListString(inZeroCrossingList));
print("\n");
end dumpZeroCrossingList;
Expand All @@ -465,7 +465,7 @@ protected function dumpWhenClauseList "function dumpWhenClauseList"
input list<BackendDAE.WhenClause> inWhenClauseList;
input String heading;
algorithm
print("\n" +& heading +& "\n" +& underline +& "\n");
print("\n" +& heading +& "\n" +& UNDERLINE +& "\n");
print(whenClauseListString(inWhenClauseList));
print("\n");
end dumpWhenClauseList;
Expand All @@ -474,7 +474,7 @@ protected function dumpConstraintArray "function dumpConstraintArray"
input array<DAE.Constraint> inConstraintArray;
input String heading;
algorithm
print("\n" +& heading +& "\n" +& underline +& "\n");
print("\n" +& heading +& "\n" +& UNDERLINE +& "\n");
dumpConstraints(arrayList(inConstraintArray), 0);
print("\n");
end dumpConstraintArray;
Expand All @@ -489,7 +489,7 @@ protected
algorithm
(pattern, (diffVars, diffedVars)) := inPattern;

print("\n" +& heading +& "\n" +& underline +& "\n");
print("\n" +& heading +& "\n" +& UNDERLINE +& "\n");
print("independents [or inputs] (" +& intString(listLength(diffVars)) +& ")\n");
ComponentReference.printComponentRefList(diffVars);

Expand Down Expand Up @@ -962,7 +962,7 @@ public function dumpComponents
input BackendDAE.StrongComponents inComps;
algorithm
print("StrongComponents\n");
print(underline +& "\n");
print(UNDERLINE +& "\n");
List.map_0(inComps,dumpComponent);
end dumpComponents;

Expand Down Expand Up @@ -2685,7 +2685,7 @@ protected
list<list<Integer>> m_1;
algorithm
print("\nIncidence Matrix (row: equation)\n");
print(underline +& "\n");
print(UNDERLINE +& "\n");
mlen := arrayLength(m);
mlen_str := intString(mlen);
print("number of rows: ");
Expand All @@ -2707,7 +2707,7 @@ protected
list<list<Integer>> m_1;
algorithm
print("\nTranspose Incidence Matrix (row: var)\n");
print(underline +& "\n");
print(UNDERLINE +& "\n");
mlen := arrayLength(m);
mlen_str := intString(mlen);
print("number of rows: ");
Expand Down Expand Up @@ -2907,7 +2907,7 @@ protected
String len_str;
algorithm
print("Matching\n");
print(underline +& "\n");
print(UNDERLINE +& "\n");
len := arrayLength(v);
len_str := intString(len);
print(len_str);
Expand Down
27 changes: 15 additions & 12 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -180,7 +180,7 @@ algorithm
case (BackendDAE.ALGORITHM(size=size, alg=alg, source=source),_)
equation
DAE.ALGORITHM_STMTS(statementLst=stmts) = alg;
(stmts,eqns) = generateInitialWhenAlg(stmts,iEqns);
(stmts,eqns) = generateInitialWhenAlg(stmts,true,iEqns);
alg = DAE.ALGORITHM_STMTS(stmts);
eqns = List.consOnTrue(List.isNotEmpty(stmts), BackendDAE.ALGORITHM(size, alg, source), eqns);
then
Expand All @@ -195,11 +195,12 @@ protected function generateInitialWhenAlg "function generateInitialWhenAlg
This function generates out of a given when-algorithm, a algorithm for the initialization-problem.
This is a helper function for inlineWhenForInitialization3."
input list< DAE.Statement> inStmts;
input Boolean first;
input list< BackendDAE.Equation> iEqns;
output list< DAE.Statement> outStmts;
output list< BackendDAE.Equation> oEqns;
algorithm
(outStmts,oEqns) := matchcontinue(inStmts,iEqns)
(outStmts,oEqns) := matchcontinue(inStmts,first,iEqns)
local
DAE.Exp condition "The when-condition" ;
DAE.ComponentRef left "Left hand side of equation" ;
Expand All @@ -216,19 +217,19 @@ algorithm
DAE.ElementSource algSource "origin of algorithm";
list< BackendDAE.Equation> eqns;

case ({},_) then ({},iEqns);
case ({},_,_) then ({},iEqns);

// active when equation during initialization
case (DAE.STMT_WHEN(exp=condition, statementLst=stmts)::rest,_)
case (DAE.STMT_WHEN(exp=condition, statementLst=stmts)::rest,_,_)
equation
true = Expression.containsInitialCall(condition, false);
(rest,eqns) = generateInitialWhenAlg(rest,iEqns);
(rest,eqns) = generateInitialWhenAlg(rest,false,iEqns);
stmts = listAppend(stmts, rest);
then
(stmts,eqns);

// single inactive when equation during initialization
case (((stmt as (DAE.STMT_WHEN(exp=condition, source=source)))::{}),_)
case (((stmt as (DAE.STMT_WHEN(exp=condition, source=source)))::{}),true,_)
equation
false = Expression.containsInitialCall(condition, false);
crefLst = CheckModel.algorithmStatementListOutputs({stmt});
Expand All @@ -238,21 +239,21 @@ algorithm
({},eqns);

// inactive when equation during initialization
case (((stmt as (DAE.STMT_WHEN(exp=condition, source=source)))::rest),_)
case (((stmt as (DAE.STMT_WHEN(exp=condition, source=source)))::rest),_,_)
equation
false = Expression.containsInitialCall(condition, false);
crefLst = CheckModel.algorithmStatementListOutputs({stmt});
stmts = List.map1(crefLst, generateInactiveWhenAlgStatementForInitialization, source);
(rest,eqns) = generateInitialWhenAlg(rest,iEqns);
(rest,eqns) = generateInitialWhenAlg(rest,false,iEqns);
stmts = listAppend(stmts, rest);
then
(stmts,eqns);

// no when equation
case (stmt::rest,_)
case (stmt::rest,_,_)
equation
// false = isWhenStmt(stmt);
(rest,eqns) = generateInitialWhenAlg(rest,iEqns);
(rest,eqns) = generateInitialWhenAlg(rest,false,iEqns);
then
(stmt::rest,eqns);

Expand Down Expand Up @@ -668,15 +669,17 @@ algorithm
BackendDAE.BackendDAE inDAE;
BackendDAE.Shared shared;
DAE.ComponentRef cr,pcr;
String msg;

// over-determined system
case(BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns),(shared,(inDAE,initVars)))
equation
nVars = BackendVariable.varsSize(vars);
nEqns = BackendDAEUtil.equationSize(eqns);
true = intGt(nEqns, nVars);

Debug.fcall(Flags.PEDANTIC, Error.addCompilerWarning, "Trying to fix over-determined initial system... [not implemented yet!]");
Debug.fcall2(Flags.PEDANTIC, BackendDump.dumpEqSystem, isyst, "Trying to fix over-determined initial system");
msg = "Trying to fix over-determined initial system Variables " +& intString(nVars) +& " Equations " +& intString(nEqns) +& "... [not implemented yet!]";
Debug.fcall(Flags.PEDANTIC, Error.addCompilerWarning, msg);
then fail();

// under-determined system with var = pre(var) and only var and pre(var)
Expand Down
14 changes: 11 additions & 3 deletions Compiler/BackEnd/RemoveSimpleEquations.mo
Expand Up @@ -181,7 +181,13 @@ algorithm
unreplacable = traverseCrefUnreplacable(cr,NONE(),unreplacable);
then
((e, unreplacable));
case _ then inExp;
/* This is a test for the initial system
case((DAE.CALL(path=Absyn.IDENT(name = "pre"),expLst={e as DAE.CREF(componentRef=cr)}), unreplacable))
equation
unreplacable = BaseHashSet.add(cr,unreplacable);
then
((e, unreplacable));
*/ case _ then inExp;
end matchcontinue;
end traverserExpUnreplacable;

Expand Down Expand Up @@ -1604,6 +1610,7 @@ algorithm
DAE.ComponentRef cr;
case (BackendDAE.VAR(varName=cr,varKind=kind),_)
equation
false = BackendVariable.isVarDiscrete(var);
//false = BackendVariable.isStateorStateDerVar(var) "cr1 not state";
BackendVariable.isVarKindVariable(kind) "cr1 not constant";
false = BackendVariable.isVarOnTopLevelAndOutput(var);
Expand Down Expand Up @@ -2343,7 +2350,7 @@ protected function handleVarSetAttributes
algorithm
oVars := matchcontinue(iAttributes,inVar,i,iVars,ishared)
local
Boolean fixedset;
Boolean fixedset,isdiscrete;
Option<DAE.Exp> nominalset;
tuple<Option<DAE.Exp>,Option<DAE.Exp>> minmaxset;
Integer nNominal;
Expand All @@ -2352,8 +2359,9 @@ algorithm
BackendDAE.Variables vars;
case((fixedset,startvalues,nominalset,nNominal,minmaxset),_,_,_,_)
equation
isdiscrete = BackendVariable.isVarDiscrete(inVar);
// start and fixed
v = mergeStartFixedAttributes(inVar,fixedset,startvalues,ishared);
v = Debug.bcallret4(not isdiscrete,mergeStartFixedAttributes,inVar,fixedset,startvalues,ishared,inVar);
// nominal
v = mergeNominalAttribute(nominalset,nNominal,v);
// min max
Expand Down

0 comments on commit 857e2dc

Please sign in to comment.