Skip to content

Commit

Permalink
- Changed DAE.ComponentRef to SimVar in zeroCrossingsNeedSave
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4708 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Rickard Lindberg committed Dec 16, 2009
1 parent fa6edcf commit 8fcbe1f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 46 deletions.
32 changes: 18 additions & 14 deletions Compiler/SimCode.mo
Expand Up @@ -308,7 +308,7 @@ uniontype SimCode
list<SimEqSystem> parameterEquations;
list<SimEqSystem> removedEquations;
list<DAELow.ZeroCrossing> zeroCrossings;
list<list<DAE.ComponentRef>> zeroCrossingsNeedSave;
list<list<SimVar>> zeroCrossingsNeedSave;
list<HelpVarInfo> helpVarInfo;
list<SimWhenClause> whenClauses;
list<DAE.ComponentRef> discreteModelVars;
Expand Down Expand Up @@ -1200,7 +1200,7 @@ algorithm
list<SimEqSystem> parameterEquations;
list<SimEqSystem> removedEquations;
list<DAELow.ZeroCrossing> zeroCrossings;
list<list<DAE.ComponentRef>> zeroCrossingsNeedSave;
list<list<SimVar>> zeroCrossingsNeedSave;
list<SimWhenClause> whenClauses;
list<DAE.ComponentRef> discreteModelVars;
case (dae,dlow,ass1,ass2,m,mt,comps,class_,filename,funcfilename,fileDir,functions)
Expand Down Expand Up @@ -2152,26 +2152,26 @@ protected function createZeroCrossingsNeedSave
input Integer[:] ass1;
input Integer[:] ass2;
input list<list<Integer>> blocks;
output list<list<DAE.ComponentRef>> needSave;
output list<list<SimVar>> needSave;
algorithm
needSave :=
matchcontinue (zeroCrossings, dae, dlow, ass1, ass2, blocks)
local
DAELow.ZeroCrossing zc;
list<DAELow.ZeroCrossing> rest_zc;
list<Integer> eql;
list<DAE.ComponentRef> needSave;
list<list<DAE.ComponentRef>> needSave_rest;
list<SimVar> needSaveTmp;
list<list<SimVar>> needSave_rest;
case ({}, _, _, _, _, _)
then {};
case ((zc as DAELow.ZERO_CROSSING(occurEquLst=eql)) :: rest_zc, dae, dlow,
ass1, ass2, blocks)
equation
needSave = createZeroCrossingNeedSave(dae, dlow, ass1, ass2, eql,
blocks);
needSaveTmp = createZeroCrossingNeedSave(dae, dlow, ass1, ass2, eql,
blocks);
needSave_rest = createZeroCrossingsNeedSave(rest_zc, dae, dlow, ass1,
ass2, blocks);
then needSave :: needSave_rest;
then needSaveTmp :: needSave_rest;
end matchcontinue;
end createZeroCrossingsNeedSave;

Expand All @@ -2182,12 +2182,12 @@ protected function createZeroCrossingNeedSave
input Integer[:] ass2;
input list<Integer> eqns2;
input list<list<Integer>> blocks;
output list<DAE.ComponentRef> needSave;
output list<SimVar> needSave;
algorithm
needSave :=
matchcontinue (dae, dlow, ass1, ass2, eqns2, blocks)
local
list<DAE.ComponentRef> crs;
list<SimVar> crs;
Integer cg_id,eqn_1,v,eqn,cg_id,cg_id_1,numValues;
list<Integer> block_,rest;
DAE.ComponentRef cr;
Expand All @@ -2210,6 +2210,8 @@ algorithm
Integer[:] ass1,ass2;
list<list<Integer>> blocks;
DAELow.ExternalObjectClasses eoc;
DAELow.Var dlowvar;
SimVar simvar;
case (_,_,_,_,{},_)
then {};
/* zero crossing for mixed system */
Expand All @@ -2221,10 +2223,11 @@ algorithm
block_ = getZcMixedSystem(dlow, eqn, blocks, ass2);
eqn_1 = eqn - 1;
v = ass2[eqn_1 + 1];
(DAELow.VAR(cr,_,_,_,_,_,_,_,_,_,_,_,_,_)) = DAELow.getVarAt(vars, v);
(dlowvar as DAELow.VAR(cr,_,_,_,_,_,_,_,_,_,_,_,_,_)) = DAELow.getVarAt(vars, v);
crs = createZeroCrossingNeedSave(dae, dlow, ass1, ass2, rest, blocks);
simvar = dlowvarToSimvar(dlowvar);
then
(cr :: crs);
(simvar :: crs);
/* zero crossing for single equation */
case (dae, (dlow as DAELow.DAELOW(orderedVars = vars)), ass1, ass2,
(eqn :: rest), blocks)
Expand All @@ -2233,10 +2236,11 @@ algorithm
equation
eqn_1 = eqn - 1;
v = ass2[eqn_1 + 1];
(DAELow.VAR(cr,_,_,_,_,_,_,_,_,_,_,_,_,_)) = DAELow.getVarAt(vars, v);
(dlowvar as DAELow.VAR(cr,_,_,_,_,_,_,_,_,_,_,_,_,_)) = DAELow.getVarAt(vars, v);
crs = createZeroCrossingNeedSave(dae, dlow, ass1, ass2, rest, blocks);
simvar = dlowvarToSimvar(dlowvar);
then
(cr :: crs);
(simvar :: crs);
end matchcontinue;
end createZeroCrossingNeedSave;

Expand Down
28 changes: 14 additions & 14 deletions Compiler/SimCodeC.mo
Expand Up @@ -72,7 +72,7 @@ algorithm
list<SimCode.SimWhenClause> i_whenClauses;
list<SimCode.HelpVarInfo> i_helpVarInfo;
list<SimCode.SimEqSystem> i_allEquations;
list<list<DAE.ComponentRef>> i_zeroCrossingsNeedSave;
list<list<SimCode.SimVar>> i_zeroCrossingsNeedSave;
list<DAELow.ZeroCrossing> i_zeroCrossings;
list<SimCode.SimEqSystem> i_nonStateDiscEquations;
list<SimCode.SimEqSystem> i_removedEquations;
Expand Down Expand Up @@ -2127,7 +2127,7 @@ end functionZeroCrossing;

protected function lm_52
input Tpl.Text in_txt;
input list<DAE.ComponentRef> in_items;
input list<SimCode.SimVar> in_items;

output Tpl.Text out_txt;
algorithm
Expand All @@ -2141,14 +2141,14 @@ algorithm
then txt;

case ( txt,
i_cref :: rest )
SimCode.SIMVAR(name = i_name) :: rest )
local
list<DAE.ComponentRef> rest;
DAE.ComponentRef i_cref;
list<SimCode.SimVar> rest;
DAE.ComponentRef i_name;
equation
txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(2));
txt = Tpl.writeTok(txt, Tpl.ST_STRING("save("));
txt = cref(txt, i_cref);
txt = cref(txt, i_name);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(");"));
txt = Tpl.popBlock(txt);
txt = Tpl.nextIter(txt);
Expand All @@ -2158,7 +2158,7 @@ algorithm
case ( txt,
_ :: rest )
local
list<DAE.ComponentRef> rest;
list<SimCode.SimVar> rest;
equation
txt = lm_52(txt, rest);
then txt;
Expand All @@ -2167,7 +2167,7 @@ end lm_52;

protected function lm_53
input Tpl.Text in_txt;
input list<list<DAE.ComponentRef>> in_items;
input list<list<SimCode.SimVar>> in_items;

output Tpl.Text out_txt;
algorithm
Expand All @@ -2181,10 +2181,10 @@ algorithm
then txt;

case ( txt,
i_crefs :: rest )
i_vars :: rest )
local
list<list<DAE.ComponentRef>> rest;
list<DAE.ComponentRef> i_crefs;
list<list<SimCode.SimVar>> rest;
list<SimCode.SimVar> i_vars;
Integer i_i0;
equation
i_i0 = Tpl.getIteri_i0(txt);
Expand All @@ -2193,7 +2193,7 @@ algorithm
txt = Tpl.writeTok(txt, Tpl.ST_STRING(":"));
txt = Tpl.writeTok(txt, Tpl.ST_NEW_LINE());
txt = Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE, SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE()));
txt = lm_52(txt, i_crefs);
txt = lm_52(txt, i_vars);
txt = Tpl.popIter(txt);
txt = Tpl.writeTok(txt, Tpl.ST_NEW_LINE());
txt = Tpl.writeTok(txt, Tpl.ST_STRING(" break;"));
Expand All @@ -2204,7 +2204,7 @@ algorithm
case ( txt,
_ :: rest )
local
list<list<DAE.ComponentRef>> rest;
list<list<SimCode.SimVar>> rest;
equation
txt = lm_53(txt, rest);
then txt;
Expand All @@ -2213,7 +2213,7 @@ end lm_53;

public function functionHandleZeroCrossing
input Tpl.Text txt;
input list<list<DAE.ComponentRef>> i_zeroCrossingsNeedSave;
input list<list<SimCode.SimVar>> i_zeroCrossingsNeedSave;

output Tpl.Text out_txt;
algorithm
Expand Down
28 changes: 14 additions & 14 deletions Compiler/susan_codegen/SimCode/SimCodeC.mo
Expand Up @@ -72,7 +72,7 @@ algorithm
list<SimCode.SimWhenClause> i_whenClauses;
list<SimCode.HelpVarInfo> i_helpVarInfo;
list<SimCode.SimEqSystem> i_allEquations;
list<list<DAE.ComponentRef>> i_zeroCrossingsNeedSave;
list<list<SimCode.SimVar>> i_zeroCrossingsNeedSave;
list<DAELow.ZeroCrossing> i_zeroCrossings;
list<SimCode.SimEqSystem> i_nonStateDiscEquations;
list<SimCode.SimEqSystem> i_removedEquations;
Expand Down Expand Up @@ -2127,7 +2127,7 @@ end functionZeroCrossing;

protected function lm_52
input Tpl.Text in_txt;
input list<DAE.ComponentRef> in_items;
input list<SimCode.SimVar> in_items;

output Tpl.Text out_txt;
algorithm
Expand All @@ -2141,14 +2141,14 @@ algorithm
then txt;

case ( txt,
i_cref :: rest )
SimCode.SIMVAR(name = i_name) :: rest )
local
list<DAE.ComponentRef> rest;
DAE.ComponentRef i_cref;
list<SimCode.SimVar> rest;
DAE.ComponentRef i_name;
equation
txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(2));
txt = Tpl.writeTok(txt, Tpl.ST_STRING("save("));
txt = cref(txt, i_cref);
txt = cref(txt, i_name);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(");"));
txt = Tpl.popBlock(txt);
txt = Tpl.nextIter(txt);
Expand All @@ -2158,7 +2158,7 @@ algorithm
case ( txt,
_ :: rest )
local
list<DAE.ComponentRef> rest;
list<SimCode.SimVar> rest;
equation
txt = lm_52(txt, rest);
then txt;
Expand All @@ -2167,7 +2167,7 @@ end lm_52;

protected function lm_53
input Tpl.Text in_txt;
input list<list<DAE.ComponentRef>> in_items;
input list<list<SimCode.SimVar>> in_items;

output Tpl.Text out_txt;
algorithm
Expand All @@ -2181,10 +2181,10 @@ algorithm
then txt;

case ( txt,
i_crefs :: rest )
i_vars :: rest )
local
list<list<DAE.ComponentRef>> rest;
list<DAE.ComponentRef> i_crefs;
list<list<SimCode.SimVar>> rest;
list<SimCode.SimVar> i_vars;
Integer i_i0;
equation
i_i0 = Tpl.getIteri_i0(txt);
Expand All @@ -2193,7 +2193,7 @@ algorithm
txt = Tpl.writeTok(txt, Tpl.ST_STRING(":"));
txt = Tpl.writeTok(txt, Tpl.ST_NEW_LINE());
txt = Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE, SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE()));
txt = lm_52(txt, i_crefs);
txt = lm_52(txt, i_vars);
txt = Tpl.popIter(txt);
txt = Tpl.writeTok(txt, Tpl.ST_NEW_LINE());
txt = Tpl.writeTok(txt, Tpl.ST_STRING(" break;"));
Expand All @@ -2204,7 +2204,7 @@ algorithm
case ( txt,
_ :: rest )
local
list<list<DAE.ComponentRef>> rest;
list<list<SimCode.SimVar>> rest;
equation
txt = lm_53(txt, rest);
then txt;
Expand All @@ -2213,7 +2213,7 @@ end lm_53;

public function functionHandleZeroCrossing
input Tpl.Text txt;
input list<list<DAE.ComponentRef>> i_zeroCrossingsNeedSave;
input list<list<SimCode.SimVar>> i_zeroCrossingsNeedSave;

output Tpl.Text out_txt;
algorithm
Expand Down
6 changes: 3 additions & 3 deletions Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -626,7 +626,7 @@ int function_zeroCrossing(long *neqm, double *t, double *x, long *ng,

// This function should only save in cases. The rest is done in
// function_updateDependents.
functionHandleZeroCrossing(list<list<ComponentRef>> zeroCrossingsNeedSave) ::=
functionHandleZeroCrossing(list<list<SimVar>> zeroCrossingsNeedSave) ::=
<<
int handleZeroCrossing(long index)
{
Expand All @@ -635,8 +635,8 @@ int handleZeroCrossing(long index)
mem_state = get_memory_state();
switch(index) {
<zeroCrossingsNeedSave of crefs:
'case <i0>:<\n><crefs of cref: ' save(<cref(cref)>);' "\n"><\n> break;' "\n">
<zeroCrossingsNeedSave of vars:
'case <i0>:<\n><vars of SIMVAR: ' save(<cref(name)>);' "\n"><\n> break;' "\n">
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Compiler/susan_codegen/SimCode/SimCodeTV.mo
Expand Up @@ -86,7 +86,7 @@ package SimCode
list<SimEqSystem> parameterEquations;
list<SimEqSystem> removedEquations;
list<DAELow.ZeroCrossing> zeroCrossings;
list<list<DAE.ComponentRef>> zeroCrossingsNeedSave;
list<list<SimVar>> zeroCrossingsNeedSave;
list<HelpVarInfo> helpVarInfo;
list<SimWhenClause> whenClauses;
list<DAE.ComponentRef> discreteModelVars;
Expand Down

0 comments on commit 8fcbe1f

Please sign in to comment.