CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF for Robin Boundary Condition (https://www.cfd-online.com/Forums/fluent-udf/165392-udf-robin-boundary-condition.html)

msuccess January 16, 2016 06:37

UDF for Robin Boundary Condition
 
I’m simulating the mass fraction profile of a solution passing through a rectangular channel as shown in the figure below. http://img1.ph.126.net/COt-YwgH85Vu7...4052173224.jpg

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 1e-10
#define J 1e-4
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! :)

`e` January 20, 2016 16:23

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.

msuccess January 22, 2016 07:01

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.6e-9
#define J 6.7e-5
#define dy 1e-5

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)/(1-J/D*dy);
}
end_f_loop(f,t)
}


All times are GMT -4. The time now is 15:17.