modelica-3rdparty / ExternalMedia

The ExternalMedia library provides a framework for interfacing external codes computing fluid properties to Modelica.Media-compatible component models.
53 stars 36 forks source link

Communication protocol error. Expected 'DONE', received 'calc_transport has the value of 1 #83

Closed thorade closed 1 year ago

thorade commented 1 year ago

I am testing the library with Impact, and after changing some comments to C89 format (see PR #79) and compiling the source code to .so file I am able to simulate some of the smaller models like ExternalMedia.Test.TestMedium.TestConstants

But for several of the "real" models like ExternalMedia.Test.CoolProp.Pentane.Pentane_hs I receive an error message as below:

Error at line 6, column 22, in package 'ExternalMedia.Media.BaseClasses.ExternalTwoPhaseMedium':
    Could not evaluate binding expression for constant 'fluidConstants': '{externalFluidConstants}'
    in function 'ExternalMedia.Test.CoolProp.Pentane.Pentane_hs.wf.getMolarMass'
    Failed to evaluate external function 'TwoPhaseMedium_getMolarMass_C_impl', 
    error in process communication: 'Communication protocol error. 
    Expected 'DONE', received 'calc_transport has the value of 1'

Any idea what I am doing wrong?

thorade commented 1 year ago

It seems that Modelon Impact expects external code to use ModelicaMessage etc, but ExternalMEdia is using stdout for communication, and Impact does that, too.

thorade commented 1 year ago

This could be fixed on either library or tool side. Modelon compiler team will fix it on the tool side, so there is nothing to do here. Closing this. Will put a comment once it is fixed

casella commented 1 year ago

@thorade the code we wrote uses ModelicaMessage etc., but the code we used, i.e. CoolProp, uses stdout, or maybe even cout. Ideally, we'd like to keep it as it is. I'm not aware of limitations in Modelica external functions that forbid using stdout.

Of course errors and exceptions are different: in that case, you really need to catch them and pass them properly to ModelicaError, so that the runtime can take appropriate action (e.g., retry with a shorter time step).

BTW, doing that is currently a pain, and required a quite convoluted hack to work in all OSs and tools. I would very much appreciate your comment on modelica/ModelicaSpecification#2191, on behalf of Modelon, so we can push that forward.

If we can reach an agreement on a standard way to export ModelicaUtilities symbols in all tools, we could simplify the code of ExternalMedia considerably. In fact, the ExternalMedia source code is ready for that, we would only need to remove parts that are no longer necessary.