Coder Social home page Coder Social logo

modelica-3rdparty / externalmedia Goto Github PK

View Code? Open in Web Editor NEW
52.0 16.0 36.0 58.42 MB

The ExternalMedia library provides a framework for interfacing external codes computing fluid properties to Modelica.Media-compatible component models.

Modelica 37.81% C 7.35% C++ 49.29% CMake 2.72% Motoko 2.82%
modelica modelica-library

externalmedia's Introduction

ExternalMedia

The ExternalMedia library provides a framework for interfacing external codes computing fluid properties to Modelica.Media-compatible component models.

The latest releases of the library can be downloaded here:

  • The precompiled Modelica library can be found in the zip-file
  • The manual can be downloaded as PDF
  • The full source code is also available as compressed file

Library overview

The ExternalMedia library provides a framework for interfacing external codes computing fluid properties to Modelica.Media-compatible component models. The latest 4.x.x releases are compatible with Modelica Standard Library (MSL) 4.0.0 and later, while 3.3.x versions are provided for legacy models that still use MSL 3.2.3.

The current version of the library supports pure and pseudo-pure fluids models, possibly two-phase, compliant with the Modelica.Media.Interfaces.PartialTwoPhaseMedium interface. Please have a look at the dedicated introduction section for an in-depth description of the architecture.

The latest releases of the library include built-in access to the open-source CoolProp software and a pre-compiled interface to the FluidProp commercial software. CoolProp medium models work out of the box without the need of any further installation. FluidProp medium models require to install the FluidProp software with proper licensing to access the media of your interest and to compute the property derivatives, which are required by ExternalMedia. The library works with FluidProp version 3.0 and later. It might work with previous versions of that software, but compatibility is no longer guaranteed. Please refer to the chapter on FluidProp and the dedicated chapter on CoolProp for further details.

The latest releases were tested with Dymola and OpenModelica on Windows and Linux. Support for more tools and operating systems might be added in the future, please let us know if you want to contribute.

You can modify the library to add an interface to your own solver. If your solver is open-source, please contact the developers, so we can add it to the official ExternalMedia library.

Installation instructions for the ExternalMedia library

For OpenModelica, you can install and manage ExternalMedia using the built-in Package Manager. Please note that due to currently unresolved issues about the definition of backwards compatibility, if you have installed both version 3.3.x and version 4.x.x, the class loader will always load version 4.x.x even in case of a uses annotation requiring version 3.3.2. In that case, please load ExternalMedia 3.3.2 manually when you start the OMEdit session, you can find it in your .openmodelica/libraries directory.

For use with Dymola, you can download the zip file with the library and unzip it in your file system. The released library already contains all the pre-compiled binaries for all operating systems, so it should work out of the box.

Install the latest version 3.3.x of External Media if your models still uses Modelica Standard Library 3.2.3, otherwise install the latest version 4.x.x.

If you want to experiment with the code and recompile the libraries, check the compilation instructions.

Modelica integration

The Modelica Language Specification mentions annotations for External Libraries and Include Files in section 12.9.4. Following the concepts put forward there, the ExternalMedia package provides several pre-compiled shared libraries supporting a selection of operating systems, C-compilers and Modelica tools.

Please open the package.mo file inside the ExternalMedia folder to load the library. If your Modelica tool is able to find a matching precompiled binary for your configuration, you should now be able to run the examples.

Compiling ExternalMedia from sources

ExternalMedia extensively relies of external functions using code from pre-compiled dynamic libraries. The released versions include binaries for Windows and Linux, supporting CoolProp and FluidProp. If you want to experiment with other external codes or operating systems, you can build the ExternalMedia binary libraries yourself. All you need to compile ExternalMedia, besides your C/C++ compiler, is the CMake software by Kitware. If you would like to include the CoolProp library, you also need a working Python installation.

Please consult the compilation guide for further instructions and details on how to compile ExternalMedia for different Modelica tools and operating systems.

License

This Modelica package is free software and the use is completely at your own risk; it can be redistributed and/or modified under the terms of the BSD 3-clause license.

Development and contribution

ExternalMedia has been around since 2006 and many different people have contributed to it. The history page provides a lot of useful insights and explains how the software became what it is today.

Current main developers:

  • Francesco Casella started the development in 2006 and coordinates the current development effort.
  • Jorrit Wronski and Ian Bell took care of the integration of CoolProp in the library and of CMake-based compilation.
  • Federico Terraneo helped getting the library to work with different Modelica tools and operating systems.

Please report problems using the library GitHub issue tracker.

externalmedia's People

Contributors

bilderbuchi avatar casella avatar fedetft avatar jonwel avatar jowr avatar rfranke avatar thorade avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

externalmedia's Issues

Linker Errors Using Coolprop Media

I cloned this version:
git status
On branch v4-dev (18.02.2022 13:56)
Your branch is up to date with 'origin/v4-dev'.
Generated ExternalMedia.lib on Windows 10 with
cmake 2.23.0 and VS2019
in GitBash:

cmake -B build -S Projects -DCMAKE_BUILD_TYPE=Release -DFLUIDPROP:BOOL=ON -DCOOLPROP:BOOL=ON
cmake -B build -S Projects -DCMAKE_BUILD_TYPE=Release -DFLUIDPROP:BOOL=ON -DCOOLPROP:BOOL=ON
cmake --build build --config Release --target install

-> no errors.

Loading ExternalMedia in Dymola 2022:
Running "External.Media.Test.Coolprop.CO2.TestStatesSupercritical" out of the box:

Compiling and linking the model (Visual C++).
64-bit mode activated.
dsmodel.c
dsmodel.c(347): warning C4133: 'function': incompatible types - from 'DymStruc0 *' to 'ExternalThermodynamicState *'
dsmodel.c(391): warning C4133: 'function': incompatible types - from 'DymStruc0 *' to 'ExternalThermodynamicState *'
dsmodel.c(1005): warning C4267: 'function': conversion from 'size_t' to 'int', possible loss of data
Creating library dymosim.lib and object dymosim.exp
LINK : warning LNK4199: /DELAYLOAD:ExternalMediaLib.dll ignored; no imports found from ExternalMediaLib.dll
dsmodel.obj : error LNK2019: unresolved external symbol TwoPhaseMedium_getMolarMass_C_impl referenced in function ExternalMedia_Media_CoolPropMedium_getMolarMassx_0Unique14_M
dsmodel.obj : error LNK2019: unresolved external symbol TwoPhaseMedium_getCriticalTemperature_C_impl referenced in function ExternalMedia_Media_CoolPropMedium_getCriticalTemperaturex_0Unique15_M
dsmodel.obj : error LNK2019: unresolved external symbol TwoPhaseMedium_getCriticalPressure_C_impl referenced in function ExternalMedia_Media_CoolPropMedium_getCriticalPressurex_0Unique16_M
dsmodel.obj : error LNK2019: unresolved external symbol TwoPhaseMedium_getCriticalMolarVolume_C_impl referenced in function ExternalMedia_Media_CoolPropMedium_getCriticalMolarVolumex_0Unique17_M
dsmodel.obj : error LNK2019: unresolved external symbol TwoPhaseMedium_setState_ph_C_impl referenced in function ExternalMedia_Media_CoolPropMedium_setStatex_0phx_0Unique18_M
dsmodel.obj : error LNK2019: unresolved external symbol TwoPhaseMedium_setState_pT_C_impl referenced in function ExternalMedia_Media_CoolPropMedium_setStatex_0pTx_0Unique19_M
dymosim.ex_ : fatal error LNK1120: 6 unresolved externals

Error generating Dymosim.

Has anyone an idea, what I have done wrong?
Thank you in advance for any hints.

Switch to alternative REfProp EoS

For some fluids RefProp has implemented more than one equation of state, e.g. the short EoS from Span. Can I switch to those EoS, and if yes, how would I do it?

TTSE medium model doesn't work properly

@jowr, I'm very interested at using the TTSE and bicubic interpolations for my simulations.

I tried the TestStatesSupercritical example in the attached package, which sets enable_TTSE=1 in the CO2 medium model. The first time I ran the program, the simulation executable ran for quite some time, generating a ludicrous amount of output. I understand it was generating the table file, but I suspect it spent most of the CPU time just sending the dump to the screen. I guess we may want to suppress this output, and give instead a message like "precomputing the tables, please wait, this will only be carried out the first time you use the TTSE properties", possibly with some explicit reference to where these tables are actually saved (to be honest, I don't have the slightest idea, which is kind of creepy).

The second time I ran it, I briefly saw the message "Simulation successfully terminated" flashing in the executable command windows, followed by several garbled characters. Unfortunately, when the executable process exits, Dymola reports "Simulation in progress; use Simulation->Show Log if you want to see the actual log file. (It may initially be empty.)" and does not load any result file. In fact, there is no result .mat file at all in Dymola's output directory. Something fishy's happening, but I have little clue what it is.

Did you manage to run some TTSE or bicubic medium model successfully in ExternalMedia during your tests? Do you have any idea what is happening here?

Thanks!

externalMedia3.3.1 not working with openmodelica 1.18.1

I can't get a complete working ExternalMedia library working with openModelica
I working with openModelica 1.18.1 with OM simulator 2.1.1
compilator Mingw ( from openmodelica installer)
with the zipped version of ExternalMedia 3.3.1

I'm havig the following errors when running for example the TestStatesSat test

[1] 10:24:58 Traduction Erreur
[ExternalMedia.Media.BaseClasses.ExternalTwoPhaseMedium: 186:15-190:19]: External function ‘TwoPhaseMedium_getMolarMass_C_impl‘ could not be found in any of the given shared libraries:
C:/Users/be92251/Downloads/ExternalMedia_v3.3.1/ExternalMedia 3.3.1/Resources/Library/win64/ExternalMediaLib.dll
C:/Users/be92251/Downloads/ExternalMedia_v3.3.1/ExternalMedia 3.3.1/Resources/Library/ExternalMediaLib.dll

[2] 10:24:58 Traduction Erreur
[ExternalMedia.Media.BaseClasses.ExternalTwoPhaseMedium: 198:15-202:26]: External function ‘TwoPhaseMedium_getCriticalPressure_C_impl‘ could not be found in any of the given shared libraries:
C:/Users/be92251/Downloads/ExternalMedia_v3.3.1/ExternalMedia 3.3.1/Resources/Library/win64/ExternalMediaLib.dll
C:/Users/be92251/Downloads/ExternalMedia_v3.3.1/ExternalMedia 3.3.1/Resources/Library/ExternalMediaLib.dll

and this from the compiler

TestStatesSat_functions.c:113:42: warning: incompatible pointer types passing 'ExternalMedia_Test_TestMedium_TestStatesSat_Medium_SaturationProperties *' to parameter of type 'ExternalSaturationProperties *' (aka 'struct ExternalSaturationProperties *') [-Wincompatible-pointer-types] TwoPhaseMedium_setSat_T_C_impl(_T_ext, &_sat_ext, MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp1)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp2)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp3))); ^~~~~~~~~ C:/Users/be92251/Downloads/ExternalMedia_v3.3.1/ExternalMedia 3.3.1/Resources/Include\externalmedialib.h:197:99: note: passing argument to parameter 'sat' here EXTERNALMEDIA_EXPORT void TwoPhaseMedium_setSat_T_C_impl(double T, ExternalSaturationProperties *sat, const char *mediumName, const char *libraryName, const char *substanceName); ^ TestStatesSat_functions.c:153:42: warning: incompatible pointer types passing 'ExternalMedia_Test_TestMedium_TestStatesSat_Medium_SaturationProperties *' to parameter of type 'ExternalSaturationProperties *' (aka 'struct ExternalSaturationProperties *') [-Wincompatible-pointer-types] TwoPhaseMedium_setSat_p_C_impl(_p_ext, &_sat_ext, MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp1)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp2)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp3))); ^~~~~~~~~ C:/Users/be92251/Downloads/ExternalMedia_v3.3.1/ExternalMedia 3.3.1/Resources/Include\externalmedialib.h:196:99: note: passing argument to parameter 'sat' here EXTERNALMEDIA_EXPORT void TwoPhaseMedium_setSat_p_C_impl(double p, ExternalSaturationProperties *sat, const char *mediumName, const char *libraryName, const char *substanceName); ^ TestStatesSat_functions.c:196:53: warning: incompatible pointer types passing 'ExternalMedia_Test_TestMedium_TestStatesSat_Medium_ThermodynamicState *' to parameter of type 'ExternalThermodynamicState *' (aka 'struct ExternalThermodynamicState *') [-Wincompatible-pointer-types] TwoPhaseMedium_setState_pT_C_impl(_p_ext, _T_ext, &_state_ext, MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp1)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp2)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp3))); ^~~~~~~~~~~ C:/Users/be92251/Downloads/ExternalMedia_v3.3.1/ExternalMedia 3.3.1/Resources/Include\externalmedialib.h:171:110: note: passing argument to parameter 'state' here EXTERNALMEDIA_EXPORT void TwoPhaseMedium_setState_pT_C_impl(double p, double T, ExternalThermodynamicState *state, const char *mediumName, const char *libraryName, const char *substanceName); ^ TestStatesSat_functions.c:247:65: warning: incompatible pointer types passing 'ExternalMedia_Test_TestMedium_TestStatesSat_Medium_ThermodynamicState *' to parameter of type 'ExternalThermodynamicState *' (aka 'struct ExternalThermodynamicState *') [-Wincompatible-pointer-types] TwoPhaseMedium_setState_ph_C_impl(_p_ext, _h_ext, _phase_ext, &_state_ext, MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp1)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp2)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp3))); ^~~~~~~~~~~ C:/Users/be92251/Downloads/ExternalMedia_v3.3.1/ExternalMedia 3.3.1/Resources/Include\externalmedialib.h:170:121: note: passing argument to parameter 'state' here EXTERNALMEDIA_EXPORT void TwoPhaseMedium_setState_ph_C_impl(double p, double h, int phase, ExternalThermodynamicState *state, const char *mediumName, const char *libraryName, const char *substanceName); ^ TestStatesSat_functions.c:349:65: warning: incompatible pointer types passing 'ExternalMedia_Test_TestMedium_TestStatesSat_completeBubbleDewStates1_Medium_ThermodynamicState *' (aka 'ExternalMedia_Test_TestMedium_TestStatesSat_Medium_ThermodynamicState *') to parameter of type 'ExternalThermodynamicState *' (aka 'struct ExternalThermodynamicState *') [-Wincompatible-pointer-types] TwoPhaseMedium_setState_ph_C_impl(_p_ext, _h_ext, _phase_ext, &_state_ext, MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp1)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp2)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp3))); ^~~~~~~~~~~ C:/Users/be92251/Downloads/ExternalMedia_v3.3.1/ExternalMedia 3.3.1/Resources/Include\externalmedialib.h:170:121: note: passing argument to parameter 'state' here EXTERNALMEDIA_EXPORT void TwoPhaseMedium_setState_ph_C_impl(double p, double h, int phase, ExternalThermodynamicState *state, const char *mediumName, const char *libraryName, const char *substanceName); ^ TestStatesSat_functions.c:416:9: error: use of undeclared identifier '_completeBubbleDewStates1' _MM = _completeBubbleDewStates1._bubbleStateOnePhase._Medium._externalFluidConstants._molarMass; ^ TestStatesSat_functions.c:523:9: error: use of undeclared identifier '_completeBubbleDewStates1' _MM = _completeBubbleDewStates1._bubbleStateTwoPhase._Medium._externalFluidConstants._molarMass; ^ TestStatesSat_functions.c:630:9: error: use of undeclared identifier '_completeBubbleDewStates1' _MM = _completeBubbleDewStates1._dewStateOnePhase._Medium._externalFluidConstants._molarMass; ^ TestStatesSat_functions.c:737:9: error: use of undeclared identifier '_completeBubbleDewStates1' _MM = _completeBubbleDewStates1._dewStateTwoPhase._Medium._externalFluidConstants._molarMass; ^ TestStatesSat_functions.c:879:65: warning: incompatible pointer types passing 'ExternalMedia_Test_TestMedium_TestStatesSat_completeBubbleDewStates2_Medium_ThermodynamicState *' (aka 'ExternalMedia_Test_TestMedium_TestStatesSat_Medium_ThermodynamicState *') to parameter of type 'ExternalThermodynamicState *' (aka 'struct ExternalThermodynamicState *') [-Wincompatible-pointer-types] TwoPhaseMedium_setState_ph_C_impl(_p_ext, _h_ext, _phase_ext, &_state_ext, MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp1)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp2)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp3))); ^~~~~~~~~~~ C:/Users/be92251/Downloads/ExternalMedia_v3.3.1/ExternalMedia 3.3.1/Resources/Include\externalmedialib.h:170:121: note: passing argument to parameter 'state' here EXTERNALMEDIA_EXPORT void TwoPhaseMedium_setState_ph_C_impl(double p, double h, int phase, ExternalThermodynamicState *state, const char *mediumName, const char *libraryName, const char *substanceName); ^ TestStatesSat_functions.c:946:9: error: use of undeclared identifier '_completeBubbleDewStates2' _MM = _completeBubbleDewStates2._bubbleStateOnePhase._Medium._externalFluidConstants._molarMass; ^ TestStatesSat_functions.c:1053:9: error: use of undeclared identifier '_completeBubbleDewStates2' _MM = _completeBubbleDewStates2._bubbleStateTwoPhase._Medium._externalFluidConstants._molarMass;

Can someone explain me how to run it without errors on openmodelica?

Many thanks

WaterComparison does not compile with OM 1.18 beta1

I am working on a model, and encountered some errors, that I also found to occur in a Test model, using OpenModelica 1.18 beta1 (64bit) and ExternalMedia 3.3.0 on Windows 10. In short, some external functions cannot be found in the dll.

On compilation (or Check All) of ExternalMedia.Test.WaterComparison, I get errors

[1] 16:06:50 Translation Error
[ExternalMedia.Media.BaseClasses.ExternalTwoPhaseMedium: 192:15-196:29]: External function ‘TwoPhaseMedium_getCriticalTemperature_C_impl‘ could not be found in any of the given shared libraries:
  <snip>/ExternalMedia/Modelica/ExternalMedia 3.3.0_release/Resources/Library/win64/ExternalMediaLib.dll
  <snip>/ExternalMedia/Modelica/ExternalMedia 3.3.0_release/Resources/Library/ExternalMediaLib.dll

[2] 16:06:50 Translation Error
[ExternalMedia.Media.BaseClasses.ExternalTwoPhaseMedium: 204:15-208:29]: External function ‘TwoPhaseMedium_getCriticalMolarVolume_C_impl‘ could not be found in any of the given shared libraries:
  <snip>/ExternalMedia/Modelica/ExternalMedia 3.3.0_release/Resources/Library/win64/ExternalMediaLib.dll
  <snip>/ExternalMedia/Modelica/ExternalMedia 3.3.0_release/Resources/Library/ExternalMediaLib.dll

[3] 16:06:50 Translation Error
[ExternalMedia.Media.BaseClasses.ExternalTwoPhaseMedium: 186:15-190:19]: External function ‘TwoPhaseMedium_getMolarMass_C_impl‘ could not be found in any of the given shared libraries:
  <snip>/ExternalMedia/Modelica/ExternalMedia 3.3.0_release/Resources/Library/win64/ExternalMediaLib.dll
  <snip>/ExternalMedia/Modelica/ExternalMedia 3.3.0_release/Resources/Library/ExternalMediaLib.dll

[4] 16:06:50 Translation Error
[ExternalMedia.Media.BaseClasses.ExternalTwoPhaseMedium: 198:15-202:26]: External function ‘TwoPhaseMedium_getCriticalPressure_C_impl‘ could not be found in any of the given shared libraries:
  <snip>/ExternalMedia/Modelica/ExternalMedia 3.3.0_release/Resources/Library/win64/ExternalMediaLib.dll
  <snip>/ExternalMedia/Modelica/ExternalMedia 3.3.0_release/Resources/Library/ExternalMediaLib.dll

Curiously, those .dll files do not exist at those locations, Resources/Library/ only contains subfolders, and Resources/Library/win64/ contains vs201* subfolders, but with .lib, not .dll files.

Initially, I suspected that OM somehow messes up library discovery, but then I ran another test case, ExternalMedia.Test.TestMedium.TestConstants. On Check All, this also complains about not finding an external function (in this case TwoPhaseMedium_getCriticalTemperature_C_impl), but compiles successfully, without the above translation errors!

installing for Openmodelica

Hi

I have run cmake as per compilation instructions and I get a header and library file generated. These are

externalmedialib.h and libExternalMediaLib.a

However, from OMedir after I load the library and try to do a test I get the folling error:

[ExternalMedia.Media.BaseClasses.ExternalTwoPhaseMedium: 198:15-202:26]: External function ‘TwoPhaseMedium_getCriticalPressure_C_impl‘ could not be found in any of the given shared libraries:
/home/cbranch/Modelica/Libraries/ExternalMedia/Modelica/ExternalMedia 3.3.0/Resources/Library/linux64/libExternalMediaLib.so
/home/cbranch/Modelica/Libraries/ExternalMedia/Modelica/ExternalMedia 3.3.0/Resources/Library/libExternalMediaLib.so

It seems to be looking for a shared library .so extension and the CMAKE makes a static. Is this the reason for not finding these external functions?

How do I make the CMAKE compile a shared library if that is the solution to the problem?

Also the library is in a folder gcc93 will modelica find it or should I copy up a level into linix64 where it seems to be looking?

Dymola Water - CoolProp - TC Error

When using the Media Water - CoolProp - TC I sometimes get a very strange error:

The following error was detected at time: 101.9
Number of steps in density_TP has exceeded 30 with inputs T=305.595,p=101325,rho_guess=994.895 for fluid Water
The stack of functions is:
ExternalMedia.Media.CoolPropMedium.setState_ph_Unique15
ExternalMedia.Media.CoolPropMedium.setState_ph_Unique15(sinkP2.p0, condenser.SecondaryFluid.Cells[1].h, 0)
Integration terminated before reaching "StopTime" at T = 102

It seems like it does not manage to obtain the density, even though the temperature and pressure are in a fairly normal region and the guess value of the density gives a quite good starting value. Has anyone else experienced this kind of problem? The error vanishes, for example, when using the StandardWater media included in Modelica. Unfortunately I need the Water - CoolProp - TC for the Cell1Dim Component in the Thermocycle Library.

I am using the newest Thermocycle and External Media Libraries.

Best regards, Felix

Update interface for newer CoolProp version 6.1.X

Hello,
the wrapper with ExternalMedia is not maintained anymore here since 3 years.

The wrapper seemed to be in sync with version 4.2.x of coolprop.

There is precompiled librarie for windows but I was not able to compile it directly from source. Some simple update have to be made in this libraries. Maybe it is a good idea to update it ? Integrate it with CoolProp ?

I will open the same issue in CoolProp.

The work will be :
-> make to CMake (easier to make cross compilation)
-> change functions from v4.X to 6.X

What do you think ?
I may take some times to make this change with some helps.

Thomas

Compilation failure when using ExternalMedia

Dear,

I am trying to use the ThermoCycle-library. I cannot simulate the examples from this library and I scoped the problem down to issues in the ExternalMedia-library. I cannot simulate any of the examples of this library. I get following error with respect to compiling and linking the model (Visual C++) :

image

I am using following versions:

  • Dymola 2020
  • Modelica 3.2.2 / 3.2.3 (tested both)
  • Visual Studio 2013/ Visual C++ 2013 Express Edition (12.0)

Has someone encountered this problem before and a possible solution?

Kind regards

Issue with TTSE interpolation when using setState_pT for supercritical CO2

I just tried out the newly released 3.3.1 version using Dymola 2022 under Windows 10, 64 bits. The examples in the ExternalMedia library seem to work fine.

I then tested the BICUBIC and TTSE CO2 medium model. I confirm that the issue I had in #29 is now fixed, the first time I ran the model it took some time to generate the tables, and then the simulation ran correctly. Subsequent simulations went like a breeze.

I tested the CO2 medium model on an isobaric line at 90 bars, which is supercritical, but not too much, so I expect to see significant real-gas effects. The setState_pT function is used, see the test model TestInterpolatedCO2.mo.txt. I report the plots of density:

immagine

There is clearly a problem with the TTSE interpolation between 85 and 150 bars. Above 150 bars, all seems fine. @jowr, could you please have a look?

Cannot compile Tests of ExternalMedia lib on Windows

Hi everyone,

I am beginner in Modelica and I have some troubles with the ExternalMedia library on Windows. I installed it as specified in the "Installation.txt". I use OMEdit v1.13.0 (32-bit) and MSL 3.2.2 (but I have the same problem with MSL 3.2 and 3.2.1).

When I launch ExternalMedia.Test.TestMedium.TestConstants, compilation process fails and I get the following error :

ExternalMedia.Test.TestMedium.TestConstants.c: In function 'ExternalMedia_Test_TestMedium_TestConstants_eqFunction_2':
ExternalMedia.Test.TestMedium.TestConstants.c:75:55: error: '$PMedium$PfluidConstants$lB1$rB$PcriticalTemperature' undeclared (first use in this function)
   data->localData[0]->realVars[0] /* Tc variable */ = $PMedium$PfluidConstants$lB1$rB$PcriticalTemperature;
                                                       ^
ExternalMedia.Test.TestMedium.TestConstants.c:75:55: note: each undeclared identifier is reported only once for each function it appears in
<builtin>: recipe for target 'ExternalMedia.Test.TestMedium.TestConstants.o' failed
\tools\msys\mingw32\bin\mingw32-make: *** [ExternalMedia.Test.TestMedium.TestConstants.o] Error 1
\tools\msys\mingw32\bin\mingw32-make: *** Waiting for unfinished jobs....
Compilation process failed. Exited with code 2.

Thus, I can't use the ExternalMedia library. Do you have an hint on how to fix this ?

Thanks a lot,
Adrien

Here is the full compilation output:

C:/OpenModelica1.13.0-32bit//share/omc/scripts/Compile.bat ExternalMedia.Test.TestMedium.TestConstants gcc mingw32 parallel 4 0
PATH = "C:\OpenModelica1.13.0-32bit\tools\msys\mingw32\bin;C:\OpenModelica1.13.0-32bit\tools\msys\mingw32\bin\..\..\usr\bin;"
gcc  -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse     -I"C:/OpenModelica1.13.0-32bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ExternalMedia_Test_TestMedium_TestConstants -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o ExternalMedia.Test.TestMedium.TestConstants.o ExternalMedia.Test.TestMedium.TestConstants.c
gcc  -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse     -I"C:/OpenModelica1.13.0-32bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ExternalMedia_Test_TestMedium_TestConstants -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o ExternalMedia.Test.TestMedium.TestConstants_functions.o ExternalMedia.Test.TestMedium.TestConstants_functions.c
gcc  -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse     -I"C:/OpenModelica1.13.0-32bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ExternalMedia_Test_TestMedium_TestConstants -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o ExternalMedia.Test.TestMedium.TestConstants_records.o ExternalMedia.Test.TestMedium.TestConstants_records.c
gcc  -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse     -I"C:/OpenModelica1.13.0-32bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ExternalMedia_Test_TestMedium_TestConstants -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o ExternalMedia.Test.TestMedium.TestConstants_01exo.o ExternalMedia.Test.TestMedium.TestConstants_01exo.c
gcc  -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse     -I"C:/OpenModelica1.13.0-32bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ExternalMedia_Test_TestMedium_TestConstants -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o ExternalMedia.Test.TestMedium.TestConstants_02nls.o ExternalMedia.Test.TestMedium.TestConstants_02nls.c
ExternalMedia.Test.TestMedium.TestConstants.c: In function 'ExternalMedia_Test_TestMedium_TestConstants_eqFunction_2':
ExternalMedia.Test.TestMedium.TestConstants.c:75:55: error: '$PMedium$PfluidConstants$lB1$rB$PcriticalTemperature' undeclared (first use in this function)
   data->localData[0]->realVars[0] /* Tc variable */ = $PMedium$PfluidConstants$lB1$rB$PcriticalTemperature;
                                                       ^
ExternalMedia.Test.TestMedium.TestConstants.c:75:55: note: each undeclared identifier is reported only once for each function it appears in
<builtin>: recipe for target 'ExternalMedia.Test.TestMedium.TestConstants.o' failed
\tools\msys\mingw32\bin\mingw32-make: *** [ExternalMedia.Test.TestMedium.TestConstants.o] Error 1
\tools\msys\mingw32\bin\mingw32-make: *** Waiting for unfinished jobs....
Compilation process failed. Exited with code 2.

Compilation failure in Dymola 2021

Dear,

I am trying to use ExternalMedia, but when testing the example of that library I get the following error .

Capture d’écran 2022-03-28 144600

I'm using the following versions:

  • Dymola 2021
  • Modelica 4.0.0
  • Visual Studio 2019/ Visual C++ 2019 (16)

I've downloaded ExternalMedia (branch MSL4.0), run the file "BuildLib-Dymola-VS2019.bat", then the 2 file .lib (ExternalMediaLib.Dymola-vs2019 and ExternalMediaLib) have been well created.

Thank you for your help,

Regards,

Requirements for new release of ExternalMedia and action plan

High-level requirements for the new release of ExternalMedia

  • Run under Windows and Linux (possibly also MacOS)
  • Run with 32-bit and 64-bit simulation runtimes
  • Run at least with Dymola and OpenModelica (possibly also other Modelica tools)
  • Easy installation: ideally, the library should run in all the above-mentioned Modelica tools as-is, with as little as possible installation actions.
  • Easy management of dependencies on other software, currently CoolProp and FluidProp

v3.2.3 with CoolProp

Dear all

Would you be interested in creating an intermediate branch that handles some of the issues we experienced earlier? We could make a minor release for v3.2.3 and then have a structured discussion for how to address v4.0.

I have now made a new version of the CMake scripts that uses CMake to pull the CoolProp sources, if enabled. There is no fixed connection between the ExternalMedia code and CoolProp anymore. This is a first step towards handling #8, but we are not ready to close it since we do not use the shared library, yet.

I also started to integrate GitHub actions as suggested by @beutlich - this could be the solution for #7.

I can make a pull request - but feel free to suggest other ways to address the roadmap for this project. Maybe we can start with creating GitHub draft releases and the tag new issues with the appropriate version numbers?

getting started

Apologies if this is all a bit basic, as I'm new to ExternalMedia, and indeed media as a whole in modelica. I have tried to load and run ExternalMedia 3.3.0 in both OpenModelica and Dymola. On Dymola I can run ExternalMedia.Test.TestMedium.TestBasePropertiesDynamic without problems. On OM I get the following error message:
C:/Program Files/OpenModelica1.17.0-64bit/share/omc/scripts/Compile.bat ExternalMedia.Test.TestMedium.TestBasePropertiesDynamic msvc15 mingw64 parallel 20 0
PATH = "C:\PROGRA1\OPENMO1.0-6\tools\msys\mingw64\bin;C:\PROGRA1\OPENMO1.0-6\tools\msys\mingw64\bin....\usr\bin;"
mingw32-make: Entering directory 'C:/Users/John/AppData/Local/Temp/OPENMO1/OMEdit/EXTERN3.TES'
mingw32-make: Leaving directory 'C:/Users/John/AppData/Local/Temp/OPENMO1/OMEdit/EXTERN3.TES'
ExternalMedia.Test.TestMedium.TestBasePropertiesDynamic.makefile:18: *** missing separator. Stop.
Compilation process failed. Exited with code 2.

The offending line in the makefile is this: !IF "$(PCH_FILE)" == ""

OM also gives this error:
[1] 18:05:06 Translation Error
[C:/OM117/OM64bit/OMCompiler/Compiler/NFFrontEnd/NFEvalFunction.mo: 181:7-183:92]: Internal error NFEvalFunction.evaluateExternal failed on ExternalMedia.Test.TestMedium.TestBasePropertiesDynamic.Medium.getMolarMass, evaluation of userdefined external functions not yet implemented

Any ideas what I need to tweak to get it to work? Or is it more terminal?

Meanwhile, in Dymola, I wanted to try running ExternalMedia.Test.MSL_Models.IncompressibleFluidNetwork, which says in the description "needs medium definition" so I changed a line to
replaceable package NewMedium=ExternalMedia.Media.TestMedium;

and now I get this error message when checking the model:

Check of ExternalMedia.Test.MSL_Models.IncompressibleFluidNetwork:

Base class FluidConstants is replaceable
Near file: C:/Program Files/Dymola 2020/Modelica/Library/Modelica 3.2.3/Media/package.mo, line 6328
Context: Modelica.Media.Interfaces.PartialTwoPhaseMedium.FluidConstants.constructor

Must translate function ExternalMedia.Media.TestMedium.setState_pT_Unique26.

Internal error: trying to compile function but did not find it.

Any suggestions?

Once I've got through this beginners pain, I will need to know how to define CoolProps media in this package - I want to use some refrigerants.
Thanks

What version of CoolProp is supported?

When looking into CMakeLists.txt it looks the CoolProp version is set to 5.1.1. When I try to use 6.4.1 on Windows the compilation fails with the error:

CPstrings.h(14): fatal error C1083: Cannot open include file: 'fmt/format.h': No such fil e or directory.

MinGW 9.1.0 compilation

Please, is it possible to build the library with MinGW 9.1.0 on Windows? Has anybody tried that? Thank you.

Not possible to compile ExternalMedia/CoolProp for XUbuntu due to missing dependencies

Hello,

I have been trying for a week now to compile ExternalMedia on a fresh Xubuntu 18.04 system in order to be able to use CoolProp with OpenModelica but it seems to be impossible as a lot of dependecies during the installation fail. Please have a look at my Issue #14 to get an idea of what I mean. Although I received very good instructions and hints from Thomas Pedot I did dot manage to complete the compilation.

I would be happy if the instructions in the CompileHowTwo.txt file could be updated with instructions that do actually work. Otherwise you might want to inform the community that an installation of ExternalMedia on Linux is no longer supported in order to avoid people from waisting their time.

Best regards
Christian

FMU export in Dymola 2017

Hello, I am now using External Media Library in Dymola 2017 and trying to FMU export on my original model incorporating library External Media Library.
But, I cannot success creating FMU files. Is this library compatible with FMU creation?

Using ExternalMedia to access RefProp via CoolProp

We welcome any suggestions for the following issue using External Media (v3.3.0) within OpenModelica (runing Modelica v3.2.3):


The following Modelica code works:

model CoolPropTest

package Medium = 
ExternalMedia.Media.CoolPropMedium(
mediumName = "Water");

Medium.AbsolutePressure p1 = 8e6;
Medium.SpecificEnthalpy h1 = 1.0e5;

Medium.Density d;

equation

d = Medium.density_ph(p1, h1, 0);

end CoolPropTest;


Using the same code to access RefProp does not work

model CoolPropTest

package Medium = 
ExternalMedia.Media.CoolPropMedium(
mediumName = "REFPROP::Water");

Medium.AbsolutePressure p1 = 8e6;
Medium.SpecificEnthalpy h1 = 1.0e5;

Medium.Density d;

equation

d = Medium.density_ph(p1, h1, 0);

end CoolPropTest;

error Code:

calc_transport has the value of 1
TTSE is off
enable_TTSE has the value of 0
BICUBIC is off
enable_BICUBIC has the value of 0
enable_EXTTP has the value of 1
twophase_derivsmoothing_xend has the value of 0.0
rho_smoothing_xend has the value of 0.0
debug has the value of 0

This backend does not implement calc_specify_phasefunction
simulation terminated by an assertation at initialization
Simulation process failed. Exited with code -1.


Thanks,
Patrick

Compiling as shared library

I have tested the shared library compilation with Dymola 2022x on Windows. That seems to work fine. However, could any of you OM guys take over from here? I would be happy to help with CMake etc, but I am not familiar with OpenModelica at all...

Build Tools Versioning

Following on from #40 I've had another go compiling the library and whilst I can 'successfully' compile the library a lot of the tests fail for a variety of reasons. I even tried using gcc 7.5 as suggested here with no improvement.

#27 (comment)

Have also tried some combos of the openmodelica version etc. Do you have a gcc, cmake, openmodelica, ubuntu combination that you know builds and runs the tests successfully? I am particularly interested in super critical CO2.

Many thanks,

Compiling ExternalMedia using VS2017 Community

Dear all,

I am trying to compile ExternalMedia using Visual Studio 2017 but I can't achieve to build the static library. I modified the "BuildLib-Dymola-VS2012.bat" file into "BuildLib-Dymola-VS2017.bat" and ran that file based on the info from "ExternalMedia/Projects/CompilationHowTo.txt". However, the static library is not built and copied as mentionned in that file.

Here is a copy of the bat file I am using:

REM ******** set the variables ************
REM call both to ensure that one works

call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"

call BuildLib-VS "Visual Studio 15 2017"

echo "Copying files to External Media 3.2.1"
copy ExternalMediaLib.lib "..\Modelica\ExternalMedia 3.2.1\Resources\Library\win32\ExternalMediaLib.Dymola-vs2017.lib"
copy ExternalMediaLib.lib "..\Modelica\ExternalMedia 3.2.1\Resources\Library\win32\ExternalMediaLib.lib"
del ExternalMediaLib.lib
copy Sources\externalmedialib.h "..\Modelica\ExternalMedia 3.2.1\Resources\Include"
echo "All done"	
PAUSE

I also tried to call "vcvars32.bat" instead of "vcvarsall.bat" but without getting much better results. The static library is built and copied but the compilation of the test examples in Dymola 2019 still fails.

Did anyone already try to compile the library using VS2017 and got passed these issues?

I can of course provide more info on the errors I am getting if needed. Thanks in advance for your help. Best,

Bertrand

Remaining issues of ExternalMedia when using OpenModelica

I tried the new 3.3.1 release out of the .zip file with a recent nightly build OpenModelica v1.19.0-dev-559-g262ad75b37 (64-bit).

ExternalMedia.Test.TestMedium.TestState compiles and simulates successfully. This is a non-trivial outcome, because it means that the whole external function machinery works correctly and that the static libraries compiled by CMAKE are found and linked correctly to the omc-generated code.

That said, there are several things that still need to be fixed. I am opening separate tickets for each of them and collect them here.

Cannot compile Tests with CoolProp - undeclared identifier '_fluidConstants'

Hello,
I'm still failing to compile test with CoolProp using the version 6.1.0 of CoolProp (described here)

Running TestStatesSupercritical

make -j4 -f ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical.makefile
clang   -fPIC -O0 -march=native      "-I/media/thomas/DATA/Developpments/ExternalMedia-fork/Modelica/ExternalMedia 3.2.1/Resources/Include" -I"/usr/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ExternalMedia_Test_CoolProp_CO2_TestStatesSupercritical -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical.o ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical.c
clang   -fPIC -O0 -march=native      "-I/media/thomas/DATA/Developpments/ExternalMedia-fork/Modelica/ExternalMedia 3.2.1/Resources/Include" -I"/usr/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ExternalMedia_Test_CoolProp_CO2_TestStatesSupercritical -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_functions.o ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_functions.c
clang   -fPIC -O0 -march=native      "-I/media/thomas/DATA/Developpments/ExternalMedia-fork/Modelica/ExternalMedia 3.2.1/Resources/Include" -I"/usr/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ExternalMedia_Test_CoolProp_CO2_TestStatesSupercritical -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_records.o ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_records.c
clang   -fPIC -O0 -march=native      "-I/media/thomas/DATA/Developpments/ExternalMedia-fork/Modelica/ExternalMedia 3.2.1/Resources/Include" -I"/usr/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ExternalMedia_Test_CoolProp_CO2_TestStatesSupercritical -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_01exo.o ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_01exo.c
clang   -fPIC -O0 -march=native      "-I/media/thomas/DATA/Developpments/ExternalMedia-fork/Modelica/ExternalMedia 3.2.1/Resources/Include" -I"/usr/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ExternalMedia_Test_CoolProp_CO2_TestStatesSupercritical -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_02nls.o ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_02nls.c
clang   -fPIC -O0 -march=native      "-I/media/thomas/DATA/Developpments/ExternalMedia-fork/Modelica/ExternalMedia 3.2.1/Resources/Include" -I"/usr/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=ExternalMedia_Test_CoolProp_CO2_TestStatesSupercritical -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_03lsy.o ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_03lsy.c
ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_functions.c:85:53: warning: incompatible pointer types passing 'ExternalMedia_Test_CoolProp_CO2_TestStatesSupercritical_Medium_ThermodynamicState *' (aka 'struct ExternalMedia_Test_CoolProp_CO2_TestStatesSupercritical_Medium_ThermodynamicState_s *') to parameter of type 'ExternalThermodynamicState *' [-Wincompatible-pointer-types]
  TwoPhaseMedium_setState_pT_C_impl(_p_ext, _T_ext, &_state_ext, MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp1)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp2)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp3)));
                                                    ^~~~~~~~~~~
/media/thomas/DATA/Developpments/ExternalMedia-fork/Modelica/ExternalMedia 3.2.1/Resources/Include/externalmedialib.h:144:96: note: passing argument to parameter 'state' here
        EXPORT void TwoPhaseMedium_setState_pT_C_impl(double p, double T, ExternalThermodynamicState *state, const char *mediumName, const char *libraryName, const char *substanceName);
                                                                                                      ^
ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_functions.c:133:65: warning: incompatible pointer types passing 'ExternalMedia_Test_CoolProp_CO2_TestStatesSupercritical_Medium_ThermodynamicState *' (aka 'struct ExternalMedia_Test_CoolProp_CO2_TestStatesSupercritical_Medium_ThermodynamicState_s *') to parameter of type 'ExternalThermodynamicState *' [-Wincompatible-pointer-types]
  TwoPhaseMedium_setState_ph_C_impl(_p_ext, _h_ext, _phase_ext, &_state_ext, MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp1)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp2)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp3)));
                                                                ^~~~~~~~~~~
/media/thomas/DATA/Developpments/ExternalMedia-fork/Modelica/ExternalMedia 3.2.1/Resources/Include/externalmedialib.h:143:107: note: passing argument to parameter 'state' here
        EXPORT void TwoPhaseMedium_setState_ph_C_impl(double p, double h, int phase, ExternalThermodynamicState *state, const char *mediumName, const char *libraryName, const char *substanceName);
                                                                                                                 ^
ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_functions.c:238:138: error: use of undeclared identifier '_fluidConstants'
  _MM = ((ExternalMedia_Test_GenericModels_CompleteThermodynamicState$completeState1_Medium_FluidConstants*)(generic_array_element_addr(&_fluidConstants, sizeof(ExternalMedia_Test_GenericModels_CompleteThermodynamicState$completeState1_Medium_FluidConstants), 1, /* modelica_integer */ ((modelica_integer) 1))))->_molarMass;
                                                                                                                                         ^
ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_functions.c:383:138: error: use of undeclared identifier '_fluidConstants'
  _MM = ((ExternalMedia_Test_GenericModels_CompleteThermodynamicState$completeState2_Medium_FluidConstants*)(generic_array_element_addr(&_fluidConstants, sizeof(ExternalMedia_Test_GenericModels_CompleteThermodynamicState$completeState2_Medium_FluidConstants), 1, /* modelica_integer */ ((modelica_integer) 1))))->_molarMass;
                                                                                                                                         ^
2 warnings and 2 errors generated.
<builtin>: recipe for target 'ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_functions.o' failed
make: *** [ExternalMedia.Test.CoolProp.CO2.TestStatesSupercritical_functions.o] Error 1
make: *** Waiting for unfinished jobs....
Compilation process failed. Exited with code 2.

Add CI system

Even though we might not cover all cases (see #4 (comment)), a basic CI system should help to improve code quality. I volunteer to start with Travis CI and AppVeyor if there are no objections.

Upgrade to MSL 4.0.0

I just had a discussion with @bilderbuchi and @imkelisa at the Modelica Conference. They have already moved all of their libraries to MSL 4.0.0, so it would be nice to also have ExternalMedia there.

It also doesn't make much sense to develop new funcionaltiy on the MSL 3.2.3 branch.

I would propose that we run the MSL 4.0.0 conversion script and release a version 4.0.0 right away.

We can then have some bugfix versions 3.3.x for critical bugs, but otherwise continue under MSL 4.0.0

@jowr, are you fine with that?

Compiling ExternalMedia for OMC now

@JonWel, @jowr, I have some requests by people who need to run the library right away on OMC, but are running into trouble with the released 3.2.1. I also verified myself that it doesn't work, possibly because something was broken in the OMC code generation since when I compiled for 3.2.1 in 2015, as I get gcc complaining about undefined symbols in the C code when trying to run some examples in the library.

One option is to try to fix 3.2.1, but I wonder if it would make more sense to compile what we have now on v.3.3.0-dev. Was the library tested and deployable with OMC when you stopped developing coolprop/ExternalMedia in 2016? What do you suggest?

Thanks!

sCO2 from CoolProp failing in compressor model

Hello,
I am trying to set up a sCO2 Brayton cycle using the ExternalMedia package, however, the sCO2 fluid causes failure in my turbomachinery components. Provided below is the error text.

I wanted to know if this is related to the fluid package or something else.

Thank you.

Error text:

Log-file of program ./dymosim
(generated: Sat Apr 9 15:47:42 2022)

dymosim started
... "Unnamed4" simulating
... "dsin.txt" loading (dymosim input file)
Error: The following error was detected at time: 0
Invalid values for inputs p=100000 h=0 for fluid CarbonDioxide
The stack of functions is:
ExternalMedia.Media.CoolPropMedium.setState_ph_Unique6
ExternalMedia.Media.CoolPropMedium.setState_ph_Unique6(100000.0, Comp1.gas_iso.h, 0)
ExternalMedia.Media.CoolPropMedium.temperature_ph_Unique21(Comp1.gas_iso.p, Comp1.gas_iso.h, Comp1.gas_iso.phaseInput)

First evaluation failed for non-linear solver.

Error: The following error was detected at time: 0
Invalid values for inputs p=100000 h=0 for fluid CarbonDioxide
The stack of functions is:
ExternalMedia.Media.CoolPropMedium.setState_ph_Unique6
ExternalMedia.Media.CoolPropMedium.setState_ph_Unique6(100000.0, Comp1.gas_iso.h, 0)
ExternalMedia.Media.CoolPropMedium.temperature_ph_Unique21(Comp1.gas_iso.p, Comp1.gas_iso.h, Comp1.gas_iso.phaseInput)

Non-linear solver will attempt to handle this problem.

Error: The following error was detected at time: 0
Invalid values for inputs p=100000 h=1e-08 for fluid CarbonDioxide
The stack of functions is:
ExternalMedia.Media.CoolPropMedium.setState_ph_Unique6
ExternalMedia.Media.CoolPropMedium.setState_ph_Unique6(100000.0, Comp1.gas_iso.h, 0)
ExternalMedia.Media.CoolPropMedium.temperature_ph_Unique21(Comp1.gas_iso.p, Comp1.gas_iso.h, Comp1.gas_iso.phaseInput)

Non-linear solver will attempt to handle this problem.

Warning: Failed to solve nonlinear system using Newton solver.
During initialization at time: 0
Tag: initialization.nonlinear[2]
For debugging information enable
Simulation/Setup/Debug/Nonlinear solver diagnostics/Detailed logging of failed nonlinear solutions.
Error: Integrator failed to start model.

ERROR: The simulation of Unnamed4 FAILED

TestState fails with assertion error on state.phase

With ExternalMedia 3.3.0 and OM nightly (i.e. >1.17), running ExternalMedia.Test.TestMedium.TestState fails with

The following assertion has been violated at time 0.002000
state.phase >= 0 and state.phase <= 2
Variable violating min/max constraint: 0 <= state.phase <= 2, has value: 1

Note that the printed value actually complies with the required assertion range! Maybe the passed value is a string or somesuch type that fails the assertion but looks identical when printed?

I suspect that this compilation warning (also reported in #10) could be connected:

TestState_functions.c:52:65: warning: incompatible pointer types passing 'ExternalMedia_Test_TestMedium_TestState_Medium_ThermodynamicState *' to parameter of type 'ExternalThermodynamicState *' (aka 'struct ExternalThermodynamicState *') [-Wincompatible-pointer-types]
  TwoPhaseMedium_setState_ph_C_impl(_p_ext, _h_ext, _phase_ext, &_state_ext, MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp1)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp2)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp3)));
                                                                ^~~~~~~~~~~
<...>/Modelica/ExternalMedia 3.3.0/Resources/Include\externalmedialib.h:170:121: note: passing argument to parameter 'state' here
        EXTERNALMEDIA_EXPORT void TwoPhaseMedium_setState_ph_C_impl(double p, double h, int phase, ExternalThermodynamicState *state, const char *mediumName, const char *libraryName, const char *substanceName);
                                                                                                                               ^

CoolProp compilation fails on Xubuntu, not finding CoolPropTools.h / not linking to target library

Hello.

I am currently trying to compile the CoolProp library on a fresh Xubuntu intall (18.04) for use with OpenModelica.

My first approach was to clone ExternalMedia from "https://github.com/modelica/ExternalMedia" (using the --recursive parameter) and then to follow the ComileHowTwo-instructions, but the compilation terminates not finding CoolPropTools.h. Apparently the makefiles do not provide cloning of the missing files and I have no idea how to do so.

Then I realized that there is another repository at https://github.com/coolprop/ExternalMedia which seemed to be more up-to-date. So my second approach was to recursively clone from there and after struggling with the BuildLib-CMake.sh (had to re-link the shell from /bin/dash to /bin/bash since the pushd/popd commands were not found) the compilation got further but finally terminated with the following error

CMake Error at /home/christian/Dokumente/Git/ExternalMedia/externals/CoolProp.git CMakeLists.txt:422 (target_link_libraries):
Object library target "CoolProp" may not link to anything.

I have also tried using "make -f makefile library" according to the "CompilationHowTwo.txt" instructions, but the result is the same.

I have no idea how to fix this and would be very happy if you could give me a hint what else to try and which repository is the right one.

Best regards
Christian

A very specific successful install (coolprop v4 + EM master + dymola)

I've seen a lot of issues with compiling EM and thought I'd share a success story, even if it's a bit outdated CP.

I installed the current EM master (not the dev branch) with coolprop v4.2.4 on Ubuntu 18.04 for use with Dymola 2019. I'll share my build process below, I make no gaurantees but at the least I can confirm that all EM checks pass in dymola.

Download 159518e
which is the current latest EM on the EM master branch

Download https://sourceforge.net/projects/coolprop/files/CoolProp/4.2.4/

Extract and put the folder in the CoolProp folder (also labeled coolprop) into ExternalMedia//externals/coolprop/trunk/

Navigate to ExternalMedia/Projects and run the linux makefile:

make -f makefile-linux -j40

Once this finishes, you must rename the library folder:

Navigate to ExternalMedia/Modelica/ExternalMedia 3.2.1/Resources/Library

Rename the linux32 folder to linux64

You may now load the package.mo in ExternalMedia/Modelica/ExternalMedia 3.2.1 in dymola

Sorry this isn't actually an issue..

Integer state.phase not returned correctly in OpenModelica

Run ExternalMedia.Test.TestMedium.TestState with the latest nightly build of OpenModelica.

The simulation runs successfully and produces the expected results for all the real variables of the state record. However, the phase value, which is supposed to be an integer equal to one, is returned as zero at the initial time and then as 6.2148e12.

This is probably a bug in OpenModelica that needs to be investigated and fixed, see OMC #8591

Some tests fail at runtime with v.3.3.0 due to wrong error management

@jowr, I ran some tests of v.3.3.0-dev using Dymola 2021 under Windows 10 and Visual Studio 2017 Community edition, here are the results:

  • Test.CoolProp.CO2.TestStatesSupercritical runs
  • Test.CoolProp.CO2.TestStatesTranscritical runs
  • Test.CoolProp.CO2.TestStatesSatSubcritical hangs at runtime
  • Test.CoolProp.CO2.TestBasePropertiesExplicit runs
  • Test.CoolProp.CO2.TestBasePropertiesImplicit hangs at runtime
  • Test.CoolProp.CO2.TestBasePropertiesDynamic runs
  • Test.CoolProp.CO2.TestBasePropertiesTranscritical runs

Failing tests report this error message on the simulation runtime command window: Press the Stop button in Dymola to end the simulation!, which is called either here or here.

This is very old and very crude code that aborted the simulation immediately in case any errors were reported from the called property computation functions - it was put there back in 2006 when Christoph Richter was experimenting with DLL libraries, which do not allow to call the ModelicaError function, because it was not visible from witin the DLL, but only if the library was statically linked with the generated code from the Modelica tool.

However, aborting the simulation as soon as an error is encountered is not a good idea in general. Many errors are caused by ODE solvers taking too bold steps, or by Newton solvers taking too large undamped steps, which cause the inputs of the setState_xx function to go beyond their range of validity. If the ModelicaError function is called in this cases, as done here, then the solver can retry with a smaller step, and in many cases it will eventually succeed.

I understand the library is statically linked as of today, so I am not sure if the old code meant for the DLL is called on purpose, or because of some mistake in how the CMake scripts set up the macros.

The idea is that, in case we are using static linking, we should always call ModelicaError. If we want to compile the library into a DLL, we should change the structure of the functions that can fail so that they simpy return an error code, and then have the ModelicaError function called by a thin, statically linked layer that will in turn call the DLL functions.

Can you please comment on this?

Thanks!

R1233zd simulation hangs

Hello,
I tried simulating R1233zd with ExternalMedia v4-dev, however, simulation hangs indefinitely without using the CPU both with Dymola 2022 and OpenModelica 1.18.1 on Linux (didn't try with Windows).
The problem seems specific to R1233zd, as the same model with R134A works fine.
I also tried compiling the same CoolProp version used by v4-dev and calling it directly from C++, e.g.

    printf("%f\n",PropsSI("T", "P", 1.5e5, "H", 2e5, "R1233zd(E)"));
    printf("%f\n",PropsSI("D", "P", 1.5e5, "T", 300, "R1233zd(E)"));

and it works fine, so the issue seems related to ExternalMedia itself.
I'm attaching the example models, a minimum working example with R134A and a non working example with R1233zd
fede.tar.gz
.

Improve precision of BICUBIC interpolation close to the critical point

I am involved in several studies of sCO2 systems, for which the interpolated CO2 medium of CoolProp is extremely handy. However, sCO2 systems exploit the strong real-gas effects close to the critical point, so it is important that the fluid properties are computed with a decent approximation in the region just above the critical point in the ph-plane.

The attached model TestInterpolatedCO2.mo.txt computes the fluid properties on an isobaric line at 90 bar, which is relatively close to the critical pressure (but not too close either), using the setState_pT function.

These two plots show the comparison between the full CoolProp model and the BICUBIC interpolation, when giving pT as input and retrieving density and specific enthalpy
immagine
immagine
The maximum error on density is about 8%, which is not dramatic, but still significant.

Is there a simple way to increase the number of data points of the interpolation table, by just adding stuff to the medium configuration string? I understand doubling the number of nodes on both axes would increase the table size by a factor four, but give the cubic approximation, the error will shrink by 2^4, i.e. become less than 0.5%.

It could also be useful if one could specify the upper and lower limits of pressure, cutting out useless data points that will never be used for the application at hand (e.g. 74 and 300 bars for sCO2 cycles).

Pressure to PQ_flash [100000 Pa] must be in range [ 51764 Pa, 7.3773e+06 Pa]

Hello,
I experience difficulties with ExternalMedia (might be CoolProp ?).
I compiled with Visual Studio and CoolProp 6.1.0

My media is defined as:

package CO2Bicubic "Model for CO2 with tabular activated"
    extends ExternalMedia.Media.CoolPropMedium(
    mediumName = "CarbonDioxide",
    substanceNames = {"CO2|enable_BICUBIC=1"},
    ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.ph,
    SpecificEnthalpy(start=2e5));},
    annotation (
      Documentation(info = "<html>
http://www.coolprop.org/coolprop/Tabular.html
</html>"));
end CO2Bicubic;

and my model is:

block PipeExternalCO2
  extends Tests;
  replaceable package Medium =Media.CO2;
Modelica.Blocks.Sources.Ramp ramp1(
    offset=1e5,
    startTime=2,
    duration=0,
    height=1e6)
              annotation (Placement(transformation(extent={{-40,70},{-20,90}})));
Modelica.Fluid.Sources.Boundary_pT boundary4(
    nPorts=1,
    redeclare package Medium = Medium,
    use_p_in=true,
    use_T_in=false,
    p=5000000)                                          annotation (Placement(
      transformation(extent={{10,-10},{-10,10}}, rotation=90,
      origin={0,60})));
inner Modelica.Fluid.System system(
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyStateInitial,
    momentumDynamics=Modelica.Fluid.Types.Dynamics.SteadyStateInitial,
    p_ambient=4500000)
  annotation (Placement(transformation(extent={{-90,70},{-70,90}})));
Modelica.Fluid.Pipes.DynamicPipe pipe4(
    redeclare package Medium = Medium,
    use_T_start=true,
    nNodes=5,
    diameter=2.54e-2,
    m_flow_start=0.02,
    height_ab=50,
    length=50,
    p_a_start=5200000,
    p_b_start=5000000,
    modelStructure=Modelica.Fluid.Types.ModelStructure.a_v_b)
                                                            annotation (
    Placement(transformation(
      extent={{-10,-10},{10,10}},
      rotation=90,
      origin={0,-12})));
Modelica.Fluid.Sources.Boundary_pT boundary1(
    nPorts=1,
    redeclare package Medium = Medium,
    p=5500000)                                                     annotation (Placement(
      transformation(extent={{-10,-10},{10,10}},    rotation=90,
      origin={0,-80})));
equation 
  connect(ramp1.y, boundary4.p_in) annotation (Line(points={{-19,80},{-14,80},{-14,
          72},{-8,72}}, color={0,0,127}));
  connect(boundary4.ports[1], pipe4.port_b)
    annotation (Line(points={{0,50},{0,-2},{4.44089e-16,-2}},
                                             color={0,127,255}));
  connect(pipe4.port_a, boundary1.ports[1])
    annotation (Line(points={{-6.66134e-16,-22},{-6.66134e-16,-30},{0,-30},{0,-70}},
                                              color={0,127,255}));
end PipeExternalCO2;

I don't know where this error comes from but I think there is some initialization somewhere.

Any ideas on how to solve this ?

Regards,
Thomas

Managing CoolProp interface dependencies - Tree structure

The goal of ExternalMedia library is to provide a framework for interfacing external codes computing fluid properties to Modelica.Media-compatible component models.

The dependency will follow the recommendation stated by @casella and @adrpo : Download the sources and build the dependency

How to integrate CoolProp in ExternalMedia project:

  1. As a submodule in git
    I don't know how submodule works in git but many blogs seems to say that is a really difficult path to make it work simply. I might be wrong.

  2. git subtree
    Alternative to git submodules : git subtree

  3. External CMake project (ExternalProject_Add).
    This how to explain a simple integration: External CMake Project

For me, the third solution is easier to maintain and understand.
What do you think ? What do I miss ?

Minor Error in the Tutorial

Hello, in the Tutorial at page 6 it is written:

"$ cmake –build build –target install"

shouldn't that be

"$ cmake --build build --target install"

greez

Failed to differentiate the equation ExternalMedia.Media.CoolPropMedium.setState_ph_

Hello,
I have a simple model using ExternalMedia which I'm not able to debug.

It maybe a pure modelica issue but I have no idea how to solve it.

It might be a duplicate of modelica/ModelicaStandardLibrary#1575 and ibell/coolprop#61

model CO2InternalCycleSimple1
  //   package Medium = Modelica.Media.IdealGases.SingleGases.CO2 "Medium model";
  //   package Medium = Modelica.Media.R134a "Medium model";
  //  package Medium = ExternalMedia.Examples.CO2CoolProp "Medium model";
  package Medium = Media.CO2 "Medium model";
  parameter Modelica.SIunits.AbsolutePressure p_sink=6000000;

  inner Modelica.Fluid.System system(
    p_ambient=p_sink,
    T_ambient=873.15,
    m_flow_start=1e-5,
    p_start=p_sink,
    T_start=573.15)
    annotation (Placement(visible=true, transformation(extent={{56,-6},{76,14}}, rotation=0)));
  Modelica.Fluid.Machines.SweptVolume cylinder1(
    redeclare package Medium = Medium,
    T_start=system.T_start,
    p_start=system.p_start,
    use_HeatTransfer=true,
    use_portsData=false,
    use_T_start=true,
    nPorts=1,
    pistonCrossArea=Modelica.Constants.pi,
    clearance=1e-4)
              annotation (smoothOrder=20, Placement(visible=true, transformation(extent={{-34,64},{-6,36}},
          rotation=0)));

  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor heatCapacitor1(C=500*25, T(start=773.15))
    annotation (Placement(visible=true, transformation(extent={{-54,50},{-34,70}}, rotation=0)));

  Modelica.Fluid.Sources.Boundary_ph  sink(
    p=p_sink,
    redeclare package Medium = Medium,
    nPorts=1)
    annotation (Placement(visible=true, transformation(extent={{98,-58},{78,-38}}, rotation=0)));
  Modelica.Mechanics.Translational.Components.Fixed
                                 fixed2(s0=1) annotation (Placement(
        transformation(extent={{-26,-10},{-6,10}})));
    annotation (Placement(transformation(extent={{-58,-74},{-38,-54}})));
initial equation 

equation 
  connect(heatCapacitor1.port, cylinder1.heatPort)
    annotation (Line(points={{-44,50},{-34,50}}, color={191,0,0}));
  // Ajout
  connect(sink.ports[1], cylinder1.ports[1])
    annotation (Line(points={{78,-48},{32,-48},{32,64},{-20,64}}, color={0,127,255}));
  connect(fixed2.flange, cylinder1.flange)
    annotation (Line(points={{-16,0},{-18,0},{-18,36},{-20,36}}, color={0,127,0}));
  annotation (
    smoothOrder=20,
    Diagram(coordinateSystem(extent={{-100,-100},{100,100}}, preserveAspectRatio=false)),
    Icon(coordinateSystem(extent={{-100,-100},{100,100}})),
    experiment(
      Interval=0.0001,
      Tolerance=1e-05,
      __Dymola_Algorithm="Radau"));
end CO2InternalCycleSimple1;

CO2 media is defined as:

package CO2 "Model for CO2"
  extends ExternalMedia.Media.CoolPropMedium(
    mediumName="CarbonDioxide",
    substanceNames={"CO2"},
    ThermoStates=Modelica.Media.Interfaces.Choices.IndependentVariables.ph,
    SpecificEnthalpy(start=1e5),
    AbsolutePressure(start=1e5));
  annotation (Documentation(info="<html>
http://www.coolprop.org/coolprop/Tabular.html
</html>"));
end CO2;

Cannot compile ExternalMedia under Linux with current CoolProp

During the build process with the command "make -f makefile-linux header library" or similarly with the script "BuildLib-CMake.sh" the following error occurs:

cp: der Aufruf von stat für '../externals/CoolProp.build.gcc/CoolProp.dir/Release/*.o' ist nicht möglich: Datei oder Verzeichnis nicht gefunden

(call not possible. File or Folder not found)

So it is compiling but there is no object file or Release folder created.

So I suppose as the ExternalMedia library is outdated, it is not compatible with the new CoolProp. I am not experienced in changing cmake properties etc. in order to make it work again. I would appreciate, if someone can help me to compile this library on linux.

Compilation error in Dymola 2022x

Screenshot 2022-02-20 071432
can anyone know where can I find externalmedia.h, I am not able to get it.

If any one has advanced version in this, please send me a copy..

Thank you

ExternalMedia not working when using it through "Medium.BaseProperties" model

Hi there,

I'm using you fantastic ExternalMedia library and I'm getting translation errors when using it through a Medium.BaseProperties model.

I wrote the code below in order to show the error. In the code, Test1 fails and Test2 runs correctly when using NH3CoolProp Medium. Note that both models run correctly when using package Medium = Modelica.Media.IdealGases.SingleGases.NH3.

Here is the code:

package ExternalMediaError

package NH3CoolProp "CoolProp model of NH3"
extends ExternalMedia.Media.CoolPropMedium(
mediumName = "Ammonia",
substanceNames = {"NH3"},
ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.ph,
SpecificEnthalpy (start=2e5));
end NH3CoolProp;

partial model Test0
package Medium = ExternalMediaError.NH3CoolProp;
//package Medium = Modelica.Media.IdealGases.SingleGases.NH3;
parameter Medium.AbsolutePressure p0 = 1e5;
parameter Medium.Temperature T0 = 350;
Medium.IsobaricExpansionCoefficient beta;
end Test0;

model Test1
extends Test0;
Medium.BaseProperties medium(
preferredMediumStates=true,
p(start=p0, fixed=false),
T(start=T0, fixed=false));

equation
medium.T = T0;
medium.p = p0;
beta = Medium.isobaricExpansionCoefficient(medium.state);
annotation(experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-06, Interval = 0.002));
end Test1;

model Test2
extends Test0;
Medium.ThermodynamicState state;
Medium.Density d = Medium.density(state) "Density";
Medium.SpecificInternalEnergy u = Medium.specificInternalEnergy(state);
Medium.SpecificInternalEnergy h = Medium.specificEnthalpy(state);

equation
state = Medium.setState_pT(p0, T0);
beta = Medium.isobaricExpansionCoefficient(state);

annotation(experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-06, Interval = 0.002));

end Test2;

end ExternalMediaError;

Here are the errors (OMEdit 1.18.0 running on Windows 10):

[1] 16:29:44 Translation Error
[ExternalMedia.Media.BaseClasses.ExternalTwoPhaseMedium: 186:15-190:19]: External function ‘TwoPhaseMedium_getMolarMass_C_impl‘ could not be found in any of the given shared libraries:
C:/Users/ferrucci/OneDrive/workspace/modelica/openModelica/lib/ExternalMedia 3.3.0/Resources/Library/win64/ExternalMediaLib.dll
C:/Users/ferrucci/OneDrive/workspace/modelica/openModelica/lib/ExternalMedia 3.3.0/Resources/Library/ExternalMediaLib.dll

[2] 16:29:44 Translation Error
[ExternalMedia.Media.BaseClasses.ExternalTwoPhaseMedium: 198:15-202:26]: External function ‘TwoPhaseMedium_getCriticalPressure_C_impl‘ could not be found in any of the given shared libraries:
C:/Users/ferrucci/OneDrive/workspace/modelica/openModelica/lib/ExternalMedia 3.3.0/Resources/Library/win64/ExternalMediaLib.dll
C:/Users/ferrucci/OneDrive/workspace/modelica/openModelica/lib/ExternalMedia 3.3.0/Resources/Library/ExternalMediaLib.dll

Notes:
I don't know why it's complaining about ExternalMediaLib.dll, since I'm using libExternalMediaLib.a

OpenModelica cannot handle package constants coming from external functions in static libraries

Run ExternalMedia.Test.TestMedium.TestConstants with the latest nightly build of OpenModelica. The following error is generated:

[1] 20:08:32 Translation Error
[ExternalMedia.Media.BaseClasses.ExternalTwoPhaseMedium: 192:15-196:29]: External function ‘TwoPhaseMedium_getCriticalTemperature_C_impl‘ could not be found in any of the given shared libraries:
  C:/Program Files/OpenModelica1.19.0-dev-64bit/lib//omc/ExternalMediaLib.dll
  D:/Lavoro/Modelica/ExternalMedia 3.3.1/Resources/Library/win64/ExternalMediaLib.dll
  D:/Lavoro/Modelica/ExternalMedia 3.3.1/Resources/Library/ExternalMediaLib.dll

The reason for that is that the OpenModelica front-end tries to constant-evaluate the package constant Medium.externalFluidConstants.criticalTemperature at compile time during flattening. This constant is bound to the external function Medium.getCriticalTemperature(), which calls an external function to get the value from the external solver.

Recent improvements to version 1.19.0-dev of OpenModelica make it possible for the front-end to call such external functions, provided that they are available in dynamically linked/shared libraries. This will be addressed in #50.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.