Showing results for 
Search instead for 
Do you mean 
Solved! Go to solution

Ameset: Problems with C utilities



I have a question concerning the use of 'C utilities' in Ameset. Specifically the ones that don't have a return value, such as the utility ' tpf_sat3_t_(tg, rhogSat, rholSat, pressSatA, fi) '  found in the two-phase flow library.


I want to vary the temperature of the fluid (Oxygen) and find the corresponding Saturation pressure.

The inputs are 'tg' (temperature of the fluid) and 'fi'(fluid index). The outputs are the vapor/liquid densities ( rhogSat/rholSat) and the Saturation pressure (pressSatA).


I can't understand where the error comes from. The program compiles and runs, but the three outputs always stay the same (pressSatA= 12.8377 barA ; rhogSat= 31.36 kg/m**3 and rholSat= -1 kg/m**3).


I have included the files containing the amesim model and the C code text of the component I programed "SATURATION_UTILITY".

Here is a FileX link if you want the pack with the component:


Thanks in advance.


**Note: I work with internal variables and parameters; the input/output of the component are not used.


Re: Ameset: Problems with C utilities

Hi JasonTse,

A few word about your development:

- I suppose that you are trying to create a capacitive (C) component,

- In this case you need to set the C structure and fluid index check at initialization level to correctly switch to the executable phase,

- To do so, just set the following lines at the very begining of the initialization function:


   /* Fluid index check */
   if(ip[0] < 0)
      error = 2;
      skfi     = ip[0];
      /* Get the number of each capacitive element. */
      ic[0]  = tpf_cnum_(&skfi);
      *cnum1 = ic[0];


Since i don't have the spe file of your submodel, i cannot really test this. Just start like this, we will surely continue to discuss in the coming days

Re: Ameset: Problems with C utilities

Hi JasonTse,


Note also that "vg" is a state variable. It can not be set directly with a value in the code of the submodel (except at first call of after a discontinuity restart).

However, its derivative "vgdt" must be set in the code at each call.

Accepted by topic author JasonTse
‎04-04-2017 02:55 PM

Re: Ameset: Problems with C utilities

Hi everyone,


I found the error.

In the utility's arguments I didn't use the fluid index "skfi" found in the Interger Parameters. 

For some reason I had also created an internal variable "fi" (which in the program was also declared as a "double" instead of an integer "int"). I set fi = skfi and used this as an arguement.


Now, using directly "skfi" it works fine! 

Thanks for your responses!

Re: Ameset: Problems with C utilities

Thank you,


It was indeed a problem with the fluid index. I wrote what was wrong as a reply to my post.

Il keep in mind this check for the index for future programs!


Re: Ameset: Problems with C utilities



Thanks for your remark! I will keep it in mind in the futur.

I posted what was my problem as a reply to my post.