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/)
-   -   Restricting area in if statement (https://www.cfd-online.com/Forums/fluent-udf/104809-restricting-area-if-statement.html)

Blackhawks84 July 16, 2012 12:12

Restricting area in if statement
 
Hello,
I have a UDF question about restrictions along the x axis. Right now, I have a 10mm by 10mm non uniform rectangular grid with the area of interest square uniform. I am using a source term to model mass transfer from liquid into vapor along the interface. There is a small bubble patch implemented at (10,0), sideways I know. I have set up my code below for you. The problem I am having is how to restrict the source term to be applied only from the (9.5,0) to (10,0) on the grid. There are no restrictions in the y direction. I was thinking of using another if statement involving the x value of centroid being less than 9.5 along with the first if statement. This is what I came up with and I am not sure if I am heading in the right direction. Thank you for your time.

Bradley

# include"udf.h"
# include"mem.h"
# include"metric.h"
# include"math.h"
/*calculating and storing the source term*/
DEFINE_EXECUTE_AT_END(source_memory)
{
#if !RP_HOST
Domain *d;
Thread *t;
cell_t c;
double vof;
double vof_gradient;
double st;
double m_flux = 34.234; /*define mass flux*/
d=Get_Domain(2); /*liquid domain*/
real x[ND_ND];
thread_loop_c (t,d)
{
begin_c_loop (c,t)
{
vof = C_UDSI(c,t,0);
vof_gradient = C_UDMI(c,t,0);
C_CENTROID(x,c,t);
if (((vof_gradient < 0.001)||(vof < 0.001)||(vof > 0.999)) && (x[0] < 0.0095))
{
C_UDMI(c,t,1) = 0;
}
else
st = -(2*vof*vof_gradient*m_flux); /*negative sign because mass is leaving the liquid domain*/
C_UDMI(c,t,1) = st;
}
end_c_loop (c,t)
}
#endif
}

flotus1 July 18, 2012 01:48

Restricting the area with the if-statement like you did in your code usually works.
Just keep in mind that the sources are applied on a "per-cell" base.
So if the cell centroid of a cell is within the range you want the source term to be applied, but the cell extents to lets say 0.009, then your results will suffer from this inaccuracy.

Blackhawks84 July 22, 2012 13:42

Quote:

Originally Posted by flotus1 (Post 372035)
Restricting the area with the if-statement like you did in your code usually works.
Just keep in mind that the sources are applied on a "per-cell" base.
So if the cell centroid of a cell is within the range you want the source term to be applied, but the cell extents to lets say 0.009, then your results will suffer from this inaccuracy.

thank you for the response. I tried my code and it did not work out as well as planed. Is there a way to only call out an adjacent row of cell centroids along a boundary condition of a wall? Because I want to have two distinct factors for the source term to be applied. I want it to be at the interface and the centroid of the cells adjacent to the wall boundary condition.

flotus1 July 22, 2012 15:32

I am not sure if this is possible.

If your mesh is block-structured with a clearly defined cell size, you could easily change the threshold of the if-statement accordingly.

With unstructured mesh types, you could perhaps loop over the faces of every cell and check if one of the faces belongs to the boundary. Perhaps you could do this by evaluating the centroid position of the face.
Good luck ;)

Blackhawks84 July 22, 2012 16:50

Quote:

Originally Posted by flotus1 (Post 372885)
I am not sure if this is possible.

If your mesh is block-structured with a clearly defined cell size, you could easily change the threshold of the if-statement accordingly.

With unstructured mesh types, you could perhaps loop over the faces of every cell and check if one of the faces belongs to the boundary. Perhaps you could do this by evaluating the centroid position of the face.
Good luck ;)

thank you for the reply. i have an non uniform structured grid. the new way i am thinking of doing it for a try is to change the loop to over the adjacent cells like this. let me know what you think.

# include"udf.h"
# include"mem.h"
# include"metric.h"
# include"math.h"
/*calculating and storing the source term*/
DEFINE_EXECUTE_AT_END(source_memory)
{
#if !RP_HOST
Domain *d;
face_t f;
Thread *t *t0, *ct;
cell_t c, c0;
real CC[ND_ND];
/*will be 2D axisymmetric*/
int Zone_ID = 6; /*zone id boundary conditions, 6 = base wall*/
double vof;
double vof_gradient;
double st;
double m_flux = 34.234; /*define mass flux*/
d=Get_Domain(2); /*liquid domain*/
/*initialize cells: loops over all cells in the liquid domain*/
thread_loop_c(ct,d)
{
begin_c_loop(c,ct)
{
C_UDMI(c,t,1) = 0;
/*fills the UDM with 0*/
}
end_c_loop(c,ct)
}
thread_loop_f(ct,d)
{
/*loops over all faces on the base wall in the liquid domain*/
t = Lookup_Thread(d, Zone_ID);
begin_f_loop(f,t)
{
/*c0 and t0 identify the adjacent cell*/
c0 = F_C0(f,t);
t0 = THREAD_T0(t);
/*loops over all cells adjacent to wall*/
vof = C_UDSI(c,t,0); /*DEFINE_ADJUST(store_vof,d): C_UDSI(c,t,0) = C_VOF(c,t);*/
vof_gradient = C_UDMI(c,t,0); /*DEFINE_EXECUTE_AT_END(grad_vof):
C_UDMI(c,t,0) = NV_MAG(C_UDSI_G(c,t,0));*/
if ((vof_gradient < 0.001)||(vof < 0.001)||(vof > 0.999))
{
C_UDMI(c0,t0,1) = 0;
}
else
{
st = -(2*vof*vof_gradient*m_flux);
/*negative sign because mass is leaving the liquid domain*/
C_UDMI(c0,t0,1) = st;
}
}
end_f_loop(f,t)
}
#endif
}


All times are GMT -4. The time now is 18:13.