#6303 closed defect (fixed)
Issue with records in Chemical library
Reported by: | Francesco Casella | Owned by: | Per Östlund |
---|---|---|---|
Priority: | blocker | Milestone: | 1.17.0 |
Component: | New Instantiation | Version: | 1.16.0 |
Keywords: | Cc: | Karim Adbdelhak, Mahder Alemseged Gebremedhin, matejak.marek@… |
Description
There are several test cases failing in the Chemical library, see, e.g., Chemical.Examples.EnzymeKinetics, that fail for the same reason:
Chemical_Chemical.Examples.EnzymeKinetics.c:149:3: error: use of undeclared identifier \'P_stateOfMatter_SubstanceData\'\n P_stateOfMatter_SubstanceData tmp1;
The flattened model shows the default constructor function
function Chemical.Examples.EnzymeKinetics.P.stateOfMatter.SubstanceData "Automatically generated record constructor for Chemical.Examples.EnzymeKinetics.P.stateOfMatter.SubstanceData" input Real MolarWeight = 0.01801528; input Real z = 0.0; input Real DfG = 0.0; input Real DfH = 0.0; input Real gamma = 1.0; input Real Cp = 0.0; input String[1] References = {""}; input Real DfG_25degC_1bar = 0.0; input Real DfH_25degC = 0.0; input Boolean SelfClustering = false; input Real SelfClustering_dH = 0.0; input Real SelfClustering_dS = 0.0; input Real density = 1000.0; output SubstanceData res; end Chemical.Examples.EnzymeKinetics.P.stateOfMatter.SubstanceData;
maybe something goes wrong because it contains an array of Strings which is still unsupported?
Change History (7)
comment:1 by , 4 years ago
Component: | Code Generation → New Instantiation |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 4 years ago
Priority: | high → blocker |
---|
comment:3 by , 4 years ago
Cc: | added |
---|
Here are some more clues I got on Windows with the latest nightly build. When flattening the model with the NF, I get
P.molarEntropyPure = Chemical.Examples.EnzymeKinetics.P.stateOfMatter.molarEntropyPure( P.stateOfMatter.SubstanceData(0.01801528, 0.0, -123947.8094685, 0.0, 1.0, 0.0, {""}, 0.0, 0.0, false, 0.0, 0.0, 1000.0), P.temperature, P.pressure, P.electricPotential, P.moleFractionBasedIonicStrength, {});
and subsequently this C-code
/* equation index: 210 type: SIMPLE_ASSIGN P.molarEntropyPure = Chemical.Examples.EnzymeKinetics.P.stateOfMatter.molarEntropyPure(P.stateOfMatter.SubstanceData(0.01801528, 0.0, -123947.8094685, 0.0, 1.0, 0.0, {""}, 0.0, 0.0, false, 0.0, 0.0, 1000.0), solution.temperature, solution.BasePressure, 0.0, 0.0, {}) */ void Chemical_Examples_EnzymeKinetics_eqFunction_210(DATA *data, threadData_t *threadData) { TRACE_PUSH const int equationIndexes[2] = {1,210}; P_stateOfMatter_SubstanceData tmp0;
which gives trouble because P.stateOfMatter.SubstanceData
is not defined, while Chemical.Examples.EnzymeKinetics.P.stateOfMatter.SubstanceData
is. I guess the flat code should instead be:
P.molarEntropyPure = Chemical.Examples.EnzymeKinetics.P.stateOfMatter.molarEntropyPure( Chemical.Examples.EnzymeKinetics.P.stateOfMatter.SubstanceData( 0.01801528, 0.0, -123947.8094685, 0.0, 1.0, 0.0, {""}, 0.0, 0.0, false, 0.0, 0.0, 1000.0), P.temperature, P.pressure, P.electricPotential, P.moleFractionBasedIonicStrength, {});
When using the OF, the flat model is
P.molarEntropyPure = Chemical.Components.Substance$P.stateOfMatter.molarEntropyPure( /*.Chemical.Components.Substance$P.stateOfMatter.SubstanceData*/(P.substanceData), P.temperature, P.pressure, P.electricPotential, P.moleFractionBasedIonicStrength, {});
leading to this C-code
/* equation index: 416 type: SIMPLE_ASSIGN P.molarEntropyPure = Chemical.Components.Substance$P.stateOfMatter.molarEntropyPure((*.Chemical.Components.Substance$P.stateOfMatter.SubstanceData*)(P.substanceData), solution.temperature, solution.BasePressure, 0.0, E.solution.I, {}) */ void Chemical_Examples_EnzymeKinetics_eqFunction_416(DATA *data, threadData_t *threadData) { TRACE_PUSH const int equationIndexes[2] = {1,416}; string_array tmp43; string_array_create(&tmp43, ((modelica_string*)&((&data->simulationInfo->stringParameter[2] /* P.substanceData.References[1] PARAM */)[calc_base_index_dims_subs(1, 1, ((modelica_integer) 1))])), 1, 1); data->localData[0]->realVars[166] /* P.molarEntropyPure variable */ = omc_Chemical_Components__omcQSubstance_24P_stateOfMatter_molarEntropyPure(threadData, omc_Chemical_Components__omcQSubstance_24P_stateOfMatter__omcQSubstanceData_24P_24substanceData(threadData, data->simulationInfo->realParameter[59] /* P.substanceData.MolarWeight PARAM */, data->simulationInfo->realParameter[64] /* P.substanceData.z PARAM */, data->simulationInfo->realParameter[55] /* P.substanceData.DfG PARAM */, data->simulationInfo->realParameter[57] /* P.substanceData.DfH PARAM */, data->simulationInfo->realParameter[63] /* P.substanceData.gamma PARAM */, data->simulationInfo->realParameter[54] /* P.substanceData.Cp PARAM */, tmp43, data->simulationInfo->realParameter[56] /* P.substanceData.DfG_25degC_1bar PARAM */, data->simulationInfo->realParameter[58] /* P.substanceData.DfH_25degC PARAM */, data->simulationInfo->booleanParameter[11] /* P.substanceData.SelfClustering PARAM */, data->simulationInfo->realParameter[60] /* P.substanceData.SelfClustering_dH PARAM */, data->simulationInfo->realParameter[61] /* P.substanceData.SelfClustering_dS PARAM */, data->simulationInfo->realParameter[62] /* P.substanceData.density PARAM */), data->localData[0]->realVars[5] /* solution.temperature STATE(1) */, data->simulationInfo->realParameter[139] /* solution.BasePressure PARAM */, 0.0, data->localData[0]->realVars[112] /* E.solution.I DUMMY_STATE */, _OMC_LIT15); TRACE_POP }
that can be successfully compiled.
@perost, could you fix the NF so that it doesn't refer to undefined record constructor functions in the function call?
comment:6 by , 4 years ago
I guess is no need to wait for tomorrow:
https://libraries.openmodelica.org/branches/history/master/2021-01-10%2012:09:32..2021-01-12%2001:14:51.html
comment:7 by , 4 years ago
EnzymeKinetics
now works fine, alongside with other 9 models in the library that now simulate.
Other models now pass the code generation phase, but then fail because of event issues, e.g. HemoglobinTitration or Joels57, but this is another story, see #6339.
Note that these models were successful when handled by the old frontend, as they got broken on master when we switched on the new frontend by default.
I hope this holds a clue to fix the problem. What has changed from OF to NF that negatively affects the code generation later on?