Skip to content

Commit

Permalink
Preserve dimensions when augmenting expandable connector (#9867)
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed Dec 6, 2022
1 parent 2f98c48 commit c55c8cc
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFExpandableConnectors.mo
Expand Up @@ -88,6 +88,7 @@ algorithm
csets := ConnectionSets.emptySets(listLength(expandable_conns) + listLength(undeclared_conns));
csets := addExpandableConnectorsToSets(expandable_conns, csets);
(undeclared_conns, csets) := List.mapFold(undeclared_conns, addUndeclaredConnectorToSets, csets);

// Extract the sets of connected connectors.
csets_array := ConnectionSets.extractSets(csets);

Expand Down Expand Up @@ -423,6 +424,7 @@ algorithm
// Create a normal non-expandable complex type for the augmented expandable connector.
complex_ty := Typing.makeConnectorType(cls_tree, isExpandable = false);
ty := Type.COMPLEX(cls_node, complex_ty);
ty := Type.liftArrayLeftList(ty, Type.arrayDims(InstNode.getType(exp_node)));
cls := Class.setType(ty, cls);
InstNode.updateClass(cls, cls_node);
InstNode.componentApply(exp_node, Component.setType, ty);
Expand Down
69 changes: 69 additions & 0 deletions testsuite/flattening/modelica/scodeinst/ExpandableConnector9.mo
@@ -0,0 +1,69 @@
// name: ExpandableConnector9
// keywords: expandable connector
// status: correct
// cflags: -d=newInst
//
//

expandable connector CellBus
Real lossPower;
end CellBus;

expandable connector StackBus
CellBus[3, 2] cellBus;
end StackBus;

model HeatFlowSensor
connector RealOutput = output Real;
RealOutput Q_flow;
end HeatFlowSensor;

model Cell
HeatFlowSensor heatFlowSensor;
CellBus cellBus2;
equation
connect(heatFlowSensor.Q_flow, cellBus2.lossPower);
end Cell;

model ExpandableConnector9
replaceable Cell[3, 2] cell;
StackBus stackBus;
equation
connect(cell.cellBus2, stackBus.cellBus);
end ExpandableConnector9;

// Result:
// class ExpandableConnector9
// Real cell[1,1].heatFlowSensor.Q_flow;
// Real cell[1,1].cellBus2.lossPower;
// Real cell[1,2].heatFlowSensor.Q_flow;
// Real cell[1,2].cellBus2.lossPower;
// Real cell[2,1].heatFlowSensor.Q_flow;
// Real cell[2,1].cellBus2.lossPower;
// Real cell[2,2].heatFlowSensor.Q_flow;
// Real cell[2,2].cellBus2.lossPower;
// Real cell[3,1].heatFlowSensor.Q_flow;
// Real cell[3,1].cellBus2.lossPower;
// Real cell[3,2].heatFlowSensor.Q_flow;
// Real cell[3,2].cellBus2.lossPower;
// Real stackBus.cellBus[1,1].lossPower;
// Real stackBus.cellBus[1,2].lossPower;
// Real stackBus.cellBus[2,1].lossPower;
// Real stackBus.cellBus[2,2].lossPower;
// Real stackBus.cellBus[3,1].lossPower;
// Real stackBus.cellBus[3,2].lossPower;
// equation
// cell[1,1].heatFlowSensor.Q_flow = cell[1,1].cellBus2.lossPower;
// cell[1,2].heatFlowSensor.Q_flow = cell[1,2].cellBus2.lossPower;
// cell[2,1].heatFlowSensor.Q_flow = cell[2,1].cellBus2.lossPower;
// cell[2,2].heatFlowSensor.Q_flow = cell[2,2].cellBus2.lossPower;
// cell[3,1].heatFlowSensor.Q_flow = cell[3,1].cellBus2.lossPower;
// cell[3,2].heatFlowSensor.Q_flow = cell[3,2].cellBus2.lossPower;
// cell[1,1].cellBus2.lossPower = stackBus.cellBus[1,1].lossPower;
// cell[1,2].cellBus2.lossPower = stackBus.cellBus[1,2].lossPower;
// cell[2,1].cellBus2.lossPower = stackBus.cellBus[2,1].lossPower;
// cell[2,2].cellBus2.lossPower = stackBus.cellBus[2,2].lossPower;
// cell[3,1].cellBus2.lossPower = stackBus.cellBus[3,1].lossPower;
// cell[3,2].cellBus2.lossPower = stackBus.cellBus[3,2].lossPower;
// end ExpandableConnector9;
// endResult
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/scodeinst/Makefile
Expand Up @@ -418,6 +418,7 @@ ExpandableConnector5.mo \
ExpandableConnector6.mo \
ExpandableConnector7.mo \
ExpandableConnector8.mo \
ExpandableConnector9.mo \
ExpandableConnectorFlow1.mo \
ExpandableConnectorFlow2.mo \
ExpandableConnectorNonDecl1.mo \
Expand Down

0 comments on commit c55c8cc

Please sign in to comment.