CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   span-wise averaging (https://www.cfd-online.com/Forums/fluent-udf/153839-span-wise-averaging.html)

syavash June 4, 2015 17:43

span-wise averaging
 
Hello mates,

I have developed a UDF which is able to perform span-wise averaging in the homogenous direction. It can be handy in LES or DNS simulation if one would want to plot span-wise averaged streamlines. Note that this UDF only works if there is already a time-averaged solution (Data sampling checked).
Enjoy!!

Code:

DEFINE_ON_DEMAND(Span_Averaged)
{
Domain *d = Get_Domain(1);
Thread *t0 = Lookup_Thread(d,ID);  /* ID is of periodic BC */
Thread *t;
cell_t c;
face_t f;
double x[ND_ND],x2[ND_ND],xc[ND_ND];
double X, Y, u_mean, v_mean, w_mean, SUM_u, SUM_v, SUM_w, u_Averaged, v_Averaged, w_Averaged, TOL, temp1, temp2, temp3;
int counter = 0;
int counter2 = 0;
TOL = 2e-3;

SUM_u = 0.0; 
SUM_v = 0.0;
SUM_w = 0.0;

#if !RP_HOST
  begin_f_loop(f,t0)
    {
      F_AREA(x2,f,t0);
      F_CENTROID(x,f,t0);
      X = x[0];
      Y = x[1];
      counter2 +=1;
      Message("face %d\n", counter2);   
     
  thread_loop_c(t,d)
    {     
        if (FLUID_THREAD_P(t))
        {
            begin_c_loop(c,t)
                {
                 
                  C_CENTROID(xc,c,t);
                  if (ABS((xc[0] - X) / X) < TOL && ABS((xc[1] - Y) / Y) < TOL)
                    {   
                   
                       
                        counter +=1;
                        u_mean = C_STORAGE_R(c,t, SV_U_MEAN)/delta_time_sampled;
                        v_mean = C_STORAGE_R(c,t, SV_V_MEAN)/delta_time_sampled;
                        w_mean = C_STORAGE_R(c,t, SV_W_MEAN)/delta_time_sampled;
                        SUM_u = SUM_u + u_mean;
                        SUM_v = SUM_v + v_mean;
                        SUM_w = SUM_w + w_mean;
                   
                    }
                }
              end_c_loop(c,t)
        }             
        if (counter > 0)
        {
              u_Averaged = SUM_u / counter;
              v_Averaged = SUM_v / counter;
              w_Averaged = SUM_w / counter;
              temp1 = u_Averaged;
              temp2 = v_Averaged;
              temp3 = w_Averaged;
        }
        else
        {
              u_Averaged = temp1;
              v_Averaged = temp2;
              w_Averaged = temp3;
        }
              SUM_u = 0.0;
              SUM_v = 0.0;
              SUM_w = 0.0;
              Message("counter %d\n", counter);       
              counter = 0;
              begin_c_loop(c,t)
                {
                  C_CENTROID(xc,c,t);
                  if (ABS((xc[0] - X) / X) < TOL && ABS((xc[1] - Y) / Y) < TOL)
                    {   
                    C_UDMI(c, t, 0) = u_Averaged;   
                    C_UDMI(c, t, 1) = v_Averaged;
                    C_UDMI(c, t, 2) = w_Averaged;                                                                                     
                    }
                }
              end_c_loop(c,t)
             
    }     
       
    }
  end_f_loop(f,t0)   
#endif
}

Note: The parameter "TOL" should be adjusted to make sure all the cells in the span-wise direction are taken into account!
Another point, this code only works with Hexa grids!

Regards


All times are GMT -4. The time now is 22:23.