OpenModelica / OpenModelica

OpenModelica is an open-source Modelica-based modeling and simulation environment intended for industrial and academic usage.
https://openmodelica.org
Other
814 stars 305 forks source link

Compilation fails with model using ExternalMedia #11375

Open albertoleva opened 10 months ago

albertoleva commented 10 months ago

SETUP

OpenModelica 1.21.0 OMSimulator 2.1.1~188-gaf996ad-linux MSL 3.2.3 ExternalMedia 3.3.2

MODEL

model EM_prova_003
 package Medium
         extends ExternalMedia.Media.CoolPropMedium(
          mediumName = "R134A",
          substanceNames = {"R134A"},
          ThermoStates =
          Modelica.Media.Interfaces.Choices.IndependentVariables.ph,
          SpecificEnthalpy(start=2e5)
         );
 end Medium;

 parameter Modelica.SIunits.Volume V=1;
 parameter Modelica.SIunits.ThermalConductance G=100;
 parameter Modelica.SIunits.Temperature Text=273.15+20;
 parameter Modelica.SIunits.Pressure pext=1e5;

 Medium.ThermodynamicState state1;
 Modelica.SIunits.Pressure p(start=1e5,fixed=true);
 Modelica.SIunits.SpecificEnthalpy h(start=165e3,fixed=true);

 Modelica.SIunits.Power P;
 Modelica.SIunits.Mass M;
 Modelica.SIunits.Energy E;

equation
  state1 = Medium.setState_phX(p,h);

  M = V*state1.d; 

  E = M*(h-p/state1.d);

  der(E) = P-G*(state1.T-Text);
  der(M) = 0.001*(pext-state1.p);

  P = 0;

annotation(
    experiment(StartTime = 0, StopTime = 1000, Tolerance = 1e-6, Interval = 2),
    __OpenModelica_commandLineOptions = "--matchingAlgorithm=PFPlusExt --indexReductionMethod=dynamicStateSelection -d=initialization,NLSanalyticJacobian",
    __OpenModelica_simulationFlags(lv = "LOG_STDOUT,LOG_ASSERT,LOG_STATS", s = "dassl", variableFilter = ".*"));
end EM_prova_003;

EXPECTED BEHAVIOUR

Simulate.

ACTUAL BEHAVIOUR --- see note at end

The model translates but then the C code compilation fails with

make -j12 -f EM_prova_003.makefile
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003.o EM_prova_003.c
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_functions.o EM_prova_003_functions.c
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_records.o EM_prova_003_records.c
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_01exo.o EM_prova_003_01exo.c
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_02nls.o EM_prova_003_02nls.c
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_03lsy.o EM_prova_003_03lsy.c
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_04set.o EM_prova_003_04set.c
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_05evt.o EM_prova_003_05evt.c
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_06inz.o EM_prova_003_06inz.c
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_07dly.o EM_prova_003_07dly.c
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_08bnd.o EM_prova_003_08bnd.c
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_09alg.o EM_prova_003_09alg.c
EM_prova_003_02nls.c:186:90: error: no member named 'nominal' in 'struct INTEGER_ATTRIBUTE'
  sysData->nominal[i] = data->modelData->integerVarsData[1].attribute /* state1.phase */.nominal;
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                    ^
1 error generated.
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_10asr.o EM_prova_003_10asr.c
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_11mix.o EM_prova_003_11mix.c
clang  -Os -fPIC -falign-functions -mfpmath=sse -fno-dollars-in-identifiers -Wno-parentheses-equality     "-I/home/alberto/git-repos-local/ExternalMedia/Modelica/ExternalMedia/Resources/Include" -I"/usr/bin/../include/omc/c" -I"/usr/bin/../include/omc" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=EM_prova_003 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o EM_prova_003_12jac.o EM_prova_003_12jac.c
make: *** [<builtin>: EM_prova_003_02nls.o] Error 1
make: *** Waiting for unfinished jobs....
Compilation process failed. Exited with code 2.

NOTE

The reason might reside in the following translation issue

[1] 09:45:50 Translation Warning
The tearing heuristic was not able to avoid discrete iteration variables because otherwise the system could not have been torn. This may lead to problems during simulation.

I cannot figure out a reason why the model cannot be torn --- apologies if missing something relevant.

casella commented 10 months ago

I'm not sure why you write the model like this. Using M and E as states is not a good idea, you should use p and h as states. The simplest way to do that is to write explicit equations such as

dM_dt = dM_dp*der(p) + dM_dh*der(h);
dM_dt = w_in - w_out;
dM_dp = V*Medium.density_derp_h;
dM_dh = V*Medium.densty_derh_p;

there are also way to get the change of variables done automatically, but it's a bit involved, not sure it's worth it. and then compu