# Find out location of a point in the mesh using a UDF

 FLUENT solves conservation equations for mass and momentum and stores the solution variables (e.g. temperature, pressure) at the grid cell centroids. In order to compare the value of the solver variable at a known point, we need to locate the cell in which the given point lies. The value of this cell represents the value of the solver variable at that location. The following example shows how to locate the cell using SV_locate_point(x,z,c) macro once the point coordinates are known. Once the cell is located, we can use the solver data to perform other mathematical operations as required. This UDF will read data from a file "points.txt" which will contain coordinates for some points in the domain. Now the UDF will find corresponding cell, in which given point lies and write the coordinate of cell centroid and pressure in Â'results.outÂ' file. /************* UDF Starts***********************/ #include "udf.h" #include "dpm.h" DEFINE_ON_DEMAND(locate_point) { CX_Cell_Id *c; cell_t ct; Thread *t; real z; real x = {0.0, 0.0, 0.0}; real pressure; int N,i; FILE *output,*points; points = fopen("points.txt","r"); output = fopen("results.out","w"); fscanf(points,"%d n",&N); /* Read points from the file one by one and write corresponding cell centroid and pressure in Â'results.outÂ' */ for ( i=0;ict.c; t = c->ct.t; C_CENTROID(z, ct, t); /*Returns centroid of the cell*/ pressure=C_P(ct,t); fprintf(output, "Given point %e %e, %enFound Cell at %e, %e, %enPressure %enn",x,x,x,z,z,z,pressure); } fclose(output); fclose(points); } /**************UDF Ends*************************/