Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RuedKamp committed Nov 6, 2015
2 parents e6a9a5d + b635a28 commit b612c7a
Show file tree
Hide file tree
Showing 79 changed files with 3,171 additions and 2,215 deletions.
12 changes: 3 additions & 9 deletions Compiler/BackEnd/BackendDAEFunc.mo
Expand Up @@ -44,17 +44,11 @@ public import BackendDAE;
/*************************************/

public
partial function preOptimizationDAEModule "
This is the interface for pre-optimization modules."
partial function optimizationModule
"This is the interface for pre/post-optimization modules."
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
end preOptimizationDAEModule;

partial function postOptimizationDAEModule "
This is the interface for post-optimization modules."
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
end postOptimizationDAEModule;
end optimizationModule;

partial function stateDeselectionFunc
input BackendDAE.BackendDAE inDAE;
Expand Down
343 changes: 143 additions & 200 deletions Compiler/BackEnd/BackendDAEUtil.mo

Large diffs are not rendered by default.

169 changes: 99 additions & 70 deletions Compiler/BackEnd/Initialization.mo

Large diffs are not rendered by default.

31 changes: 19 additions & 12 deletions Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -139,22 +139,29 @@ protected
BackendDAE.Var dummyVar;
BackendDAE.Variables v;
algorithm
BackendDAE.DAE(eqs = eqs) := inBackendDAE;
// lochel: This module fails for some models (e.g. #3543)
try
BackendDAE.DAE(eqs = eqs) := inBackendDAE;

// prepare a DAE
DAE := BackendDAEUtil.copyBackendDAE(inBackendDAE);
DAE := BackendDAEOptimize.collapseIndependentBlocks(DAE);
DAE := BackendDAEUtil.transformBackendDAE(DAE, SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.EXACT())), NONE(), NONE());
// prepare a DAE
DAE := BackendDAEUtil.copyBackendDAE(inBackendDAE);
DAE := BackendDAEOptimize.collapseIndependentBlocks(DAE);
DAE := BackendDAEUtil.transformBackendDAE(DAE, SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.EXACT())), NONE(), NONE());

// get states for DAE
BackendDAE.DAE(eqs = {BackendDAE.EQSYSTEM(orderedVars = v)}, shared=shared) := DAE;
states := BackendVariable.getAllStateVarFromVariables(v);
// get states for DAE
BackendDAE.DAE(eqs = {BackendDAE.EQSYSTEM(orderedVars = v)}, shared=shared) := DAE;
states := BackendVariable.getAllStateVarFromVariables(v);

// generate sparse pattern
(sparsePattern, coloredCols) := generateSparsePattern(DAE, states, states);
shared := addBackendDAESharedJacobianSparsePattern(sparsePattern, coloredCols, BackendDAE.SymbolicJacobianAIndex, shared);
// generate sparse pattern
(sparsePattern, coloredCols) := generateSparsePattern(DAE, states, states);
shared := addBackendDAESharedJacobianSparsePattern(sparsePattern, coloredCols, BackendDAE.SymbolicJacobianAIndex, shared);

outBackendDAE := BackendDAE.DAE(eqs, shared);
outBackendDAE := BackendDAE.DAE(eqs, shared);
else
// skip this optimization module
Error.addCompilerWarning("The optimization module detectJacobianSparsePattern failed. This module will be skipped and the transformation process continued.");
outBackendDAE := inBackendDAE;
end try;
end detectSparsePatternODE;

// =============================================================================
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/Uncertainties.mo
Expand Up @@ -140,7 +140,7 @@ algorithm
//print("- Flatten ok\n");
dlow = BackendDAECreate.lower(dae,cache,graph,BackendDAE.EXTRA_INFO(description,outputFile));
//(dlow_1,funcs1) = BackendDAEUtil.getSolvedSystem(dlow, funcs,SOME({"removeSimpleEquations","removeFinalParameters", "removeEqualFunctionCalls", "expandDerOperator"}), NONE(), NONE(),NONE());
(dlow_1) = BackendDAEUtil.getSolvedSystem(dlow,"", SOME({"removeSimpleEquations","removeUnusedVariables","removeEqualFunctionCalls", "expandDerOperator"}), NONE(), NONE(),SOME({""}));
(dlow_1) = BackendDAEUtil.getSolvedSystem(dlow,"", SOME({"removeSimpleEquations","removeUnusedVariables","removeEqualFunctionCalls","expandDerOperator"}), NONE(), NONE(), SOME({}));
//print("* Lowered Ok \n");

dlow_1 = removeSimpleEquationsUC(dlow_1);
Expand Down
89 changes: 86 additions & 3 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -1652,8 +1652,81 @@ algorithm
DAE.CREF_QUAL(componentRef = outCref) := inCref;
end crefRest;

public function crefTypeFull2
"Helper function to crefTypeFull."
input DAE.ComponentRef inCref;
output DAE.Type outType;
output list<DAE.Dimension> outDims;
algorithm
(outType, outDims) := match(inCref)
local
DAE.ComponentRef cr;
DAE.Type ty, basety;
list<DAE.Dimension> dims, restdims;
list<DAE.Subscript> subs;

case DAE.CREF_IDENT(identType = ty, subscriptLst = subs)
equation
(ty,dims) = Types.flattenArrayType(ty);
dims = List.stripN(dims,listLength(subs));
then (ty,dims);

case DAE.CREF_QUAL(identType = ty, subscriptLst = subs, componentRef = cr)
equation
(ty,dims) = Types.flattenArrayType(ty);
dims = List.stripN(dims,listLength(subs));

(basety, restdims) = crefTypeFull2(cr);
dims = listAppend(dims, restdims);
then (basety, dims);

else
equation
true = Flags.isSet(Flags.FAILTRACE);
Debug.trace("ComponentReference.crefTypeFull2 failed on cref: ");
Debug.traceln(printComponentRefStr(inCref));
then
fail();
end match;
end crefTypeFull2;

public function crefTypeFull
"mahge:
This function gives the type of a cref.
This is done by considering how many dimensions and subscripts
the cref has. It also takes in to consideration where the subscripts
are loacated in a qualifed cref. e.g. consider :
record R
Real [4]
end R;

R a[3][2];

if we have a cref a[1][1].b[1] --> Real
a[1].b --> Real[2][4]
a.b[1] --> Real[3][2]
a[1][1].b --> Real[4]
a[1].b[1] --> Real[2]

"
input DAE.ComponentRef inCref;
output DAE.Type outType;
protected
DAE.Type ty;
list<DAE.Dimension> dims;
algorithm
(ty,dims) := crefTypeFull2(inCref);
if listEmpty(dims) then
outType := ty;
else
outType := DAE.T_ARRAY(ty, dims, Types.getTypeSource(ty));
end if;
end crefTypeFull;

public function crefType
"Function for extracting the type of the first identifier of a cref."
" ***deprecated. Use crefTypeFull unless you really specifically want the type of the first cref.
Function for extracting the type of the first identifier of a cref.
"
input DAE.ComponentRef inCref;
output DAE.Type outType;
algorithm
Expand All @@ -1675,7 +1748,12 @@ algorithm
end match;
end crefType;

public function crefLastType "returns the 'last' type of a cref.
public function crefLastType
" ***deprecated.
mahge: Use crefTypeFull unless you really specifically want the type of the last cref.
Remember the type of a cref is not the same as the type of the last cref!!.

returns the 'last' type of a cref.
For instance, for the cref 'a.b' it returns the type in identifier 'b'
adrpo:
NOTE THAT THIS WILL BE AN ARRAY TYPE IF THE LAST CREF IS AN ARRAY TYPE
Expand Down Expand Up @@ -1787,7 +1865,12 @@ algorithm
end match;
end crefFirstCref;

public function crefTypeConsiderSubs "Function: crefTypeConsiderSubs
public function crefTypeConsiderSubs
" ***deprecated.
mahge: use crefTypeFull(). This is not what you want. We need to consider not just the last subs but all subs.
We can have slices.

Function: crefTypeConsiderSubs
Author: PA
Function for extracting the type out of a componentReference and consider the influence of the last subscript list.
For exampel. If the last cref type is Real[3,3] and the last subscript list is {Expression.INDEX(1)}, the type becomes Real[3], i.e
Expand Down
61 changes: 60 additions & 1 deletion Compiler/FrontEnd/Expression.mo
Expand Up @@ -3242,7 +3242,25 @@ algorithm
end match;
end makeCrefExp;

public function crefExp "

public function crefToExp
" mahge:
creates a DAE.Exp from a cref by exrtacting the type from the types of the cref (if qualified) and
considering the dimensions and subscripts that exist in the cref.
"
input DAE.ComponentRef cr;
output DAE.Exp cref;
algorithm
cref := DAE.CREF(cr,ComponentReference.crefTypeFull(cr));
end crefToExp;




public function crefExp
" ***deprecated.
mahge: use crefToExp(). This is not correct. We need to consider more than just the last subs.

Author: BZ, 2008-08
generate an DAE.CREF(ComponentRef, Type) from a ComponenRef, make array type correct from subs"
input DAE.ComponentRef cr;
Expand Down Expand Up @@ -11832,6 +11850,47 @@ algorithm
outExp := makePureBuiltinCall("vector",{exp},tp);
end makeVectorCall;


public function expandExpression
" mahge:
Expands a given expression to a list of expression. this means flattening any records in the
expression and vectorizing arrays.

Currently can only handle crefs and array expressions. Maybe we need to handle binary operations at least.

Right now this is used in generating simple residual equations from complex ones in SimCode.
"

input DAE.Exp inExp;
output list<DAE.Exp> outExps;
algorithm
(outExps) := match (inExp)
local
DAE.ComponentRef cr;
list<DAE.ComponentRef> crlst;
list<DAE.Exp> expl;
String msg;

case (DAE.CREF(cr,_))
algorithm
crlst := ComponentReference.expandCref(cr,true);
outExps := List.map(crlst, crefToExp);
then outExps;

case DAE.ARRAY(_,_,expl)
algorithm
expl := List.mapFlat(expl,expandExpression);
then expl;

else
algorithm
msg := "- Expression.expandExpression failed for " + ExpressionDump.printExpStr(inExp);
Error.addMessage(Error.INTERNAL_ERROR, {msg});
then
fail();
end match;
end expandExpression;

public function extendArrExp "author: Frenkel TUD 2010-07
alternative name: vectorizeExp"
input DAE.Exp inExp;
Expand Down

0 comments on commit b612c7a

Please sign in to comment.