
[Sponsors] 
January 16, 2016, 07:37 
UDF for Robin Boundary Condition

#1 
New Member
Join Date: Jan 2016
Posts: 2
Rep Power: 0 
I’m simulating the mass fraction profile of a solution passing through a rectangular channel as shown in the figure below.
The inlet boundary is velocity inlet with a uniform velocity, e.g 0.05m/s. The mass fraction of the solute is 0.0001. The outlet is fully developed outflow. The upper and bottom edges are defined as wall. The mass fraction at the upper wall is the same as the inlet, 0.0001. But for the bottom wall, a UDF is hooked to define the mass species boundary condition. Here are my UDF codes: #include "udf.h" #define D 1e10 #define J 1e4 DEFINE_PROFILE(mass_fraction_profile, t, i) { real x[ND_ND]; real y; cell_t c; face_t f; Thread *t0; begin_f_loop(f,t) { F_CENTROID(x, f, t); y=x[1]; t0=THREAD_T0(t); c=F_C0(f,t); F_PROFILE(f,t,i)=D/J*(C_YI_G(c,t0,i)[1]); } end_f_loop(f,t) } The governing equation is D∙∂m/∂y+J∙m=0. D, J are known. The expected result is that the mass fraction is increasing from the upper wall to the bottom, with the highest mass fraction (m) at the bottom wall. But the simulation result shows the opposite, with the mass fraction decreasing from the top to the bottom. If I change the value of D and J, sometimes the mass fraction can not converge. If I set the bottom boundary mass fraction to a constant 0.2, the result seems right with the mass fraction increasing from the top wall to the bottom wall, which means there's something wrong with the UDF. So could anyone please help me figure out where goes wrong? What are the correct UDF codes? Thank you very much! Last edited by msuccess; January 16, 2016 at 09:28. 

January 20, 2016, 17:23 

#2 
Senior Member
Join Date: Mar 2015
Posts: 800
Rep Power: 11 
You're using the gradient macro for the mass fraction gradient at each time the profile is called (probably every time step). The gradient data is not available on the first iteration, a fix by HenrikS is suggested here.


January 22, 2016, 08:01 

#3 
New Member
Join Date: Jan 2016
Posts: 2
Rep Power: 0 
Thank you very much for your reply. I've already turned it on and tried several iterations before hooking the UDF, but it still doesn't work. As for including the code as he suggested, I'm not sure whether it also works for mass fraction, or how to adjust it to fit my case.
I have tried another way to write my code as below, but the result is not right either. Would you help me figure out what the problem is? Thx. #include "udf.h" #define D 1.6e9 #define J 6.7e5 #define dy 1e5 DEFINE_PROFILE(mass_fraction_profile, t, i) { real x[ND_ND]; real y; cell_t c; face_t f; begin_f_loop(f,t) { F_CENTROID(x, f, t); y=x[1]; c=F_C0(f,t); F_PROFILE(f,t,i)= C_YI(c,t,i)/(1J/D*dy); } end_f_loop(f,t) } 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
write a UDF to give a velocity boundary condition at an interior face  Tharanga  Fluent UDF and Scheme Programming  15  June 17, 2015 23:02 
several fields modified by single boundary condition  schröder  OpenFOAM Programming & Development  3  April 21, 2015 05:09 
An error has occurred in cfx5solve:  volo87  CFX  5  June 14, 2013 17:44 
Boundary Condition Types Using Scheme and UDF  Nasir  FLUENT  0  September 15, 2008 21:54 
UDF : boundary condition ID  Flav  FLUENT  4  June 28, 2001 09:52 