Opened 7 years ago
Closed 6 years ago
#4541 closed defect (fixed)
connect last array element using [end]
Reported by: | Owned by: | Adrian Pop | |
---|---|---|---|
Priority: | high | Milestone: | 2.1.0 |
Component: | New Instantiation | Version: | |
Keywords: | Cc: | Per Östlund |
Description
I took the example Modelica.Electrical.Analog.Examples.HeatingResistor and removed the graphical part and renamed it, this gives me:
model End_connect Modelica.Electrical.Analog.Basic.HeatingResistor heatingResistor(R_ref=100, alpha=1e-3, T_ref=293.15, i(start=0)); Modelica.Electrical.Analog.Basic.Ground G; Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage1(V=220, freqHz=1); Modelica.Thermal.HeatTransfer.Components.ThermalConductor thermalConductor(G=50); Modelica.Thermal.HeatTransfer.Celsius.FixedTemperature fixedTemperature(T=20); equation connect(SineVoltage1.n, G.p); connect(heatingResistor.heatPort, thermalConductor.port_a); connect(SineVoltage1.p, heatingResistor.p); connect(G.p, heatingResistor.n); connect(thermalConductor.port_b, fixedTemperature.port); annotation (experiment(StopTime=5)); end End_connect;
This checks, translates and simulates just fine.
Now, I made every component an array and connect them as below:
model End_connect parameter Integer nEle=5; Modelica.Electrical.Analog.Basic.HeatingResistor heatingResistor[nEle](each R_ref=100, each alpha=1e-3, each T_ref=293.15, each i(start=0)); Modelica.Electrical.Analog.Basic.Ground G[nEle]; Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage1[nEle](each V=220, each freqHz=1); Modelica.Thermal.HeatTransfer.Components.ThermalConductor thermalConductor[nEle](each G=50); Modelica.Thermal.HeatTransfer.Celsius.FixedTemperature fixedTemperature[nEle](each T=20); equation // connect first connect(SineVoltage1[1].n, G[1].p); connect(heatingResistor[1].heatPort, thermalConductor[1].port_a); connect(SineVoltage1[1].p, heatingResistor[1].p); connect(G[1].p, heatingResistor[1].n); connect(thermalConductor[1].port_b, fixedTemperature[1].port); // connect middle for i in 2:nEle-1 loop connect(SineVoltage1[i].n, G[i].p); connect(heatingResistor[i].heatPort, thermalConductor[i].port_a); connect(SineVoltage1[i].p, heatingResistor[i].p); connect(G[i].p, heatingResistor[i].n); connect(thermalConductor[i].port_b, fixedTemperature[i].port); end for; //connect last connect(SineVoltage1[end].n, G[end].p); connect(heatingResistor[end].heatPort, thermalConductor[end].port_a); connect(SineVoltage1[end].p, heatingResistor[end].p); connect(G[end].p, heatingResistor[end].n); connect(thermalConductor[end].port_b, fixedTemperature[end].port); annotation (experiment(StopTime=5)); end End_connect;
This checks, translates and simulates just fine in Dymola, but not in OpenModelica.
Is this syntax wrong and should be fixed in my model? How?
Or is it a bug in OpenModelica?
Note: The same error appears e.g. here:
https://libraries.openmodelica.org/branches/master/BuildingSystems/files/BuildingSystems_BuildingSystems.Technologies.ThermalStorages.Examples.FluidStorage.err
Change History (8)
comment:1 by , 7 years ago
Cc: | added |
---|---|
Component: | *unknown* → Frontend |
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 7 years ago
@perost just showed me a 3.4 spec draft where they are parameter expressions. So yes, this seems to be an OM bug.
comment:3 by , 7 years ago
Thanks for clarifying.
The link to th eModelica trac is broken, this is a working one:
https://trac.modelica.org/Modelica/ticket/2206
https://trac.modelica.org/Modelica/ticket/1082
Relevant sections in the 3.4 Spec:
section 3.8.2 and section 10.5.2
https://modelica.org/news_items/release_of_modelica_3_4
https://modelica.org/documents/ModelicaSpec34.pdf
comment:4 by , 7 years ago
We re-wrote the one single model in our library that used [end] in connect equations (which was easy, because the arrays were declared using a variable already).
Leaving this ticket open though, assuming you want to support usage of [end] in connect equations in the future.
comment:5 by , 7 years ago
Found another model with the same error message here:
https://libraries.openmodelica.org/branches/master/BuildingSystems/files/BuildingSystems_BuildingSystems.Technologies.SolarThermal.Examples.BigCollectorInstallationWithStorage.err
That is now also rewritten.
comment:6 by , 7 years ago
Component: | Frontend → New Instantiation |
---|---|
Milestone: | Future → 2.0.0 |
comment:7 by , 6 years ago
Milestone: | 2.0.0 → 2.1.0 |
---|
comment:8 by , 6 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Using end
in connect equations works just fine in the new frontend, so I guess this can be considered fixed.
But
end
is not a parameter expression according to the specification (seems to be an error). Neither issize(X,N)
, but that works if you want something equivalent in your model (although more clunky to write).Implementation note: The problem is that connectors use some special function instead of the general-purpose expression elaboration (I assume for performance reasons), and Expression.fromAbsynExp cannot represent
end
in any meaningful way since it needs type information to be evaluated (which this function lacks)... It could be represented bysize(X,N)
here (but only if the name of the variable and the dimension were passed along and the dimension has integer size).I created m:#2206 to clarify what is allowed in the spec.