Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 82.4% 14 / 0 / 17
Functions: -% 0 / 1 / 1
Branches: 87.5% 14 / 0 / 16

OMCompiler/Compiler/NFFrontEnd/NFConnectionSets.mo
Line Branch Exec Source
1 /*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36 encapsulated package NFConnectionSets
37 import DisjointSets;
38 import ComponentRef = NFComponentRef;
39 import Connector = NFConnector;
40 import Connection = NFConnection;
41 import Connections = NFConnections;
42 import BrokenEdges = NFConnections.BrokenEdges;
43
44 protected
45 import Flags;
46 import List;
47
48 public
49 package ConnectionSets
50 extends DisjointSets(redeclare type Entry = Connector);
51
52 redeclare function extends EntryHash
53 algorithm
54 282071 hash := Connector.hash(entry);
55 end EntryHash;
56
57 redeclare function extends EntryEqual
58 algorithm
59 70234 isEqual := Connector.isEqual(entry1, entry2);
60 end EntryEqual;
61
62 redeclare function extends EntryString
63 algorithm
64 ✗ str := Connector.toString(entry);
65 end EntryString;
66
67 function fromConnections
68 "Creates a new DisjointSets from a list of connection and flow variables."
69 input Connections connections;
70 output ConnectionSets.Sets sets;
71 algorithm
72 // Approximate the size of the sets using the connections and flow variables.
73 1571 sets := ConnectionSets.emptySets(
74 listLength(connections.connections) + listLength(connections.flows));
75
76 // Add flow variable to the sets, unless disabled by flag.
77
1/2
✓ Branch 1 taken 1571 times.
✗ Branch 2 not taken.
1571 if not Flags.isSet(Flags.DISABLE_SINGLE_FLOW_EQ) then
78 1571 sets := List.fold(connections.flows, addSingleConnector, sets);
79 end if;
80
81 // Add the connections.
82 1571 sets := List.fold1(connections.connections, addConnection, connections.broken, sets);
83 end fromConnections;
84
85 function addScalarConnector
86 "Adds a single connector to the connection sets."
87 input Connector conn;
88 input output ConnectionSets.Sets sets;
89 algorithm
90 ✗ sets := add(conn, sets);
91 end addScalarConnector;
92
93 function addConnector
94 input Connector conn;
95 input output ConnectionSets.Sets sets;
96 algorithm
97 ✗ sets := addList(Connector.scalarize(conn), sets);
98 end addConnector;
99
100 function addSingleConnector
101 "Adds a connector to the sets if it does not already exist"
102 input Connector conn;
103 input output ConnectionSets.Sets sets;
104 algorithm
105 29436 sets := find(conn, sets);
106 end addSingleConnector;
107
108 function addConnection
109 "Adds a connection to the sets, which means merging the two sets that the
110 connectors belong to, unless they already belong to the same set."
111 input Connection connection;
112 input BrokenEdges broken;
113 input output ConnectionSets.Sets sets;
114 algorithm
115
4/4
✓ Branch 0 taken 1483 times.
✓ Branch 1 taken 65368 times.
✓ Branch 3 taken 44 times.
✓ Branch 4 taken 1439 times.
66851 if not listEmpty(broken) and isBroken(connection.lhs, connection.rhs, broken) then
116 44 return;
117 end if;
118
119 // TODO: Check variability of connectors. It's an error if either
120 // connector is constant/parameter while the other isn't.
121 66807 sets := merge(connection.lhs, connection.rhs, sets);
122 end addConnection;
123
124 function isBroken
125 input Connector c1, c2;
126 input BrokenEdges broken;
127 output Boolean b = false;
128 protected
129 ComponentRef cr1, cr2;
130 algorithm
131 1483 cr1 := Connector.name(c1);
132 1483 cr2 := Connector.name(c2);
133 // print("Check: connect(" + ComponentRef.toString(cr1) + ", " + ComponentRef.toString(cr2) + ")\n");
134
135
2/2
✓ Branch 0 taken 13764 times.
✓ Branch 1 taken 1439 times.
15203 for c in broken loop
136
7/8
✓ Branch 1 taken 74 times.
✓ Branch 2 taken 13690 times.
✓ Branch 4 taken 30 times.
✓ Branch 5 taken 44 times.
✓ Branch 7 taken 16 times.
✓ Branch 8 taken 13704 times.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
13764 if ComponentRef.isPrefix(c.lhs, cr1) and ComponentRef.isPrefix(c.rhs, cr2) or
137 ComponentRef.isPrefix(c.lhs, cr2) and ComponentRef.isPrefix(c.rhs, cr1)
138 then
139 // print("Ignore broken: connect(" + Connector.toString(c1) + ", " + Connector.toString(c2) + ")\n");
140 b := true;
141 break;
142 end if;
143 end for;
144 end isBroken;
145 end ConnectionSets;
146
147 annotation(__OpenModelica_Interface="nf_frontend");
148 end NFConnectionSets;
149