CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Fluent UDF and Scheme Programming (
-   -   UDF for Species Mass Fraction Gradient *IN SPECIFIC ZONE * -- e.g. along axis of sym. (

ksiegs2 February 27, 2011 13:55

UDF for Species Mass Fraction Gradient *IN SPECIFIC ZONE * -- e.g. along axis of sym.
Hello all!

I am trying to write a UDF to export data for species mass fraction concentration gradient *along the axis of symmetry* of my 2D axisymmetric model.

I can get the data to output for all of the nodes in the 2D domain, but I cannot figure out how to output data only for the specific zone I need.

Right now it exports the species mass fraction gradient vector as one long vector for all nodes, with no indication as to which data point came from which node, or even which zone.

Does anyone know how to selectively output data from just a single zone? Or how to determine where each data point is coming from?

Thank you very much.

[I created my UDF by adapting the pressures_to_file.c UDF in the Fluent V12 users guide, if that helps.]

Thanks again!

This is the code: (I tried just substituting zone_ID for FLUID_ID, but that didn't work, so it's commented out now. The code leaves the option for the serial, node or host versions to run. In this case, the serial version runs.)

/************************************************** ******************/
#include "udf.h"
# define FLUID_ID 2
/* Different variables are needed on different nodes */
/*int zone_ID = 1;*/ /*designates axis of symmetry as zone of interest */
#if !RP_HOST
Domain *domain=Get_Domain(1);
Thread *thread;
cell_t c;
int i;
#if !RP_NODE
FILE *fp = NULL;
char filename[]="h2_grad_axis.txt";
int size; /* data passing variables */
real *array;
int pe;
/* Only Serial and Compute Nodes have data on threads */
#if !RP_HOST
#if !RP_NODE /* SERIAL or HOST */
if ((fp = fopen(filename, "w"))==NULL)
Message("\n Warning: Unable to open %s for writing\n",filename);
Message("\nWriting H2 Mass Fraction Gradient in X-Direction to %s...",filename);
/* UDF Now does 3 different things depending on SERIAL, NODE or HOST */
Message("(Serial version running...)");
fprintf(fp, "%g\n", C_YI_G(c,thread,2));/* Simply write out h2 mass fraction x-direction gradient data*/
#endif /* !PARALLEL */
/* Each Node loads up its data passing array */
array = (real *)malloc(size * sizeof(real));
array[c]= C_YI_G(c,thread,2);
/* Set pe to destination node */
/* If on node_0 send data to host */
/* Else send to node_0 because */
/* compute nodes connect to node_0 & node_0 to host */
pe = (I_AM_NODE_ZERO_P) ? node_host : node_zero;
PRF_CSEND_INT(pe, &size, 1, myid);
PRF_CSEND_REAL(pe, array, size, myid);
free(array);/* free array on nodes after data sent */
/* node_0 now collect data sent by other compute nodes */
/* and sends it straight on to the host */
compute_node_loop_not_zero (pe)
PRF_CRECV_INT(pe, &size, 1, pe);
array = (real *)malloc(size * sizeof(real));
PRF_CRECV_REAL(pe, array, size, pe);
PRF_CSEND_INT(node_host, &size, 1, myid);
PRF_CSEND_REAL(node_host, array, size, myid);
free((char *)array);
#endif /* RP_NODE */
Message("(Node version running...)");
compute_node_loop (pe) /* only acts as a counter in this loop */
/* Receive data sent by each node and write it out to the file */
PRF_CRECV_INT(node_zero, &size, 1, node_zero);
array = (real *)malloc(size * sizeof(real));
PRF_CRECV_REAL(node_zero, array, size, node_zero);
for (i=0; i<size; i++)
fprintf(fp, "%g\n", array[i]);
Message("(Host version running...)");
#endif /* RP_HOST */
#if !RP_NODE /* SERIAL or HOST */
fclose(fp); /* Close the file that was only opened if on SERIAL or HOST */

All times are GMT -4. The time now is 11:36.