Skip to content

Commit

Permalink
Replace BackendDAE record constructors with BackendDAEUtil helper fun…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
gossen authored and OpenModelica-Hudson committed Jun 22, 2015
1 parent 7ae1fb4 commit 47ff858
Show file tree
Hide file tree
Showing 26 changed files with 1,555 additions and 1,866 deletions.
6 changes: 1 addition & 5 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -135,11 +135,7 @@ algorithm
ieqnarr := BackendEquation.listEquation(ieqns);
einfo := BackendDAE.EVENT_INFO(timeEvents, whenclauses_1, {}, {}, {}, 0, arrayCreate(0, DAE.INFERRED_CLOCK()));
symjacs := {(NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {})};
outBackendDAE := BackendDAE.DAE(BackendDAE.EQSYSTEM(vars_1,
eqnarr,
NONE(),
NONE(),
BackendDAE.NO_MATCHING(), {}, BackendDAE.UNKNOWN_PARTITION())::{},
outBackendDAE := BackendDAE.DAE(BackendDAEUtil.createEqSystem(vars_1, eqnarr)::{},
BackendDAE.SHARED(knvars,
extVars,
aliasVars,
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -4820,7 +4820,7 @@ algorithm

case BackendDAE.EQSYSTEM(orderedVars, orderedEqs, _, _, _, stateSets, partitionKind) equation
(orderedEqs, _) = BackendEquation.traverseEquationArray_WithUpdate(orderedEqs, addTimeAsState2, inFoo);
then BackendDAE.EQSYSTEM(orderedVars, orderedEqs, NONE(), NONE(), BackendDAE.NO_MATCHING(), stateSets, partitionKind);
then BackendDAEUtil.createEqSystem(orderedVars, orderedEqs, stateSets, partitionKind);

else inSystem;
end matchcontinue;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -293,7 +293,7 @@ algorithm
vars_1 = BackendVariable.listVar1(var_lst_1);
eqns_1 = BackendEquation.listEquation(eqn_lst1);
(mixedSystem, _) = BackendEquation.iterationVarsinRelations(eqn_lst1, vars_1);
syst = BackendDAE.EQSYSTEM(vars_1, eqns_1, NONE(), NONE(), BackendDAE.NO_MATCHING(), {}, BackendDAE.UNKNOWN_PARTITION());
syst = BackendDAEUtil.createEqSystem(vars_1, eqns_1);
(m, mt) = BackendDAEUtil.incidenceMatrix(syst, BackendDAE.ABSOLUTE(), NONE());
// calculate jacobian. If constant, linear system of equations. Otherwise nonlinear
(jac, shared) = SymbolicJacobian.calculateJacobian(vars_1, eqns_1, m, true, ishared);
Expand Down
43 changes: 43 additions & 0 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -8070,6 +8070,21 @@ algorithm
inStateSets, inPartitionKind );
end createEqSystem;

public function createEmptyShared
input BackendDAE.BackendDAEType backendDAEType;
input BackendDAE.ExtraInfo ei;
input FCore.Cache cache;
input FCore.Graph graph;
output BackendDAE.Shared shared;
protected
BackendDAE.Variables emptyVars = BackendVariable.emptyVars();
BackendDAE.EquationArray emptyEqs = BackendEquation.emptyEqns();
DAE.FunctionTree functions = DAEUtil.avlTreeNew();
algorithm
shared := BackendDAE.SHARED( emptyVars, emptyVars, emptyVars, emptyEqs, emptyEqs, {}, {}, cache, graph,
DAEUtil.avlTreeNew(), BackendDAEUtil.emptyEventInfo(), {}, backendDAEType, {}, ei);
end createEmptyShared;

public function makeSingleEquationComp
input Integer eqIdx;
input Integer varIdx;
Expand Down Expand Up @@ -8266,6 +8281,32 @@ algorithm
symjacs=symjacs, info=info, aliasVars=aliasVars, initialEqs=initialEqs, removedEqs=removedEqs, eventInfo=eventInfo );
end setSharedInitialEqns;

public function setSharedSymJacs
input BackendDAE.Shared inShared;
input BackendDAE.SymbolicJacobians symjacs;
output BackendDAE.Shared outShared;
protected
BackendDAE.Variables knownVars, externalObjects, aliasVars;
list<DAE.Constraint> constraints;
list<DAE.ClassAttributes> classAttrs;
FCore.Cache cache;
FCore.Graph graph;
DAE.FunctionTree functionTree;
BackendDAE.ExternalObjectClasses extObjClasses;
BackendDAE.BackendDAEType backendDAEType;
BackendDAE.EquationArray initialEqs;
BackendDAE.ExtraInfo info;
BackendDAE.EquationArray removedEqs;
BackendDAE.EventInfo eventInfo;
algorithm
BackendDAE.SHARED( knownVars=knownVars, externalObjects=externalObjects, constraints=constraints, classAttrs=classAttrs, cache=cache,
graph=graph, extObjClasses=extObjClasses, backendDAEType=backendDAEType, initialEqs=initialEqs, info=info,
removedEqs=removedEqs, eventInfo=eventInfo, aliasVars=aliasVars, functionTree=functionTree ) := inShared;
outShared := BackendDAE.SHARED( knownVars=knownVars, externalObjects=externalObjects, constraints=constraints, classAttrs=classAttrs, cache=cache,
graph=graph, functionTree=functionTree, extObjClasses=extObjClasses, backendDAEType=backendDAEType,
symjacs=symjacs, info=info, aliasVars=aliasVars, initialEqs=initialEqs, removedEqs=removedEqs, eventInfo=eventInfo );
end setSharedSymJacs;

public function setSharedFunctionTree "replaces the aliasVars in the BackendDAE.Shared
author:Waurich TUD 2014-11"
input BackendDAE.Shared inShared;
Expand Down Expand Up @@ -8293,6 +8334,8 @@ algorithm
symjacs=symjacs, info=info, initialEqs=initialEqs, removedEqs=removedEqs, eventInfo=eventInfo );
end setSharedFunctionTree;



public function setSharedEventInfo
input BackendDAE.Shared inShared;
input BackendDAE.EventInfo eventInfo;
Expand Down
82 changes: 21 additions & 61 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -1266,33 +1266,23 @@ public function equationAddDAE "author: Frenkel TUD 2011-05"
input BackendDAE.EqSystem inEqSystem;
output BackendDAE.EqSystem outEqSystem;
protected
BackendDAE.Variables orderedVars;
BackendDAE.EquationArray orderedEqs, newOrderedEqs;
Option<BackendDAE.IncidenceMatrix> m;
Option<BackendDAE.IncidenceMatrixT> mT;
BackendDAE.StateSets stateSets;
BackendDAE.BaseClockPartitionKind partitionKind;
algorithm
BackendDAE.EQSYSTEM(orderedVars, orderedEqs, m, mT, _, stateSets, partitionKind) := inEqSystem;
newOrderedEqs := addEquation(inEquation, orderedEqs);
outEqSystem := BackendDAE.EQSYSTEM(orderedVars, newOrderedEqs, m, mT, BackendDAE.NO_MATCHING(), stateSets, partitionKind);
BackendDAE.EquationArray eqs;
algorithm
BackendDAE.EQSYSTEM(orderedEqs=eqs) := inEqSystem;
outEqSystem := BackendDAEUtil.setEqSystEqs(inEqSystem, addEquation(inEquation, eqs));
outEqSystem := BackendDAEUtil.setEqSystMatching(outEqSystem, BackendDAE.NO_MATCHING());
end equationAddDAE;

public function equationsAddDAE "author: Frenkel TUD 2011-05"
input list<BackendDAE.Equation> inEquations;
input BackendDAE.EqSystem inEqSystem;
output BackendDAE.EqSystem outEqSystem;
protected
BackendDAE.Variables orderedVars;
BackendDAE.EquationArray orderedEqs, newOrderedEqs;
Option<BackendDAE.IncidenceMatrix> m;
Option<BackendDAE.IncidenceMatrixT> mT;
BackendDAE.StateSets stateSets;
BackendDAE.BaseClockPartitionKind partitionKind;
algorithm
BackendDAE.EQSYSTEM(orderedVars, orderedEqs, m, mT, _, stateSets, partitionKind) := inEqSystem;
newOrderedEqs := List.fold(inEquations, addEquation, orderedEqs);
outEqSystem := BackendDAE.EQSYSTEM(orderedVars, newOrderedEqs, m, mT, BackendDAE.NO_MATCHING(), stateSets, partitionKind);
BackendDAE.EquationArray eqs;
algorithm
BackendDAE.EQSYSTEM(orderedEqs=eqs) := inEqSystem;
outEqSystem := BackendDAEUtil.setEqSystEqs(inEqSystem, List.fold(inEquations, addEquation, eqs));
outEqSystem := BackendDAEUtil.setEqSystMatching(outEqSystem, BackendDAE.NO_MATCHING());
end equationsAddDAE;

public function requationsAddDAE "author: Frenkel TUD 2012-10
Expand All @@ -1304,57 +1294,27 @@ public function requationsAddDAE "author: Frenkel TUD 2012-10
algorithm
outShared := match (inEquations, inShared)
local
BackendDAE.Variables knvars, exobj, aliasVars;
BackendDAE.EquationArray remeqns, inieqns;
list<DAE.Constraint> constrs;
list<DAE.ClassAttributes> clsAttrs;
FCore.Cache cache;
FCore.Graph env;
DAE.FunctionTree funcs;
BackendDAE.EventInfo einfo;
BackendDAE.ExternalObjectClasses eoc;
BackendDAE.SymbolicJacobians symjacs;
BackendDAE.BackendDAEType btp;
BackendDAE.ExtraInfo ei;

BackendDAE.EquationArray eqs;
case ({}, _)
then inShared;

case (_, BackendDAE.SHARED(knvars, exobj, aliasVars, inieqns, remeqns, constrs, clsAttrs, cache, env, funcs, einfo, eoc, btp, symjacs, ei)) equation
remeqns = List.fold(inEquations, addEquation, remeqns);
then BackendDAE.SHARED(knvars, exobj, aliasVars, inieqns, remeqns, constrs, clsAttrs, cache, env, funcs, einfo, eoc, btp, symjacs, ei);
then inShared;
case (_, BackendDAE.SHARED(removedEqs=eqs)) equation
then BackendDAEUtil.setSharedRemovedEqns(inShared, List.fold(inEquations, addEquation, eqs));
end match;
end requationsAddDAE;

public function removeRemovedEqs
"
remove removedEqs
"
public function removeRemovedEqs "remove removedEqs"
input BackendDAE.Shared inShared;
output BackendDAE.Shared outShared;
protected
BackendDAE.Variables knvars, exobj, aliasVars;
BackendDAE.EquationArray remeqns, inieqns;
list<DAE.Constraint> constrs;
list<DAE.ClassAttributes> clsAttrs;
FCore.Cache cache;
FCore.Graph env;
DAE.FunctionTree funcs;
BackendDAE.EventInfo einfo;
BackendDAE.ExternalObjectClasses eoc;
BackendDAE.SymbolicJacobians symjacs;
BackendDAE.BackendDAEType btp;
BackendDAE.ExtraInfo ei;
Integer n;
BackendDAE.EquationArray eqs;
Integer n;
algorithm
(BackendDAE.SHARED(knvars, exobj, aliasVars, inieqns, remeqns, constrs, clsAttrs, cache, env, funcs, einfo, eoc, btp, symjacs, ei)) := inShared;
BackendDAE.EQUATION_ARRAY(numberOfElement=n) := remeqns;
BackendDAE.SHARED(removedEqs=eqs) := inShared;
BackendDAE.EQUATION_ARRAY(numberOfElement=n) := eqs;
for ind in 1:n loop
remeqns := equationRemove(ind, remeqns);
eqs := equationRemove(ind, eqs);
end for;

outShared := BackendDAE.SHARED(knvars, exobj, aliasVars, inieqns, remeqns, constrs, clsAttrs, cache, env, funcs, einfo, eoc, btp, symjacs, ei);

outShared := BackendDAEUtil.setSharedRemovedEqns(inShared, eqs);
end removeRemovedEqs;

public function setAtIndex "author: lochel
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendInline.mo
Expand Up @@ -130,7 +130,7 @@ algorithm
BackendDAE.StateSets stateSets;
BackendDAE.BaseClockPartitionKind partitionKind;

case (syst as BackendDAE.EQSYSTEM(orderedVars=orderedVars,orderedEqs=orderedEqs,matching=matching,stateSets=stateSets,partitionKind=partitionKind),_)
case (syst as BackendDAE.EQSYSTEM(orderedVars=orderedVars, orderedEqs=orderedEqs,matching=matching,stateSets=stateSets,partitionKind=partitionKind),_)
equation
(orderedVars,b1) = inlineVariables(orderedVars,tpl);
(orderedEqs,b2) = inlineEquationArray(orderedEqs,tpl);
Expand Down

0 comments on commit 47ff858

Please sign in to comment.