0

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?

janpeter
  • 681
  • 8
  • 22

2 Answers2

1

I know this is of no help but I noticed something similar today. I have a fluid model that uses 100% MSL components and runs without issues in OpenModelica.

However when I export it as FMU I get assertion errors about temperature being outside of the range given in the media properties.

I use the same media.

Did you try changing the fluid media?

  • I changed to MSL StandardWaterOnePhase. This water work as expected for temperature 273.16 and up, while 273.15 is I think seen as frozen. The previous type MSL ConstantPropertyLiquidWater has the corresponding limit 272.15. I tend to see this as a "bug". Still in daily life we talk about liquid water with temperature slightly below zero, but freezes if you "shake it" or enter some impurity. Not sure if the ambition is to cover this phenomenon in MSL. – janpeter Apr 27 '23 at 07:12
  • Note, I use here FMU-CS from JModelica. The FMUs from OpenModelica you have sometimes trouble with but their FMU-ME is usually "better". The OpenModelica team work to improve the FMUs and change to stable version 1.21.0 recently released may help – janpeter Apr 27 '23 at 07:16
  • Note that in the first comment above my results came from a setup where the pipe medium was not changed and still ConstantPropertyLiquidWater. When it was changed to the same medium as the tanks then the temperature limit became 27.4.4 and for slightly lower temperature error about the steam table. This is something I do not understand well, but just want to write up here for the record. – janpeter Apr 28 '23 at 08:17
0

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?

janpeter
  • 681
  • 8
  • 22