Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  - FMI: added dependecies feature for derivatives and outputs

  - expand sparse pattern structure by transposed sparse pattern


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22294 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Sep 13, 2014
1 parent be7ef97 commit 806b162
Show file tree
Hide file tree
Showing 17 changed files with 267 additions and 116 deletions.
1 change: 1 addition & 0 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -648,6 +648,7 @@ type SymbolicJacobian = tuple<BackendDAE, // symbolic equation sys

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

Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -127,7 +127,7 @@ algorithm
reqnarr := BackendEquation.listEquation(reqns);
ieqnarr := BackendEquation.listEquation(ieqns);
einfo := BackendDAE.EVENT_INFO(timeEvents, whenclauses_1, {}, {}, {}, 0, 0);
symjacs := {(NONE(), ({}, ({}, {})), {}), (NONE(), ({}, ({}, {})), {}), (NONE(), ({}, ({}, {})), {}), (NONE(), ({}, ({}, {})), {})};
symjacs := {(NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {}), (NONE(), ({}, {}, ({}, {})), {})};
outBackendDAE := BackendDAE.DAE(BackendDAE.EQSYSTEM(vars_1,
eqnarr,
NONE(),
Expand Down
14 changes: 8 additions & 6 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -1946,7 +1946,7 @@ end checkLinearSystem;
// Generate sparse pattern
//
// =============================================================================
public function detectSparsePatternODE
public function detectSparsePatternODE
input BackendDAE.BackendDAE inBackendDAE;
output BackendDAE.BackendDAE outBackendDAE;
protected
Expand Down Expand Up @@ -2023,10 +2023,10 @@ algorithm

BackendDAE.SparseColoring coloring;
list<list<DAE.ComponentRef>> translated;
list<tuple<DAE.ComponentRef,list<DAE.ComponentRef>>> sparsetuple;
list<tuple<DAE.ComponentRef,list<DAE.ComponentRef>>> sparsetuple, sparsetupleT;

case (_,{},_) then (({},({},{})),{});
case (_,_,{}) then (({},({},{})),{});
case (_,{},_) then (({},{},({},{})),{});
case (_,_,{}) then (({},{},({},{})),{});
case(BackendDAE.DAE(eqs = (syst as BackendDAE.EQSYSTEM(matching=bdaeMatching as BackendDAE.MATCHING(comps=comps, ass1=ass1)))::{}),indiffVars,indiffedVars)
equation
Debug.fcall(Flags.DUMP_SPARSE_VERBOSE,print," start getting sparsity pattern diff Vars : " +& intString(listLength(indiffedVars)) +& " diffed vars: " +& intString(listLength(indiffVars)) +&"\n");
Expand Down Expand Up @@ -2096,8 +2096,10 @@ algorithm
//Debug.execStat("generateSparsePattern -> nonZeroElements: " +& intString(nonZeroElements) +& " " ,GlobalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);

// translated to DAE.ComRefs
translated = List.mapList1_1(sparsepattern, List.getIndexFirst, diffCompRefs);
sparsetuple = List.threadTuple(diffedCompRefs, translated);
translated = List.mapList1_1(sparsepatternT, List.getIndexFirst, diffedCompRefs);
sparsetuple = List.threadTuple(diffCompRefs, translated);
sparsetupleT = List.threadTuple(diffCompRefs, translated);

// build up a bi-partied graph of pattern
Debug.fcall(Flags.DUMP_SPARSE_VERBOSE,print,"analytical Jacobians[SPARSE] -> build sparse graph.\n");
Expand Down Expand Up @@ -2135,7 +2137,7 @@ algorithm
//without coloring
//coloring = List.transposeList({diffCompRefs});
Debug.fcall(Flags.DUMP_SPARSE_VERBOSE, print, "analytical Jacobians[SPARSE] -> ready! " +& realString(clock()) +& "\n");
then ((sparsetuple, (diffCompRefs, diffedCompRefs)), coloring);
then ((sparsetupleT, sparsetuple, (diffCompRefs, diffedCompRefs)), coloring);
else
equation
Error.addMessage(Error.INTERNAL_ERROR, {"BackendDAEOptimize.generateSparsePattern failed"});
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -614,7 +614,7 @@ algorithm

case (_,_,_,BackendDAE.SHARED(knvars,exobj,av,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,einfo,eoc,btp,symjacs,ei))
equation
symjacs = {(SOME(inSymJac),inSparsePattern,inSparseColoring),(NONE(),({},({},{})),{}),(NONE(),({},({},{})),{}),(NONE(),({},({},{})),{})};
symjacs = {(SOME(inSymJac),inSparsePattern,inSparseColoring), (NONE(),({},{},({},{})),{}),(NONE(),({},{},({},{})),{}),(NONE(),({},{},({},{})),{})};
then
BackendDAE.SHARED(knvars,exobj,av,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,einfo,eoc,btp,symjacs,ei);

Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDump.mo
Expand Up @@ -665,7 +665,7 @@ protected
list<tuple< .DAE.ComponentRef, list< .DAE.ComponentRef>>> pattern;
list< .DAE.ComponentRef> diffVars, diffedVars;
algorithm
(pattern, (diffVars, diffedVars)) := inPattern;
(pattern, _, (diffVars, diffedVars)) := inPattern;

print("\n" +& heading +& "\n" +& UNDERLINE +& "\n");
print("independents [or inputs] (" +& intString(listLength(diffVars)) +& ")\n");
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/HpcOmScheduler.mo
Expand Up @@ -3018,7 +3018,7 @@ algorithm
list<SimCode.JacobianColumn> jacCols;
list<SimCode.SimVar> vars;
String name;
tuple<list<tuple<DAE.ComponentRef,list<DAE.ComponentRef>>>,tuple<list<SimCode.SimVar>,list<SimCode.SimVar>>> sparsePatt;
tuple<list<tuple<DAE.ComponentRef,list<DAE.ComponentRef>>>,list<tuple<DAE.ComponentRef,list<DAE.ComponentRef>>>,tuple<list<SimCode.SimVar>,list<SimCode.SimVar>>> sparsePatt;
list<list<DAE.ComponentRef>> colCols;
array<Integer> ass;
Integer newIdx;
Expand Down Expand Up @@ -3066,7 +3066,7 @@ algorithm
list<SimCode.JacobianColumn> jacCols;
list<SimCode.SimVar> vars;
String name;
tuple<list<tuple<DAE.ComponentRef,list<DAE.ComponentRef>>>,tuple<list<SimCode.SimVar>,list<SimCode.SimVar>>> sparsePatt;
tuple<list<tuple<DAE.ComponentRef,list<DAE.ComponentRef>>>,list<tuple<DAE.ComponentRef,list<DAE.ComponentRef>>>,tuple<list<SimCode.SimVar>,list<SimCode.SimVar>>> sparsePatt;
list<list<DAE.ComponentRef>> colCols;
array<Integer> ass;
Integer newIdx;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/SimCode.mo
Expand Up @@ -65,7 +65,7 @@ type JacobianColumn = tuple<list<SimEqSystem>, list<SimVar>, String>; // col
type JacobianMatrix = tuple<list<JacobianColumn>, // column
list<SimVar>, // seed vars
String, // matrix name
tuple<list<tuple<DAE.ComponentRef,list<DAE.ComponentRef>>>,tuple<list<SimVar>,list<SimVar>>>, // sparse pattern
tuple<list< tuple<DAE.ComponentRef,list<DAE.ComponentRef>>>,list< tuple<DAE.ComponentRef,list<DAE.ComponentRef>>>,tuple<list<SimVar>,list<SimVar>>>, // sparse pattern
list<list<DAE.ComponentRef>>, // colored cols
Integer, // max color used
Integer>; // jacobian index
Expand Down
14 changes: 13 additions & 1 deletion Compiler/BackEnd/SimCodeMain.mo
Expand Up @@ -75,6 +75,7 @@ protected import DAEUtil;
protected import Debug;
protected import Error;
protected import Flags;
protected import FMI;
protected import HpcOmEqSystems;
protected import HpcOmSimCodeMain;
protected import SimCodeDump;
Expand Down Expand Up @@ -224,15 +225,23 @@ algorithm
DAE.FunctionTree funcs;
Real timeSimCode, timeTemplates, timeBackend, timeFrontend;
String description;
Boolean symbolicJacActivated;
Boolean fmi20;
case (cache,env,_,st as GlobalScript.SYMBOLTABLE(ast=p),FMUVersion,filenameprefix,_, _)
equation
/* calculate stuff that we need to create SimCode data structure */
System.realtimeTick(GlobalScript.RT_CLOCK_FRONTEND);
//(cache,Values.STRING(filenameprefix),SOME(_)) = Ceval.ceval(cache,env, fileprefix, true, SOME(st),NONE(), msg);
(cache,env,dae,st) = CevalScript.runFrontEnd(cache,env,className,st,false);
timeFrontend = System.realtimeTock(GlobalScript.RT_CLOCK_FRONTEND);

System.realtimeTick(GlobalScript.RT_CLOCK_BACKEND);

// activate symolic jacobains for fmi 2.0
// to provide dependence information and partial derivatives
fmi20 = FMI.isFMIVersion20(FMUVersion);
symbolicJacActivated = Flags.getConfigBool(Flags.GENERATE_SYMBOLIC_LINEARIZATION);
Flags.setConfigBool(Flags.GENERATE_SYMBOLIC_LINEARIZATION, fmi20);

_ = Env.getFunctionTree(cache);
dae = DAEUtil.transformationsBeforeBackend(cache,env,dae);
description = DAEUtil.daeDescription(dae);
Expand All @@ -244,6 +253,9 @@ algorithm
(indexed_dlow_1,libs,file_dir,timeSimCode,timeTemplates) =
generateModelCodeFMU(dlow_1, p, dae, className, FMUVersion, filenameprefix, inSimSettingsOpt);

//reset config flag
Flags.setConfigBool(Flags.GENERATE_SYMBOLIC_LINEARIZATION, symbolicJacActivated);

resultValues =
{("timeTemplates",Values.REAL(timeTemplates)),
("timeSimCode", Values.REAL(timeSimCode)),
Expand Down

0 comments on commit 806b162

Please sign in to comment.