Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 0eec718

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Implementation of expandable connectors.
- Added new module ExpandableConnectors that handles expandable connections. - Changed Prefixes.ConnectorType from an enumeration into a bit field, so that it also can keep track of whether something is a connector, expandable connector, or expandable connector element. - Fixed connector form error message so that the whole connector name is printed out. - Changed OCConnectionGraph.handleOverconstrainedConnections to take a Connections record, so it only needs to be created once and so that expandable connector can be handled first. - Removed the list of broken equations from Equation.CONNECT since it wasn't used. Belonging to [master]: - #2941 - OpenModelica/OpenModelica-testsuite#1125
1 parent a385b60 commit 0eec718

27 files changed

+1328
-474
lines changed

Compiler/NFFrontEnd/NFClass.mo

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,45 @@ uniontype Class
469469
end match;
470470
end getType;
471471

472+
function setType
473+
input Type ty;
474+
input output Class cls;
475+
algorithm
476+
() := match cls
477+
case PARTIAL_BUILTIN()
478+
algorithm
479+
cls.ty := ty;
480+
then
481+
();
482+
483+
case EXPANDED_DERIVED()
484+
algorithm
485+
InstNode.classApply(cls.baseClass, setType, ty);
486+
then
487+
();
488+
489+
case INSTANCED_CLASS()
490+
algorithm
491+
cls.ty := ty;
492+
then
493+
();
494+
495+
case INSTANCED_BUILTIN()
496+
algorithm
497+
cls.ty := ty;
498+
then
499+
();
500+
501+
case TYPED_DERIVED()
502+
algorithm
503+
cls.ty := ty;
504+
then
505+
();
506+
507+
else ();
508+
end match;
509+
end setType;
510+
472511
function restriction
473512
input Class cls;
474513
output Restriction res;
@@ -503,6 +542,11 @@ uniontype Class
503542
output Boolean isConnector = Restriction.isConnector(restriction(cls));
504543
end isConnectorClass;
505544

545+
function isNonexpandableConnectorClass
546+
input Class cls;
547+
output Boolean isConnector = Restriction.isNonexpandableConnector(restriction(cls));
548+
end isNonexpandableConnectorClass;
549+
506550
function isExpandableConnectorClass
507551
input Class cls;
508552
output Boolean isConnector = Restriction.isExpandableConnector(restriction(cls));

Compiler/NFFrontEnd/NFClassTree.mo

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,45 @@ public
400400
tree := FLAT_TREE(ltree, listArray({}), comps, listArray({}), DuplicateTree.EMPTY());
401401
end fromEnumeration;
402402

403+
function addElementsToFlatTree
404+
"Adds a list of class and/or component nodes as elements to a flat class
405+
tree, in the same order as they are listed. Name conflicts will result in
406+
an duplicate element error, and trying to add nodes that are not pure
407+
class or component nodes will result in undefined behaviour."
408+
input list<InstNode> elements;
409+
input output ClassTree tree;
410+
protected
411+
LookupTree.Tree ltree;
412+
array<InstNode> cls_arr, comp_arr;
413+
list<InstNode> cls_lst = {}, comp_lst = {};
414+
array<Import> imports;
415+
DuplicateTree.Tree duplicates;
416+
Integer cls_idx, comp_idx;
417+
LookupTree.Entry lentry;
418+
algorithm
419+
FLAT_TREE(ltree, cls_arr, comp_arr, imports, duplicates) := tree;
420+
cls_idx := arrayLength(cls_arr);
421+
comp_idx := arrayLength(comp_arr);
422+
423+
for e in elements loop
424+
if InstNode.isComponent(e) then
425+
comp_idx := comp_idx + 1;
426+
lentry := LookupTree.Entry.COMPONENT(comp_idx);
427+
comp_lst := e :: comp_lst;
428+
else
429+
cls_idx := cls_idx + 1;
430+
lentry := LookupTree.Entry.CLASS(cls_idx);
431+
cls_lst := e :: cls_lst;
432+
end if;
433+
434+
ltree := addLocalElement(InstNode.name(e), lentry, tree, ltree);
435+
end for;
436+
437+
cls_arr := Array.appendList(cls_arr, listReverseInPlace(cls_lst));
438+
comp_arr := Array.appendList(comp_arr, listReverseInPlace(comp_lst));
439+
tree := FLAT_TREE(ltree, cls_arr, comp_arr, imports, duplicates);
440+
end addElementsToFlatTree;
441+
403442
function expand
404443
"This function adds all local and inherited class and component names to
405444
the lookup tree. Note that only their names are added, the elements

Compiler/NFFrontEnd/NFComplexType.mo

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ public
5050
list<InstNode> potentials;
5151
list<InstNode> flows;
5252
list<InstNode> streams;
53-
Boolean isExpandable;
5453
end CONNECTOR;
5554

55+
record EXPANDABLE_CONNECTOR
56+
list<InstNode> potentiallyPresents;
57+
list<InstNode> expandableConnectors;
58+
end EXPANDABLE_CONNECTOR;
59+
5660
record RECORD
5761
InstNode constructor;
5862
list<String> fieldNames;

Compiler/NFFrontEnd/NFComponent.mo

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import Prefixes = NFPrefixes;
5151
public
5252
constant Component.Attributes DEFAULT_ATTR =
5353
Component.Attributes.ATTRIBUTES(
54-
ConnectorType.POTENTIAL,
54+
ConnectorType.NON_CONNECTOR,
5555
Parallelism.NON_PARALLEL,
5656
Variability.CONTINUOUS,
5757
Direction.NONE,
@@ -98,7 +98,7 @@ constant Component.Attributes CONSTANT_ATTR =
9898

9999
constant Component.Attributes IMPL_DISCRETE_ATTR =
100100
Component.Attributes.ATTRIBUTES(
101-
ConnectorType.POTENTIAL,
101+
ConnectorType.NON_CONNECTOR,
102102
Parallelism.NON_PARALLEL,
103103
Variability.IMPLICITLY_DISCRETE,
104104
Direction.NONE,
@@ -114,7 +114,7 @@ uniontype Component
114114

115115
record ATTRIBUTES
116116
// adrpo: keep the order in DAE.ATTR
117-
ConnectorType connectorType;
117+
ConnectorType.Type connectorType;
118118
Parallelism parallelism;
119119
Variability variability;
120120
Direction direction;
@@ -130,7 +130,7 @@ uniontype Component
130130
output DAE.Attributes outa;
131131
algorithm
132132
outa := DAE.ATTR(
133-
connectorTypeToDAE(ina.connectorType),
133+
ConnectorType.toDAE(ina.connectorType),
134134
parallelismToSCode(ina.parallelism),
135135
variabilityToSCode(ina.variability),
136136
directionToAbsyn(ina.direction),
@@ -147,12 +147,11 @@ uniontype Component
147147
str := (if attr.isRedeclare then "redeclare " else "") +
148148
(if attr.isFinal then "final " else "") +
149149
Prefixes.unparseInnerOuter(attr.innerOuter) +
150-
Prefixes.unparseConnectorType(attr.connectorType) +
151150
Prefixes.unparseReplaceable(attr.isReplaceable) +
152151
Prefixes.unparseParallelism(attr.parallelism) +
152+
ConnectorType.unparse(attr.connectorType) +
153153
Prefixes.unparseVariability(attr.variability, ty) +
154-
Prefixes.unparseDirection(attr.direction) +
155-
Prefixes.unparseConnectorType(attr.connectorType);
154+
Prefixes.unparseDirection(attr.direction);
156155
end toString;
157156
end Attributes;
158157

@@ -647,7 +646,7 @@ uniontype Component
647646

648647
function connectorType
649648
input Component component;
650-
output ConnectorType cty;
649+
output ConnectorType.Type cty;
651650
algorithm
652651
cty := match component
653652
case UNTYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(connectorType = cty)) then cty;
@@ -657,21 +656,45 @@ uniontype Component
657656
end match;
658657
end connectorType;
659658

659+
function setConnectorType
660+
input ConnectorType.Type cty;
661+
input output Component component;
662+
algorithm
663+
() := match component
664+
local
665+
Attributes attr;
666+
667+
case UNTYPED_COMPONENT(attributes = attr)
668+
algorithm
669+
attr.connectorType := cty;
670+
component.attributes := attr;
671+
then
672+
();
673+
674+
case TYPED_COMPONENT(attributes = attr)
675+
algorithm
676+
attr.connectorType := cty;
677+
component.attributes := attr;
678+
then
679+
();
680+
681+
else ();
682+
end match;
683+
end setConnectorType;
684+
660685
function isFlow
661686
input Component component;
662-
output Boolean isFlow = connectorType(component) == ConnectorType.FLOW;
687+
output Boolean isFlow = ConnectorType.isFlow(connectorType(component));
663688
end isFlow;
664689

665690
function isConnector
666691
input Component component;
667-
output Boolean isConnector =
668-
Class.isConnectorClass(InstNode.getDerivedClass(classInstance(component)));
692+
output Boolean isConnector = ConnectorType.isConnectorType(connectorType(component));
669693
end isConnector;
670694

671695
function isExpandableConnector
672696
input Component component;
673-
output Boolean isExpandableConnector =
674-
Class.isExpandableConnectorClass(InstNode.getDerivedClass(classInstance(component)));
697+
output Boolean isConnector = ConnectorType.isExpandable(connectorType(component));
675698
end isExpandableConnector;
676699

677700
function isIdentical

Compiler/NFFrontEnd/NFComponentRef.mo

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,20 @@ public
182182
CREF(ty = ty) := cref;
183183
end nodeType;
184184

185+
function updateNodeType
186+
input output ComponentRef cref;
187+
algorithm
188+
() := match cref
189+
case CREF()
190+
algorithm
191+
cref.ty := InstNode.getType(cref.node);
192+
then
193+
();
194+
195+
else ();
196+
end match;
197+
end updateNodeType;
198+
185199
function firstName
186200
input ComponentRef cref;
187201
output String name;

Compiler/NFFrontEnd/NFConnectEquations.mo

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import Global;
6565
import BuiltinCall = NFBuiltinCall;
6666
import ComplexType = NFComplexType;
6767
import ExpandExp = NFExpandExp;
68+
import Prefixes = NFPrefixes;
6869

6970
constant Expression EQ_ASSERT_STR =
7071
Expression.STRING("Connected constants/parameters must be equal");
@@ -82,6 +83,7 @@ protected
8283
list<Equation> set_eql;
8384
potFunc potfunc;
8485
Expression flowThreshold;
86+
ConnectorType.Type cty;
8587
algorithm
8688
setGlobalRoot(Global.isInStream, NONE());
8789

@@ -91,17 +93,20 @@ algorithm
9193
flowThreshold := Expression.REAL(Flags.getConfigReal(Flags.FLOW_THRESHOLD));
9294

9395
for set in sets loop
94-
set_eql := match getSetType(set)
95-
case ConnectorType.POTENTIAL then potfunc(set);
96-
case ConnectorType.FLOW then generateFlowEquations(set);
97-
case ConnectorType.STREAM then generateStreamEquations(set, flowThreshold);
98-
else
99-
algorithm
100-
Error.addInternalError("Invalid connector type on set "
101-
+ List.toString(set, Connector.toString, "", "{", ", ", "}", true), sourceInfo());
102-
then
103-
fail();
104-
end match;
96+
cty := getSetType(set);
97+
98+
if ConnectorType.isPotential(cty) then
99+
set_eql := potfunc(set);
100+
elseif ConnectorType.isFlow(cty) then
101+
set_eql := generateFlowEquations(set);
102+
elseif ConnectorType.isStream(cty) then
103+
set_eql := generateStreamEquations(set, flowThreshold);
104+
else
105+
Error.addInternalError(getInstanceName() + " got connection set with invalid type '" +
106+
ConnectorType.toDebugString(cty) + "': " +
107+
List.toString(set, Connector.toString, "", "{", ", ", "}", true), sourceInfo());
108+
fail();
109+
end if;
105110

106111
equations := listAppend(set_eql, equations);
107112
end for;
@@ -155,7 +160,7 @@ end evaluateOperators;
155160
protected
156161
function getSetType
157162
input list<Connector> set;
158-
output ConnectorType cty;
163+
output ConnectorType.Type cty;
159164
algorithm
160165
// All connectors in a set should have the same type, so pick the first.
161166
Connector.CONNECTOR(cty = cty) :: _ := set;

Compiler/NFFrontEnd/NFConnection.mo

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,12 @@ public
4141
NFConnector rhs;
4242
end CONNECTION;
4343

44+
function toString
45+
input Connection conn;
46+
output String str;
47+
algorithm
48+
str := "connect(" + Connector.toString(conn.lhs) + ", " + Connector.toString(conn.rhs) + ")";
49+
end toString;
50+
4451
annotation(__OpenModelica_Interface="frontend");
4552
end NFConnection;

Compiler/NFFrontEnd/NFConnectionSets.mo

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ package ConnectionSets
132132
// when collecting the connections, but if the connectors themselves
133133
// contain connectors that have been deleted we need to remove them here.
134134
if not (Connector.isDeleted(c1) or Connector.isDeleted(c2)) then
135+
// TODO: Check variability of connectors. It's an error if either
136+
// connector is constant/parameter while the other isn't.
137+
135138
if listEmpty(broken) then
136139
sets := merge(c1, c2, sets);
137140
elseif isBroken(c1, c2, broken) then

Compiler/NFFrontEnd/NFConnections.mo

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ public
6060
output Connections conns = CONNECTIONS({}, {}, {});
6161
end new;
6262

63+
function fromConnectionList
64+
input list<Connection> connl;
65+
output Connections conns;
66+
algorithm
67+
conns := CONNECTIONS(connl, {}, {});
68+
end fromConnectionList;
69+
6370
function addConnection
6471
input Connection conn;
6572
input output Connections conns;

0 commit comments

Comments
 (0)