|
[Sponsors] |
October 24, 2015, 03:41 |
UDF trouble shoot
|
#1 |
New Member
Join Date: Sep 2015
Posts: 7
Rep Power: 11 |
Hi Guys,
Could I please have someones help to trouble shoot this UDF code. I keep getting - Error: received a fatal signal (Segmentation fault). - Error Object: #f So I know it has to do with the code. I stole most of the code from other places. I can compile the code and date file shows up when I 'Execute on Demand' The error shows up with I try and 'Initialize' my Thank you Guys #include "udf.h" int NPt_mu = 561; /* number of entries in density table */ /* Locate the place in the interpolation vector using bisection algorithm*/ int locate(float xx[], int n, float x) { int j = 0; int jm = 0; int jl = 0; int ju = n+1; int ascnd = 0; ascnd = (xx[n] >= xx[1]); while (ju-jl > 1) { jm = (ju+jl) >> 1; if (x >= xx[jm] == ascnd) jl = jm; else ju = jm; } if (x == xx[1]) j = 1; else if (x == xx[n]) j = n-1; else j = jl; return j; } float *pres_vec_mu,*dens_vec; #define FAST_LOOKUP TRUE /* use bisection algorithm for interpolation */ #define TABLE_MESSAGES TRUE #define DISPLAY_TABLES TRUE /* Obtaine mu given pressure */ float get_mu_from_T(float xdata) { int i = 0; int j = 0; float xL,xU,ydata; #if FAST_LOOKUP j = locate(pres_vec_mu,NPt_mu,xdata); xL = pres_vec_mu[j]; xU = pres_vec_mu[j+1]; ydata = dens_vec[j] + (xdata-xL)/(xU-xL)*( dens_vec[j+1] - dens_vec[j] ); #else for ( i=1; i<NPt_mu ;i++ ) { xL = pres_vec_mu[i]; xU = pres_vec_mu[i+1]; if ( (xdata>=xL)&&(xdata<=xU) ) { ydata = dens_vec[i] + (xdata-xL)/(xU-xL)*( dens_vec[i+1] - dens_vec[i] ); break; } } #endif if ( xdata>pres_vec_mu[NPt_mu] ) { #if TABLE_MESSAGES Message("\n pressure is above the bound of dens-array \n"); #endif ydata = dens_vec[NPt_mu]; } if ( xdata<pres_vec_mu[1] ) { #if TABLE_MESSAGES Message("\n pressure is below the bound of dens-array \n"); #endif ydata = dens_vec[1]; } return ydata; } /* Read in the data file containing density as a function of pressure */ DEFINE_ON_DEMAND(read_density) { int i = 0; float xdata,ydata; FILE* fp; fp = fopen("density.dat","r"); if ( fp!=NULL ) { #if !RP_NODE Message(" \n"); Message("Reading file density.dat \n"); Message(" \n"); #endif } else { #if !RP_NODE Message(" \n"); Message("Error opening file \n"); Message(" \n"); #endif } pres_vec_mu = (float *) malloc(NPt_mu*sizeof(float)); dens_vec = (float *) malloc(NPt_mu*sizeof(float)); if ( (pres_vec_mu==NULL)||(dens_vec==NULL) ) { #if !RP_NODE Message("Memory allocation error \n"); #endif } for ( i=1;i<=NPt_mu;i++ ) { fscanf(fp,"%f %e \n",&xdata,&ydata); pres_vec_mu[i] = xdata; dens_vec[i] = ydata; #if DISPLAY_TABLES #if !RP_NODE Message("%.1f %e \n",pres_vec_mu[i],dens_vec[i]); #endif } #else } #if !RP_NODE Message(" \n"); #endif #endif fclose(fp); } /* Interpolate density from look-up table and assign to cell value */ DEFINE_PROPERTY(density,c,t) { float mu_lam; float pres = C_T(c,t); /* interpolate mu_lam */ mu_lam = get_mu_from_T(pres); return mu_lam; } |
|
October 26, 2015, 05:57 |
|
#2 |
Senior Member
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13 |
This kind of error appear when Fluent cant reach some information. It might compile with no error, but when it runs it will try to get information (boundaries, gradient, variable values, etc) and this information is not avilable.
Since you took pieces of code from different places, it is better to have a detailed look at it and check if all the information necessary is provided. |
|
March 2, 2017, 09:31 |
|
#3 |
New Member
davoud javar
Join Date: Jan 2017
Posts: 8
Rep Power: 9 |
hello Bruno Machado
how I can give initial value for gradient of temperature (C_T_G)in sorce macro to calculate T over the channel in my case? regard |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Source Term UDF VS Porous Media Model | pchoopanya | Fluent UDF and Scheme Programming | 1 | August 28, 2013 07:12 |
Simulation with UDF for species mass fraction and velocity profile | virgy | Fluent UDF and Scheme Programming | 8 | February 7, 2012 05:30 |
UDF programming | fullmonty | FLUENT | 5 | June 30, 2011 03:40 |
UDF...UDF...UDF...UDF | Luc SEMINEL | FLUENT | 0 | November 25, 2002 05:03 |
UDF, UDF, UDF, UDF | Luc SEMINEL | Main CFD Forum | 0 | November 25, 2002 05:01 |