Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RuedKamp committed Nov 17, 2015
2 parents 62a6e06 + 446a090 commit 2e30872
Show file tree
Hide file tree
Showing 50 changed files with 1,264 additions and 948 deletions.
3 changes: 2 additions & 1 deletion Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -715,7 +715,8 @@ public
type SparsePattern = tuple<list<tuple< .DAE.ComponentRef, list< .DAE.ComponentRef>>>, // column-wise sparse pattern
list<tuple< .DAE.ComponentRef, list< .DAE.ComponentRef>>>, // row-wise sparse pattern
tuple<list< .DAE.ComponentRef>, // diff vars
list< .DAE.ComponentRef>>>; // diffed vars
list< .DAE.ComponentRef>>, // diffed vars
Integer>; // nonZeroElements

public
type SparseColoring = list<list< .DAE.ComponentRef>>; // colouring
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -134,7 +134,7 @@ algorithm
reqnarr := BackendEquation.listEquation(reqns);
ieqnarr := BackendEquation.listEquation(ieqns);
einfo := BackendDAE.EVENT_INFO(timeEvents, {}, {}, {}, 0);
symjacs := {(NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {})};
symjacs := {(NONE(), ({}, {}, ({}, {}), -1), {}), (NONE(), ({}, {}, ({}, {}), -1), {}), (NONE(), ({}, {}, ({}, {}), -1), {}), (NONE(), ({}, {}, ({}, {}), -1), {})};
outBackendDAE := BackendDAE.DAE(BackendDAEUtil.createEqSystem(vars_1, eqnarr, {}, BackendDAE.UNKNOWN_PARTITION(), reqnarr)::{},
BackendDAE.SHARED(knvars,
extVars,
Expand Down
260 changes: 191 additions & 69 deletions Compiler/BackEnd/BackendDAEUtil.mo

Large diffs are not rendered by default.

48 changes: 36 additions & 12 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -717,10 +717,12 @@ public function dumpSparsityPattern "author lochel"
protected
list<tuple< .DAE.ComponentRef, list< .DAE.ComponentRef>>> pattern;
list< .DAE.ComponentRef> diffVars, diffedVars;
Integer nnz;
algorithm
(pattern, _, (diffVars, diffedVars)) := inPattern;
(pattern, _, (diffVars, diffedVars), nnz) := inPattern;

print("\n" + heading + "\n" + UNDERLINE + "\n");
print("Number of non zero elements: " + intString(nnz) + ")\n");
print("independents [or inputs] (" + intString(listLength(diffVars)) + ")\n");
ComponentReference.printComponentRefList(diffVars);

Expand Down Expand Up @@ -3208,14 +3210,15 @@ end tupleString;

protected type DumpCompShortSystemsTpl = tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>;
protected type DumpCompShortMixedTpl = tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>;
protected type DumpCompShortTornTpl = tuple<list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>;
protected type DumpCompShortTornTpl = tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>;

public function dumpCompShort
input BackendDAE.BackendDAE inDAE;
protected
Integer sys,inp,st,dvar,dst,seq,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys,strcomps;
list<Integer> e_jc,e_jn,e_nj;
list<tuple<Integer,Integer>> te_l,te_nl;
list<tuple<Integer,Integer,Integer>> te_l;
list<tuple<Integer,Integer>> te_nl;
list<Integer> m_se,m_salg,m_sarr,m_sec;
list<tuple<Integer,Integer>> me_jc,e_jt,me_jt,me_jn,me_nj,me_lt,me_nt;
list<DAE.ComponentRef> states,discvars,discstates;
Expand Down Expand Up @@ -3312,11 +3315,12 @@ end dumpCompSystems;
protected function dumpCompTorn
input DumpCompShortTornTpl systemsTpl;
protected
list<tuple<Integer,Integer>> te_l,te_nl;
list<tuple<Integer,Integer,Integer>> te_l;
list<tuple<Integer,Integer>> te_nl;
String s_l,s_nl;
algorithm
(te_l,te_nl) := systemsTpl;
s_l := equationSizesStr(te_l,intTplString);
s_l := equationSizesStr(te_l,sizeNumNonZeroTornTplString);
s_nl := equationSizesStr(te_nl,intTplString);
Error.addMessage(Error.BACKENDDAEINFO_TORN, {s_l,s_nl});
end dumpCompTorn;
Expand Down Expand Up @@ -3371,6 +3375,19 @@ algorithm
str := "(" + intString(sz) + "," + str + "%)";
end sizeNumNonZeroTplString;

protected function sizeNumNonZeroTornTplString
input tuple<Integer,Integer,Integer> inTpl;
output String str;
protected
Integer sz,nnz,others;
Real density;
algorithm
(sz,others,nnz) := inTpl;
density := realDiv(realMul(100.0,intReal(nnz)),realMul(intReal(sz),intReal(sz)));
str := System.snprintff("%.1f",20,density);
str := "(" + intString(sz) + "," + str + "%)" + " " + intString(others);
end sizeNumNonZeroTornTplString;

protected function intTplString
input tuple<Integer,Integer> inTpl;
output String outStr;
Expand All @@ -3384,7 +3401,7 @@ end intTplString;
protected function dumpCompShort1
input BackendDAE.EqSystem inSyst;
input BackendDAE.Shared inShared;
input tuple<Integer,Integer,Integer,list<DAE.ComponentRef>,Integer,list<DAE.ComponentRef>,Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>> inTpl;
input tuple<Integer,Integer,Integer,list<DAE.ComponentRef>,Integer,list<DAE.ComponentRef>,Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>> inTpl;
output tuple<
Integer,
Integer,
Expand All @@ -3407,7 +3424,7 @@ protected
Integer sys,inp,st,dvar,seq,salg,sarr,sce,swe,sie,inp1,st1,dvar1,seq1,salg1,sarr1,sce1,swe1,sie1;
tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>> eqsys,eqsys1;
tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>> meqsys,meqsys1;
tuple<list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>> teqsys,teqsys1;
tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>> teqsys,teqsys1;
list<DAE.ComponentRef> states,states1,discvars,discvars1;
algorithm
BackendDAE.EQSYSTEM(orderedVars=vars) := inSyst;
Expand Down Expand Up @@ -3453,21 +3470,23 @@ end traversingisStateTopInputVarFinder;

protected function dumpCompShort2
input BackendDAE.StrongComponent inComp;
input tuple<Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>> inTpl;
output tuple<Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>> outTpl;
input tuple<Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>> inTpl;
output tuple<Integer,Integer,Integer,Integer,Integer,Integer,tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>>,tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>>,tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>>> outTpl;
algorithm
outTpl := match (inComp,inTpl)
local
Integer e,d,nnz;
list<Integer> ilst,ilst1;
Integer seq,salg,sarr,sce,swe,sie;
list<Integer> e_jc,e_jn,e_nj,m_se,m_salg,m_sarr,m_sec;
list<tuple<Integer,Integer>> e_jt,me_jc,me_jt,me_jn,me_nj,me_lt,me_nt,te_l,te_nl;
list<tuple<Integer,Integer,Integer>> te_l;
list<tuple<Integer,Integer>> e_jt,me_jc,me_jt,me_jn,me_nj,me_lt,me_nt,te_nl;
tuple<list<Integer>,list<tuple<Integer,Integer>>,list<Integer>,list<Integer>> eqsys;
list<tuple<Integer, Integer, BackendDAE.Equation>> jac;
tuple<list<Integer>,list<Integer>,list<Integer>,list<Integer>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>> meqsys;
tuple<list<tuple<Integer,Integer>>,list<tuple<Integer,Integer>>> teqsys;
tuple<list<tuple<Integer,Integer,Integer>>,list<tuple<Integer,Integer>>> teqsys;
list<tuple<Integer,list<Integer>>> eqnvartpllst;
list<tuple< .DAE.ComponentRef, list< .DAE.ComponentRef>>> patternLst;

case (BackendDAE.SINGLEEQUATION(),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys))
then ((seq+1,salg,sarr,sce,swe,sie,eqsys,meqsys,teqsys));
Expand Down Expand Up @@ -3509,11 +3528,16 @@ algorithm
e = listLength(ilst);
then ((seq,salg,sarr,sce,swe,sie,(e_jc,e_jt,e_jn,e::e_nj),meqsys,teqsys));

case (BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars=ilst,otherEqnVarTpl=eqnvartpllst,jac=BackendDAE.GENERIC_JACOBIAN(_,(_,_,_,nnz),_)),linear=true),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,(te_l,te_nl))) equation
d = listLength(ilst);
e = listLength(eqnvartpllst);
then ((seq,salg,sarr,sce,swe,sie,eqsys,meqsys,((d,e,nnz)::te_l,te_nl)));
/*
case (BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars=ilst,otherEqnVarTpl=eqnvartpllst),linear=true),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,(te_l,te_nl))) equation
d = listLength(ilst);
e = listLength(eqnvartpllst);
then ((seq,salg,sarr,sce,swe,sie,eqsys,meqsys,((d,e)::te_l,te_nl)));

*/
case (BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars=ilst,otherEqnVarTpl=eqnvartpllst),linear=false),(seq,salg,sarr,sce,swe,sie,eqsys,meqsys,(te_l,te_nl))) equation
d = listLength(ilst);
e = listLength(eqnvartpllst);
Expand Down
36 changes: 18 additions & 18 deletions Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -1044,8 +1044,8 @@ algorithm
list<list<DAE.ComponentRef>> translated;
list<tuple<DAE.ComponentRef,list<DAE.ComponentRef>>> sparsetuple, sparsetupleT;

case (_,{},_) then (({},{},({},{})),{});
case (_,_,{}) then (({},{},({},{})),{});
case (_,{},_) then (({},{},({},{}), -1),{});
case (_,_,{}) then (({},{},({},{}), -1),{});
case(BackendDAE.DAE(eqs = (syst as BackendDAE.EQSYSTEM(matching=bdaeMatching as BackendDAE.MATCHING(comps=comps, ass1=ass1)))::{}),indiffVars,indiffedVars)
equation
if Flags.isSet(Flags.DUMP_SPARSE_VERBOSE) then
Expand Down Expand Up @@ -1173,7 +1173,7 @@ algorithm
if Flags.isSet(Flags.DUMP_SPARSE_VERBOSE) then
print("analytical Jacobians[SPARSE] -> ready! " + realString(clock()) + "\n");
end if;
then ((sparsetupleT, sparsetuple, (diffCompRefs, diffedCompRefs)), coloring);
then ((sparsetupleT, sparsetuple, (diffCompRefs, diffedCompRefs), nonZeroElements), coloring);
else
equation
Error.addInternalError("function generateSparsePattern failed", sourceInfo());
Expand Down Expand Up @@ -1830,21 +1830,21 @@ algorithm
end if;

backendDAE2 = BackendDAEUtil.getSolvedSystemforJacobians(backendDAE,
SOME({"removeEqualFunctionCalls",
"removeSimpleEquations",
"evalFunc",
"simplifyAllExpressions"}),
{"removeEqualFunctionCalls",
"removeSimpleEquations",
"evalFunc",
"simplifyAllExpressions"},
NONE(),
NONE(),
SOME({"inlineArrayEqn",
"constantLinearSystem",
"removeSimpleEquations",
"tearingSystem",
"calculateStrongComponentJacobians",
"removeConstants",
"solveSimpleEquations",
"simplifyTimeIndepFuncCalls",
"simplifyAllExpressions"}));
{"inlineArrayEqn",
"constantLinearSystem",
"removeSimpleEquations",
"tearingSystem",
"calculateStrongComponentJacobians",
"removeConstants",
"solveSimpleEquations",
"simplifyTimeIndepFuncCalls",
"simplifyAllExpressions"});
_ = Flags.set(Flags.EXEC_STAT, b);
if Flags.isSet(Flags.JAC_DUMP) then
BackendDump.bltdump("Symbolic Jacobian",backendDAE2);
Expand Down Expand Up @@ -3139,8 +3139,8 @@ protected
BackendDAE.SymbolicJacobians symjacs;
BackendDAE.ExtraInfo ei;
algorithm
symjacs := { (SOME(inSymJac), inSparsePattern, inSparseColoring), (NONE(), ({}, {}, ({}, {})), {}),
(NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}) };
symjacs := { (SOME(inSymJac), inSparsePattern, inSparseColoring), (NONE(), ({}, {}, ({}, {}), -1), {}),
(NONE(), ({}, {}, ({}, {}), -1), {}), (NONE(), ({}, {}, ({}, {}), -1), {}) };
outShared := BackendDAEUtil.setSharedSymJacs(inShared, symjacs);
end addBackendDAESharedJacobian;

Expand Down
6 changes: 3 additions & 3 deletions Compiler/BackEnd/Uncertainties.mo
Expand Up @@ -130,7 +130,7 @@ algorithm
String outStringA,outStringB,outString,description;
list<Option<DAE.Distribution>> distributions;

Boolean forceOrdering = Flags.getConfigBool(Flags.FORCE_RECOMMENDED_ORDERING);
Boolean forceOrdering = Flags.getConfigBool(Flags.DEFAULT_OPT_MODULES_ORDERING);

case (cache,graph,_,(st as GlobalScript.SYMBOLTABLE(ast = p)),outputFile,_)
equation
Expand All @@ -142,9 +142,9 @@ 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());
Flags.setConfigBool(Flags.FORCE_RECOMMENDED_ORDERING, false);
Flags.setConfigBool(Flags.DEFAULT_OPT_MODULES_ORDERING, false);
(dlow_1) = BackendDAEUtil.getSolvedSystem(dlow, "", SOME({"removeSimpleEquations","removeUnusedVariables","removeEqualFunctionCalls","expandDerOperator"}), NONE(), NONE(), SOME({}));
Flags.setConfigBool(Flags.FORCE_RECOMMENDED_ORDERING, forceOrdering);
Flags.setConfigBool(Flags.DEFAULT_OPT_MODULES_ORDERING, forceOrdering);
//print("* Lowered Ok \n");

dlow_1 = removeSimpleEquationsUC(dlow_1);
Expand Down
67 changes: 64 additions & 3 deletions Compiler/FFrontEnd/FGraph.mo
Expand Up @@ -122,6 +122,22 @@ algorithm
outRef := listHead(currentScope(inGraph));
end lastScopeRef;

public function setLastScopeRef
input Ref inRef;
input Graph inGraph;
output Graph outGraph = inGraph;
algorithm
outGraph := match outGraph
case FCore.G()
algorithm
outGraph.scope := inRef :: listRest(outGraph.scope);
then
outGraph;

else outGraph;
end match;
end setLastScopeRef;

public function stripLastScopeRef
"remove the last ref from the current scope the graph"
input Graph inGraph;
Expand Down Expand Up @@ -800,9 +816,14 @@ public function getGraphName
protected
Absyn.Path p;
Scope s;
Ref r;
algorithm
_::s := listReverse(currentScope(inGraph));
outPath := Absyn.stringListPath(List.map(s, FNode.refName));
r::s := currentScope(inGraph);
p := Absyn.makeIdentPathFromString(FNode.refName(r));
for r in s loop
p := Absyn.QUALIFIED(FNode.refName(r), p);
end for;
Absyn.QUALIFIED(_, outPath) := p;
end getGraphName;

public function getGraphNameNoImplicitScopes
Expand Down Expand Up @@ -1728,7 +1749,7 @@ algorithm

case (_, _, _, _, _, _)
equation
crefPrefix = PrefixUtil.prefixAdd(inSourceName,{},{},inPrefix,SCode.CONST(),ClassInf.UNKNOWN(Absyn.IDENT(""))); // variability doesn't matter
crefPrefix = PrefixUtil.prefixAdd(inSourceName,{},{},inPrefix,SCode.CONST(),ClassInf.UNKNOWN(Absyn.IDENT("")), Absyn.dummyInfo); // variability doesn't matter

// name = inTargetClassName + "$" + ComponentReference.printComponentRefStr(PrefixUtil.prefixToCref(crefPrefix));
name = inTargetClassName + "$" + Absyn.pathString2NoLeadingDot(Absyn.stringListPath(listReverse(Absyn.pathToStringList(PrefixUtil.prefixToPath(crefPrefix)))), "$")
Expand Down Expand Up @@ -1960,5 +1981,45 @@ algorithm
end match;
end selectScope;

public function makeScopePartial
input Graph inEnv;
output Graph outEnv = inEnv;
protected
Node node;
Data data;
SCode.Element el;
algorithm
try
node := FNode.fromRef(lastScopeRef(inEnv));
node := match node
case FCore.N(data = data as FCore.CL(e = el))
algorithm
el := SCode.makeClassPartial(el);
data.e := el;
node.data := data;
then
node;

else node;
end match;
outEnv := setLastScopeRef(FNode.toRef(node), outEnv);
else
end try;
end makeScopePartial;

public function isPartialScope
input Graph inEnv;
output Boolean outIsPartial;
protected
SCode.Element el;
algorithm
try
FCore.N(data = FCore.CL(e = el)) := FNode.fromRef(lastScopeRef(inEnv));
outIsPartial := SCode.isPartial(el);
else
outIsPartial := false;
end try;
end isPartialScope;

annotation(__OpenModelica_Interface="frontend");
end FGraph;
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Ceval.mo
Expand Up @@ -1215,7 +1215,7 @@ protected
list<Absyn.Exp> args;
SCode.FunctionRestriction funcRest;
algorithm
(outCache,cdef,env_1) := Lookup.lookupClass(inCache,env, funcpath, false);
(outCache,cdef,env_1) := Lookup.lookupClass(inCache,env, funcpath);
SCode.CLASS(name=fid,restriction = SCode.R_FUNCTION(funcRest), classDef=SCode.PARTS(externalDecl=extdecl)) := cdef;
SCode.FR_EXTERNAL_FUNCTION(_) := funcRest;
SOME(SCode.EXTERNALDECL(oid,_,_,_,_)) := extdecl;
Expand Down

0 comments on commit 2e30872

Please sign in to comment.