CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   X-Momentum Source to water pahse in VOF (http://www.cfd-online.com/Forums/fluent/83463-x-momentum-source-water-pahse-vof.html)

 srm206 December 30, 2010 01:52

X-Momentum Source to water pahse in VOF

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 */
cell_t c;
real totv=0;
avgxvel=0.0;

{

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;

/* loop over all cell threads in the secondary phase domain */
{

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

 ComputerGuy December 30, 2010 10:39

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

 srm206 December 30, 2010 14:52

Modified the code

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 */

cell_t c;

real totv=0;

real avgxveln=0;
avgxvel=0.0;

{

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;

}

 ComputerGuy December 31, 2010 01:43

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

 srm206 January 4, 2011 12:38

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; }```

 Theodore April 17, 2011 23:12

hi, srinivas

 missingsky June 22, 2011 20:29

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 June 22, 2011 20:31

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!:)

 All times are GMT -4. The time now is 03:15.