CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF for Species Mass Fraction Gradient *IN SPECIFIC ZONE * -- e.g. along axis of sym. (http://www.cfd-online.com/Forums/fluent-udf/85488-udf-species-mass-fraction-gradient-specific-zone-e-g-along-axis-sym.html)

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
DEFINE_ON_DEMAND(h2_grad_to_file)
{
/* 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;
#else
int i;
#endif
#if !RP_NODE
FILE *fp = NULL;
char filename[]="h2_grad_axis.txt";
#endif
#if PARALLEL
int size; /* data passing variables */
real *array;
int pe;
#endif
/* Only Serial and Compute Nodes have data on threads */
#if !RP_HOST
thread=Lookup_Thread(domain,FLUID_ID);
#endif
#if !RP_NODE /* SERIAL or HOST */
if ((fp = fopen(filename, "w"))==NULL)
Message("\n Warning: Unable to open %s for writing\n",filename);
else
Message("\nWriting H2 Mass Fraction Gradient in X-Direction to %s...",filename);
#endif
/* UDF Now does 3 different things depending on SERIAL, NODE or HOST */
#if !PARALLEL /* SERIAL */
Message("(Serial version running...)");
begin_c_loop(c,thread)
fprintf(fp, "%g\n", C_YI_G(c,thread,2));/* Simply write out h2 mass fraction x-direction gradient data*/
end_c_loop(c,thread)
#endif /* !PARALLEL */
#if RP_NODE
/* Each Node loads up its data passing array */
size=THREAD_N_ELEMENTS_INT(thread);
array = (real *)malloc(size * sizeof(real));
begin_c_loop_int(c,thread)
array[c]= C_YI_G(c,thread,2);
end_c_loop_int(c,thread)
/* 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 */
if (I_AM_NODE_ZERO_P)
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 */
#if RP_HOST
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]);
free(array);
}
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 */
Message("Done\n");
#endif
}


All times are GMT -4. The time now is 13:15.