Skip to content

Commit

Permalink
- Simulation runtime change:
Browse files Browse the repository at this point in the history
  - The cref defines also define $P$old<%cref%> (and old2)
  - This is a replacement for the old() old2() functions and is a lot faster


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5956 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Aug 26, 2010
1 parent 17363ad commit 7525cd6
Show file tree
Hide file tree
Showing 15 changed files with 355 additions and 335 deletions.
45 changes: 45 additions & 0 deletions Compiler/DAEUtil.mo
Expand Up @@ -44,6 +44,7 @@ public import DAE;
public import Env;
public import SCode;
public import Values;
public import HashTable;

public constant DAE.AvlTree emptyFuncTree = DAE.AVLTREENODE(NONE(),0,NONE(),NONE());
public constant DAE.DAElist emptyDae = DAE.DAE({},emptyFuncTree);
Expand Down Expand Up @@ -5153,13 +5154,57 @@ algorithm
end matchcontinue;
end getDAEDeclsFromValueblocks;

public function transformDerInline
"Simple euler inline of the equation system; only does explicit euler, and only der(cref)"
input DAE.DAElist dae;
output DAE.DAElist d;
algorithm
d := matchcontinue dae
local
HashTable.HashTable ht;
case dae
equation
false = RTOpts.debugFlag("frontend-inline-euler");
then dae;
case dae
equation
ht = HashTable.emptyHashTable();
(d,ht) = traverseDAE(dae,simpleInlineDerEuler,ht);
then d;
end matchcontinue;
end transformDerInline;

public function simpleInlineDerEuler
"Simple euler inline of the equation system; only does explicit euler, and only der(cref)"
input DAE.Exp exp;
input HashTable.HashTable crs0;
output DAE.Exp exp1;
output HashTable.HashTable crs1;
algorithm
(exp1,crs1) := matchcontinue (exp,crs0)
local
DAE.ComponentRef cr;
case (DAE.CALL(path=Absyn.IDENT("der"),expLst={exp as DAE.CREF(componentRef = cr, ty = DAE.ET_REAL())}),crs0)
equation
exp = DAE.BINARY(
DAE.BINARY(exp,DAE.SUB(DAE.ET_REAL()),DAE.CREF(DAE.CREF_QUAL("$old",DAE.ET_REAL(),{},cr),DAE.ET_REAL())),
DAE.DIV(DAE.ET_REAL()),
DAE.CREF(DAE.CREF_IDENT("$current_step_size",DAE.ET_REAL(),{}),DAE.ET_REAL()));
crs1 = HashTable.add((cr,0),crs0);
then (exp,crs1);
case (exp,crs0) then (exp,crs0);
end matchcontinue;
end simpleInlineDerEuler;

public function transformationsBeforeBackend
input DAE.DAElist dae;
output DAE.DAElist d;
algorithm
d := dae;
// Transform if equations to if expression before going into code generation.
d := transformIfEqToExpr(d,false);
// Don't even run the function to try and do this; it doesn't work very well
// d := transformDerInline(d);
end transformationsBeforeBackend;

end DAEUtil;
2 changes: 1 addition & 1 deletion Compiler/Debug.mo
Expand Up @@ -302,7 +302,7 @@ algorithm
res = func(arg);
then
res;
case (_,_,_,def) then def;
case (false,_,_,def) then def;
end matchcontinue;
end bcallret1;

Expand Down
4 changes: 3 additions & 1 deletion Compiler/Main.mo
Expand Up @@ -576,6 +576,8 @@ algorithm

d = fixModelicaOutput(d_1);

d = Debug.bcallret1(RTOpts.debugFlag("transformsbeforedump"),DAEUtil.transformationsBeforeBackend,d,d);

Print.clearBuf();
Debug.fprint("info", "---dumping\n");
Debug.fcall("execstat",print, "*** Main -> dumping dae: " +& realString(clock()) +& "\n" );
Expand All @@ -592,7 +594,7 @@ algorithm
Debug.fcall("daedumpgraphv", DAEDump.dumpGraphviz, d);

// Do any transformations required before going into code generation, e.g. if-equations to expressions.
d = DAEUtil.transformationsBeforeBackend(d);
d = Debug.bcallret1(boolNot(RTOpts.debugFlag("transformsbeforedump")),DAEUtil.transformationsBeforeBackend,d,d);

str = Print.getString();
silent = RTOpts.silent();
Expand Down
140 changes: 85 additions & 55 deletions Compiler/SimCodeC.mo

Large diffs are not rendered by default.

0 comments on commit 7525cd6

Please sign in to comment.