FLUENT V6.2 & 6.3 - Writing out variable data into a file in ASCII format from the parallel version

FLUENT doesn't give option to write out file in ASCII format when using the parallel version
A UDF is written to export FLUENT variable data in ASCII format from FLUENT parallel.

The example UDF given below exports the pressure value at each cell center. One can suitably modify this for other variables.

/*********************************************************************/
/* UDF to write out a file in a ASCII file export format */
/* UDF can be used in parallel FLUENT 6.x version */
/* NOTE:- This UDF is tested on FLUENT-6.1.22 and FLUENT-6.2.16 with */
/* smpi as the network communicator */
/*********************************************************************/
/* How to use this UDF? */
/* (1) Please copy the UDF in your working directory */
/* (2) Compile the UDF through Define-->User-Defined-->Functions--> */
/* Compiled */
/* (3) You can execute this function whenever desired */
/* (4) If you want this to be executed after certain period, either */
/* after some iterations/time steps then set this freq.in */
/* solve-->Execute-Commands */
/* (5) e.g following command can be used in solve-->execute commands*/
/* /def ud function execute-on-demand "on_demand_write_out" */
/* What this UDF does? */
/* (1) This UDF writes out a file named "output_file.txt" in working*/
/* directory */
/* (2) Then the cellnumber, x,y,z coordinates and pressure */
/* in the file in a format similar to that of ASCII export file */
/*********************************************************************/
/* UDF written by:- Aashish Watve (asw@fluent.com) */
/*********************************************************************/
#include "udf.h"

DEFINE_ON_DEMAND(on_demand_write_out)
{
FILE* fp;

#if !RP_HOST
int cell_counter = 0, dummy;
double pressure, cell_center[ND_ND] ;
Domain *d;
Thread *t;
cell_t c;
d = Get_Domain(1); /* Get the domain using Fluent utility */
#endif

#if RP_NODE
if(!I_AM_NODE_ZERO_P)PRF_CRECV_INT(myid-1,&dummy,1,myid-1);
fp = fopen("output_file.txt",(I_AM_NODE_ZERO_P?"w":"a"));
#else
fp = fopen("output_file.txt","w");
#endif /* for RP_NODE*/

#if !RP_NODE
if (fp!=NULL)
{
Message("The file output_file.txt opened in the working directory n");
}
else
{
Message("Error in opening file n");
}
#endif /* for !RP_NODE*/

#if RP_NODE
fprintf(fp,"cell number X-cord Y-cord Z-cord Pressure");
#endif

#if !RP_HOST
thread_loop_c(t,d)
{
/*Message0("starting the loopn");*/
begin_c_loop_int(c,t)
{
cell_counter++;
C_CENTROID(cell_center,c,t);
pressure=C_P(c,t);

#if RP_2D
fprintf(fp,"n %d %10.3e %10.3e %10.3e",cell_counter, cell_center[0], cell_center[1], pressure);
#else
fprintf(fp,"n %d %10.3e %10.3e %10.3e %10.3e",cell_counter, cell_center[0], cell_center[1], cell_center[2], pressure);
/* Message("n %d %e %e %e %e",cell_counter, cell_center[0], cell_center[1], cell_center[2] ,pressure);*/
#endif
}
end_c_loop_int(c,t)
}
#endif /* for !RP_HOST*/

#if RP_NODE
fclose(fp);
if(!I_AM_NODE_LAST_P)PRF_CSEND_INT(myid+1,&dummy,1,myid);
#else
fclose(fp);
Message("nthe loop endsn");
#endif /* for RP_NODE*/
/*************************************************************************/





Show Form
No comments yet. Be the first to add a comment!