Opened 11 years ago
Last modified 6 years ago
#2385 reopened defect
Missing variable declarations in instantiated model when using expandable connectors
Reported by: | Owned by: | Adrian Pop | |
---|---|---|---|
Priority: | high | Milestone: | 2.0.0 |
Component: | New Instantiation | Version: | trunk |
Keywords: | Cc: | Peter Aronsson |
Description
Instantiating ExpandableArrayTest.Test below
package ExpandableArrayTest expandable connector B Real x; end B; block Bsource output B bout; equation bout.x = sin(time); end Bsource; model Areceiver input B bin; Real y; equation y = 2 * bin.x; end Areceiver; model Test Areceiver a1; Bsource b1; equation connect(b1.bout,a1.bin); end Test; end ExpandableArrayTest;
yields the following:
class ExpandableArrayTest.Test Real a1.y; equation a1.y = 2.0 * a1.bin.x; b1.bout.x = sin(time); end ExpandableArrayTest.Test;
where b1.bout.x and a1.bin.x are used in the equations but have no variable declaration.
If one removes the expandable qualifier for B the instantiated model is ok:
class ExpandableArrayTest.Test input Real a1.bin.x; Real a1.y; output Real b1.bout.x; equation a1.y = 2.0 * a1.bin.x; b1.bout.x = sin(time); a1.bin.x = b1.bout.x; end ExpandableArrayTest.Test;
Change History (15)
comment:1 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 11 years ago
Cc: | added |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
This is not allowed by the specification.
See https://trac.modelica.org/Modelica/ticket/1312
I'll change OpenModelica to not allow it either and report an error.
comment:5 by , 11 years ago
So, if I am interpreting this correctly, this means that for every element of an expandable connector, there has to be a connect equation to that element?
comment:6 by , 11 years ago
Simply Yes. In the case where there is a connect for the parent then this is implicit for the children.
If there is no connect equation for that element then the element is not marked as present.
If you have a binding equation for the element but not a connect equation for it then it
is an error.
comment:8 by , 11 years ago
Okay, let's try this again. I hope that this time the model is valid and that I have found an actual error. This was tested with the latest OpenModelica.
When instantiating the model ConnectorTest.Test below, the variables
As.aout.bx[1], As.aout.bx[2], Au.ain.bx[1], Au.ain.bx[2]
have no declarations but are used in equations. However, there are declarations
Real As.aout.bx; Real Au.ain.bx;
So the important thing here seems to be that bx is an array. If bx is changed to be a non-array variable, the instantiation works fine.
Using a slightly older version of the frontend the declarations of As.aout.ax and Au.ain.ax were not there, so I guess the problem is almost fixed. :)
package ConnectorTest expandable connector A Real ax; end A; expandable connector B Real bx[2]; end B; model Bsource output B bout; Real genx[2](each start = 1.0); equation connect(genx,bout.bx); genx[1] = sin(time); genx[2] = genx[1]*genx[1]; end Bsource; model Busage input B bin; Real bx[2],bx2[2]; equation connect(bx,bin.bx); bx2[1] = 2.0 * bx[1]; bx2[2] = 3.0 * bx[2]; end Busage; model Asource output A aout; Real ax; equation connect(ax,aout.ax); ax = cos(time); end Asource; model Ausage input A ain; Real ax,ax2; equation connect(ain.ax,ax); ax2 = 2.0 * ax; end Ausage; model Test Bsource Bs; Busage Bu; Asource As; Ausage Au; B Bcon; equation connect(Bs.bout,Bcon); connect(As.aout,Bcon); connect(Bcon,Bu.bin); connect(Bcon,Au.ain); end Test; end ConnectorTest;
comment:9 by , 11 years ago
We do have the declarations for the bx array:
Real As.aout.bx "virtual variable in expandable connector"; Real Au.ain.bx "virtual variable in expandable connector";
the only problem is that the array elements of bx are not expanded.
Their type is however correct in the DAE (bx has dimension 2).
I'll see if I can get these expanded to:
Real As.aout.bx[1] "virtual variable in expandable connector"; Real As.aout.bx[2] "virtual variable in expandable connector"; Real Au.ain.bx[1] "virtual variable in expandable connector"; Real Au.ain.bx[2] "virtual variable in expandable connector";
because that's the only missing thing right now.
Cheers,
Adrian Pop/
comment:10 by , 11 years ago
Partial fixes in r17890. Provide correct dimensions for virtual component in the DAE.
comment:11 by , 11 years ago
Note that if your back-end can handle unexpanded arrays in the DAE then this problem is already fixed.
comment:12 by , 11 years ago
This might be something for your test suite:
model Test import Modelica.Constants.small; expandable connector Bus end Bus; expandable connector SubBus end SubBus; connector C Real x; end C; model Component1 Bus bus; SubBus subBus; C c; equation connect(bus.subBus, subBus); connect(subBus.c, c); c.x = 42; end Component1; Component1 component; C c; Bus bus; equation connect(bus, component.bus); connect(bus.subBus, component.bus.subBus); connect(c, bus.subBus.c); end Test;
Results in (1.9.0 (r17628)):
class Test Real component.c.x; Real c.x; equation component.c.x = 42.0; component.c.x = component.subBus.c.x; bus.subBus.c.x = c.x; bus.subBus.c.x = component.bus.subBus.c.x; end Test;
See also #2484 (adrpo).
comment:13 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Fixed in r18699. Array elements virtually added to expandable connectors are expanded.
comment:14 by , 6 years ago
Component: | Frontend → New Instantiation |
---|---|
Milestone: | 1.9.1 → 1.14.0 |
omc_version: | → v1.14.0-dev-234-g5ef43cce8 (64-bit) |
Resolution: | fixed |
Status: | closed → reopened |
Original Description valid for 0.14.0-dev-234 running with flag: "-d=newInst".
comment:15 by , 6 years ago
Milestone: | 1.14.0 → 2.0.0 |
---|
I know about this bug. We remove any declarations from the expandable connector as is not clear which prefix they should have. I'll look into it.