# How to compute the integral of a variable along a line using UDF in FLUENT?

 Line surfaces in FLUENT have area in 2d and 2d-axi but not in 3d, so currently integrals on line surfaces are zero. This solution provides a sample User Defined Function (UDF) that shows how to calculate the integral of a variable (say temperature) along a line in fluent, then divide it by the length of the line, and output this number at every time step, for a large number of lines in a transient 3d simulation. /*sample UDF code to work with for line integration: you will need to augment it to use it with multiple lines, etc*/ /* UDF to calculate line integral and line lenght weighted average of a variable. by sra and fm 5/05 To have line integral and line average of variable V on a line S u need to Go to Contour panel and do compute of V on S This will fill the values necessary for computation. */ #include "udf.h" #include "surf.h" #include "cxsurf.h" #include "cxiface.h" #define SID 14 DEFINE_ON_DEMAND(line_integrals) { Surface *s; int i, j, k, index; float v; float face_val, line_int, line_ave, curve_length, tot_length; /* s is the surface having data of surface id SID s->np no of points. s->nf no of faces. s->points points to array of np points. s->ip pointer to interpolation vector of np points. s->facets facet list of the surface. length of array is nfl. s->cells pointer to cells of each point. s->nfl facet list length. */ s = SurfaceList+SID; tot_length = 0.; line_int = 0.; for (i = 0, k = 0; k < s->np; i +=s->facets[i]+1, k++) { if (s->facets[i] != 2) continue; /* makes sure only line is there */ /*facet value for line surfaces will be the cell value in which the facet lies*/ face_val = SV_Cell_Field(SVFIELD_CURRENT, s->cells+k); for (j = 0; j < s->facets[i]; j++) { index = s->facets[i+j+1]; /* sets point coord x y z*/ SET_POINT_COORD(v[j], s->points[index], X_DIM); SET_POINT_COORD(v[j], s->points[index], Y_DIM); SET_POINT_COORD(v[j], s->points[index], Z_DIM); } /* Length calculation */ curve_length = sqrt(SQR(v-v)+SQR(v-v)+SQR(v-v)); tot_length += curve_length; line_int += curve_length * face_val; } line_ave = line_int/tot_length; Message("Line integral of currently displayed variable on line of ID %d : %6fn", SID, line_int); Message("Line length average of currently displayed variable on line of ID %d : %6fn", SID, line_ave); }