Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Convert dymola model to openmodelica

Convert dymola model to openmodelica

Hello

I search to convert dymola model to openmodelica model.
My base model is https://github.com/DTU-TES/Hydrogen-Fuelling-Station

When I run the test model, I have this error :


[10] 18:25:47 Traduction Erreur
Internal error - BackendDAEOptimize.makeEquationToResidualExp failed to transform equation: pressureLoss.mediumB = HydrogenFuelingStationLibrary.Models.VerificationOfComponents.Valves.pressureLoss.Medium.setState_ph(pressureLoss.portB.p, tank1_2.portA.h_outflow, 0) to residual form!

[11] 18:25:47 Traduction Erreur
Internal error - BackendDAEOptimize.makeEquationToResidualExp failed to transform equation: tank1_2.mediumStream = HydrogenFuelingStationLibrary.Models.VerificationOfComponents.Valves.tank1_2.Medium.setState_ph(tank1_2.p, tank1_2.h, 0) to residual form!

[12] 18:25:47 Traduction Erreur
Internal error - BackendDAEOptimize.makeEquationToResidualExp failed to transform equation: tank1_1.mediumStream = HydrogenFuelingStationLibrary.Models.VerificationOfComponents.Valves.tank1_1.Medium.setState_ph(tank1_1.p, tank1_1.h, 0) to residual form!


Can you advise me to modify this part ?

Thank you for your help
Steven

Re: Convert dymola model to openmodelica

Which model are you trying to run?

Re: Convert dymola model to openmodelica

Thank you for your quick answer

I try to run models verification of componentes.
For example, I run HydrogenFuelingStationLibrary/Models/Tanks

Re: Convert dymola model to openmodelica

Hi,
I see that the library is using mediums accessed via the ExternalMedia library linked with CoolProp. I think that ExternalMedia is not working in OpenModelica, perhaps Adrian can confirm if this is the situation or not. If you can't use ExternalMedia and CoolProp, the easiest way for having a good hydrogen Medium definition I think is using HelmholtzMedia, but you will need to do some work.

Carlos

Re: Convert dymola model to openmodelica

Hi

Thank you for quick answer

Ok I give up to use this library to calculate the behavior of hydrogen.
I try since one week but I find any solution to use corretly coolprop library with openmodelica (same in recompiling)

Thank you for your help

Re: Convert dymola model to openmodelica

There is some work ongoing to fix ExternalMedia to work with OpenModelica:
https://github.com/modelica-3rdparty/Ex … .3.3.0-dev
Myself I managed to compile the C library but I haven't tested if anything works:
https://build.openmodelica.org/omc/Mode … 03.2.1.zip
I will do some testing later on with this.

However, about the Hydrogen-Fuelling-Station library, seems it not working even in Dymola:

Code:


For equation
if (pressureLoss.Vdot <> 0) then
pressureLoss.ReynoldsNumber = pressureLoss.d_in*abs(pressureLoss.Vdot/ pressureLoss.A)*pressureLoss.Diameter/pressureLoss.mu_in;
else
pressureLoss.ReynoldsNumber = 1;
end if;
found in class HydrogenFuelingStationLibrary.PressureLosses.PressureLoss, C:/home/adrpo33/dev/modelica/Hydrogen-Fuelling-Station/HydrogenFuelingStationLibrary.mo at line 3153, and used in component pressureLoss.

The DAE has 337 scalar unknowns and 337 scalar equations.

The initial conditions are not fully specified.
Dymola has selected default initial conditions.

Assuming fixed default start value for the continuous states:
compressor.E_D(start = 0.0)
compressor.EA(start = 0.0)
compressor.EB(start = 0.0)
compressor.W(start = 0.0)
heatExchangerFixedTemperature.EA(start = 0.0)
heatExchangerFixedTemperature.EB(start = 0.0)
heatExchangerFixedTemperature.EQ(start = 0.0)
heatExchangerFixedTemperature.EQ1(start = 0.0)
heatExchangerFixedTemperature.EQ2(start = 0.0)
heatExchangerFixedTemperature.Q(start = 0.0)
heatExchangerFixedTemperature.Q1(start = 0.0)
heatExchangerFixedTemperature.Q2(start = 0.0)
pressureLoss.E_D(start = 0.0)
pressureLoss.EA(start = 0.0)
pressureLoss.EB(start = 0.0)
tank1_1.E_stream(start = 0.0)
tank1_1.E_tank(start = 0.0)
tank1_1.Q(start = 0.0)
tank1_2.E_stream(start = 0.0)
tank1_2.E_tank(start = 0.0)
tank1_2.Q(start = 0.0)

Statistics

Selected continuous time states

Some variables are iteration variables of the initialization problem:
but they are not given any explicit start values. Zero will be used.

Iteration variables:
compressor.mediumB.phase
compressor.mediumIS.phase
heatExchangerFixedTemperature.mediumA.h
heatExchangerFixedTemperature.mediumA.phase
heatExchangerFixedTemperature.mediumB.phase
pressureLoss.medium1.phase
pressureLoss.medium2.phase

Error detected when generating code.

Translation aborted.

WARNINGS have been issued.

Re: Convert dymola model to openmodelica

Ok it is a good news for me this work on coolprop.
I hope that it's going to work

I find the hydrogen library linked at https://backend.orbit.dtu.dk/ws/portalf … ations.pdf

i thought it would work
Maybe, there are some errors insides this code but this library will be used like a base.

Thank you for your help. You give me hope

Re: Convert dymola model to openmodelica

In any case, thank you for your help

I am going to work on your two solutions :

Carlos, I find apublication with helmholtz coefficient for hydrogen used by refprop but I don't understand for the moment how can helmholtz coefficient inside helmholtz media to work. I compare the model for helium that is already in library and the theory of coefficient to understand the working of module.

Adrpo, I test your version of externalmedia with my configuration. I have two differents behavior :

    ExternalMedia/Examples/CO2RefProp : I have an error on the function og getMolarMass

      ExternalMedia/Test/Pentane_hs : The verification is good but I have this error :
      ExternalMedia.Test.CoolProp.Pentane_hs_functions.c: In function 'omc_ExternalMedia_Test_CoolProp_Pentane__hs_wf_setBubbleState':
      ExternalMedia.Test.CoolProp.Pentane_hs_functions.c:228:40: warning: passing argument 1 of 'TwoPhaseMedium_setBubbleState_C_impl' from incompatible pointer type [-Wincompatible-pointer-types]
         TwoPhaseMedium_setBubbleState_C_impl(_sat_ext, _phase_ext, &_state_ext, MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp1)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp2)), MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp3)));

      Thank you for your help
      Steven

      Re: Convert dymola model to openmodelica

      Hi Steven,

      I did a Python script to pass the information from CoolProp fluids (json files) to HelmholtzMedia format. In fact I have planned to pass all the fluids in CoolProp and share them, but I have not yet done the transport properties mapping. If you are interested I can make the file for Hydrogen, it should allow for all thermodynamic properties calculation plus surface tension, but viscosity and thermal conductivity will be lacking, and I think you will need them.

      Carlos

      Re: Convert dymola model to openmodelica

      Hi Carlos,

      Yes I am very insterested by this file for hydrogen.

      I was doing by hand the passage of an fld file in helhmotzfluid. It takes a long time to find the right value.

      if you want to complete your file I can provide you with the hydrogen fld file

      Thank you 

      Edited by: sdaix - Mar-19-21 17:45:47

      Re: Convert dymola model to openmodelica

      Hi Steven,
      I attach the Hydrogen medium. Decompress and put the folder inside HelmholtzFluids. The limits for enthalpy and entropy are only approximate. I made a fas test and results seem OK.
      I review also the HelmholtzMedia treatment of viscosity. It seems inherited from RefProp and the dilute viscosity term is quite confusing. For the residual viscosity there are only very few mediums coded. The treatment in CoolProp is clearer and larger, but still is quite limited, as they develop viscosity only for substances with a reference viscosity equation from temperature and density. I am thinking in rewrite the HelmholtzMedia.Interfaces.PartialHelmholtzMedium.Transport package in order to make it compatible with CoolProp and add calculation from temperature and pressure, but it will need some time.

      Regards


      Hydrogen.zip

      Attachments:

      Re: Convert dymola model to openmodelica

      Hi Carlos

      Perfect I understand. Thank you for your help.
      I Have two adding questions :

        I try to test the thermocycle library with helmholtzlibrary but I have an extra equation (20 instead of 19 for the valve model). Have you ever used this bookstore? You would know the difference between coolprop and helmholtz library to explain this problem.

        I try also to code these following equations (figure 3 and 4) for my training and I want to be sure that it is possible with this library. I have some difficulties to code theses equations.

        equation

        Re: Convert dymola model to openmodelica

        Hi Steven,

        The file attached is an XML file with no information.

        Re: Convert dymola model to openmodelica

        I thinh there are a problem

        Following link :
        https://prhyde-cdn.s3-accelerate.amazon … vision.pdf

        Re: Convert dymola model to openmodelica

        Hi Steven,

        I have run the Test_Valve example of the ThermoCycle library with no problem using: R134A from my own library, R134A from HelmholtzMedia library and the Hydrogen file for the HelmholtzMedia library that I sent to you.
        I needed to make first an adjustement. As the valve component is declared as having ThermoCycle.Media.R245fa_CP as Medium, OpenModelica was complaining about the lack of the class ExternalMedia.Media.CooPropMedium. I just changed the Medium declaration in the valve model to one of my library, you can do to one in HelmholtzMedia or in Modelica.Media, and the example run.
        On Monday I will have a look to the document you have supplied. But perhaps is good to know what do you want to simulate.


        Re: Convert dymola model to openmodelica

        Hi Carlos

        Yes you right the thermocycle library works. I made a mistake on the module of helmholtz.


        in fact, I am using this document as validation of the module. In it there is a "simple" case compose of :
        *  a source of pressure with a ramp on 600s
        * a valve with some parameter followng the pressure gradient.
                  if sonic : Pin > 2Pout
                            dm/dt=C kv Pin (rho_nominal / Temperature_in)^1/2
                  if subsonic Pin <=2Pout
                            dm/dt= 2 C kv (rho_nom (Pin - Pout) * Pout / Temperature_in)^1/2
        C is a constant equal at 257
        * a closed tank 

        Source <-->  valve <--> tank

        This system is carried out with hydrogen gas and for initial pressure at 100bar and final pressure at 437 bar at 600s at the level of source

        Once the module is validated I could develop an entire filling line for several tanks and different sizes of pipes / tanks.

        Thank you for your help
        Steven

        Re: Convert dymola model to openmodelica

        Hi Steven,
        I gave a look to the documentation. I think you need a package for fluid flow and a package for medium properties calculation. For the fluid flow, the valve should not be a problem, the only requisite is that it grants not to exceed the sound velocity. The tank could be more complicated, as it has a multilayer shell and I see that the temperature at each material layer is calculated, shape could be also important, but I do not know. As there is a dedicated library I would try to use it. It is based in ExternalMedia and CoolProp, but this should be easy to modify. All Medium definitions must support the Modelica defined interface, and in this case (fixed composition and single phase) almost all Mediums should work. A quite different point is the quality of the results offered by the Medium, and the coverage of physical properties it has. At the high pressure you need to work I think that a Medium based in a multiparameter EOS is needed. You have CoolProp, but doesn't work with OpenModelica, and HelmholtzMedia. I'm almost sure that you will need viscosity and thermal conductivity, and the file I sent doesn't perform their calculation.
        I think that the easiest for you is to finish the Hydrogen medium adding the viscosity and thermal conductivity calculation. In a dirty and fast way it can be done declaring both models as hardcoded (VS0 for viscosity and TC0 for thermal conductivity) and writing their calculation inside the dynamicViscosity_residual and thermalConductivity_background functions. The calculation of viscosity is available  here. For thermal conductivity you can look at the calculation in CoolProp.
        I am extending the HelmholtzMedia package to support transport properties from CoolProp, but I will still need some days to finish.

        Regards

        Carlos

        Re: Convert dymola model to openmodelica

        Hi Carlos

        Thank you for your reply

        I have currently coded this model which serves as a basis for the subject.
        I used the valve which is available in the fluid package and I added the properties according to helmholtz as you had thought also I took the parameters of the helium to start which was available.
        I think that the shape will be important in the thermal but in a second step, because it will surely be necessary to adjust the heat exchange surface.
        I have a lot of discrepancy between my current model and the results of the document.
        I'm looking at where the problem could be coming from and thought it was from the valve. Possibly the absence of transport properties depending on the equation of state.


        valve-cas-3.zip

        Attachments:

        Re: Convert dymola model to openmodelica

        Hi Carlos

        I come back to you after some tests, The model I sent you does not work. I tried to put several thermal resistance and inertia with finally a convetive exchange.
        The exchange between the tank and the first layer is too large, I should add a resistance related to the fluid and the second inertia remains too cold.
        I am looking to adapt a multilayer model for use. I found a law of convection in a cylinder which will allow me to model an exchange in the reservoir.

                //calculation of rayleighs number taken from 'Natural convection cooling of
                //rectangular and cylindrical containers' by Wenxian Lin, S.W. Armfield
                Ra=g*beta*d^3*Medium.specificHeatCapacityCp(medium)*
                Medium.density(medium)^2*abs(portA.T-T)/(v*k);
                beta=1/portA.T;
                Tau=time/(d^2/(a*Ra^(1/2)));
                Nu=0.104*Ra^(0.352);

        Thank you for your help
        Steven

        Re: Convert dymola model to openmodelica

        Hi Steven,

        I made a fast look at your model and the documentation. One point, I see that you are filling a 350 lts tank with a Kv=0.11 valve, as per the documentation a understand (pag.13 of D4.1) that the valve must fill 4 tanks (1400 lts total volume).
        I think that viscosity is not necessary for the valve calculation, normally valves are treated as isenthalpic. You will need it and thermal conductivity for the heat transfer at the tanks.
        And one bad new. I see that the medium has convergence problems when arriving close to 400 bars.

        Regards

        Carlos

        Re: Convert dymola model to openmodelica

        Hi Carlos,

        Well seen for the volume, I had stayed on the volume of the container. It corresponds better to what is presented in the document.

        Yes I agree with you on the physical properties. But when you're done re-adjusting your conversion file for transport properties, I'm in for it.

        For the convergence problem, it's a bit more annoying. Do you think this comes from the helmholtzfluid module? I have the impression that it gets better when you increase the inlet temperature. It may be necessary to adjust the time step?

        Thank you anyway for your help

        Regards
        STeven

        Re: Convert dymola model to openmodelica

        I come back to you I tried to check the coefficient that you entered for the equation of state. Looks good for all settings. I just didn't check HCRIT0 and SCRIT0.

        I am doing some time step testing to see if it can improve things.

        I test with helium medium, I don't have the same problem. The time step has no influence

        Steven

        Edited by: sdaix - Mar-24-21 10:45:13

        Re: Convert dymola model to openmodelica

        Hi,
        Yes the convergence problem comes from the HelmholtzMedia library. The message is related with convergence problems in the setState_phX function. So, of not easy solution.

        Carlos

        Re: Convert dymola model to openmodelica

        Hi Carlos

        So I think it's going to be complicated to use openmodelica for my project with hydrogen pure without coolprop or the helmhotlz library.

        Thank you anyway for your help

        There are 0 guests and 0 other users also viewing this topic
        You are here: