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

Store a UDF variable

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 15, 2017, 09:51
Default Store a UDF variable
  #1
New Member
 
Join Date: Sep 2017
Posts: 5
Rep Power: 9
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
Posts: 164
Rep Power: 17
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: 5
Rep Power: 9
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: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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 offline   Reply With Quote

Old   November 20, 2017, 11:41
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Stripping away all irrelevant code, I think it you want something like this:

Code:
DEFINE_ON_DEMAND(I_do_something)
{
 Domain *domain;
 Thread *t;
 cell_t c;
 real NBTF ;
 real ws_Tc = 647.286 ;
 real p1=0.98;
 real p2=-270;
 real q1=-275;
 real T;
  
 domain=Get_Domain(1);
 thread_loop_c (t,domain)
 {
  begin_c_loop (c,t)
  {
   T = C_T(c,t);
   if (T > ws_Tc) T = ws_Tc ;
   NBTF = (p1*T+p2)/(T+q1) ;
   C_UDMI(c,t,0) = NBTF;
  }
  end_c_loop (c,t)
 }
}
Code not tested, so typo's might still be there.
wadezaza likes this.
pakk is offline   Reply With Quote

Old   November 22, 2017, 07:14
Default
  #6
New Member
 
Join Date: Sep 2017
Posts: 5
Rep Power: 9
wadezaza is on a distinguished road
Pakk, thank you for your reply. This is how i managed it and it is working fine
wadezaza is offline   Reply With Quote

Old   January 10, 2020, 04:42
Default
  #7
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
hi everybody please help me
i wrote a udf for calculating the mass transfer coefficient. now i want write another udf for calculating the source term of mass transfer. i need to access the mass transfer rate variable(m_dot)

how can i calling this variable in define_source udf??
mahdi-united is offline   Reply With Quote

Reply


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
Setting cell variable values in a fluid zone using UDF eromon84 Fluent UDF and Scheme Programming 6 March 28, 2021 12:59
Monitor a variable of a UDF ChristophGradl Fluent UDF and Scheme Programming 0 June 13, 2014 05:12
global variable in udf mohsen zendehbad FLUENT 2 November 22, 2009 06:30
udf variable for wall temperature Kiran FLUENT 0 July 31, 2008 09:31
UDF compilation problem -- "undeclared variable" Henrik Ström FLUENT 1 September 21, 2005 06:25


All times are GMT -4. The time now is 21:12.