Skip to content

Commit 7388aef

Browse files
committed
[NF] Improve expandable connectors.
- Handle expandable connectors in complex arrays better.
1 parent 6fed5ce commit 7388aef

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

OMCompiler/Compiler/NFFrontEnd/NFExpandableConnectors.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ algorithm
391391
end if;
392392

393393
cls_node := InstNode.classScope(exp_node);
394+
cls_node := InstNode.clone(cls_node);
394395
cls := InstNode.getClass(cls_node);
395396
cls_tree := Class.classTree(cls);
396397

@@ -418,7 +419,6 @@ algorithm
418419
ElementSource.getInfo(c.source));
419420
vars := var :: vars;
420421
else
421-
comp_node := ClassTree.lookupElement(InstNode.name(node), cls_tree);
422422
comp_node := InstNode.resolveInner(comp_node);
423423

424424
if InstNode.isComponent(comp_node) then

OMCompiler/Compiler/NFFrontEnd/NFInstNode.mo

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,7 @@ uniontype InstNode
16001600
() := match node
16011601
local
16021602
Class cls;
1603+
Component comp;
16031604

16041605
case CLASS_NODE()
16051606
algorithm
@@ -1610,6 +1611,14 @@ uniontype InstNode
16101611
then
16111612
();
16121613

1614+
case COMPONENT_NODE()
1615+
algorithm
1616+
comp := Pointer.access(node.component);
1617+
comp := Component.setClassInstance(InstNode.clone(Component.classInstance(comp)), comp);
1618+
node.component := Pointer.create(comp);
1619+
then
1620+
();
1621+
16131622
else ();
16141623
end match;
16151624
end clone;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// name: ExpandableConnector4
2+
// keywords: expandable connector
3+
// status: correct
4+
// cflags: -d=newInst
5+
//
6+
//
7+
8+
expandable connector EC
9+
end EC;
10+
11+
model A
12+
connector RealOutput = output Real;
13+
RealOutput y = 0;
14+
EC ec;
15+
equation
16+
connect(ec.y, y);
17+
end A;
18+
19+
model ExpandableConnector4
20+
A a[3];
21+
end ExpandableConnector4;
22+
23+
// Result:
24+
// class ExpandableConnector4
25+
// Real a[3].ec.y "virtual variable in expandable connector";
26+
// Real a[2].ec.y "virtual variable in expandable connector";
27+
// Real a[1].ec.y "virtual variable in expandable connector";
28+
// Real a[1].y = 0.0;
29+
// Real a[2].y = 0.0;
30+
// Real a[3].y = 0.0;
31+
// equation
32+
// a[1].ec.y = a[1].y;
33+
// a[2].ec.y = a[2].y;
34+
// a[3].ec.y = a[3].y;
35+
// end ExpandableConnector4;
36+
// endResult

testsuite/flattening/modelica/scodeinst/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ EvaluateAllParams2.mo \
352352
ExpandableConnector1.mo \
353353
ExpandableConnector2.mo \
354354
ExpandableConnector3.mo \
355+
ExpandableConnector4.mo \
355356
ExpandableConnectorFlow1.mo \
356357
ExpandableConnectorFlow2.mo \
357358
ExpandableConnectorNonDecl1.mo \

0 commit comments

Comments
 (0)