Skip to content

Commit

Permalink
- continue removing helpVars
Browse files Browse the repository at this point in the history
  - when-coditions are checked without using helpVars anymore (c runtime)
- testsuite/simulation/modelica/initialization/gaspropreties.mos fails, because updateDiscreteSystem is called before the symbolic initialization is done. This is related to some kind of annoying workaround and will hopefully removed soon.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14796 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Jan 16, 2013
1 parent b284623 commit 65df476
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 219 deletions.
5 changes: 2 additions & 3 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -219,16 +219,15 @@ end WhenOperator;
public
uniontype WhenClause "- When Clause"
record WHEN_CLAUSE
.DAE.Exp condition "The when-condition" ;
list<WhenOperator> reinitStmtLst "List of reinit statements associated to the when clause." ;
.DAE.Exp condition "The when-condition" ;
list<WhenOperator> reinitStmtLst "List of reinit statements associated to the when clause." ;
Option<Integer> elseClause "index of elsewhen clause" ;

// HL only needs to know if it is an elsewhen the equations take care of which clauses are related.

// The equations associated to the clause are linked to this when clause by the index in the
// when clause list where this when clause is stored.
end WHEN_CLAUSE;

end WhenClause;

public
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -480,7 +480,7 @@ protected
HashTableExpToIndex.HashTable ht;
algorithm
ht := HashTableExpToIndex.emptyHashTable();
(outDAE, outTree, _) := DAEUtil.traverseDAE(inDAE, functionTree, transformBuiltinExpressions, (ht, 1, 1));
(outDAE, outTree, _) := DAEUtil.traverseDAE(inDAE, functionTree, transformBuiltinExpressions, (ht, 1, 1));
end processBuiltinExpressions;

protected function transformBuiltinExpressions "function transformBuiltinExpressions
Expand Down
75 changes: 73 additions & 2 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -187,7 +187,7 @@ algorithm
end match;
end getScalarArrayEqns;

protected function getScalarArrayEqns1"
protected function getScalarArrayEqns1 "function getScalarArrayEqns1
author: Frenkel TUD 2012-06"
input BackendDAE.Equation iEqn;
input list<BackendDAE.Equation> iAcc;
Expand Down Expand Up @@ -12540,7 +12540,20 @@ protected
BackendDAE.BackendDAEType backendDAEType;
BackendDAE.SymbolicJacobians symjacs;
list<BackendDAE.Equation> additionalInitialEquations;

list<BackendDAE.WhenClause> whenClauseLst "List of when clauses. The WhenEquation datatype refer to this list by position" ;
list<BackendDAE.ZeroCrossing> zeroCrossingLst "List of zero crossing coditions";
list<BackendDAE.ZeroCrossing> sampleLst "List of sample as before, used by cpp runtime";
list<BackendDAE.ZeroCrossing> relationsLst "List of zero crossing function as before, used by cpp runtime";
Integer relationsNumber "stores the number of relation in all zero-crossings";
Integer numberMathEvents "stores the number of math function that trigger events e.g. floor, ceil, integer, ...";

Integer index;
HashTableExpToIndex.HashTable ht; // is used to avoid redundant condition-variables
list<BackendDAE.Var> vars;
list<BackendDAE.Equation> eqns;
BackendDAE.Variables vars_;
BackendDAE.EquationArray eqns_;
algorithm
BackendDAE.DAE(systs, shared) := inDAE;
BackendDAE.SHARED(knownVars=knownVars,
Expand All @@ -12557,11 +12570,27 @@ algorithm
extObjClasses=extObjClasses,
backendDAEType=backendDAEType,
symjacs=symjacs) := shared;
BackendDAE.EVENT_INFO(whenClauseLst=whenClauseLst,
zeroCrossingLst=zeroCrossingLst,
sampleLst=sampleLst,
relationsLst=relationsLst,
relationsNumber=relationsNumber,
numberMathEvents=numberMathEvents) := eventInfo;

ht := HashTableExpToIndex.emptyHashTable();
(systs, (additionalInitialEquations, _, ht)) := List.mapFold(systs, encapsulateWhenConditions1, ({}, 1, ht));
(systs, (additionalInitialEquations, index, ht)) := List.mapFold(systs, encapsulateWhenConditions1, ({}, 1, ht));
(whenClauseLst, vars, eqns, additionalInitialEquations, ht, index) := encapsulateWhenConditionsFromWhenClause(whenClauseLst, {}, {}, {}, additionalInitialEquations, ht, index);
vars_ := BackendVariable.listVar(vars);
eqns_ := BackendEquation.listEquation(eqns);
systs := listAppend(systs, {BackendDAE.EQSYSTEM(vars_, eqns_, NONE(), NONE(), BackendDAE.NO_MATCHING(), {})});

initialEqs := BackendEquation.addEquations(additionalInitialEquations, initialEqs);
eventInfo := BackendDAE.EVENT_INFO(whenClauseLst,
zeroCrossingLst,
sampleLst,
relationsLst,
relationsNumber,
numberMathEvents);
shared := BackendDAE.SHARED(knownVars,
externalObjects,
aliasVars,
Expand All @@ -12580,6 +12609,48 @@ algorithm
Debug.fcall2(Flags.DUMP_ENCAPSULATEWHENCONDITIONS, BackendDump.dumpBackendDAE, outDAE, "DAE after PreOptModule >>encapsulateWhenConditions<<");
end encapsulateWhenConditions;

protected function encapsulateWhenConditionsFromWhenClause
input list<BackendDAE.WhenClause> inWhenClause;
input list<BackendDAE.WhenClause> inWhenClause_done;
input list<BackendDAE.Var> inVars;
input list<BackendDAE.Equation> inEqns;
input list<BackendDAE.Equation> inAdditionalInitialEquations;
input HashTableExpToIndex.HashTable inHT;
input Integer inIndex;
output list<BackendDAE.WhenClause> outWhenClause;
output list<BackendDAE.Var> outVars;
output list<BackendDAE.Equation> outEqns;
output list<BackendDAE.Equation> outAdditionalInitialEquations;
output HashTableExpToIndex.HashTable outHT;
output Integer outIndex;
algorithm
(outWhenClause, outVars, outEqns, outAdditionalInitialEquations, outHT, outIndex) := match(inWhenClause, inWhenClause_done, inVars, inEqns, inAdditionalInitialEquations, inHT, inIndex)
local
list<BackendDAE.Equation> additionalInitialEquations;
HashTableExpToIndex.HashTable ht;
Integer index;
DAE.Exp condition;
list<BackendDAE.WhenOperator> reinitStmtLst;
Option<Integer> elseClause;

list<BackendDAE.Var> vars;
list<BackendDAE.Equation> eqns;
list<BackendDAE.WhenClause> rest, whenClause_done;

case ({}, _, _, _, _, _, _) then (inWhenClause_done, inVars, inEqns, inAdditionalInitialEquations, inHT, inIndex);

case (BackendDAE.WHEN_CLAUSE(condition, reinitStmtLst, elseClause)::rest, _, _, _, _, ht, index) equation
(condition, vars, eqns, additionalInitialEquations, index, ht) = encapsulateWhenConditionsForEquations1(condition, DAE.emptyElementSource, index, ht);
vars = listAppend(vars, inVars);
eqns = listAppend(eqns, inEqns);
additionalInitialEquations = listAppend(additionalInitialEquations, inAdditionalInitialEquations);
whenClause_done = listAppend({BackendDAE.WHEN_CLAUSE(condition, reinitStmtLst, elseClause)}, inWhenClause_done);

(whenClause_done, vars, eqns, additionalInitialEquations, ht, index) = encapsulateWhenConditionsFromWhenClause(rest, whenClause_done, vars, eqns, additionalInitialEquations, ht, index);
then (whenClause_done, vars, eqns, additionalInitialEquations, ht, index);
end match;
end encapsulateWhenConditionsFromWhenClause;

protected function encapsulateWhenConditions1 "function encapsulateWhenConditions1
author: lochel
This is a helper function for encapsulateWhenConditions."
Expand Down
3 changes: 1 addition & 2 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -2417,8 +2417,7 @@ algorithm
end match;
end listVar;

public function listVar1
"function: listVar
public function listVar1 "function listVar1
author: Frenkel TUD 2012-05
ToDo: replace all listVar calls with this function, tailrecursive implementation
Takes BackendDAE.Var list and creates a BackendDAE.Variables structure, see also var_list."
Expand Down
26 changes: 13 additions & 13 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -758,19 +758,19 @@ algorithm
eavars = BackendVariable.emptyVars();
emptyeqns = BackendEquation.emptyEqns();
shared = BackendDAE.SHARED(fixvars,
evars,
eavars,
emptyeqns,
reeqns,
constraints,
classAttrs,
cache,
env,
functionTree,
BackendDAE.EVENT_INFO({}, {}, {}, {}, 0, 0),
{},
BackendDAE.INITIALSYSTEM(),
{});
evars,
eavars,
emptyeqns,
reeqns,
constraints,
classAttrs,
cache,
env,
functionTree,
BackendDAE.EVENT_INFO({}, {}, {}, {}, 0, 0),
{},
BackendDAE.INITIALSYSTEM(),
{});

// split it in independend subsystems
(systs, shared) = BackendDAEOptimize.partitionIndependentBlocksHelper(initsyst, shared, Error.getNumErrorMessages(), true);
Expand Down

0 comments on commit 65df476

Please sign in to comment.