
[Sponsors] 
December 30, 2010, 01:52 
XMomentum Source to water pahse in VOF

#1 
New Member
Srinivas Mettu
Join Date: Dec 2010
Posts: 3
Rep Power: 8 
I was trying to include an XMomentum source to water phase in VOF Model ( 2 phases, air (primary) and water (secondary)) of Fluent.
Depending the sign of volume averaged Xvelocity on water phase, I give either positive momentum or negative momentum... I am using the following two UDFs, the first one calculates avg vel and the second one gives XMomentum source... I am getting Segmentation violation error.... are there any errors in this... DEFINE_EXECUTE_AT_END(execute_at_end) { Domain *d3 = Get_Domain(3); /* secondary phase domain if multiphase */ Thread *t; cell_t c; real totv=0; avgxvel=0.0; thread_loop_c (t,d3) { if (C_VOF(c,t) > 0.0) { avgxvel= avgxvel+C_U(c,t) * C_VOLUME(c,t); totv=totv+C_VOLUME(c,t); } } avgxvel=avgxvel/totv; } DEFINE_SOURCE(cell_x_source, c, t, dS, eqn) { real source; real delta=35; /* hysteresis acceleration in m/s2 */ Domain *dw = Get_Domain(3); /* secondary phase domain if multiphase */ int phase_domain_index=3; Thread *mixture_thread=t; Thread *tw = THREAD_SUB_THREAD(mixture_thread,phase_domain_inde x); /* loop over all cell threads in the secondary phase domain */ thread_loop_c (tw,dw) { if (C_VOF(c,tw) > 0.0) { if (avgxvel > 0.0) { /* source term */ source = 1000*delta; } else { /* source term */ source = 1000*delta; } /* derivative of source term w.r.t. xvelocity. */ dS[eqn] = 0; } else { source = dS[eqn] = 0.; } } return source; } can anyone help me in this... srinivas 

December 30, 2010, 10:39 

#2 
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 9 
Srinivas,
You appear to be only looping through all cell threads in the secondary phase domain. If you're going to reference a specific cell, you also need to loop over all cells in that thread. This is probably why you're getting a violation. Have a look at the following code (unchecked): Code:
DEFINE_EXECUTE_AT_END(execute_at_end) { Domain *d3 = Get_Domain(3); /* secondary phase domain if multiphase */ Thread *t; cell_t c; real totv=0; avgxvel=0.0; thread_loop_c (t,d3) { begin_c_loop_all (c,t) { if (c_vof(c,t) > 0.0) { avgxvel= avgxvel+c_u(c,t) * c_volume(c,t); totv=totv+c_volume(c,t); } } } avgxvel=avgxvel/totv; } Additionally, if your source UDF loops over cells, you'll have to put a cell loop in it, as well. However, the DEFINE_SOURCE udf is passed a cell and a thread by the solver, so there's no reason to loop. You are changing the source term on a percell basis. If you want all the cells to have the same source term, I'd suggest doing the calculation in your avgxvel loop, writing to another UDMI, then simply having the source udf look something like: source=C_UDMI(c,t,1); dS[eqn]=C_UDMI(c,t,2); ComputerGuy Last edited by ComputerGuy; December 30, 2010 at 10:55. 

December 30, 2010, 14:52 
Modified the code

#3 
New Member
Srinivas Mettu
Join Date: Dec 2010
Posts: 3
Rep Power: 8 
Hi ComputerGuy,
thank you very much for the reply... my avgxvel variable is declared as a global variable so that it is accessible from other UDFs... I have modified the code as follows as u suggested... it compiles without any errors... but gives segmentation violation error... may be I have to use DEFINE_ADJUST instead of DEFINE_EXECUTE_AT_END so that the source term is adjusted at every iteration in the unsteady iterations... DEFINE_EXECUTE_AT_END(execute_at_end) { Domain *d3 = Get_Domain(3); /* secondary phase domain if multiphase */ Thread *t; cell_t c; real totv=0; real avgxveln=0; avgxvel=0.0; thread_loop_c (t,d3) { begin_c_loop(c,t) if (C_VOF(c,t) > 0.0) { avgxvel= avgxvel+C_U(c,t) * C_VOLUME(c,t); totv=totv+C_VOLUME(c,t); } else { } end_c_loop(c,t) } avgxvel=avgxvel/totv; printf("Average X Vel = %d\n", avgxvel); printf("Total Volume = %d\n", totv); } DEFINE_SOURCE(cell_x_source, c, t, dS, eqn) { real source; real delta=35; /* hysteresis acceleration in m/s2 */ if (C_VOF(c,t) > 0.0) { if (avgxvel > 0.0) { /* source term */ source = 1000*delta; } else { /* source term */ source = 1000*delta; } /* derivative of source term w.r.t. xvelocity. */ dS[eqn] = 0; } else { source = dS[eqn] = 0.; } return source; } 

December 31, 2010, 01:43 

#4 
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 9 
The other thought, which might be causing the segmentation error, is the fact that the DEFINE_SOURCE macro in the VOF model is passed the mixture level thread. You really want to get the VOF of one phase or another, so you could do something like:
Code:
DEFINE_SOURCE(cell_x_source, c, t, dS, eqn) { Thread *sec_th; real source; real delta=35.; /* hysteresis acceleration in m/s2 */ sec_th = THREAD_SUB_THREAD(t, 1); if (C_VOF(c,sec_th) > 0.0) { if (avgxvel > 0.0) { /* source term */ source = 1000.*delta; } else { /* source term */ source = 1000.*delta; } /* derivative of source term w.r.t. xvelocity. */ dS[eqn] = 0.; } else { source = dS[eqn] = 0.; } return source; } See if that works. I'm assuming you have two phases, and the VOF you're interested in is the second phase (phase index 1). ComputerGuy 

January 4, 2011, 12:38 
thread pointers to individual phases

#5 
New Member
Srinivas Mettu
Join Date: Dec 2010
Posts: 3
Rep Power: 8 
Hi Computer Guy,
I have tried the following code to calculate average volume weighted cell velocity over the mixture domain. It calculates the total volume and average velocity correctly. However, it loops through entire mixture domain, but I wanted it to loop through water phase only... I have tried using d = Get_Domain(2);d = Get_Domain(3); but the average vel that I got is same in all cases which is not correct.... this means that everytime I am getting the mixture domain through get domain... in order to get thread pointers to individual phases I have tried using Code:
Thread **pt; mp_thread_loop_c (t,d,pt) /* t is a mixture thread*/ Code:
DEFINE_EXECUTE_AT_END(myexecend) { Domain *d; /* declare domain pointer since it is not passed as an argument to the EXECUTE_AT_END macro */ real volume=0,vol_tot=0,velv=0,tot_vel=0,avgvel=0; Thread *t; cell_t c; d = Get_Domain(1); /* Get mixture domain */ /* Thread **pt; mp_thread_loop_c (t,d,pt) /* t is a mixture thread*/ /* Loop over all threads in the domain 'd' */ thread_loop_c(t,d) { /* Loop over all cells */ begin_c_loop(c,t) { /*if (C_VOF(c,pt[1]) > 0.0) {*/ volume = C_VOLUME(c,t); /* get cell volume */ velv= C_U(c,t)*volume; /* get volume weighted cell velocity */ vol_tot += volume; /* calculate total volume */ tot_vel += velv; /* calculate total volume weighted cell velocity */ /*}*/ } end_c_loop(c,t) } avgvel=tot_vel/vol_tot; /* calculate average volume weighted velocity */ avgxvel=avgvel; /* avgxvel is a global variable available to DEFINE_SOURCE macro */ printf("\n Total volume = %g",vol_tot); printf("\n Tot vel = %g",tot_vel); printf("\n Avg vel = %g",avgvel); } DEFINE_SOURCE(cell_x_source, c, t, dS, eqn) { Thread **pt = THREAD_SUB_THREADS(t); /*pt is an array such that pt[0] is mixture thread, pt[1] first secondary phase thread, pt[2] second secondary phase thread etc.*/ real source; real delta=35.; /* hysteresis acceleration in m/s2 */ if (C_VOF(c,pt[1]) > 0.0) { if (avgxvel > 0.0) { /* source term */ source = 1000.*delta; } else { /* source term */ source = 1000.*delta; } /* derivative of source term w.r.t. xvelocity. */ dS[eqn] = 0.; } else { source = dS[eqn] = 0.; } return source; } 

April 17, 2011, 23:12 

#6 
New Member
Join Date: Apr 2011
Posts: 4
Rep Power: 8 
hi, srinivas
how about your problem? i am intrested in your solution. could you introduce it to me? 

June 22, 2011, 20:29 

#7 
New Member
dingxueping
Join Date: Jun 2011
Posts: 2
Rep Power: 0 
hi, srinivas
how about your problem? i meet the same problem as you ,will you give me some help please ? it is urgent ,please , thank you very much! 

June 22, 2011, 20:31 

#8 
New Member
dingxueping
Join Date: Jun 2011
Posts: 2
Rep Power: 0 
hi, srinivas
how about your problem? i meet the same problem as you ,will you give me some help please ? it is urgent ,please , thank you very much! 

Tags 
average velocity, udf source 
Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
momentum source term  zwdi  FLUENT  14  June 27, 2017 15:40 
Momentum source coefficient and convergence  meh  CFX  2  November 19, 2010 17:57 
Derivation of Momentum Equation in Integral Form  Demonwolf  Main CFD Forum  2  October 29, 2009 20:53 
VOF model of water film  Pathway  FLUENT  1  July 21, 2007 07:33 
VOF and Source Term  Mickaël PERRIN  FLUENT  4  July 12, 2003 06:01 