modelicaopenmodelicajmodelica

Example MSL Fluid and Media and annotations removed gives initialisation problems?


I try to understand MSL Fluid and Media better and study the very basic example Modelica.Fluid.Examples.Tanks.EmptyTanks. Water flows simply from the upper tank to the lower tank. See the code below.

encapsulated package MSL_FLUID_MEDIA_TEST

    import Modelica.Fluid.Examples;

    model EmptyTanks1
        extends Examples.Tanks.EmptyTanks;
    end EmptyTanks1;

    import Modelica.Icons.Example;
    import Modelica.Fluid.Vessels.OpenTank;
    import Modelica.Fluid.Vessels.BaseClasses.VesselPortsData;
    import Modelica.Fluid.Pipes.StaticPipe;
    import Modelica.Media.Water;
    import Modelica.Fluid.System;
    import Modelica.Fluid.Types.Dynamics;

    model EmptyTanks2   
        extends Example;
        OpenTank tank1(
            redeclare package Medium = Water.ConstantPropertyLiquidWater,
            nPorts = 1,
            crossArea = 1,
            level_start = 1,
            portsData = {VesselPortsData(diameter = 0.1)},
            height = 1.1);
        StaticPipe pipe(
            redeclare package Medium = Water.ConstantPropertyLiquidWater,
            length = 1,
            height_ab =-1);
        OpenTank tank2(
            redeclare package Medium = Water.ConstantPropertyLiquidWater,
            nPorts = 1,
            crossArea = 1,
            level_start = 1.0e-10,
            portsData = {VesselPortsData(diameter = 0.1, height = 0.5)},
            height = 1.1);
        inner System system(energyDynamics = Dynamics.FixedInitial);        
    equation
        connect(tank1.ports[1], pipe.port_a);
        connect(pipe.port_b, tank2.ports[1]);
    end EmptyTanks2;                
    
end MSL_FLUID_MEDIA_TEST;

EmptyTanks1 is the directly imported model from MSL and works fine. EmptyTanks2 is the code copied from the example but all annotation() statements are eliminated.

Both models compile well in both JModelica and OpenModelica. But EmptyTanks2 gives initialisation errors in both softwares that I think are identical. Further EmptyTanks1 gives also initialisation problem in JModelica but ok with OpenModelica.

From the FMU I can read out the actual continuous time states by the (PyFMI) command model.get_states_list() and get the four states level and temperature of the media for each tank.

The start values of the levels are given values "up-front" in the code while the start values of the media temperatures are buried deep down in the MSL.Media code.

The log-text from JModelica running EmptyTanks1 is first a warning that the temperature is 272.15 K (and corresponds to -1.0 C) and then we get a runtime error "Evaluation of model equations during event iteration failed."

The log-text from JModelica running EmptyTanks2 is a warning about division by zero in model pipe. It is pipe.crossArea / pipe.perimeter during initialisation that gives this warning (error?). When I check the FMU after compilation the pipe.perimeter has a value >0 (actually pi/10).

The log-text from OpenModelica (OMEdit) running EmptyTanks2 gives a similar error text as JModelica and point out that pipe.perimeter is zero at time of initialisation.

Note, here is a slight difference in MSL version used and JModelica uses 3.2.2 build 3 while OpenModelica use 3.2.3. The code for EmptyTanks looks the same in each version. I doubt that the MSL version difference plays any role. I use JModelica 2.14 in Windows and OpenModelica 1.21.0 in Linux.

My goal is that the EmptyTanks2 code should work both for OpenModelica and JModelica.

What should I do?

Is it wrong to think that annotation() can be eliminated without affecting running the code?


Solution

  • Further work solved the problem, almost. From OpenModelica I see that for EmptyTanks1 the default diameter is 0.1 and if I add that information to EmptyTanks2.pipe I eliminate that problem of division by zero during initialisation. I see now that the actual MSL code do include diameter, and thus a simple misstake by me.

    In order to make the example EmptyTanks2 to works also in JModelica I need to add the initial temperature and set that to T_start = 300 K. (The ambient temperature is 293.15 K, but if I choose T_start to the same value I get an error. So, something is strange here still.)

    From OpenModelica I see that the default value of T_start are taken from "system" and this seems not to work in JModelica (with MSL 3.2.2 build 3) although T_ambient is propagated from system to the two tanks.

    Can I see this difference of MSL 3.2.2 build 3 and MSL 3.2.3 in some log-book?