CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Compile User-Defined Real Gas Model (UDRGM)

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 27, 2020, 07:41
Default REAL_mw
  #21
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Fluent does not stop users to define their own function, so, REAL_compressibility is alright. And so is REAL_mw. However, the function that is supposed to return molecular weight of the gas and needs to be included in the real functions list has to have only one argument. So, you can certainly use REAL_mw as it is but then you cannot include it in the list. If you want to include it in the list, then it should have only one argument, i.e., yi.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   March 27, 2020, 07:52
Default
  #22
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
So canīt I include the dependency of Temperature and Pressure in my REAL_mw?

I just discovered something very fishy in Fluent, I am using the following code to calculate cp:

double REAL_specific_heat(cell_t cell, Thread *thread, double Temp, double Rho, double Pabs, double yi[])
{
/*-------------------------------------------------------------------*/
/* Import Flow Conditions from Fluent */
/*-------------------------------------------------------------------*/
double Pstat = Pabs+1; /* Absolute Pressure in Pa (atmospheric + gauge)*/
double Tstat = Temp; /* Static Temperature in K */
Pstat = Pstat/101325; /* From Pa to Atm */


(SET OF INTERPOLATIONS TO OBTAIN cp)

/*-------------------------------------------------------------------*/
/* Console Display (For Debugging) */
/*-------------------------------------------------------------------*/
Message("PStat: %f (atm) TStat: %f (K) CP: %f (J/Kg/K) \n",Pstat,Tstat,cp);
/*-------------------------------------------------------------------*/
return cp; /* (J/Kg/K) */
}


However as you can see in the screenshot, Fluent is taking the Pabs as Temperature and I don really know wich value is using fot the Pabs. I donīt really understand why it is doing this as I am following the same structure in the user's guide. Maybe something is wrong with the version 19.0 and the userīs guide OR as you said in the previous post I might not be able to include some dependencies...
Attached Images
File Type: png WhatItsGoingOn..PNG (79.7 KB, 15 views)
Captain Convergence is offline   Reply With Quote

Old   March 27, 2020, 07:57
Default MW
  #23
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
How could molecular weight be a function of T and P?
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   March 27, 2020, 08:15
Default
  #24
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
Because I am simulating Hypersonic flow and my model takes into account dissociation and ionization, which changes the molecular weight of the gas and its contribution is represented mathematically in the function REAL_compressibility. Therefore I have to include the dependency of P and T in the molecular weight. In worst case scenario, I could keep it constant and calculate the speed of sound (which is the only variable really affected by the molecular weight in my model) with the REAL_compressibility function inside of it. I will try doing that this afternoon.

However, regarding my previous post, why is Fluent mixing variables?
Captain Convergence is offline   Reply With Quote

Old   March 27, 2020, 08:32
Default Ionization and Dissociation
  #25
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Ionization and/or dissociation will change the species and as such the molecular weight of the real gas but that is not because of temperature and pressure. Fluent gives option to change MW due to species fraction. Since you are trying to model it as a single specie, you should not change MW.

As far as mixing of variables is concerned, Fluent could do that if it has a bug, but I would highly doubt that for this scenario. Another possibility is that the value of temperature being reported happens to be equal to pressure value in Pa.

The argument for these functions already include Pabs. So, you do not need to add 1 to make it absolute. Even if you set operating pressure as some positive value in Fluent, which is not recommended for ideal and real gas cases, Fluent will add that value and then return Pabs. So, you are increasing pressure by 1 Pa, which is not very high but unnecessary.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   March 27, 2020, 12:29
Default Found the issue
  #26
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
The issue with my code was the Fluent version and the declaration of REAL_mw, now my code is working properly, check the attached image with the modelled Cp. Again, thank your so much for you help!
Captain Convergence is offline   Reply With Quote

Old   March 27, 2020, 12:30
Default
  #27
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
Sorry, forgot to attach the image, I got very exited hahahah
Attached Images
File Type: jpg screenshot.jpg (66.6 KB, 22 views)
Captain Convergence is offline   Reply With Quote

Old   November 4, 2020, 10:58
Default using UDRGM
  #28
Member
 
Amirreza Niazmehr
Join Date: Nov 2018
Posts: 40
Rep Power: 7
Amirreza_pro is on a distinguished road
Hi guys,
I have some problem by using UDRGM, that I found this thread.
We are going to simulate the stream of a gas over a switchgear (the physiks of the problem is not important for you
😅
)

We have our own data (table) for this gas. The ponit is that, for this gas Cp (specific heat) is changing with Temperature and Pressure both. For this purpose I should use UDRGM of Fluent, I studied also the manuel of Fluent but I could not get the Idea of using for my case.

The problem is that: I I am looking to define Cp while having different thermodynamics lookup tables giving me Cp as temp and pressure varies. Is there any template of code available for doing so or else any method through which I could calculate the coefficients for the real gas models from the data of the thermodynamic table. Actually I have my own Data (tables) and I want to read them. Can I use UDRGM of Fluent so that I can use my own Data?

Sorry, that I explained too much, I just wanted to explain my problem clearly.
Amirreza_pro is offline   Reply With Quote

Old   November 4, 2020, 12:00
Default
  #29
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
Hi,

I have attached a UDRGM that I found at ANSYS website. As you can observe, an UDRGM is a set of basic functions that Fluent will use every single time it needs a material property which is calculated from the available flow variables.

It your case you will have to program in C your interpolation functions within the UDRGM code. If you are not familiar with C, my advise is that you first program it in a languaje that you are comfortable with (i.e Matlab, python, etc...) and then you try code exactly the same in C and CHECK that your numerical outputs are the same.

Once you have checked that your program works in C and gives the right numerical values, you have just to copy and paste it to the UDRGM with minor modifications. For example your UDRGM for the CP should look like this :

double IDEAL_specific_heat(cell_t cell, Thread *thread, double Temp, double density, double P, double yi[])
{

((((( C code using the double variables Temp and P (CHECK IF IT IS THE ABSOLUTE OR STATIC PRESSURE))))))))

return cp; /* (J/Kg/K) */ (cp is the value that will be fed it to the Fluent solver as specific heat)
}


Once you are in Fluent I highly recomend you to use this code for debuggin

/*-------------------------------------------------------------------*/
/* Console Display (For Debugging) */
/*-------------------------------------------------------------------*/
Message("PStat: %f (Pa) TStat: %f (K) CP: %f (J/Kg/K) \n",Pabs,Temp,cp);
/*-------------------------------------------------------------------*/


So you will see in Fluent's console the output of your functions.

Good luck with it!
Attached Files
File Type: c UDRGM_IDEAL.c (6.4 KB, 16 views)
Captain Convergence is offline   Reply With Quote

Old   November 4, 2020, 16:47
Default
  #30
Member
 
Amirreza Niazmehr
Join Date: Nov 2018
Posts: 40
Rep Power: 7
Amirreza_pro is on a distinguished road
Thanks alot for your nice advice.
Fortunately we have the interpolation functions in C
I have just two more question:
1- My supervisor wanted to use UDRGM which exits in below link which is using
Redlich-Kwong Equation of State:
https://www.afs.enea.it/project/nept...df/node248.htm
which is using alot of constants which are related to this Redlich-Kwong Equation. I think it's wrong, while we are going to use our data (or our interpolation functions) and as use said we should use your attached file with correponding minor modifications.Am I right?

2- There is just one more problem (question), for computing for example "Enthalpy" your attached file is using "Ideal Gas Equation", so does it make a problem? I mean: What kind of equations should we use for computing Entropy, Enthalpy? ideal Gas Equations or the other state equations like Redlich-Kwong Equation of State?
It would be nice, if you can help me, I'm realy comfused
Amirreza_pro is offline   Reply With Quote

Old   November 5, 2020, 06:38
Default
  #31
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
Hi!

1) If you want to use an ideal-gas formulation with your approximation for the CP yes, you can take the function that I sent in the previous post and only modify the CP function in order to meet your needs. Otherwise you will have to modify the other functions as you want.

2) Well it is a problem if you don't want to use an ideal formulation. Maybe you should check the expected values in your simulation and make sure that which has model (ideal or Redlich-Kwong) can calculate the variables for those values of P and T. The enthalpy is given by h=T*Cp. The formula for the entropy is something that you will have to find for your case because I don't know which are the exact physics in your problem, but you can calculate it from the passed variables from the solver to your functions. Nonetheless, I think that the entropy is not used in the calculations and if you calculate it wrong, you will have an error in your entropy calculation that won't affect the other flow variables. But the enthalpy has to be calculated properly because it plays a major role in the energy equation.

By the way, the link you sent me is from FLUENT's 12.0. There have been a lof of changes in the way the UDRGM should be coded, the one that I sent to you works in FLUENT 19. So go an check the UDF manual of the most recent version if your are using it.
Captain Convergence is offline   Reply With Quote

Old   November 6, 2020, 06:30
Default
  #32
Member
 
Amirreza Niazmehr
Join Date: Nov 2018
Posts: 40
Rep Power: 7
Amirreza_pro is on a distinguished road
Thanks alot dear friend for your nice advice
Amirreza_pro is offline   Reply With Quote

Reply

Tags
udrgm


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
FLUENT 19.2 User Defined Real Gas Model udf problem MKPP FLUENT 1 June 23, 2019 21:39
Continuing User Defined Real Gas Model issues aeroman FLUENT 6 April 8, 2016 03:34
Parallel User Defined Real Gas Model aeroman FLUENT 4 July 1, 2015 06:09
using METIS functions in fortran dokeun Main CFD Forum 7 January 29, 2013 04:06
error message cuteapathy CFX 14 March 20, 2012 06:45


All times are GMT -4. The time now is 22:35.