Changeset 55dd85a1 in OpenModelica
- Timestamp:
- 2020-10-21T17:07:52+02:00 (3 years ago)
- 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)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
OMCompiler/Compiler/NFFrontEnd/NFArrayConnections.mo
re52a6fad r55dd85a1 65 65 uniontype SetVertex 66 66 record SET_VERTEX 67 Co mponentRefname;67 Connector name; 68 68 SBSet vs; 69 69 end SET_VERTEX; … … 72 72 input SetVertex v1; 73 73 input SetVertex v2; 74 output Boolean equal = Co mponentRef.isEqual(v1.name, v2.name);74 output Boolean equal = Connector.isEqual(v1.name, v2.name); 75 75 end isEqual; 76 76 77 77 function isNamed 78 78 input SetVertex v; 79 input Co mponentRefname;80 output Boolean equal = Co mponentRef.isEqual(v.name, name);79 input Connector name; 80 output Boolean equal = Connector.isEqual(v.name, name); 81 81 end isNamed; 82 82 end SetVertex; … … 163 163 (flatModel, conns) := collect(flatModel); 164 164 165 if listEmpty(conns) then166 return;167 end if;168 169 165 graph := AdjacencyList.new(SetVertex.isEqual, SetEdge.isEqual); 170 166 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); 172 168 173 169 (vss, emap1, emap2) := createMaps(graph); … … 205 201 206 202 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 207 234 input list<Equation> equations; 208 235 input SBGraph graph; … … 226 253 range := Ceval.evalExp(range, Ceval.EvalTarget.RANGE(Equation.info(eq))); 227 254 body := applyIterator(eq.iterator, range, eq.body); 228 nmvTable := createGraph(body, graph, vCount, eCount, nmvTable);255 nmvTable := addConnectionsToGraph(body, graph, vCount, eCount, nmvTable); 229 256 then 230 257 (); … … 238 265 end match; 239 266 end for; 240 end createGraph;267 end addConnectionsToGraph; 241 268 242 269 function applyIterator … … 263 290 AdjacencyList.VertexDescriptor d1, d2; 264 291 SourceInfo info = ElementSource.getInfo(source); 292 list<Connector> lhs_conns, rhs_conns; 293 Connector lhs_conn, rhs_conn; 265 294 algorithm 266 295 (lhs_cr, lhs_subs) := separate(Expression.toCref(lhs)); 267 296 (rhs_cr, rhs_subs) := separate(Expression.toCref(rhs)); 268 297 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); 271 303 272 304 updateGraph(d1, d2, mi1, mi2, graph, eCount); … … 284 316 285 317 function getConnectIntervals 286 input Co mponentRef cr;318 input Connector conn; 287 319 input list<Subscript> subs; 288 320 input SBGraph graph; … … 308 340 Expression sub_exp; 309 341 algorithm 310 (outMI, d, outNmvTable) := createVertex(c r, graph, vCount, nmvTable);342 (outMI, d, outNmvTable) := createVertex(conn, graph, vCount, nmvTable); 311 343 miv := SBMultiInterval.intervals(outMI); 312 344 … … 340 372 341 373 function createVertex 342 input Co mponentRef cr;374 input Connector conn; 343 375 input SBGraph graph; 344 376 input Vector<Integer> vCount; … … 356 388 Vector<Integer> new_vc; 357 389 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)); 360 393 361 394 if isSome(od) then … … 366 399 end if; 367 400 368 dims := crefDims( cr);401 dims := crefDims(Connector.name(conn)); 369 402 370 403 if listEmpty(dims) then … … 409 442 s := SBSet.addAtomicSet(SBAtomicSet.new(mi), s); 410 443 411 v := SET_VERTEX(c r, s);444 v := SET_VERTEX(conn, s); 412 445 d := AdjacencyList.addVertex(graph, v); 413 446 414 outNmvTable := BaseHashTable.addUnique((ComponentRef.toString(cr), mi), nmvTable); 447 name := Connector.toString(conn) + "$" + Connector.faceString(conn); 448 outNmvTable := BaseHashTable.addUnique((name, mi), nmvTable); 415 449 end createVertex; 416 450 … … 647 681 end for; 648 682 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; 657 698 end createMaps; 658 699 … … 668 709 array<InstNode> iterators; 669 710 list<Variable> pot_vars, flow_vars; 670 list< tuple<String, ComponentRef>> vars;711 list<ComponentRef> vars; 671 712 list<Expression> iter_expl; 672 713 algorithm … … 719 760 input SBAtomicSet aset; 720 761 input SBSet dom; 721 input list< tuple<String, ComponentRef>> vars;762 input list<ComponentRef> vars; 722 763 input array<InstNode> iterators; 723 764 input list<Expression> iterExps; … … 731 772 array<SBInterval> inters; 732 773 array<Expression> ranges; 733 list< tuple<String, ComponentRef>> vars1, vars2;774 list<ComponentRef> vars1, vars2; 734 775 list<Equation> eql; 735 776 list<Expression> inds, iter_expl; … … 755 796 756 797 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; 759 800 input list<Expression> inds1; 760 801 input list<Expression> inds2; 761 802 output list<Equation> equations = {}; 762 803 protected 763 ComponentRef cr1, cr2;764 804 Expression l, r; 765 805 Type ty; … … 768 808 algorithm 769 809 for var1 in vars1 loop 770 (_, cr1) := var1;771 772 810 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); 778 814 ty := Expression.typeOf(l); 779 815 … … 807 843 list<Expression> expl, inds; 808 844 Boolean is_sum; 809 list< tuple<String, ComponentRef>> vars;845 list<ComponentRef> vars; 810 846 Expression e, sum_exp; 811 847 Type ty; … … 828 864 829 865 for var in vars loop 830 e := generateConnector( Util.tuple22(var), inds);866 e := generateConnector(var, inds); 831 867 832 868 if is_sum then … … 958 994 input SBSet sauxi; 959 995 input SBGraph graph; 960 output list< tuple<String, ComponentRef>> res = {};996 output list<ComponentRef> res = {}; 961 997 protected 962 998 list<SetVertex> vl; … … 966 1002 if not SBSet.isEmpty(SBSet.intersection(v.vs, sauxi)) then 967 1003 for var in vars loop 968 if ComponentRef.isPrefix( v.name, var.name) then969 res := (ComponentRef.toString(v.name), var.name):: res;1004 if ComponentRef.isPrefix(Connector.name(v.name), var.name) then 1005 res := var.name :: res; 970 1006 end if; 971 1007 end for; -
OMCompiler/Compiler/NFFrontEnd/NFConnector.mo
re84fce5 r55dd85a1 38 38 import NFPrefixes.Variability; 39 39 import DAE; 40 import Flags; 40 41 41 42 protected … … 44 45 import NFInstNode.InstNode; 45 46 import ElementSource; 46 import Flags;47 47 import Component = NFComponent; 48 48 import NFClassTree.ClassTree; … … 199 199 output String str = ComponentRef.toString(conn.name); 200 200 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; 201 206 202 207 function hash -
testsuite/flattening/modelica/scodeinst/ArrayConnect1.mo
re52a6fad r55dd85a1 16 16 17 17 model ArrayConnect1 18 parameter Integer N = 10 00;18 parameter Integer N = 10; 19 19 A S, R[N], C[N], G; 20 20 equation … … 32 32 // Result: 33 33 // class ArrayConnect1 34 // final parameter Integer N = 10 00;34 // final parameter Integer N = 10; 35 35 // Real S.p.e; 36 36 // Real S.p.f; 37 37 // Real S.n.e; 38 38 // Real S.n.f; 39 // Real[10 00] R.n.f;40 // Real[10 00] R.n.e;41 // Real[10 00] R.p.f;42 // Real[10 00] R.p.e;43 // Real[10 00] C.n.f;44 // Real[10 00] C.n.e;45 // Real[10 00] C.p.f;46 // Real[10 00] 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; 47 47 // Real G.p.e; 48 48 // Real G.p.f; … … 52 52 // R[1].p.e = S.p.e; 53 53 // S.p.f + R[1].p.f = 0.0; 54 // for $i1 in 1:10 00loop54 // for $i1 in 1:10 loop 55 55 // C[$i1].n.e = S.n.e; 56 56 // end for; 57 57 // G.p.e = S.n.e; 58 58 // S.n.f + G.p.f + sum(C[:].n.f) = 0.0; 59 // for $i1 in 1:9 99loop60 // 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; 61 61 // end for; 62 // for $i1 in 1:999loop63 // 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; 64 64 // end for; 65 // for $i1 in 2:1000loop66 // 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; 67 67 // 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; 70 71 // end ArrayConnect1; 71 72 // endResult -
testsuite/flattening/modelica/scodeinst/ArrayConnect2.mo
re52a6fad r55dd85a1 53 53 // Real G.n.f; 54 54 // equation 55 // C[1000].n.e = C[1].n.e; 56 // C[1].n.f + C[1000].n.f = 0.0; 55 57 // R[1].p.e = S.p.e; 56 58 // 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; 60 63 // 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; 67 65 // for $i1 in 1:999 loop 68 66 // C[$i1].p.e = R[$i1 + 1].p.e; 69 67 // end for; 70 68 // 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; 72 73 // end for; 73 74 // C[1000].p.e = R[1000].n.e; 74 75 // C[1000].p.f + R[1000].n.f = 0.0; 76 // G.n.f = 0.0; 75 77 // end ArrayConnect2; 76 78 // endResult -
testsuite/flattening/modelica/scodeinst/ArrayConnect3.mo
re52a6fad r55dd85a1 83 83 // cells[$i1,100].r.f + cells[$i1,1].l.f = 0.0; 84 84 // 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; 88 87 // 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; 93 91 // 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; 95 99 // for $i2 in 1:99 loop 96 100 // cells[1000,$i2].r.f = 0.0; … … 99 103 // cells[1000,$i2].l.f = 0.0; 100 104 // end for; 101 // for $i1 in 1:999 loop102 // cells[$i1,100].d.f = 0.0;103 // end for;104 // for $i1 in 2:1000 loop105 // cells[$i1,100].u.f = 0.0;106 // end for;107 105 // end ArrayConnect3; 108 106 // endResult
Note: See TracChangeset
for help on using the changeset viewer.