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

X-Momentum Source to water pahse in VOF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 30, 2010, 00:52
Default X-Momentum Source to water pahse in VOF
  #1
New Member
 
Srinivas Mettu
Join Date: Dec 2010
Posts: 3
Rep Power: 15
srm206 is on a distinguished road
I was trying to include an X-Momentum source to water phase in VOF Model ( 2 phases, air (primary) and water (secondary)) of Fluent.
Depending the sign of volume averaged X-velocity 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 X-Momentum 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. x-velocity. */
dS[eqn] = 0;
}
else
{

source = dS[eqn] = 0.;
}

}



return source;

}


can anyone help me in this...

srinivas
srm206 is offline   Reply With Quote

Old   December 30, 2010, 09:39
Default
  #2
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
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;
}
I'm not sure why you've written the EXECUTE_AT_END function, however. It doesn't appear to be changing anything, and the value of avgxvel will be lost immediately after the function executes. It would be better to write the value to a user-defined memory location (C_UDMI) and get it from there.

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 per-cell 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 09:55.
ComputerGuy is offline   Reply With Quote

Old   December 30, 2010, 13:52
Default Modified the code
  #3
New Member
 
Srinivas Mettu
Join Date: Dec 2010
Posts: 3
Rep Power: 15
srm206 is on a distinguished road
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. x-velocity. */
dS[eqn] = 0;
}
else
{

source = dS[eqn] = 0.;
}





return source;

}
srm206 is offline   Reply With Quote

Old   December 31, 2010, 00:43
Default
  #4
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
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. x-velocity. */
   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
ComputerGuy is offline   Reply With Quote

Old   January 4, 2011, 11:38
Default thread pointers to individual phases
  #5
New Member
 
Srinivas Mettu
Join Date: Dec 2010
Posts: 3
Rep Power: 15
srm206 is on a distinguished road
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*/
but when I compile this code it gives me error.... Ideally, using the thread 't' and domain 'd' corresponding to mixture domain I should get threat pointers pt[0] and pt[1].... I am very confused...

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. x-velocity. */
   dS[eqn] = 0.;
 }
 else
 {
  source = dS[eqn] = 0.;
 }
 
 return source;
}
srm206 is offline   Reply With Quote

Old   April 17, 2011, 23:12
Default
  #6
New Member
 
Join Date: Apr 2011
Posts: 4
Rep Power: 15
Theodore is on a distinguished road
hi, srinivas
how about your problem? i am intrested in your solution. could you introduce it to me?
Theodore is offline   Reply With Quote

Old   June 22, 2011, 20:29
Default
  #7
New Member
 
dingxueping
Join Date: Jun 2011
Posts: 2
Rep Power: 0
missingsky is on a distinguished road
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!
missingsky is offline   Reply With Quote

Old   June 22, 2011, 20:31
Default
  #8
New Member
 
dingxueping
Join Date: Jun 2011
Posts: 2
Rep Power: 0
missingsky is on a distinguished road
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!
missingsky is offline   Reply With Quote

Reply

Tags
average velocity, udf source


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
Momentum source coefficient and convergence meh CFX 9 October 12, 2020 08:37
momentum source term zwdi FLUENT 14 June 27, 2017 15:40
Derivation of Momentum Equation in Integral Form Demonwolf Main CFD Forum 2 October 29, 2009 19: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


All times are GMT -4. The time now is 20:42.