CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   How can we save flow variables in a file by udf? (https://www.cfd-online.com/Forums/fluent/110854-how-can-we-save-flow-variables-file-udf.html)

 moh.sob December 22, 2012 18:05

How can we save flow variables in a file by udf?

Hi everybody,
I want to calculate rate of deformation tensor in some points around a sphere. so I wrote a UDF , but it doesn't work !!!
Can any body help me that how I can use converged steady solution to calculate velocity gradients, etc.
After that I want to save these data in a txt file. I don't know which macros can export data to a txt file from a udf !!!

Best

 moh.sob December 23, 2012 06:22

here is my udf:

#include "udf.h"
#include "surf.h"
#include "cxiface.h"
#include "cxndsearch.h"

DEFINE_ON_DEMAND( rate_of_deformation_tensor )
{
/* Note: All the variables must be defined first. */

Domain *d;

/* Determine Coordinates */
cell_t c;
CX_Cell_Id cx_cell;
real NV_VEC( pt );
real c_centroid[ ND_ND ];
real V_Grad[ ND_ND ][ ND_ND ];
real D[ ND_ND ][ ND_ND ];
int i, j, k;

FILE *fp;
fp = fopen( "Rate of Deformation Tensor.txt", "w" );

d = Get_Domain(2);

NV_D( pt, =, -3.0, 0.0, 0.0 );

/* Search */

//CX_Start_ND_Point_Search( pt );
//cx_cell = *CX_Find_Cell_With_Point( pt );
//CX_End_ND_Point_Search( );

//c = RP_CELL( &cx_cell ); /* the right cell number */
//C_CENTROID( c_centroid, c, t );

//Message( "Coordinate of the specified point: x = %g, y = %g, z = %g\n", pt[0], pt[1], pt[2] );
//Message( "Coordinate of the cell found: x = %g, y = %g, z = %g\n", c_centroid[0], c_centroid[1], c_centroid[2] );

c = 10;

/*************** Calculate Rate of Deformation Tensor *******/

for( i = 0; i < ND_ND; i++ )
V_Grad[ 0 ][ i ] = C_U_G(c,t)[ i ];

for( j = 0; j < ND_ND; j++ )
V_Grad[ 1 ][ j ] = C_V_G(c,t)[ j ];

for( k = 0; k < ND_ND; k++ )
V_Grad[ 2 ][ k ] = C_W_G(c,t)[ k ];

printf( "Writing UDF data from data file...\n" );

for( i = 0; i < ND_ND; i++ )
{
for( j = 0; j < ND_ND; j++ )
{
D[ i ][ j ] = 0.5 * ( V_Grad[ i ][ j ] + V_Grad[ j ][ i ] );
fprintf( fp, "%g \t", D[ i ][ j] );
//printf( "%g \t", D[ i ][ j] );
}

fprintf( fp, "\n" );
// printf( "\n" );
}

fclose( fp );
}

just send "FILE *fp" to before DEFINE_ON_DEMAND, like this:
-------------------------------
#include "udf.h"
#include "surf.h"
#include "cxiface.h"
#include "cxndsearch.h"
FILE *fp;
DEFINE_ON_DEMAND( rate_of_deformation_tensor )
-------------------------------
It have been solved on my computer.

 moh.sob December 23, 2012 17:28

I changed my udf due to your idea ! but it is doesn't run yet !!!!

ممنون از اینکه وقت گذاشتید و فایل رو بررسی کردید

 fangdian December 25, 2012 10:21

Quote:
 Originally Posted by moh.sob (Post 398704) Hi everybody, I want to calculate rate of deformation tensor in some points around a sphere. so I wrote a UDF , but it doesn't work !!! Can any body help me that how I can use converged steady solution to calculate velocity gradients, etc. After that I want to save these data in a txt file. I don't know which macros can export data to a txt file from a udf !!! Best
what is the symptom？ why can you say it doesn't work?
can't it pass the compile?

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