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

Restricting area in if statement

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 16, 2012, 12:12
Default Restricting area in if statement
  #1
New Member
 
Bradley J
Join Date: Jul 2012
Location: Cincinnati, OH
Posts: 12
Rep Power: 13
Blackhawks84 is on a distinguished road
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
}

Last edited by Blackhawks84; July 16, 2012 at 17:14. Reason: Updated code
Blackhawks84 is offline   Reply With Quote

Old   July 18, 2012, 01:48
Default
  #2
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
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.
flotus1 is offline   Reply With Quote

Old   July 22, 2012, 13:42
Default
  #3
New Member
 
Bradley J
Join Date: Jul 2012
Location: Cincinnati, OH
Posts: 12
Rep Power: 13
Blackhawks84 is on a distinguished road
Quote:
Originally Posted by flotus1 View Post
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.
Blackhawks84 is offline   Reply With Quote

Old   July 22, 2012, 15:32
Default
  #4
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
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
flotus1 is offline   Reply With Quote

Old   July 22, 2012, 16:50
Default
  #5
New Member
 
Bradley J
Join Date: Jul 2012
Location: Cincinnati, OH
Posts: 12
Rep Power: 13
Blackhawks84 is on a distinguished road
Quote:
Originally Posted by flotus1 View Post
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
}
Blackhawks84 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
Problem with reference area alfaben STAR-CCM+ 3 April 21, 2020 09:46
Non overlap area fractions saisanthoshm88 CFX 11 September 17, 2015 18:42
Water subcooled boiling Attesz CFX 7 January 5, 2013 03:32
CFX Solver Memory Error mike CFX 1 March 19, 2008 07:22
Storing Surface Area of each cell in a file? Markus Alzon FLUENT 0 June 21, 2007 08:38


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