Loop Over cells through which a surface created for postprocessing passes


It is sometimes necessary to retrieve the values of specific variables on a surface that was created for post processing using some other variable. This could be done by looping over cells with the same conditions as was used for creating the original surface. But this does not get the cells along the surface curvature. The present udf (DEFINE_ON_DEMAND) does that. It gets the cells through which the surface passes and write the cell center coordinate and cell index in a file. You can then retrieve any other variable that is needed, once cell indices and the cell thread are known.
Before executing this udf, please remember to display the corresponding surface. This is necessary because cortex does not store the data regarding surface unless it is called. If the data changes then all these surface data is deleted and will be created again when called.
This udf can not be used in Windows o/s. Windows does not support this kind of links.
/*****************************************************************************
* Udf to retrieve the cells and thread (and subsequently all other variables)
* through which a surface, created for postprocessing, passes
* Written by Suman Basu of Fluent India
****************************************************************************/

#include "udf.h"
#include "surf.h"
#define SURFID 4 /*this is the id of the surface of interest
could be checked from Surface->Manage GUI panel*/

DEFINE_ON_DEMAND(loop_over_surface)
{
int phase_domain_index;
real x[ND_ND];
cell_t cell;
CX_Cell_Id c;
Surface surf=SurfaceList[SURFID];
int i;
Thread *cell_thread;
FILE *fp;

fp=fopen("store.dat","a");

Message("%d",surf.np);

for(i=0;i<surf.np;i++)
{
c=surf.points[i].cell;
cell=RP_CELL(&c);
cell_thread=RP_THREAD(&c);
C_CENTROID(x,cell,cell_thread);
/*writes the X and Y coordinates of the cell centroid and cell index in the file*/
fprintf(fp,"%g %g %dn",x[0],x[1],cell);
}

fclose(fp);
}





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