CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   On demand UDF error (

RS May 10, 2007 12:54

On demand UDF error

I am getting the "segmentation violation" error when i execute the on demand udf. I got this udf from fluent website..the only part i changed is SID 14 and s=1+SID This is how I go:

Read the case file...Read the data file...compile the UDF....Allocate memory (3)....execute on demand....ERROR...

I tried reading the UDF before reading case n data file...that dint help...

Heres my UDF:

/* 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[2][3]; 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 = 1+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][0], s->points[index], X_DIM); SET_POINT_COORD(v[j][1], s->points[index], Y_DIM); SET_POINT_COORD(v[j][2], s->points[index], Z_DIM); } /* Length calculation */ curve_length = sqrt(SQR(v[0][0]-v[1][0])+SQR(v[0][1]-v[1][1])+SQR(v[0][2]-v[1][2])); 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 : %6f\n", SID, line_int); Message("Line length average of currently displayed variable on line of ID %d : %6f\n", SID, line_ave); }

All times are GMT -4. The time now is 16:19.