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

span-wise averaging

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 4, 2015, 18:43
Default span-wise averaging
  #1
Senior Member
 
Ehsan Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18
syavash is on a distinguished road
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
syavash is offline   Reply With Quote

Reply


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
Starting field averaging using libFunctionObject after certain time eelcovv OpenFOAM Programming & Development 25 December 7, 2015 23:28
How to do spatial averaging - LES pipe flows ? Dan1788 OpenFOAM Running, Solving & CFD 0 December 12, 2014 15:50
RANS - time averaging? Connor STAR-CCM+ 1 April 5, 2011 05:52
When to use mass flow averaging cspectre CFX 2 December 6, 2009 06:30
Averaging LES iko FLUENT 3 July 3, 2008 06:55


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