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: https://ent.normandie-univ.fr/filex/get?k=da1Sc7lFdT9bCI4G8vG
Thanks in advance.
**Note: I work with internal variables and parameters; the input/output of the component are not used.
Solved! Go to Solution.
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)
error = 2;
skfi = ip;
/* Get the number of each capacitive element. */
ic = tpf_cnum_(&skfi);
*cnum1 = ic;
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
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.
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!
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!