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

 User Name Remember Me Password
 Register Blogs Members List Search Today's Posts Mark Forums Read

 LinkBack Thread Tools Display Modes
 January 13, 2011, 03:37 help with UDF for contact angle based on contact line velocity #1 Member   Sandeep Join Date: Jul 2010 Posts: 48 Rep Power: 6 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

 January 13, 2011, 23:59 #2 Senior Member   Real Name :) Join Date: Jan 2010 Location: United States Posts: 180 Rep Power: 7 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, 08:25 #3 Member   Sandeep Join Date: Jul 2010 Posts: 48 Rep Power: 6 Hello all, Please help me debugging my code!! I am explaining below my problem in more detail. As you have guessed I am doing a VOF model with phase 2 considering a non-newtonian fluid and phase 1 as air. Now for the wall boundary condition, I want to specify a contact angle(Advancing Contact Angle-ACA) when the droplet is spreading and another contact angle(Receding Contact Angle-RCA) when the droplet is recoiling till 25 ms and then I would be using equilibruim contact angle-ECA till the end of my simulation(100 ms). I have attached a link below which has a jpeg file showing my mesh and intial case-data files for the problem. I have considered my problem as a 2D-axysymmetric case as show in the figure with X and Y directions. https://docs.google.com/leaf?id=0B1VmHLzTrnyVM2EwMzA0NjEtMzhlYi00NmRhLTkyN GQtNmViZGE4OWZhZDkw&sort=name&layout=list&num=50 To write the UDF I have the following logic in my mind and also attached my code and compilataion error log file at the end Here is my logic: 1. Consider the cell thread and find for the cell whose volume of fraction equal to 0.5 ( assuming my interface lies here) 2. Create an array which has the radial velocities extracted from previous step in case if there are more than one cell with vof = 0.5 3. store the radial velocity which is having higher y value into a new variable 4. check for the contact angle criteria #include "udf.h" #include "mem.h" DEFINE_PROFILE( contact_angle_BC, t, i) //Macro used to define the boundary condition { real theta, temp, vcl, x, r_v; //Declaration of required variables used real c_t = CURRENT_TIME; //Variable for CURRENT_TIME cell_t c; //Define Cell Thread of the boundary x = 1; //Define a dummy variable starting with 1 to use this as an array index begin_c_loop(c,t) //Begin cell thread loop of the boundary { temp = C_VOF(c,t); //Store the Volume of fraction of the cell in a temp variable if (temp = 0.5) //Condition for storing radial velocity { vcl[x] = C_V(c,t); //radial velocity stored in vcl array x = x+1; //array index variable increment } } r_v = vcl[x]; //store the value of radial velocity of the cell whose y co-ordinate is high of all the stored VOF values in a new variable if (c_t <= 0.025) //Condition for the Contact angle { if (r_v >= 0) theta = 120; else theta = 80; } else theta = 107; return theta; } C_UDMI(cell,thread,0)=theta; //User defined memory to check the value of theta LOG file __________________ or d in lnamd64/[23]*; do \ ( \ cd \$d; \ for f in ../../src/*.[ch] ../../src/makefile; do \ if [ ! -f `basename \$f` ]; then \ echo "# linking to" \$f "in" \$d; \ ln -s \$f .; \ fi; \ done; \ echo ""; \ echo "# building library in" \$d; \ if [ "" = "1" ]; then \ echo "# using gcc64"; \ make ARCHC=gcc64 -k>makelog 2>&1; \ else \ if [ "" = "1" ]; then \ echo "# using gcc"; \ make ARCHC=gcc -k>makelog 2>&1; \ else \ make -k>makelog 2>&1; \ fi; \ fi;\ cat makelog; \ ) \ done # linking to ../../src/DCA.c in lnamd64/2ddp # linking to ../../src/makefile in lnamd64/2ddp # building library in lnamd64/2ddp make[1]: Entering directory `/nfs/03/ucn0987/FLUENT/Test31/libudf/lnamd64/2ddp' # Generating udf_names.c because of makefile DCA.c make[2]: Entering directory `/nfs/03/ucn0987/FLUENT/Test31/libudf/lnamd64/2ddp' make libudf.so "CFLAGS=-D_lnamd64 -D_GNU_SOURCE -fpic -shared -ansi -Wall -O -DPTR_RESTRICT= " "LDFLAGS=-shared -lm" make[3]: Entering directory `/nfs/03/ucn0987/FLUENT/Test31/libudf/lnamd64/2ddp' # Compiling udf_names.o because of udf_names.c cc -D_lnamd64 -D_GNU_SOURCE -fpic -shared -ansi -Wall -O -DPTR_RESTRICT= -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/`expr "\`pwd\`" : '.*/\(.*\)/[23].*'`/`basename "\`pwd\`"` -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/src -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/cortex/src -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/client/src -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/tgrid/src -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/multiport/src -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/multiport/mpi_wrapper/include -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/multiport/mpi_wrapper/src -I. -c udf_names.c # Compiling DCA.o because of DCA.c cc -D_lnamd64 -D_GNU_SOURCE -fpic -shared -ansi -Wall -O -DPTR_RESTRICT= -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/`expr "\`pwd\`" : '.*/\(.*\)/[23].*'`/`basename "\`pwd\`"` -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/src -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/cortex/src -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/client/src -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/tgrid/src -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/multiport/src -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/multiport/mpi_wrapper/include -I/usr/local/ansys/13/v130/fluent/fluent13.0.0/multiport/mpi_wrapper/src -I. -c DCA.c DCA.c: In function â€˜contact_angle_BCâ€™: DCA.c:12: warning: suggest parentheses around assignment used as truth value DCA.c:14: error: subscripted value is neither array nor pointer DCA.c:18: error: subscripted value is neither array nor pointer DCA.c:30: warning: â€˜returnâ€™ with a value, in function returning void DCA.c:31: error: expected declaration or statement at end of input DCA.c:31: error: expected declaration or statement at end of input DCA.c:31: error: expected declaration or statement at end of input DCA.c:5: warning: unused variable â€˜xâ€™ make[3]: *** [DCA.o] Error 1 make[3]: Target `libudf.so' not remade because of errors. make[3]: Leaving directory `/nfs/03/ucn0987/FLUENT/Test31/libudf/lnamd64/2ddp' make[2]: *** [lnamd64] Error 2 make[2]: Leaving directory `/nfs/03/ucn0987/FLUENT/Test31/libudf/lnamd64/2ddp' make[1]: *** [default] Error 2 make[1]: Leaving directory `/nfs/03/ucn0987/FLUENT/Test31/libudf/lnamd64/2ddp' __________________________________________________ _____________ I really appreciate for any sort of help!! Thanks and Regards Sandeep

 January 18, 2011, 21:42 #4 Senior Member   Join Date: Nov 2009 Posts: 411 Rep Power: 10 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, 22:27 #5 Member   Sandeep Join Date: Jul 2010 Posts: 48 Rep Power: 6 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, 22:34 #6 Senior Member   Join Date: Nov 2009 Posts: 411 Rep Power: 10 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, 22:58 #7 Member   Sandeep Join Date: Jul 2010 Posts: 48 Rep Power: 6 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, 01:57 #8 Senior Member   Join Date: Nov 2009 Posts: 411 Rep Power: 10 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, 02:28 #9 Member   Sandeep Join Date: Jul 2010 Posts: 48 Rep Power: 6 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, 12:17 #10 Senior Member   Join Date: Nov 2009 Posts: 411 Rep Power: 10 How many cells has your grid ? Do

 January 21, 2011, 13:51 #11 Member   Sandeep Join Date: Jul 2010 Posts: 48 Rep Power: 6 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, 16:54 #12 Senior Member   Join Date: Nov 2009 Posts: 411 Rep Power: 10 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, 01:38 #13 Member   Sandeep Join Date: Jul 2010 Posts: 48 Rep Power: 6 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, 15:54 #14 New Member   Baiqiu Join Date: Jan 2011 Posts: 3 Rep Power: 6 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, 14: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?

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post eberberovic OpenFOAM Running, Solving & CFD 14 November 4, 2014 06:45 rmousavibt Fluent UDF and Scheme Programming 10 March 7, 2014 08:00 AlmostSurelyRob OpenFOAM 3 June 24, 2011 13:06 gandesk Fluent UDF and Scheme Programming 1 November 1, 2010 10:00 Häwimeddel FLUENT 2 April 20, 2009 10:08

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

 Contact Us - CFD Online - Top