CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   UDF for second order moments in LES (http://www.cfd-online.com/Forums/fluent/30278-udf-second-order-moments-les.html)

 Jimmy September 6, 2002 11:16

UDF for second order moments in LES

finally i solved my problem, here's the UDF i made if someone's interested (it runs in parallel without any problem).

/************************************************** ************************/

/* UDF computing some Reynolds Stresses and Density-Velocity correlations */

/* Skewness and Flateness are also computed */

/************************************************** ************************/

#include "udf.h"

#include "sg.h"

#include "math.h"

#include "metric.h"

/****************************************/

/* Application domain (over fluid only) */

/****************************************/

/* 1 fluide fluid cell */

/***********************/

/* User Define Scalars */

/***********************/

enum { /* Mean Values */

UMOY,VMOY,WMOY,RhoMoy,

/* Fluctuations */

Uprime,Vprime,Wprime,Rhoprime,

/* Reynolds stresses */

UprimeVprimeMoy,UprimeWprimeMoy,VprimeWprimeMoy,

/* Density velocity correlations */

RhoprimeUprimeMoy,RhoprimeVprimeMoy,RhoprimeWprime Moy,

/* Standard deviations */

UcarreMoy,VcarreMoy,WcarreMoy,RhocarreMoy,

/* Skewness and flatness */

Uprime3Moy,Uprime4Moy,Su,Fu

};

{

/**********************/

/* GLOBAL VARIABLES */

/**********************/

static int count=0; /* user counter of time step */

int n1,n2=50; /* fluent counters of time step */

int n3=286 /* offset (nb of time steps done before including subroutine) */

cell_t c;

/***************************************/

/* Initialisation of time step counter */

/***************************************/

n1 = RP_Get_Integer("time-step")-n3;

/****************************************/

/* message dispalayed at each iteration */

/****************************************/

Message(" Counters %d %d \n",count,n1);

/************************************************** ***/

/* First n2 time steps mean values only are computed */

/************************************************** ***/

if ((count <= n2) && (count == n1)) /* updating statistics at each time step */

{

Message(" Inside mean loop counters %d %d \n",count,n1);

count++;

begin_c_loop(c,t_fluid)

{

/***************/

/* Mean Values */

/***************/

C_UDSI(c,t_fluid,UMOY) = ( C_UDSI(c,t_fluid,UMOY)*(count - 1) + C_U(c,t_fluid) )/count;

C_UDSI(c,t_fluid,VMOY) = ( C_UDSI(c,t_fluid,VMOY)*(count - 1) + C_V(c,t_fluid) )/count;

C_UDSI(c,t_fluid,WMOY) = ( C_UDSI(c,t_fluid,WMOY)*(count - 1) + C_W(c,t_fluid) )/count;

C_UDSI(c,t_fluid,RhoMoy) = ( C_UDSI(c,t_fluid,RhoMoy)*(count - 1) + C_R(c,t_fluid) )/count;

/****************/

/* Fluctuations */

/****************/

C_UDSI(c,t_fluid,Uprime) = 0.0;

C_UDSI(c,t_fluid,Vprime) = 0.0;

C_UDSI(c,t_fluid,Wprime) = 0.0;

C_UDSI(c,t_fluid,Rhoprime) = 0.0;

/************************/

/* Reynolds stresses */

/************************/

C_UDSI(c,t_fluid,UprimeVprimeMoy) = 0.0;

C_UDSI(c,t_fluid,UprimeWprimeMoy) = 0.0;

C_UDSI(c,t_fluid,VprimeWprimeMoy) = 0.0;

/****************/

/* Correlations */

/****************/

C_UDSI(c,t_fluid,RhoprimeUprimeMoy) = 0.0;

C_UDSI(c,t_fluid,RhoprimeVprimeMoy) = 0.0;

C_UDSI(c,t_fluid,RhoprimeWprimeMoy) = 0.0;

/***********************/

/***********************/

C_UDSI(c,t_fluid,UcarreMoy) = 0.0;

C_UDSI(c,t_fluid,VcarreMoy) = 0.0;

C_UDSI(c,t_fluid,WcarreMoy) = 0.0;

C_UDSI(c,t_fluid,RhocarreMoy) = 0.0;

/*****************************/

/* Dissymetry and Flatness F */

/*****************************/

C_UDSI(c,t_fluid,Uprime3Moy) = 0.0;

C_UDSI(c,t_fluid,Uprime4Moy) = 0.0;

C_UDSI(c,t_fluid,Su) = 0.0;

C_UDSI(c,t_fluid,Fu) = 0.0;

}

end_c_loop(c,t_fluid)

}

else /* after n2 iteration statistics are computed */

{ if ((count > n2) && (count == n1)) /* updating statistics at each time step */

{

Message(" inside statistic loop %d %d\n",count,n1);

count++ ;

begin_c_loop(c,t_fluid)

{

/**************/

/* Mean Values */

/****************/

C_UDSI(c,t_fluid,UMOY) = ( C_UDSI(c,t_fluid,UMOY)*(count - 1) + C_U(c,t_fluid) )/count;

C_UDSI(c,t_fluid,VMOY) = ( C_UDSI(c,t_fluid,VMOY)*(count - 1) + C_V(c,t_fluid) )/count;

C_UDSI(c,t_fluid,WMOY) = ( C_UDSI(c,t_fluid,WMOY)*(count - 1) + C_W(c,t_fluid) )/count;

C_UDSI(c,t_fluid,RhoMoy) = ( C_UDSI(c,t_fluid,RhoMoy)*(count - 1) + C_R(c,t_fluid) )/count;

/***************/

/* Fluctuations */

/****************/

C_UDSI(c,t_fluid,Uprime) =C_UDSI(c,t_fluid,UMOY) - C_U(c,t_fluid);

C_UDSI(c,t_fluid,Vprime) =C_UDSI(c,t_fluid,VMOY) - C_V(c,t_fluid);

C_UDSI(c,t_fluid,Wprime) =C_UDSI(c,t_fluid,WMOY) - C_W(c,t_fluid);

C_UDSI(c,t_fluid,Rhoprime) =C_UDSI(c,t_fluid,RhoMoy) - C_R(c,t_fluid);

/********************/

/* Reynolds Stresses */

/**********************/

C_UDSI(c,t_fluid,UprimeVprimeMoy) = ( C_UDSI(c,t_fluid,UprimeVprimeMoy)*(count - n2 - 1) + (C_UDSI(c,t_fluid,Uprime) * C_UDSI(c,t_fluid,Vprime)) )/(count - n2);

C_UDSI(c,t_fluid,UprimeWprimeMoy) = ( C_UDSI(c,t_fluid,UprimeWprimeMoy)*(count - n2 - 1) + (C_UDSI(c,t_fluid,Uprime) * C_UDSI(c,t_fluid,Wprime)) )/(count - n2);

C_UDSI(c,t_fluid,VprimeWprimeMoy) = ( C_UDSI(c,t_fluid,VprimeWprimeMoy)*(count - n2 - 1) + (C_UDSI(c,t_fluid,Vprime) * C_UDSI(c,t_fluid,Wprime)) )/(count - n2);

/***************/

/* Correlations */

/*****************/

C_UDSI(c,t_fluid,RhoprimeUprimeMoy) = ( C_UDSI(c,t_fluid,RhoprimeUprimeMoy)*(count - n2 - 1) + (C_UDSI(c,t_fluid,Rhoprime) * C_UDSI(c,t_fluid,Uprime)) )/(count - n2);

C_UDSI(c,t_fluid,RhoprimeVprimeMoy) = ( C_UDSI(c,t_fluid,RhoprimeVprimeMoy)*(count - n2 - 1) + (C_UDSI(c,t_fluid,Rhoprime) * C_UDSI(c,t_fluid,Vprime)) )/(count - n2);

C_UDSI(c,t_fluid,RhoprimeWprimeMoy) = ( C_UDSI(c,t_fluid,RhoprimeWprimeMoy)*(count - n2 - 1) + (C_UDSI(c,t_fluid,Rhoprime) * C_UDSI(c,t_fluid,Wprime)) )/(count - n2);

/*********************/

/* Standard deviation */

/***********************/

C_UDSI(c,t_fluid,UcarreMoy) = ( C_UDSI(c,t_fluid,UcarreMoy)*(count - n2 - 1) + (C_UDSI(c,t_fluid,Uprime)*C_UDSI(c,t_fluid,Uprime) ) )/(count - n2);

C_UDSI(c,t_fluid,VcarreMoy) = ( C_UDSI(c,t_fluid,VcarreMoy)*(count - n2 - 1) + (C_UDSI(c,t_fluid,Vprime)*C_UDSI(c,t_fluid,Vprime) ) )/(count - n2);

C_UDSI(c,t_fluid,WcarreMoy) = ( C_UDSI(c,t_fluid,WcarreMoy)*(count - n2 - 1) + (C_UDSI(c,t_fluid,Wprime)*C_UDSI(c,t_fluid,Wprime) ) )/(count - n2);

C_UDSI(c,t_fluid,RhocarreMoy) = ( C_UDSI(c,t_fluid,RhocarreMoy)*(count - n2 - 1) + (C_UDSI(c,t_fluid,Rhoprime)*C_UDSI(c,t_fluid,Rhopr ime)) )/(count - n2);

/******************************/

/* Skewness Su and Flatness Fu */

/********************************/

C_UDSI(c,t_fluid,Uprime3Moy) = ( C_UDSI(c,t_fluid,Uprime3Moy)*(count - n2 - 1) + pow(C_UDSI(c,t_fluid,Uprime),3) ) /(count - n2);

C_UDSI(c,t_fluid,Uprime4Moy) = ( C_UDSI(c,t_fluid,Uprime4Moy)*(count - n2 - 1) + pow(C_UDSI(c,t_fluid,Uprime),4) ) /(count - n2);

C_UDSI(c,t_fluid,Su) = C_UDSI(c,t_fluid,Uprime3Moy)/pow(C_UDSI(c,t_fluid,UcarreMoy),1.5);

C_UDSI(c,t_fluid,Fu) = C_UDSI(c,t_fluid,Uprime4Moy)/pow(C_UDSI(c,t_fluid,UcarreMoy),2);

}

end_c_loop(c,t_fluid)

}

} }

 All times are GMT -4. The time now is 21:41.