ExternalMedia icon indicating copy to clipboard operation
ExternalMedia copied to clipboard

TestState fails with assertion error on state.phase

Open bilderbuchi opened this issue 4 years ago • 4 comments

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);
                                                                                                                               ^

bilderbuchi avatar Jun 25 '21 08:06 bilderbuchi

An equivalent problem occurs in function TwoPhaseMedium_setState_pT_C_impl (see also #10).

bilderbuchi avatar Jun 25 '21 08:06 bilderbuchi

Btw, I don't know if runtests.mos is actually used, but it's missing the tests TestMedium.TestConstants, TestMedium.TestState, TestMedium.TestSat.

bilderbuchi avatar Jun 25 '21 08:06 bilderbuchi

A quick re-check with OM 1.18.1 and the new ExternalMedia 3.3.1 shows that this still occurs.

bilderbuchi avatar Feb 18 '22 09:02 bilderbuchi

Probably related to https://github.com/OpenModelica/OpenModelica/issues/8591.

casella avatar May 20 '22 22:05 casella

I checked with a recent OM nightly (1.21.0-dev-318) and current master (db55653) with binaries from the CI job, and the assertion does not print anymore.

The compilation warning still occurs:

TestState_functions.c:50:70: warning: incompatible pointer types passing 'ExternalMedia_Test_TestMedium_TestState_Medium_ThermodynamicState_external *' to parameter of type 'ExternalThermodynamicState *' (aka 'struct ExternalThermodynamicState *') [-Wincompatible-pointer-types]
  TwoPhaseMedium_setState_ph_C_impl_wrap(_p_ext, _h_ext, _phase_ext, &_state_ext, MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp1)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp2)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp3)));
                                                                     ^~~~~~~~~~~
./TestState_includes.h:13:108: note: passing argument to parameter 'state' here
    void TwoPhaseMedium_setState_ph_C_impl_wrap(double p, double h, int phase, ExternalThermodynamicState *state, const char *mediumName, const char *libraryName, const char *substanceName)

The runtests.mos files seems heavily outdated/old, but that's probably easy to fix/not that relevant anymore.

bilderbuchi avatar Mar 20 '23 12:03 bilderbuchi

This should be fixed with ExternalMedia 3.3.2, if used with OMC 1.21.0 or later

casella avatar Apr 12 '23 21:04 casella