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

Store a UDF variable

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   November 15, 2017, 09:51
Default Store a UDF variable
  #1
New Member
 
Join Date: Sep 2017
Posts: 4
Rep Power: 2
wadezaza is on a distinguished road
Hello,

i am using a UDF to set my own property in Fluent (2D, wet steam model) and want to save a UDF variable to be able to plot it in postprocessing. I know i need to use UD Memory and first allocate the appropriate number of Memory locations. In my case i just need one to save the value of the variable "NBTF". Unfortunately i am always getting a constant value in NBTF even though it is a function of the temperature which is changing
May someone please tell me if something is wrong with my code? Here is the begin and the part of the code with my NBTF variable.

#include "udf.h"
#include "stdio.h"
#include "ctype.h"
#include "stdarg.h"
/*Global Constants for this model*/
real ws_TPP = 338.150 ;
real ws_aaa = 0.01 ;
real cpg = 1882.0 ;

DEFINE_ON_DEMAND(I_do_nothing)
{

}
void wetst_init(Domain *domain)
{
ws_Tc = 647.286 ;/*Critical Temp. */
ws_Pc = 22089000.00 ;/*Critical Pressure */
mw_f = 18.016 ;/*fluid droplet molecular weight (water) */
Rgas_v = 461.50 ;/*vapor Gas Const*/
}
.
.
.
real wetst_surft(real T)
{
Domain *domain;
Thread *t;
cell_t c;
real sigma ;
real sigma_u ;
real NBTF ;
real Tr ;
real a1= 82.27 ;
real a2= 75.612 ;
real a3= -256.889 ;
real a4= 95.928 ;
real p1=0.98;
real p2=-270;
real q1=-275;

if (T > ws_Tc) T = ws_Tc ;
Tr = T/ws_Tc ;
sigma_u = 0.001*(a1 + Tr*(a2+ Tr*(a3+ Tr*a4))) ;

NBTF = (p1*T+p2)/(T+q1) ;
sigma = NBTF*sigma_u ;

domain=Get_Domain(1);
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDMI(c,t,0) = NBTF;
}
end_c_loop (c,t)
}
return sigma ;
}

Regards.
wadezaza is offline   Reply With Quote

Old   November 16, 2017, 04:06
Default
  #2
Senior Member
 
Join Date: Feb 2010
Location: China
Posts: 115
Rep Power: 10
gearboy is on a distinguished road
Quote:
Originally Posted by wadezaza View Post
Hello,

i am using a UDF to set my own property in Fluent (2D, wet steam model) and want to save a UDF variable to be able to plot it in postprocessing. I know i need to use UD Memory and first allocate the appropriate number of Memory locations. In my case i just need one to save the value of the variable "NBTF". Unfortunately i am always getting a constant value in NBTF even though it is a function of the temperature which is changing
May someone please tell me if something is wrong with my code? Here is the begin and the part of the code with my NBTF variable.

#include "udf.h"
#include "stdio.h"
#include "ctype.h"
#include "stdarg.h"
/*Global Constants for this model*/
real ws_TPP = 338.150 ;
real ws_aaa = 0.01 ;
real cpg = 1882.0 ;

DEFINE_ON_DEMAND(I_do_nothing)
{

}
void wetst_init(Domain *domain)
{
ws_Tc = 647.286 ;/*Critical Temp. */
ws_Pc = 22089000.00 ;/*Critical Pressure */
mw_f = 18.016 ;/*fluid droplet molecular weight (water) */
Rgas_v = 461.50 ;/*vapor Gas Const*/
}
.
.
.
real wetst_surft(real T)
{
Domain *domain;
Thread *t;
cell_t c;
real sigma ;
real sigma_u ;
real NBTF ;
real Tr ;
real a1= 82.27 ;
real a2= 75.612 ;
real a3= -256.889 ;
real a4= 95.928 ;
real p1=0.98;
real p2=-270;
real q1=-275;

if (T > ws_Tc) T = ws_Tc ;
Tr = T/ws_Tc ;
sigma_u = 0.001*(a1 + Tr*(a2+ Tr*(a3+ Tr*a4))) ;

NBTF = (p1*T+p2)/(T+q1) ;
sigma = NBTF*sigma_u ;

domain=Get_Domain(1);
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDMI(c,t,0) = NBTF;
}
end_c_loop (c,t)
}
return sigma ;
}

Regards.
You should call wetst_surft function in your UDF executable macros, such as DEFINE_EXECUTE_AT_END, DEFINE_SOURCE, DEFINE ADJUST, etc. Furthermore, do not forget to hook these UDF macros.

real wetst_surft(real T) is just a definition, won't be executed unless you call it in your UDF macros.
gearboy is offline   Reply With Quote

Old   November 16, 2017, 06:40
Default
  #3
New Member
 
Join Date: Sep 2017
Posts: 4
Rep Power: 2
wadezaza is on a distinguished road
Hi Gearboy,

thanks for your reply. Sorry i did not get your point. Why do i need to add a new DEFINE Macro? The code is still working fine. The problem is the constant value i am getting for NBTF in my UD Memory. Here are the final lines of my code. You may need it to help me

UDF_EXPORT WS_Functions WetSteamFunctionList =
{
wetst_init,
wetst_satP,
wetst_satT,
.
.
.
wetst_ktl,
wetst_surft
};
wadezaza is offline   Reply With Quote

Old   November 16, 2017, 18:56
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 110
Rep Power: 6
AlexanderZ is on a distinguished road
You should use build-in macros (such as DEFINE_ON_DEMAND, DEFINE_ADJUST or others, depends on your algorithm) to execute your functions.
Read Ansys Fluent Customization manual, you may find there information and tutorials regarding UDMs

Best regards
AlexanderZ is online now   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Monitor a variable of a UDF ChristophGradl Fluent UDF and Scheme Programming 0 June 13, 2014 04:12
Setting cell variable values in a fluid zone using UDF eromon84 Fluent UDF and Scheme Programming 5 October 15, 2013 05:16
global variable in udf mohsen zendehbad FLUENT 2 November 22, 2009 06:30
udf variable for wall temperature Kiran FLUENT 0 July 31, 2008 08:31
UDF compilation problem -- "undeclared variable" Henrik Ström FLUENT 1 September 21, 2005 05:25


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