# help with UDF for contact angle based on contact line velocity

 Register Blogs Members List Search Today's Posts Mark Forums Read

 January 13, 2011, 02:37 help with UDF for contact angle based on contact line velocity #1 Member   Sandeep Join Date: Jul 2010 Posts: 48 Rep Power: 15 Hello all, I am doing a case of 2 phase problem where a liquid droplet spreading on a solid substrate. Till now I have been using constant contact angle as a wall boundary condition between the liquid phase and the solid substrate. Now that I want to use two different contact angles based on the contact line velocity (intersection of solid liquid and air phases) condition. The condition is if you consider the droplet spreading has positive contact line velocity and negative contact line velocity when recoiling, then during positive contact line velocity assign one contact angle and during negative contact line velocity assign another contact angle. I know, for defining the boundary conditions we will use DEFINE_PROFILE macro. But in my case I have to extract contact line velocity and then check if the velocity is positive or negative and then assign back a contact angle back to the fluent for further iterations. I hope I made my doubt clear to you and It would be great if anyone can help me writing this UDF. Thanks Sandeep hospital0968 likes this.

 January 13, 2011, 22:59 #2 Senior Member   Real Name :) Join Date: Jan 2010 Location: United States Posts: 192 Rep Power: 16 This requires your UDF to track the interface. I'm assuming you're using the VOF model. In this case, loop over all the cells in your secondary phase. Wherever the volume fraction is not equal to 1 and not equal to 0 (that is, some mixture of the two phases), you can assume you're at an interface. From there, you can extract the velocity of these cells and apply whatever algorithm you want to implement. Assuming your system is spreading in the +x and -x directions, if the x-component of the cell's centroid is greater than 0 and its x-velocity is positive, it is spreading. If the x-component of the cell's centroid is less than 0 and its x-velocity is negative, it's spreading...etc... This interface approximation is only really valid if the phases are segregated; this isn't a trivial problem. Perhaps there's an easier way, but I can't think of one. ComputerGuy

 January 18, 2011, 20:42 #4 Senior Member   Join Date: Nov 2009 Posts: 411 Rep Power: 19 if (temp = 0.5) //Condition for storing radial velocity Should be: if (temp == 0.5) //Condition for storing radial velocity ================================ But the actual error is here: real theta, temp, vcl, x, r_v; //Declaration of required variables used ...... vcl[x] = C_V(c,t); //radial velocity stored in vcl array Your vcl array is not declared as an array. My advice for you is to read a C programming tutorial, don't take this personally but I have the impression you aren't so good at C (at least not for now). So, take 1 week and read a C tutorial, or a C book (let me know if you need some references) then you can check your UDF. Do

 January 18, 2011, 21:27 #5 Member   Sandeep Join Date: Jul 2010 Posts: 48 Rep Power: 15 hi dohander, Thanks for your reply. I know that am very poor at C and I will agree with you nothing to take wrong in it. Actually I have modified the code. Please look below and tell me if you have any suggestions to me. #include "udf.h" #include "mem.h" #include "metric.h" #include "math.h" DEFINE_PROFILE( contact_angle_BC, t, i) { float theta,temp,rv; int y; float vcl[10]; float ct = CURRENT_TIME; cell_t c; y = 1; begin_c_loop(c,t) { temp = C_VOF(c,t); if (temp == 0.5) { vcl[y] = C_V(c,t); y = y+1; } else rv = 0; } end_c_loop(c,t) rv = vcl[y]; if (ct <= 0.025) { if (rv >= 0) theta = 120; else theta = 80; } else {theta = 107;} } Thanks sandeep

 January 18, 2011, 21:34 #6 Senior Member   Join Date: Nov 2009 Posts: 411 Rep Power: 19 I see no obvious C error, however you could have logical errors in your code. Not really sure, but your y is incremented with 1 for each cell from your grid, so unless you have exactly 10 cells your vcl array will overflow. Run the code and see if you will have errors. Do

 January 18, 2011, 21:58 #7 Member   Sandeep Join Date: Jul 2010 Posts: 48 Rep Power: 15 In that case can I just leave the array definition as empty instead of 10 in it?? like the following float vcl[];

 January 19, 2011, 00:57 #8 Senior Member   Join Date: Nov 2009 Posts: 411 Rep Power: 19 Nope, you can't. You need to add a size to your array. It should be a function that gives you the numbers of grid cells, use this number.

 January 21, 2011, 01:28 #9 Member   Sandeep Join Date: Jul 2010 Posts: 48 Rep Power: 15 Hi, I did not realize that even my UDF was successful at compilation, it is showing error when I try to hook to the contact angle UDF panel. It says FLUENT received fatel signal (SEGMENTATION VIOLATION). What could be the probable reason. Please help me. #include "udf.h" #include "mem.h" #include "metric.h" DEFINE_PROFILE( contact_angle_BC, t, i) { float radial_velocity; int y, j; float contact_line_velocity[200]; for (j=1;j<=200;j++) { contact_line_velocity[j]=0; } face_t f; y = 1; begin_f_loop(f,t) { cell_t c0 = F_C0(f,t); if (C_VOF(c0,t) == 0.5) { contact_line_velocity[y] = C_V(c0,t); y = y+1; } } end_f_loop(f,t) radial_velocity = contact_line_velocity[y]; if (CURRENT_TIME <= 0.025) { if (radial_velocity >= 0) F_PROFILE(f,t,i) = 120; else F_PROFILE(f,t,i) = 80; } else { F_PROFILE(f,t,i) = 107; } } Thanks Sandeep

 January 21, 2011, 11:17 #10 Senior Member   Join Date: Nov 2009 Posts: 411 Rep Power: 19 How many cells has your grid ? Do

 January 21, 2011, 12:51 #11 Member   Sandeep Join Date: Jul 2010 Posts: 48 Rep Power: 15 Hi DO, My grid is simple rectangular domain with 200 Y node points and 360 X node points. I am applying my UDF to the boundary which is having 200 node points. that is parallel to Y direction. sandeep

 January 21, 2011, 15:54 #12 Senior Member   Join Date: Nov 2009 Posts: 411 Rep Power: 19 for (j=1;j<=200;j++) Here is your problem, your are trying to write on contact_line_velocity[200] on the last iteration! If you want to initialize this with ZERO try this approach: float contact_line_velocity[200]; for (j=0;j<200;j++) { contact_line_velocity[j]=0; } You are in C, not in Matlab or Fortran, so your arrays starts at 0 and ends at 199! Please read a C programming book Do

 January 22, 2011, 00:38 #13 Member   Sandeep Join Date: Jul 2010 Posts: 48 Rep Power: 15 Hi Do, Thanks for your input. The code you had send me is working properly. I am able to compile the code but when I try to hook to the contact angle panel, it sage fluent segment violation error. I debugged with checking each and every line and I found that for extracting cell VOF value, fluent is not accepting C_VOF macro. Can you tell me what is the way to extract vof value of a cell?? Thanks in advance Sandeep

 January 25, 2011, 14:54 #14 New Member   Baiqiu Join Date: Jan 2011 Posts: 3 Rep Power: 15 A.2 Commenting Your C Code It is good programming practice to document your C code with comments that are useful for explaining the purpose of the function. In a single line of code, your comments must begin with the /* identifier, followed by text, and end with the */ identifier from the help file, it should be replaced by /*****/, and // is illegal

 October 29, 2012, 13:58 Contact Angle in UDF files #15 New Member   Ontario Join Date: Oct 2012 Posts: 1 Rep Power: 0 Hi All I am modeling 2-phale flow problem which is droplet impact on porous material in FLUENT. I have a UDF file for my VOF method, surface tension and viscosity. I would like to modify contact angle in the UDF file as well as a function of z direction. For example I am going to define contact angle = a for z<0 and contact angle = b for z>=0. I couldn't add this in my UDF and there was no useful document available online. Could you help me please?