Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
niklwors committed Jul 6, 2015
2 parents 7fcda78 + 98ca067 commit 1195db0
Show file tree
Hide file tree
Showing 48 changed files with 3,408 additions and 4,755 deletions.
8 changes: 7 additions & 1 deletion Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -126,9 +126,16 @@ uniontype Shared "Data shared for all equation-systems"
BackendDAEType backendDAEType "indicate for what the BackendDAE is used";
SymbolicJacobians symjacs "Symbolic Jacobians";
ExtraInfo info "contains extra info that we send around like the model name";
PartitionsInfo partitionsInfo;
end SHARED;
end Shared;

uniontype PartitionsInfo
record PARTITIONS_INFO
array<.DAE.ClockKind> clocks;
end PARTITIONS_INFO;
end PartitionsInfo;

uniontype ExtraInfo "extra information that we should send around with the DAE"
record EXTRA_INFO "extra information that we should send around with the DAE"
String description "the model description string";
Expand Down Expand Up @@ -536,7 +543,6 @@ uniontype EventInfo
list<ZeroCrossing> sampleLst "[deprecated] list of sample as before, only used by cpp runtime (TODO: REMOVE ME)";
list<ZeroCrossing> relationsLst "list of zero crossing function as before";
Integer numberMathEvents "stores the number of math function that trigger events e.g. floor, ceil, integer, ...";
array<.DAE.ClockKind> clocks;
end EVENT_INFO;
end EventInfo;

Expand Down
5 changes: 3 additions & 2 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -133,7 +133,7 @@ algorithm
eqnarr := BackendEquation.listEquation(eqns);
reqnarr := BackendEquation.listEquation(reqns);
ieqnarr := BackendEquation.listEquation(ieqns);
einfo := BackendDAE.EVENT_INFO(timeEvents, whenclauses_1, {}, {}, {}, 0, arrayCreate(0, DAE.INFERRED_CLOCK()));
einfo := BackendDAE.EVENT_INFO(timeEvents, whenclauses_1, {}, {}, {}, 0);
symjacs := {(NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {})};
outBackendDAE := BackendDAE.DAE(BackendDAEUtil.createEqSystem(vars_1, eqnarr)::{},
BackendDAE.SHARED(knvars,
Expand All @@ -149,7 +149,8 @@ algorithm
einfo,
extObjCls,
BackendDAE.SIMULATION(),
symjacs,inExtraInfo));
symjacs,inExtraInfo,
BackendDAE.PARTITIONS_INFO(BackendDAEUtil.emptyClocks())));
BackendDAEUtil.checkBackendDAEWithErrorMsg(outBackendDAE);
neqStr := intString(BackendDAEUtil.equationSize(eqnarr));
nvarStr := intString(BackendVariable.varsSize(vars_1));
Expand Down
141 changes: 54 additions & 87 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -217,29 +217,15 @@ protected function simplifyTimeIndepFuncCallsShared "pre(param) -> param
author: Frenkel TUD 2012-06"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
protected
BackendDAE.Shared shared;
algorithm
outDAE := match inDAE
local
BackendDAE.Variables knvars, aliasVars;
BackendDAE.EquationArray remeqns, inieqns;
BackendDAE.EventInfo eventInfo;
BackendDAE.EqSystems systs;
BackendDAE.Shared shared;

case BackendDAE.DAE(systs, shared as BackendDAE.SHARED (
knownVars=knvars, aliasVars=aliasVars, initialEqs=inieqns, removedEqs=remeqns, eventInfo=eventInfo ))
algorithm
BackendDAEUtil.traverseBackendDAEExpsVarsWithUpdate( knvars, Expression.traverseSubexpressionsHelper,
(traverserExpsimplifyTimeIndepFuncCalls, (knvars, aliasVars, false)) );
BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate( inieqns, Expression.traverseSubexpressionsHelper,
(traverserExpsimplifyTimeIndepFuncCalls, (knvars, aliasVars, false)) );
BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(remeqns, Expression.traverseSubexpressionsHelper,
(traverserExpsimplifyTimeIndepFuncCalls, (knvars, aliasVars, false)) );
(eventInfo, _) := traverseEventInfoExps( eventInfo, Expression.traverseSubexpressionsHelper,
(traverserExpsimplifyTimeIndepFuncCalls, (knvars, aliasVars, false)) );
shared.eventInfo := eventInfo;
then BackendDAE.DAE(systs, shared);
end match;
shared := inDAE.shared;
BackendDAEUtil.traverseBackendDAEExpsVarsWithUpdate(shared.knownVars, Expression.traverseSubexpressionsHelper, (traverserExpsimplifyTimeIndepFuncCalls, (shared.knownVars, shared.aliasVars, false)));
BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(shared.initialEqs, Expression.traverseSubexpressionsHelper, (traverserExpsimplifyTimeIndepFuncCalls, (shared.knownVars, shared.aliasVars, false)));
BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(shared.removedEqs, Expression.traverseSubexpressionsHelper, (traverserExpsimplifyTimeIndepFuncCalls, (shared.knownVars, shared.aliasVars, false)));
(shared.eventInfo, _) := traverseEventInfoExps(shared.eventInfo, Expression.traverseSubexpressionsHelper, (traverserExpsimplifyTimeIndepFuncCalls, (shared.knownVars, shared.aliasVars, false)));
outDAE := BackendDAE.DAE(inDAE.eqs, shared);
end simplifyTimeIndepFuncCallsShared;

protected function traverseEventInfoExps<T>
Expand All @@ -259,14 +245,13 @@ protected
list<BackendDAE.WhenClause> whenClauseLst;
list<BackendDAE.ZeroCrossing> zeroCrossingLst, sampleLst, relationsLst;
Integer numberMathEvents;
array<DAE.ClockKind> clocks;
algorithm
BackendDAE.EVENT_INFO(timeEvents, whenClauseLst, zeroCrossingLst, sampleLst, relationsLst, numberMathEvents, clocks) := iEventInfo;
BackendDAE.EVENT_INFO(timeEvents, whenClauseLst, zeroCrossingLst, sampleLst, relationsLst, numberMathEvents) := iEventInfo;
(whenClauseLst, outTypeA) := traverseWhenClauseExps(whenClauseLst, func, inTypeA, {});
(zeroCrossingLst, outTypeA) := traverseZeroCrossingExps(zeroCrossingLst, func, outTypeA, {});
(sampleLst, outTypeA) := traverseZeroCrossingExps(sampleLst, func, outTypeA, {});
(relationsLst, outTypeA) := traverseZeroCrossingExps(relationsLst, func, outTypeA, {});
oEventInfo := BackendDAE.EVENT_INFO(timeEvents, whenClauseLst, zeroCrossingLst, sampleLst, relationsLst, numberMathEvents, clocks);
oEventInfo := BackendDAE.EVENT_INFO(timeEvents, whenClauseLst, zeroCrossingLst, sampleLst, relationsLst, numberMathEvents);
end traverseEventInfoExps;

protected function traverseWhenClauseExps<T>
Expand Down Expand Up @@ -3939,16 +3924,15 @@ end updateStatesVars;
// =============================================================================

public function addedScaledVars
" added var_norm = var/nominal,
where var is state.
"
"added var_norm = var/nominal, where var is state."
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
outDAE := if Flags.isSet(Flags.ADD_SCALED_VARS) or Flags.isSet(Flags.ADD_SCALED_VARS_INPUT) then
addedScaledVarsWork(inDAE)
else
inDAE;
if Flags.isSet(Flags.ADD_SCALED_VARS) or Flags.isSet(Flags.ADD_SCALED_VARS_INPUT) then
outDAE := addedScaledVarsWork(inDAE);
else
outDAE := inDAE;
end if;
end addedScaledVars;

protected function addedScaledVarsWork
Expand All @@ -3957,24 +3941,18 @@ protected function addedScaledVarsWork
protected
list<BackendDAE.EqSystem> systlst;
list<BackendDAE.EqSystem> osystlst = {};

BackendDAE.Variables vars;
BackendDAE.EquationArray eqns;

BackendDAE.Variables vars;
BackendDAE.Variables knvars;
list<BackendDAE.Var> kvarlst, lst_states, lst_inputs, lst_normv, lst_new_var = {};
list<BackendDAE.Var> kvarlst, lst_states, lst_inputs;
BackendDAE.Var tmpv;
DAE.ComponentRef cref;
DAE.Exp norm, y_norm, y, lhs;
BackendDAE.Equation eqn;
BackendDAE.Shared oshared;
BackendDAE.EqSystem syst;

algorithm
BackendDAE.DAE(systlst, oshared) := inDAE;
BackendDAE.SHARED(knownVars=knvars) := oshared;
kvarlst := BackendVariable.varList(knvars);
kvarlst := BackendVariable.varList(oshared.knownVars);
lst_inputs := List.select(kvarlst, BackendVariable.isVarOnTopLevelAndInputNoDerInput);
// states
if Flags.isSet(Flags.ADD_SCALED_VARS) then
Expand Down Expand Up @@ -4051,15 +4029,15 @@ end addedScaledVarsWork;
// =============================================================================

public function sortEqnsVars
input BackendDAE.BackendDAE iDAE;
output BackendDAE.BackendDAE oDAE;
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
oDAE := if Flags.isSet(Flags.SORT_EQNS_AND_VARS) then sortEqnsVarsWork(iDAE) else iDAE;
outDAE := if Flags.isSet(Flags.SORT_EQNS_AND_VARS) then sortEqnsVarsWork(inDAE) else inDAE;
end sortEqnsVars;

protected function sortEqnsVarsWork
input BackendDAE.BackendDAE iDAE;
output BackendDAE.BackendDAE oDAE = iDAE;
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE = inDAE;
protected
list<BackendDAE.EqSystem> systlst, new_systlst = {};
BackendDAE.Shared shared;
Expand All @@ -4077,8 +4055,8 @@ protected
list<BackendDAE.Var> var_lst;
list<BackendDAE.Equation> eqn_lst;
algorithm
//BackendDump.bltdump("START:", oDAE);
BackendDAE.DAE(systlst, shared) := iDAE;
//BackendDump.bltdump("START:", outDAE);
BackendDAE.DAE(systlst, shared) := inDAE;
BackendDAE.SHARED(functionTree=functionTree) := shared;
for syst in systlst loop
syst := match syst
Expand Down Expand Up @@ -4121,8 +4099,8 @@ algorithm
new_systlst := syst :: new_systlst;
end for; //syst

oDAE:= BackendDAE.DAE(new_systlst, shared);
//BackendDump.bltdump("ENDE:", oDAE);
outDAE:= BackendDAE.DAE(new_systlst, shared);
//BackendDump.bltdump("ENDE:", outDAE);
end sortEqnsVarsWork;

protected function sortEqnsVarsWorkTpl
Expand Down Expand Up @@ -4180,15 +4158,15 @@ end compWeightsEqns;
// =============================================================================

public function simplifyLoops
input BackendDAE.BackendDAE iDAE;
output BackendDAE.BackendDAE oDAE;
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
oDAE := if Flags.getConfigInt(Flags.SIMPLIFY_LOOPS) > 0 then simplifyLoopsMain(iDAE) else iDAE;
outDAE := if Flags.getConfigInt(Flags.SIMPLIFY_LOOPS) > 0 then simplifyLoopsMain(inDAE) else inDAE;
end simplifyLoops;

protected function simplifyLoopsMain
input BackendDAE.BackendDAE iDAE;
output BackendDAE.BackendDAE oDAE = iDAE;
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE = inDAE;
protected
list<BackendDAE.EqSystem> systlst, new_systlst = {};
BackendDAE.Shared shared;
Expand All @@ -4208,9 +4186,9 @@ protected
Integer ne, nv;
Boolean simDAE;
algorithm
//BackendDump.bltdump("START:", oDAE);
BackendDAE.DAE(systlst, shared) := iDAE;
BackendDAE.SHARED(functionTree=functionTree) := shared;
//BackendDump.bltdump("START:", outDAE);
shared := inDAE.shared;
functionTree := shared.functionTree;

simDAE := match shared
case BackendDAE.SHARED(backendDAEType = BackendDAE.SIMULATION()) then true;
Expand All @@ -4223,7 +4201,7 @@ algorithm
print("\n***noSIM***\n");
end if;
end if;
for syst in systlst loop
for syst in inDAE.eqs loop
update := false;
ass1 := {};
ass2 := {};
Expand All @@ -4242,9 +4220,9 @@ algorithm
nSyst := if update then simplifyLoopsUpdateMatching(vars, eqns, syst, listReverse(ass1), listReverse(ass2), ne, nv, functionTree, listReverse(compOrders)) else syst;
new_systlst := nSyst :: new_systlst;
end for; //syst
oDAE:= BackendDAE.DAE(new_systlst, shared);
//oDAE:= BackendDAE.DAE(listReverse(new_systlst), shared);
//BackendDump.bltdump("ENDE:", oDAE);
outDAE:= BackendDAE.DAE(new_systlst, shared);
//outDAE:= BackendDAE.DAE(listReverse(new_systlst), shared);
//BackendDump.bltdump("ENDE:", outDAE);

if Flags.isSet(Flags.DUMP_SIMPLIFY_LOOPS) then
print("END: simplifyLoops\n");
Expand Down Expand Up @@ -4709,22 +4687,20 @@ protected function symEulerWork
input Boolean b " true => add, false => remove euler equation";
output BackendDAE.BackendDAE outDAE;
protected
list<BackendDAE.EqSystem> systlst, osystlst = {};
list<BackendDAE.EqSystem> osystlst = {};
BackendDAE.EqSystem syst_;
BackendDAE.Shared shared;
BackendDAE.Var tmpv;
DAE.ComponentRef cref;
algorithm
BackendDAE.DAE(systlst, shared) := inDAE;

// make dt
cref := ComponentReference.makeCrefIdent(BackendDAE.symEulerDT, DAE.T_REAL_DEFAULT, {});
tmpv := BackendVariable.makeVar(cref);
//tmpv := BackendVariable.setVarKind(tmpv, BackendDAE.PARAM());
tmpv := BackendVariable.setBindExp(tmpv, SOME(DAE.RCONST(0.0)));
shared := BackendVariable.addKnVarDAE(tmpv, shared);
shared := BackendVariable.addKnVarDAE(tmpv, inDAE.shared);

for syst in systlst loop
for syst in inDAE.eqs loop
(syst_, shared) := symEulerUpdateSyst(syst, b, shared);
osystlst := syst_ :: osystlst;
end for;
Expand Down Expand Up @@ -5029,27 +5005,19 @@ algorithm
end matchcontinue;
end traverserExpapplyRewriteRulesBackend;

protected function applyRewriteRulesBackendShared
"@author: adrpo"
protected function applyRewriteRulesBackendShared "@author: adrpo"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
protected
BackendDAE.Shared shared;
algorithm
outDAE := match inDAE
local
BackendDAE.Variables knvars;
BackendDAE.EquationArray remeqns, inieqns;
BackendDAE.EqSystems systs;
BackendDAE.Shared shared;
case BackendDAE.DAE(systs, shared as BackendDAE.SHARED( knownVars=knvars,
initialEqs=inieqns, removedEqs=remeqns ))
algorithm
BackendDAEUtil.traverseBackendDAEExpsVarsWithUpdate(knvars, traverserapplyRewriteRulesBackend, false);
BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(inieqns, traverserapplyRewriteRulesBackend, false);
BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(remeqns, traverserapplyRewriteRulesBackend, false);
// not sure if we should apply the rules on the event info!
// (ei,_) = traverseEventInfoExps(eventInfo,traverserapplyRewriteRulesBackend, false);
then BackendDAE.DAE(systs, shared);
end match;
shared := inDAE.shared;
BackendDAEUtil.traverseBackendDAEExpsVarsWithUpdate(shared.knownVars, traverserapplyRewriteRulesBackend, false);
BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(shared.initialEqs, traverserapplyRewriteRulesBackend, false);
BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(shared.removedEqs, traverserapplyRewriteRulesBackend, false);
// not sure if we should apply the rules on the event info!
// (ei, _) := traverseEventInfoExps(eventInfo, traverserapplyRewriteRulesBackend, false);
outDAE := BackendDAE.DAE(inDAE.eqs, shared);
end applyRewriteRulesBackendShared;

// =============================================================================
Expand All @@ -5060,12 +5028,11 @@ end applyRewriteRulesBackendShared;
public function listAllIterationVariables "author: lochel"
input BackendDAE.BackendDAE inBackendDAE;
protected
list<BackendDAE.EqSystem> eqs;
BackendDAE.BackendDAEType backendDAEType;
list<String> warnings;
algorithm
BackendDAE.DAE(eqs=eqs, shared=BackendDAE.SHARED(backendDAEType=backendDAEType)) := inBackendDAE;
warnings := listAllIterationVariables0(eqs);
BackendDAE.DAE(shared=BackendDAE.SHARED(backendDAEType=backendDAEType)) := inBackendDAE;
warnings := listAllIterationVariables0(inBackendDAE.eqs);

Error.addCompilerNotification("List of all iteration variables (DAE kind: " + BackendDump.printBackendDAEType2String(backendDAEType) + ")\n" + stringDelimitList(warnings, "\n"));
end listAllIterationVariables;
Expand Down

0 comments on commit 1195db0

Please sign in to comment.