Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Test of Modelica.Media / ExternalMedia

Test of Modelica.Media / ExternalMedia

Hi,

I've installed the externalmedia package on my computer https://www.modelica.org/libraries/ExternalMedia with the goal of using it from openmodelica. I know that this package works fine with dymola. I created a model which tests the package:

model Example
  ExternalMedia.Media.TestMedium.ThermodynamicState state;
  SI.Density d;
  SI.SpecificEnthalpy h;
equation
  state = TestMedium.setState_pT(1e5, 300);
  d     = TestMedium.density(state);
  h     = TestMedium.specificEnthalpy(state);
end Example;

However, when I try to compile the above model with: "omc +d=failtrace Example.mo ExternalMedia Modelica.Media"  I see that the processor usage goes to 100%  and the shell dumps out the following message:

ClassLoader.loadClassFromMp failed
ClassLoader.loadClassFromMp failed

Does someone have an idea what this means?

KR,

Re: Test of Modelica.Media / ExternalMedia

ClassLoader.loadClassFromMp failed means nothing. In fact, loading the classes probably succeeded.

Note that OpenModelica does not yet support Modelica.Media however:

Code:

Error processing file: Example.mo

[./ExternalMedia/Interfaces/PartialExternalTwoPhaseMedium.mo:17:3-31:24:writable] Error: Class getMolarMass not found in scope ExternalMedia.Media.TestMedium (looking for a function or record).
[./ExternalMedia/Interfaces/PartialExternalTwoPhaseMedium.mo:17:3-31:24:writable] Error: Looking for a function FluidConstants but found a RECORD.
[/usr/lib/omlibrary/msl31//Modelica/Media/package.mo:5527:3-5527:75:readonly] Error: Failed to elaborate expression: {externalFluidConstants}
Error: Failed to elaborate expression: {externalFluidConstants}
[./ExternalMedia/Interfaces/PartialExternalTwoPhaseMedium.mo:17:3-31:24:writable] Error: Class getMolarMass not found in scope ExternalMedia.Media.TestMedium (looking for a function or record).
[./ExternalMedia/Interfaces/PartialExternalTwoPhaseMedium.mo:17:3-31:24:writable] Error: Looking for a function FluidConstants but found a RECORD.
[/usr/lib/omlibrary/msl31//Modelica/Media/package.mo:5527:3-5527:75:readonly] Error: Failed to elaborate expression: {externalFluidConstants}
Error: Failed to elaborate expression: {externalFluidConstants}
[Example.mo:2:3-2:58:writable] Error: Class ExternalMedia.Media.TestMedium.ThermodynamicState not found in scope Example while instantiating state.

With +d=scodeFlatten (experimental Modelica.Media flag):

Code:

$ OPENMODELICALIBRARY=/usr/lib/omlibrary/msl31/:. omc +d=scodeFlatten Example.mo ExternalMedia Modelica.Media 

/home/marsj/dev/trunk/build//bin/omc 1.7.0 (r8597)
Error processing file: Example.mo
[Example.mo:3:3-3:15:writable] Error: Class SI.Density not found in scope Example.

When fixing that, it still fails at the previous error, however...

Re: Test of Modelica.Media / ExternalMedia

The offending code is:

Code:

  redeclare replaceable function extends getMolarMass 

  external "C" MM=  TwoPhaseMedium_getMolarMass_(mediumName, libraryName, substanceName)
    annotation(Include="#include \"externalmedialib.h\"", Library="ExternalMediaLib");
  end getMolarMass;

We don't (yet) support external declarations when doing class extends current/smile

Re: Test of Modelica.Media / ExternalMedia

Thanks for the quick answer. I've updated the example to take care of the SI stuff. However, as I understand it the above code will not work anyhow for the current version of OpenModelica. Will support for external declarations when doing class extent be available in OpenModelica in the near future?

Re: Test of Modelica.Media / ExternalMedia

Yes. Adrian Pop noticed this problem on Monday this week, so I am assuming he is working on it. Of course, I am certain there are more issues with the model anyway current/sad

Re: Test of Modelica.Media / ExternalMedia

Hi,


I've tested the new RC1 version on the same code as before. The compiler sees the process the model further, but it stops after getting the following error:


[SimCodeC.tpl:2927:14-2927:14:writable] Error: Template error: Unknown external type OTHER
Error: Variable substanceName not found in scope ExternalMedia.Media.TestMedium.getMolarMass
Error: Variable libraryName not found in scope ExternalMedia.Media.TestMedium.getMolarMass
Error: Variable substanceName not found in scope ExternalMedia.Media.TestMedium.getMolarMass
Error: Variable libraryName not found in scope ExternalMedia.Media.TestMedium.getMolarMass
Error: Variable substanceName not found in scope ExternalMedia.Media.TestMedium.getCriticalTemperature
Error: Variable libraryName not found in scope ExternalMedia.Media.TestMedium.getCriticalTemperature
Error: Variable substanceName not found in scope ExternalMedia.Media.TestMedium.getCriticalTemperature
Error: Variable libraryName not found in scope ExternalMedia.Media.TestMedium.getCriticalTemperature
Error: Variable substanceName not found in scope ExternalMedia.Media.TestMedium.getCriticalPressure
Error: Variable libraryName not found in scope ExternalMedia.Media.TestMedium.getCriticalPressure
Error: Variable substanceName not found in scope ExternalMedia.Media.TestMedium.getCriticalPressure
Error: Variable libraryName not found in scope ExternalMedia.Media.TestMedium.getCriticalPressure
Error: Variable substanceName not found in scope ExternalMedia.Media.TestMedium.getCriticalMolarVolume
Error: Variable libraryName not found in scope ExternalMedia.Media.TestMedium.getCriticalMolarVolume
Error: Variable substanceName not found in scope ExternalMedia.Media.TestMedium.getCriticalMolarVolume
Error: Variable libraryName not found in scope ExternalMedia.Media.TestMedium.getCriticalMolarVolume
[SimCodeC.tpl:2927:14-2927:14:writable] Error: Template error: Unknown external type OTHER


In the generated code for ExternalMedia_Media_TestMedium_getMolarMass.h I recognize that the generated header-file are missing some arguments in the TwoPhaseMedium_getMolarMass_ function:


extern double TwoPhaseMedium_getMolarMass_(const char*,
#error "[SimCodeC.tpl:2927:14-2927:14] Unknown external type OTHER"
,
#error "[SimCodeC.tpl:2927:14-2927:14] Unknown external type OTHER"
);
#ifdef __cplusplus
extern "C" {
#endif
#include "externalmedialib.h"
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
}
#endif
#endif



Are these errors related to the omc compiler or is this something related to my model?
KR,
Geir Arne

Re: Test of Modelica.Media / ExternalMedia

This is related to a task needed to handle Modelica.Media: http://openmodelica.org:8080/cb/issue/1334

You can try fn1, fn2 and fn3 yourself if you want to see smaller examples that show what OMC does not yet handle current/smile

Code:

model M

  function fn1
    output Real r;
  external "C" r = sin(c1+c3);
  end fn1;

  function fn2
    output Real r := sin(c1+c3);
  end fn2;

  function fn3
    output Real r;
  algorithm
    r := sin(c1+c3);
  end fn3;
  constant Real c1 = 1.0;
  constant Real c2 = fn1();
  constant Real c3 = c1+1.0;
end M;

(The problem is that the constants are not instantiated in the correct order, so the type of the expression becomes unknown...)

There are 0 guests and 0 other users also viewing this topic
You are here: