Opened 6 years ago
Closed 6 years ago
#5075 closed defect (duplicate)
Package names flattened incorrectly by the NF within function bodies
Reported by: | Francesco Casella | Owned by: | Per Östlund |
---|---|---|---|
Priority: | high | Milestone: | 2.0.0 |
Component: | New Instantiation | Version: | |
Keywords: | Cc: |
Description
Please check Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater. The model flattened with the old FE contains the following function
function Modelica.Fluid.Examples.AST_BatchPlant.BaseClasses.InnerTank$B5$InnerTankSide.Medium.setState_pTX "Inline before index reduction" "Return thermodynamic state of water as function of p, T, and optional region" input Real p(quantity = "Pressure", unit = "Pa", displayUnit = "bar", min = 611.657, max = 100000000.0, start = 5000000.0, nominal = 1000000.0) "Pressure"; input Real T(quantity = "ThermodynamicTemperature", unit = "K", displayUnit = "degC", min = 273.15, max = 2273.15, start = 500.0, nominal = 500.0) "Temperature"; input Real[:] X(quantity = "MassFraction", unit = "kg/kg", min = 0.0, max = 1.0, nominal = 0.1) = {1.0} "Mass fractions"; output Modelica.Fluid.Examples.AST_BatchPlant.BaseClasses.InnerTank$B5$InnerTankSide.Medium.ThermodynamicState state "Thermodynamic state record"; input Integer phase(min = 0, max = 2) = 0 "2 for two-phase, 1 for one-phase, 0 if not known"; input Integer region = 0 "If 0, region is unknown, otherwise known and this input"; algorithm state := Modelica.Fluid.Examples.AST_BatchPlant.BaseClasses.InnerTank$B5$InnerTankSide.Medium.ThermodynamicState(1, Modelica.Fluid.Examples.AST_BatchPlant.BaseClasses.InnerTank$B5$InnerTankSide.Medium.specificEnthalpy_pT(p, T, 0, region), Modelica.Fluid.Examples.AST_BatchPlant.BaseClasses.InnerTank$B5$InnerTankSide.Medium.density_pT(p, T, 0, region), T, p); end Modelica.Fluid.Examples.AST_BatchPlant.BaseClasses.InnerTank$B5$InnerTankSide.Medium.setState_pTX;
whereas the NF renders this as
function Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.volume4.Medium.setState_pTX "Inline before index reduction" "Return thermodynamic state of water as function of p, T, and optional region" input Real p(quantity = "Pressure", unit = "Pa", displayUnit = "bar", min = 611.657, max = 100000000.0, start = 5000000.0, nominal = 1000000.0) "Pressure"; input Real T(quantity = "ThermodynamicTemperature", unit = "K", displayUnit = "degC", min = 273.15, max = 2273.15, start = 500.0, nominal = 500.0) "Temperature"; input Real[:] X = {1.0} "Mass fractions"; input Integer phase(min = 0, max = 2) = 0 "2 for two-phase, 1 for one-phase, 0 if not known"; input Integer region = 0 "If 0, region is unknown, otherwise known and this input"; output volume4.Medium.ThermodynamicState state "Thermodynamic state record"; algorithm state := Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.volume4.Medium.ThermodynamicState(1, Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.volume4.Medium.specificEnthalpy_pT(p, T, 0, region), Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.volume4.Medium.density_pT(p, T, 0, region), T, p); end Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.volume4.Medium.setState_pTX;
which causes the generation of incorrect C code that fails to compile.
I understand all paths beginning with Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.volume4
should instead begin with Modelica.Fluid.Examples.AST_BatchPlant.BaseClasses.InnerTank$B5$InnerTankSide
Change History (11)
comment:1 by , 6 years ago
comment:2 by , 6 years ago
No. The NF uses the instance hierarchy to make functions unique while the current frontend is doing it a bit differently creating unique scopes with $
sign. The problem surely lies someplace else.
comment:3 by , 6 years ago
There seems to be a problem with the automatically generated record constructors: in some places they are fully qualified, in others they are not.
In Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater_functions.h
DLLExport volume4_Medium_ThermodynamicState omc_volume4_Medium_ThermodynamicState (threadData_t *threadData, modelica_integer omc_phase, modelica_real omc_h, modelica_real omc_d, modelica_real omc_T, modelica_real omc_p); typedef B5_Medium_ThermodynamicState volume4_Medium_ThermodynamicState;
In Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater_functions.c it appears
both fully qualified and not fully qualified:
Modelica_Fluid_Examples_AST__BatchPlant_BatchPlant__StandardWater_volume4_Medium_ThermodynamicState tmp1; volume4_Medium_ThermodynamicState _state;
Same thing happens in the instantiateModel.
comment:4 by , 6 years ago
As far as I can tell in the function calls the record constructors are fully qualified, in the function output the type name of the record is not fully qualified.
follow-up: 7 comment:5 by , 6 years ago
Some fix attempt in PR: https://github.com/OpenModelica/OMCompiler/pull/2616
In the DAE we have:
function Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.Medium.setState_phX "Inline before index reduction" "Return thermodynamic state of water as function of p, h, and optional region" input Real p(quantity = "Pressure", unit = "Pa", displayUnit = "bar", min = 611.657, max = 100000000.0, start = 5000000.0, nominal = 1000000.0) "Pressure"; input Real h(quantity = "SpecificEnergy", unit = "J/kg", min = -10000000000.0, max = 10000000000.0, start = 100000.0, nominal = 500000.0) "Specific enthalpy"; input Real[:] X = {1.0} "Mass fractions"; input Integer phase(min = 0, max = 2) = 0 "2 for two-phase, 1 for one-phase, 0 if not known"; input Integer region = 0 "If 0, region is unknown, otherwise known and this input"; output Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.B5.Medium.ThermodynamicState state "Thermodynamic state record"; algorithm state := Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.volume4.Medium.ThermodynamicState(if region == 0 then 0 else if region == 4 then 2 else 1, h, Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.Medium.density_ph(p, h, 0, region), Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.Medium.temperature_ph(p, h, 0, region), p); annotation(Inline = true); end Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.Medium.setState_phX; // equation V3.state_b = Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.Medium.setState_phX(V3.port_b.p, V3.port_b.h_outflow, array(V3.port_b.Xi_outflow[$i1] for $i1 in 1:0), 0, 0);
In the generated equation we get:
/* equation index: 3819 type: ALGORITHM V3.state_b := Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater.Medium.setState_phX(B1.p_ambient, V3.port_b.h_outflow, {}, 0, 0); */ void Modelica_Fluid_Examples_AST_BatchPlant_BatchPlant_StandardWater_eqFunction_3819(DATA *data, threadData_t *threadData) { TRACE_PUSH const int equationIndexes[2] = {1,3819}; base_array_t tmp51; Modelica_Fluid_Examples_AST__BatchPlant_BatchPlant__StandardWater_Medium_ThermodynamicState tmp52; simple_alloc_1d_base_array(&tmp51, 0, NULL); tmp52 = omc_Modelica_Fluid_Examples_AST__BatchPlant_BatchPlant__StandardWater_Medium_setState__phX(threadData, data->simulationInfo->realParameter[12], data->localData[0]->realVars[1486] /* V3.port_b.h_outflow variable */, tmp51, ((modelica_integer) 0), ((modelica_integer) 0)); data->localData[0]->integerVars[124] /* V3.state_b.phase DISCRETE */ = tmp52._phase; data->localData[0]->realVars[1494] /* V3.state_b.h variable */ = tmp52._h; data->localData[0]->realVars[1493] /* V3.state_b.d variable */ = tmp52._d; data->localData[0]->realVars[1492] /* V3.state_b.T variable */ = tmp52._T; data->localData[0]->realVars[1495] /* V3.state_b.p variable */ = tmp52._p; TRACE_POP }
which refers to a non existing record type Modelica_Fluid_Examples_AST__BatchPlant_BatchPlant__StandardWater_Medium_ThermodynamicState
.
comment:6 by , 6 years ago
I guess we need to generate more record constructors and we should probably have an analysis to check if the records are basically the same, even if their actual scope is different.
comment:7 by , 6 years ago
Replying to adrpo:
Some fix attempt in PR: https://github.com/OpenModelica/OMCompiler/pull/2616
The whole handling of functions and record constructors needs to be redesigned, because currently they're shared in many places where they shouldn't be shared. That's why you get missing constructors sometimes, because the wrong constructors are reused and the correct ones are newer generated. Prefixing the names with the root class will probably not do much, but you can always try it and see what happens.
comment:9 by , 6 years ago
The compilation now fails at the beginning of the back-end operations wit
[/var/lib/hudson/slave/workspace/OpenModelica_TEST_LIBS/OpenModelica/OMCompiler/build/lib/omlibrary/Modelica trunk/Fluid/Pipes.mo:262:7-262:90:writable] Error: Assertion triggered during translation: "Parameter length must be greater or equal height_ab.".
Not sure what the root cause still is.
comment:11 by , 6 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
See also #5019