Changeset e52a6fad in OpenModelica


Ignore:
Timestamp:
2020-10-21T15:09:43+02:00 (3 years ago)
Author:
Adrian Pop <adrian.pop@…>
Children:
bb19ac5
Parents:
baf3ba92
git-author:
Per Östlund <perost86@…> (10/21/20 12:36:55)
git-committer:
Adrian Pop <adrian.pop@…> (10/21/20 15:09:43)
Message:

Array connection improvements

  • Fix connecting variables with different number of dimensions.
  • Avoid unnecessary range step values in more cases.
  • Fix SimplifyExp.simplifyCall so that simplified arguments aren't discarded in some cases when the call itself couldn't be simplified.
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/NFFrontEnd/NFArrayConnections.mo

    r74f72fe re52a6fad  
    372372      Vector.update(vCount, 1, vc + 1);
    373373
    374       mi := SBMultiInterval.fromList({SBInterval.new(vc, 1, vc)});
     374      mi := SBMultiInterval.fromArray(arrayCreate(Vector.size(vCount), SBInterval.new(vc, 1, vc)));
    375375    else
    376376      ints := arrayCreate(listLength(dims), SBInterval.newEmpty());
     
    547547  protected
    548548    array<SBInterval> ints1, ints2, mi;
    549     Integer mi1_sz, mi2_sz, ints1_i, ints2_i, sz, sz1, sz2;
     549    Integer mi1_sz, mi2_sz, sz, sz1, sz2;
    550550    Integer count, aux_ec;
    551551    array<Real> g1, g2, o1, o2;
     
    560560  algorithm
    561561    ints1 := SBMultiInterval.intervals(mi1);
    562     ints1_i := 1;
    563562    mi1_sz := SBMultiInterval.size(mi1);
    564563
    565564    ints2 := SBMultiInterval.intervals(mi2);
    566     ints2_i := 1;
    567565    mi2_sz := SBMultiInterval.size(mi2);
    568566
     
    581579
    582580    for i in 1:sz loop
    583       sz1 := SBInterval.size(ints1[ints1_i]);
    584       sz2 := SBInterval.size(ints2[ints2_i]);
     581      sz1 := SBInterval.size(ints1[i]);
     582      sz2 := SBInterval.size(ints2[i]);
    585583
    586584      if sz1 <> sz2 and sz1 <> 1 and sz2 <> 1 then
     
    592590      mi[i] := SBInterval.new(aux_ec, 1, aux_ec + count - 1);
    593591
    594       i1 := ints1[ints1_i];
    595       i2 := ints2[ints2_i];
     592      i1 := ints1[i];
     593      i2 := ints2[i];
    596594
    597595      if sz1 == 1 then
     
    616614
    617615      Vector.push(new_ec, aux_ec + count);
    618 
    619       if mi1_sz > 1 or mi2_sz == 1 then
    620         ints1_i := ints1_i + 1;
    621       end if;
    622 
    623       if mi2_sz > 1 or mi1_sz == 1 then
    624         ints2_i := ints2_i + 1;
    625       end if;
    626616    end for;
    627617
     
    717707  protected
    718708    Integer lo = SBInterval.lowerBound(interval);
    719     Integer step = SBInterval.stepValue(interval);
    720709    Integer hi = SBInterval.upperBound(interval);
    721710  algorithm
     
    723712      range := Expression.INTEGER(lo);
    724713    else
    725       range := Expression.makeRange(
    726         Expression.INTEGER(lo),
    727         if step == 1 then NONE() else SOME(Expression.INTEGER(step)),
    728         Expression.INTEGER(hi)
    729       );
     714      range := Expression.makeIntegerRange(lo, SBInterval.stepValue(interval), hi);
    730715    end if;
    731716  end intervalToRange;
     
    10351020        outExpl := Expression.INTEGER(SBInterval.lowerBound(i2)) :: outExpl;
    10361021      elseif i1_sz == 1 and forFlow then
    1037         e := Expression.makeRange(
    1038           Expression.INTEGER(SBInterval.lowerBound(i2)),
    1039           SOME(Expression.INTEGER(SBInterval.stepValue(i2))),
    1040           Expression.INTEGER(SBInterval.upperBound(i2))
    1041         );
     1022        e := Expression.makeIntegerRange(
     1023          SBInterval.lowerBound(i2), SBInterval.stepValue(i2), SBInterval.upperBound(i2));
    10421024        outExpl := e :: outExpl;
    10431025        flowRange := true;
  • OMCompiler/Compiler/NFFrontEnd/NFExpression.mo

    rc9471b8 re52a6fad  
    10051005  end makeRange;
    10061006
     1007  function makeIntegerRange
     1008    input Integer start;
     1009    input Integer step;
     1010    input Integer stop;
     1011    output Expression rangeExp;
     1012  protected
     1013    Expression start_exp, stop_exp;
     1014    Option<Expression> step_exp;
     1015  algorithm
     1016    start_exp := Expression.INTEGER(start);
     1017    stop_exp := Expression.INTEGER(stop);
     1018
     1019    if start == stop or
     1020       step == 1 and start <= stop or
     1021       step == -1 and start >= stop then
     1022      step_exp := NONE();
     1023    else
     1024      step_exp := SOME(Expression.INTEGER(step));
     1025    end if;
     1026
     1027    rangeExp := makeRange(start_exp, step_exp, stop_exp);
     1028  end makeIntegerRange;
     1029
    10071030  function applySubscripts
    10081031    "Subscripts an expression with the given list of subscripts."
  • OMCompiler/Compiler/NFFrontEnd/NFSimplifyExp.mo

    r32725bb re52a6fad  
    177177              callExp := Expression.stripBindingInfo(callExp);
    178178            else
     179              callExp := Expression.CALL(call);
    179180            end try;
    180181          else
     
    183184              callExp := simplifyBuiltinCall(Function.nameConsiderBuiltin(call.fn), args, call);
    184185            else
    185               // nothing
     186              callExp := Expression.CALL(call);
    186187            end if;
    187188          end if;
  • testsuite/flattening/modelica/scodeinst/ArrayConnect1.mo

    r1019c41e re52a6fad  
    5656//   end for;
    5757//   G.p.e = S.n.e;
    58 //   S.n.f + G.p.f + sum(C[1:1:1000].n.f) = 0.0;
     58//   S.n.f + G.p.f + sum(C[:].n.f) = 0.0;
    5959//   for $i1 in 1:999 loop
    6060//     R[$i1].n.e = R[$i1 + 1].p.e;
  • testsuite/flattening/modelica/scodeinst/ArrayConnect2.mo

    r1019c41e re52a6fad  
    6161//   C[1].n.e = S.n.e;
    6262//   G.p.e = S.n.e;
    63 //   S.n.f + G.p.f + C[1].n.f + sum(C[2:1:999].n.f) + C[1000].n.f = 0.0;
     63//   S.n.f + G.p.f + C[1].n.f + sum(C[2:999].n.f) + C[1000].n.f = 0.0;
    6464//   for $i1 in 1:999 loop
    6565//     R[$i1].n.e = R[$i1 + 1].p.e;
  • testsuite/flattening/modelica/scodeinst/ArrayConnect3.mo

    r74f72fe re52a6fad  
    8383//     cells[$i1,100].r.f + cells[$i1,1].l.f = 0.0;
    8484//   end for;
     85//   S.p.e = cells[1,1].u.e;
     86//   for $i2 in 2:100 loop
     87//     cells[1,$i2].u.e = cells[1,1].u.e;
     88//   end for;
     89//   cells[1,1].u.f + sum(cells[1,2:100].u.f) + S.p.f = 0.0;
     90//   S.n.e = cells[1000,1].d.e;
     91//   for $i2 in 2:100 loop
     92//     cells[1000,$i2].d.e = cells[1000,1].d.e;
     93//   end for;
     94//   cells[1000,1].d.f + sum(cells[1000,2:100].d.f) + S.n.f = 0.0;
    8595//   for $i2 in 1:99 loop
    8696//     cells[1000,$i2].r.f = 0.0;
     
    8999//     cells[1000,$i2].l.f = 0.0;
    90100//   end for;
    91 //   for $i2 in 1:100 loop
    92 //     cells[1000,$i2].d.f = 0.0;
    93 //   end for;
    94101//   for $i1 in 1:999 loop
    95102//     cells[$i1,100].d.f = 0.0;
    96 //   end for;
    97 //   for $i2 in 1:100 loop
    98 //     cells[1,$i2].u.f = 0.0;
    99103//   end for;
    100104//   for $i1 in 2:1000 loop
Note: See TracChangeset for help on using the changeset viewer.