Changeset 55dd85a1 in OpenModelica


Ignore:
Timestamp:
2020-10-21T17:07:52+02:00 (3 years ago)
Author:
Adrian Pop <adrian.pop@…>
Parents:
ef5f7a1e
git-author:
Per Östlund <perost86@…> (10/21/20 13:47:28)
git-committer:
Adrian Pop <adrian.pop@…> (10/21/20 17:07:52)
Message:

Fix unconnected flow and inside/outside.

  • Change from ComponentRef to Connector in the AdjacencyList vertices to handle inside/outside connectors correctly.
  • Add all flow variables in the model as inside connectors to make sure equations are generated for all the unconnected flow variables.
Files:
5 edited

Legend:

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

    re52a6fad r55dd85a1  
    6565  uniontype SetVertex
    6666    record SET_VERTEX
    67       ComponentRef name;
     67      Connector name;
    6868      SBSet vs;
    6969    end SET_VERTEX;
     
    7272      input SetVertex v1;
    7373      input SetVertex v2;
    74       output Boolean equal = ComponentRef.isEqual(v1.name, v2.name);
     74      output Boolean equal = Connector.isEqual(v1.name, v2.name);
    7575    end isEqual;
    7676
    7777    function isNamed
    7878      input SetVertex v;
    79       input ComponentRef name;
    80       output Boolean equal = ComponentRef.isEqual(v.name, name);
     79      input Connector name;
     80      output Boolean equal = Connector.isEqual(v.name, name);
    8181    end isNamed;
    8282  end SetVertex;
     
    163163    (flatModel, conns) := collect(flatModel);
    164164
    165     if listEmpty(conns) then
    166       return;
    167     end if;
    168 
    169165    graph := AdjacencyList.new(SetVertex.isEqual, SetEdge.isEqual);
    170166    nmv_table := NameVertexTable.new();
    171     nmv_table := createGraph(conns, graph, v_count, e_count, nmv_table);
     167    nmv_table := createGraph(flatModel.variables, conns, graph, v_count, e_count, nmv_table);
    172168
    173169    (vss, emap1, emap2) := createMaps(graph);
     
    205201
    206202  function createGraph
     203    input list<Variable> variables;
     204    input list<Equation> equations;
     205    input SBGraph graph;
     206    input Vector<Integer> vCount;
     207    input Vector<Integer> eCount;
     208    input output NameVertexTable.Table nmvTable;
     209  algorithm
     210    nmvTable := addFlowsToGraph(variables, graph, vCount, nmvTable);
     211    nmvTable := addConnectionsToGraph(equations, graph, vCount, eCount, nmvTable);
     212  end createGraph;
     213
     214  function addFlowsToGraph
     215    input list<Variable> variables;
     216    input SBGraph graph;
     217    input Vector<Integer> vCount;
     218    input output NameVertexTable.Table nmvTable;
     219  protected
     220    Connector conn;
     221    ComponentRef parent_cr;
     222  algorithm
     223    for var in variables loop
     224      if Variable.isFlow(var) then
     225        parent_cr := ComponentRef.rest(var.name);
     226        conn := Connector.fromFacedCref(parent_cr, ComponentRef.nodeType(parent_cr), NFConnector.Face.INSIDE,
     227          ElementSource.createElementSource(var.info));
     228        (_, _, nmvTable) := createVertex(conn, graph, vCount, nmvTable);
     229      end if;
     230    end for;
     231  end addFlowsToGraph;
     232
     233  function addConnectionsToGraph
    207234    input list<Equation> equations;
    208235    input SBGraph graph;
     
    226253            range := Ceval.evalExp(range, Ceval.EvalTarget.RANGE(Equation.info(eq)));
    227254            body := applyIterator(eq.iterator, range, eq.body);
    228             nmvTable := createGraph(body, graph, vCount, eCount, nmvTable);
     255            nmvTable := addConnectionsToGraph(body, graph, vCount, eCount, nmvTable);
    229256          then
    230257            ();
     
    238265      end match;
    239266    end for;
    240   end createGraph;
     267  end addConnectionsToGraph;
    241268
    242269  function applyIterator
     
    263290    AdjacencyList.VertexDescriptor d1, d2;
    264291    SourceInfo info = ElementSource.getInfo(source);
     292    list<Connector> lhs_conns, rhs_conns;
     293    Connector lhs_conn, rhs_conn;
    265294  algorithm
    266295    (lhs_cr, lhs_subs) := separate(Expression.toCref(lhs));
    267296    (rhs_cr, rhs_subs) := separate(Expression.toCref(rhs));
    268297
    269     (mi1, d1, nmvTable) := getConnectIntervals(lhs_cr, lhs_subs, graph, vCount, nmvTable, info);
    270     (mi2, d2, nmvTable) := getConnectIntervals(rhs_cr, rhs_subs, graph, vCount, nmvTable, info);
     298    lhs_conn := Connector.fromCref(lhs_cr, ComponentRef.nodeType(lhs_cr), source);
     299    rhs_conn := Connector.fromCref(rhs_cr, ComponentRef.nodeType(rhs_cr), source);
     300
     301    (mi1, d1, nmvTable) := getConnectIntervals(lhs_conn, lhs_subs, graph, vCount, nmvTable, info);
     302    (mi2, d2, nmvTable) := getConnectIntervals(rhs_conn, rhs_subs, graph, vCount, nmvTable, info);
    271303
    272304    updateGraph(d1, d2, mi1, mi2, graph, eCount);
     
    284316
    285317  function getConnectIntervals
    286     input ComponentRef cr;
     318    input Connector conn;
    287319    input list<Subscript> subs;
    288320    input SBGraph graph;
     
    308340    Expression sub_exp;
    309341  algorithm
    310     (outMI, d, outNmvTable) := createVertex(cr, graph, vCount, nmvTable);
     342    (outMI, d, outNmvTable) := createVertex(conn, graph, vCount, nmvTable);
    311343    miv := SBMultiInterval.intervals(outMI);
    312344
     
    340372
    341373  function createVertex
    342     input ComponentRef cr;
     374    input Connector conn;
    343375    input SBGraph graph;
    344376    input Vector<Integer> vCount;
     
    356388    Vector<Integer> new_vc;
    357389    SBInterval int;
    358   algorithm
    359     od := AdjacencyList.findVertex(graph, function SetVertex.isNamed(name = cr));
     390    String name;
     391  algorithm
     392    od := AdjacencyList.findVertex(graph, function SetVertex.isNamed(name = conn));
    360393
    361394    if isSome(od) then
     
    366399    end if;
    367400
    368     dims := crefDims(cr);
     401    dims := crefDims(Connector.name(conn));
    369402
    370403    if listEmpty(dims) then
     
    409442    s := SBSet.addAtomicSet(SBAtomicSet.new(mi), s);
    410443
    411     v := SET_VERTEX(cr, s);
     444    v := SET_VERTEX(conn, s);
    412445    d := AdjacencyList.addVertex(graph, v);
    413446
    414     outNmvTable := BaseHashTable.addUnique((ComponentRef.toString(cr), mi), nmvTable);
     447    name := Connector.toString(conn) + "$" + Connector.faceString(conn);
     448    outNmvTable := BaseHashTable.addUnique((name, mi), nmvTable);
    415449  end createVertex;
    416450
     
    647681    end for;
    648682
    649     e :: es := AdjacencyList.edges(graph);
    650     emap1 := e.es1;
    651     emap2 := e.es2;
    652 
    653     for e in es loop
    654       emap1 := SBPWLinearMap.combine(e.es1, emap1);
    655       emap2 := SBPWLinearMap.combine(e.es2, emap2);
    656     end for;
     683    es := AdjacencyList.edges(graph);
     684
     685    if listEmpty(es) then
     686      emap1 := SBPWLinearMap.newEmpty();
     687      emap2 := SBPWLinearMap.newEmpty();
     688    else
     689      e :: es := AdjacencyList.edges(graph);
     690      emap1 := e.es1;
     691      emap2 := e.es2;
     692
     693      for e in es loop
     694        emap1 := SBPWLinearMap.combine(e.es1, emap1);
     695        emap2 := SBPWLinearMap.combine(e.es2, emap2);
     696      end for;
     697    end if;
    657698  end createMaps;
    658699
     
    668709    array<InstNode> iterators;
    669710    list<Variable> pot_vars, flow_vars;
    670     list<tuple<String, ComponentRef>> vars;
     711    list<ComponentRef> vars;
    671712    list<Expression> iter_expl;
    672713  algorithm
     
    719760    input SBAtomicSet aset;
    720761    input SBSet dom;
    721     input list<tuple<String, ComponentRef>> vars;
     762    input list<ComponentRef> vars;
    722763    input array<InstNode> iterators;
    723764    input list<Expression> iterExps;
     
    731772    array<SBInterval> inters;
    732773    array<Expression> ranges;
    733     list<tuple<String, ComponentRef>> vars1, vars2;
     774    list<ComponentRef> vars1, vars2;
    734775    list<Equation> eql;
    735776    list<Expression> inds, iter_expl;
     
    755796
    756797  function generatePotentialEquations2
    757     input list<tuple<String, ComponentRef>> vars1;
    758     input list<tuple<String, ComponentRef>> vars2;
     798    input list<ComponentRef> vars1;
     799    input list<ComponentRef> vars2;
    759800    input list<Expression> inds1;
    760801    input list<Expression> inds2;
    761802    output list<Equation> equations = {};
    762803  protected
    763     ComponentRef cr1, cr2;
    764804    Expression l, r;
    765805    Type ty;
     
    768808  algorithm
    769809    for var1 in vars1 loop
    770       (_, cr1) := var1;
    771 
    772810      for var2 in vars2 loop
    773         (_, cr2) := var2;
    774 
    775         if ComponentRef.firstName(cr1) == ComponentRef.firstName(cr2) then
    776           l := generateConnector(cr1, inds1);
    777           r := generateConnector(cr2, inds2);
     811        if ComponentRef.firstName(var1) == ComponentRef.firstName(var2) then
     812          l := generateConnector(var1, inds1);
     813          r := generateConnector(var2, inds2);
    778814          ty := Expression.typeOf(l);
    779815
     
    807843    list<Expression> expl, inds;
    808844    Boolean is_sum;
    809     list<tuple<String, ComponentRef>> vars;
     845    list<ComponentRef> vars;
    810846    Expression e, sum_exp;
    811847    Type ty;
     
    828864
    829865      for var in vars loop
    830         e := generateConnector(Util.tuple22(var), inds);
     866        e := generateConnector(var, inds);
    831867
    832868        if is_sum then
     
    958994    input SBSet sauxi;
    959995    input SBGraph graph;
    960     output list<tuple<String, ComponentRef>> res = {};
     996    output list<ComponentRef> res = {};
    961997  protected
    962998    list<SetVertex> vl;
     
    9661002      if not SBSet.isEmpty(SBSet.intersection(v.vs, sauxi)) then
    9671003        for var in vars loop
    968           if ComponentRef.isPrefix(v.name, var.name) then
    969             res := (ComponentRef.toString(v.name), var.name) :: res;
     1004          if ComponentRef.isPrefix(Connector.name(v.name), var.name) then
     1005            res := var.name :: res;
    9701006          end if;
    9711007        end for;
  • OMCompiler/Compiler/NFFrontEnd/NFConnector.mo

    re84fce5 r55dd85a1  
    3838  import NFPrefixes.Variability;
    3939  import DAE;
     40  import Flags;
    4041
    4142protected
     
    4445  import NFInstNode.InstNode;
    4546  import ElementSource;
    46   import Flags;
    4747  import Component = NFComponent;
    4848  import NFClassTree.ClassTree;
     
    199199    output String str = ComponentRef.toString(conn.name);
    200200  end toString;
     201
     202  function faceString
     203    input Connector conn;
     204    output String str = if conn.face == Face.INSIDE then "inside" else "outside";
     205  end faceString;
    201206
    202207  function hash
  • testsuite/flattening/modelica/scodeinst/ArrayConnect1.mo

    re52a6fad r55dd85a1  
    1616
    1717model ArrayConnect1
    18   parameter Integer N = 1000;
     18  parameter Integer N = 10;
    1919  A S, R[N], C[N], G;
    2020equation
     
    3232// Result:
    3333// class ArrayConnect1
    34 //   final parameter Integer N = 1000;
     34//   final parameter Integer N = 10;
    3535//   Real S.p.e;
    3636//   Real S.p.f;
    3737//   Real S.n.e;
    3838//   Real S.n.f;
    39 //   Real[1000] R.n.f;
    40 //   Real[1000] R.n.e;
    41 //   Real[1000] R.p.f;
    42 //   Real[1000] R.p.e;
    43 //   Real[1000] C.n.f;
    44 //   Real[1000] C.n.e;
    45 //   Real[1000] C.p.f;
    46 //   Real[1000] C.p.e;
     39//   Real[10] R.n.f;
     40//   Real[10] R.n.e;
     41//   Real[10] R.p.f;
     42//   Real[10] R.p.e;
     43//   Real[10] C.n.f;
     44//   Real[10] C.n.e;
     45//   Real[10] C.p.f;
     46//   Real[10] C.p.e;
    4747//   Real G.p.e;
    4848//   Real G.p.f;
     
    5252//   R[1].p.e = S.p.e;
    5353//   S.p.f + R[1].p.f = 0.0;
    54 //   for $i1 in 1:1000 loop
     54//   for $i1 in 1:10 loop
    5555//     C[$i1].n.e = S.n.e;
    5656//   end for;
    5757//   G.p.e = S.n.e;
    5858//   S.n.f + G.p.f + sum(C[:].n.f) = 0.0;
    59 //   for $i1 in 1:999 loop
    60 //     R[$i1].n.e = R[$i1 + 1].p.e;
     59//   for $i1 in 1:9 loop
     60//     C[$i1].p.e = R[$i1].n.e;
    6161//   end for;
    62 //   for $i1 in 1:999 loop
    63 //     C[$i1].p.e = R[$i1 + 1].p.e;
     62//   for $i1 in 2:10 loop
     63//     R[$i1].p.e = R[$i1 - 1].n.e;
    6464//   end for;
    65 //   for $i1 in 2:1000 loop
    66 //     C[$i1 - 1].p.f + R[$i1 - 1].n.f + R[$i1].p.f = 0.0;
     65//   for $i1 in 1:9 loop
     66//     R[$i1].n.f + R[$i1 + 1].p.f + C[$i1].p.f = 0.0;
    6767//   end for;
    68 //   C[1000].p.e = R[1000].n.e;
    69 //   C[1000].p.f + R[1000].n.f = 0.0;
     68//   C[10].p.e = R[10].n.e;
     69//   R[10].n.f + C[10].p.f = 0.0;
     70//   G.n.f = 0.0;
    7071// end ArrayConnect1;
    7172// endResult
  • testsuite/flattening/modelica/scodeinst/ArrayConnect2.mo

    re52a6fad r55dd85a1  
    5353//   Real G.n.f;
    5454// equation
     55//   C[1000].n.e = C[1].n.e;
     56//   C[1].n.f + C[1000].n.f = 0.0;
    5557//   R[1].p.e = S.p.e;
    5658//   S.p.f + R[1].p.f = 0.0;
    57 //   C[1000].n.e = S.n.e;
    58 //   for $i1 in 2:999 loop
    59 //     C[$i1].n.e = S.n.e;
     59//   G.p.e = S.n.e;
     60//   S.n.f + G.p.f = 0.0;
     61//   for $i1 in 3:999 loop
     62//     C[$i1].n.e = C[2].n.e;
    6063//   end for;
    61 //   C[1].n.e = S.n.e;
    62 //   G.p.e = S.n.e;
    63 //   S.n.f + G.p.f + C[1].n.f + sum(C[2:999].n.f) + C[1000].n.f = 0.0;
    64 //   for $i1 in 1:999 loop
    65 //     R[$i1].n.e = R[$i1 + 1].p.e;
    66 //   end for;
     64//   sum(C[2:999].n.f) = 0.0;
    6765//   for $i1 in 1:999 loop
    6866//     C[$i1].p.e = R[$i1 + 1].p.e;
    6967//   end for;
    7068//   for $i1 in 2:1000 loop
    71 //     C[$i1 - 1].p.f + R[$i1 - 1].n.f + R[$i1].p.f = 0.0;
     69//     C[$i1 - 1].p.f + R[$i1].p.f = 0.0;
     70//   end for;
     71//   for $i1 in 1:999 loop
     72//     R[$i1].n.f = 0.0;
    7273//   end for;
    7374//   C[1000].p.e = R[1000].n.e;
    7475//   C[1000].p.f + R[1000].n.f = 0.0;
     76//   G.n.f = 0.0;
    7577// end ArrayConnect2;
    7678// endResult
  • testsuite/flattening/modelica/scodeinst/ArrayConnect3.mo

    re52a6fad r55dd85a1  
    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;
     85//   for $i2 in 1:100 loop
     86//     cells[1,$i2].u.e = S.p.e;
    8887//   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;
     88//   sum(cells[1,:].u.f) + S.p.f = 0.0;
     89//   for $i2 in 1:100 loop
     90//     cells[1000,$i2].d.e = S.n.e;
    9391//   end for;
    94 //   cells[1000,1].d.f + sum(cells[1000,2:100].d.f) + S.n.f = 0.0;
     92//   sum(cells[1000,:].d.f) + S.n.f = 0.0;
     93//   for $i1 in 1:999 loop
     94//     cells[$i1,100].d.f = 0.0;
     95//   end for;
     96//   for $i1 in 2:1000 loop
     97//     cells[$i1,100].u.f = 0.0;
     98//   end for;
    9599//   for $i2 in 1:99 loop
    96100//     cells[1000,$i2].r.f = 0.0;
     
    99103//     cells[1000,$i2].l.f = 0.0;
    100104//   end for;
    101 //   for $i1 in 1:999 loop
    102 //     cells[$i1,100].d.f = 0.0;
    103 //   end for;
    104 //   for $i1 in 2:1000 loop
    105 //     cells[$i1,100].u.f = 0.0;
    106 //   end for;
    107105// end ArrayConnect3;
    108106// endResult
Note: See TracChangeset for help on using the changeset viewer.