Opened 11 years ago

Last modified 5 years ago

#2385 reopened defect

Missing variable declarations in instantiated model when using expandable connectors

Reported by: carlj@… Owned by: adrpo
Priority: high Milestone: 2.0.0
Component: New Instantiation Version: trunk
Keywords: Cc: petar

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 Changed 11 years ago by adrpo

  • Owner changed from somebody to adrpo
  • Status changed from new to assigned

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.

comment:2 Changed 11 years ago by adrpo

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixed in r17521.

comment:3 Changed 11 years ago by adrpo

Properly fixed in r17523 as it was more complicated than I thought.

comment:4 Changed 11 years ago by adrpo

  • Cc petar added
  • Resolution fixed deleted
  • Status changed from closed to 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 Changed 11 years ago by carlj@…

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 Changed 11 years ago by adrpo

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:7 Changed 11 years ago by sjoelund.se

  • Milestone changed from 1.9.0 to 1.9.1

Postponed until 1.9.1

comment:8 Changed 11 years ago by carlj@…

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 Changed 11 years ago by adrpo

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 Changed 10 years ago by adrpo

Partial fixes in r17890. Provide correct dimensions for virtual component in the DAE.

comment:11 Changed 10 years ago by adrpo

Note that if your back-end can handle unexpanded arrays in the DAE then this problem is already fixed.

comment:12 Changed 10 years ago by choeger

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).

Last edited 10 years ago by adrpo (previous) (diff)

comment:13 Changed 10 years ago by adrpo

  • Resolution set to fixed
  • Status changed from reopened to closed

Fixed in r18699. Array elements virtually added to expandable connectors are expanded.

comment:14 Changed 5 years ago by GeRo

  • Component changed from Frontend to New Instantiation
  • Milestone changed from 1.9.1 to 1.14.0
  • omc_version set to v1.14.0-dev-234-g5ef43cce8 (64-bit)
  • Resolution fixed deleted
  • Status changed from closed to reopened

Original Description valid for 0.14.0-dev-234 running with flag: "-d=newInst".

comment:15 Changed 5 years ago by casella

  • Milestone changed from 1.14.0 to 2.0.0
Note: See TracTickets for help on using tickets.