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[3];

real x[3] = {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;i<N;i++ )

{

fscanf(points,"%e%e%en",&x[0],&x[1],&x[2]);

SV_locate_point(x, z, c);

ct = c->ct.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[0],x[1],x[2],z[0],z[1],z[2],pressure);

}

fclose(output);

fclose(points);

}

/**************UDF Ends*************************/





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