Fluent Access Violation error after a specific iteration number
Hello everyone,
I am getting problems while iterating in Fluent. Before posting here, I tried to search in the forum for any similar cases, but never figured out any useful thread. So here is my problem : I have in my case 2 velocityinlet surfaces, with a given velocity profile for each surface. The velocity components at the boundary cells must be imported from an external file. For that, I wrote a library of 6 udf functions, 3 udfs that reads the x,y and z velocity components for the first surface cells from 3 files, and 3 udfs for the other surface. The library is compiled and loaded in Fluent without any error. For each velocity inlet component on the 2 surfaces, the corresponding udf is attributed. The iterations start normally but after 83 exact iterations, I get the error : FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: () I tried to write the case and data files before getting the error, exit Fluent and then reopen the saved case and data files. The simulation continues normally for other 83 iterations. So I must always save the case and data files before 83 successive iterations, reopen Fluent and continue iterations till the convergence. I tried with other similar cases, I got the same problem but with a different successive iterations number. Desperately trying to solve out these "magic numbers" problem, I decided to share it with you. For any idea or suggestion, I'm ready to hear from you. Thanks for the assistance 
There are some generic threads about this on the FLUENT University boards:
http://university.fluent.com/forum/v...00549a58d0c280 http://university.fluent.com/forum/v...9eaf9650f7564c You can't post there anymore, but it's still a good reference. 
I have already checked these threads. The difference with my case is that the error messages reported in these threads are gotten while activating the udf or while initialization, both working nicely in my case. The error I get is displayed while iterating and for a given number of successive iterations, and I can't figure out if the problem is generated from my udf or from Fluent because the simulation continues normally after exiting and starting calculation from where it crashes before.

Have you tried printing something in the command window to keep track of where you are in the UDF in order to debug? Add some statements to your code that prints "point 1", "point 2", etc, throughout your UDF to see exactly where it is crashing. It sounds like your counting something in your UDF, and when you get to 83 iterations, the execution switched to a different part of the code where you have a problem. (I have no clue if this is actually the problem, this is only what I would try. I hope it helps in at least some small way.)

Thanks for your idea and the support.
That's what I tried to do : I printed message at the beginning and the end of each udf, then I executed the same simulation several times. After 83 iterations, simulation crashed inside one UDF, but surprisingly each time it is crashed randomly in one of the 6 UDFs, meaning that if it crashed the first time in UDF n°2, the next same simulation it can pass this UDF but will crash as example in UDF n°4 !! There are no tricks in my UDFs, just open a file, read values inside in the order and attribute them to the mesh faces (just three code lines for each UDF), this is repeated every iteration. I also checked that the mesh faces number is the same as the values number in the 6 files, to insure that all the mesh faces are initialized correctly with the specified boundary while iterating. This avoids the memory stack that can accumulate over iterations and can possibly lead to the error. I know it is a strange problem, but I manage to autosave my data after 80 successive iterations, then run again the calculations. At the convergence, the boundary conditions are the same as defined in my files, and I get logical results. The problem is that I must keep up manually this procedure from the beginning till the convergence. 
I think the ACCESS_VIOLATION error is thrown when your code is looking for something that isn't there. Since your UDF involves file input/output, you might be trying to open a file that hasn't been created yet. You should add a line in your code before you try to open a file that checks to see if the file actually exists. If it doesn't, then have your code print a message that tells you where the failure occurred. This way, you can see what file your code was looking for when it crashed, and then you can try to figure out why it wasn't there.

Bug fixed !!
Accidentally I put the file pointer destructor "fclose" inside an if statement loop which is not always true. The memory leaks cause the ACCESS_VIOLATION error after 83 iterations. Thank you Chris for the help. 
Awesome! I'm glad it works for you!

Very urgent FLUENT FATAL SIGNAL(Access Violation)
Hiii the following UDF gives access violation fatal error during execution in FLUENT while running in interpreted mode.
I'm trying to simulate a 2D fluidised bed and I have used this UDF to update mass fractions of two species(Oxygen and Ozone(Ozone decomposition)) ie. for the volumetric rate, in two phases according to an equation of mass balance using finite difference method. I have tried a lot and I'm running out of time. Kindly help me in this regard. Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: () #include "udf.h" #include "threads.h" #define C_NFACES(c,t)(cell_type_nfaces[(int)(C_TYPE((c),(t)))]) real deltaT = 0.0002; real uX = 0.01; real uY = 0.02; int h = 200; real dAM = 0.00001; real epsilon = 0.95; real kG = 1; real epsilonS = 0.97; real kR = 5.4; real dCell = 0.01; real dP = 1; int l = 20; DEFINE_EXECUTE_ON_LOADING(inst_cValues, libname) { Thread *t; cell_t c; Domain *d; Thread **pt; /* initialize pt */ thread_loop_c(t,d) { begin_c_loop(c,t) { if(Data_Valid_P()) { pt = THREAD_SUB_THREADS(t); C_YI(c, pt[0], 0) = 0.2097; C_YI(c, pt[1], 0) = 0; C_YI(c, pt[0], 1) = 0.1; C_YI(c, pt[1], 1) = 0; } } end_c_loop(c,t) } } DEFINE_ADJUST(adjustRate, d) { Thread* t; cell_t c, c1, c2; Thread *newT; face_t f; cell_t leftCell, rightCell, aboveCell, belowCell; int count = 0, temp1, temp2, temp3, temp4; int n = 0; int nz; cell_t adjC; real x1[ND_ND], x2[ND_ND]; Thread **pt; Thread *ft; int boundThread = 1; int x_coord,y_coord, x; d = Get_Domain(1); thread_loop_c(t, d) { begin_c_loop(c, t) { count = 0; C_CENTROID( x1, c, t); x_coord = x1[0]/dCell; y_coord = x1[1]/dCell; c_face_loop( c, t, nz) { f = C_FACE(c, t, nz); ft = C_FACE_THREAD(c,t,nz); c1 = c; c2 = c; if(!(x_coord == 0  x_coord == l1  y_coord == 0  y_coord == h1)) c1 = F_C0(f, t); if(!(x_coord == 0  x_coord == l1  y_coord == 0  y_coord == h1)) c2 = F_C1(f, t); if(c1 == c) { C_CENTROID( x2, c2, t); adjC = c2; } else { C_CENTROID(x2, c1, t); adjC = c1; } if(x1[0] > x2[0]) { leftCell = adjC; count++; } else if(x1[0] < x2[0]) { rightCell = adjC; count++; } else if(x1[1] > x2[1]) { belowCell = adjC; count++; } else if(x1[1] < x2[1]) { aboveCell = adjC; count++; } } if(count >= 4 && Data_Valid_P()) { x = (int)x1[0]/dCell; pt = THREAD_SUB_THREADS(t); temp1 = dAM/x*( C_YI_M1(rightCell, pt[0], 0)  C_YI_M1(leftCell, pt[0], 0) )/2/h + dAM *( C_YI_M1(rightCell, pt[0], 0)2*C_YI_M1(c, pt[0], 0)+C_YI_M1(leftCell, pt[0], 0) )/h/h + dAM*( C_YI_M1(aboveCell, pt[0], 0)2*C_YI_M1(c, pt[0], 0)+C_YI_M1(belowCell, pt[0], 0) )/h/h + 6*(1epsilon)/dP*kG*( C_YI_M1(c, pt[0], 0)C_YI_M1(c, pt[1], 0) )// + (1epsilon)*epsilonS*kR*C_YI_M1(c, t, 1) + C_YI_M1(c, pt[0], 0)/deltaT  uX*( C_YI_M1(rightCell, pt[0], 0)C_YI_M1(leftCell, pt[0], 0) )/2/h  uX*C_YI_M1(c, pt[0], 0)/x  uY*( C_YI_M1(aboveCell, pt[0], 0)C_YI_M1(belowCell, pt[0], 0) )/2/h; temp1 *= deltaT; if(temp1 > 0 && temp1 < 1) C_YI(c, pt[0], 0) = temp1; else C_YI(c, pt[0], 0) = 0; temp2 = 6/dP*kG*( C_YI_M1(c, pt[0], 0)C_YI_M1(c, pt[1], 0) ) + epsilonS*kR*C_YI_M1(c, pt[1], 0) + C_YI_M1(c, pt[1], 0)/deltaT; temp2 *= deltaT; if(temp2 > 0 && temp2 < 1) C_YI(c, pt[1], 0) = temp2; else C_YI(c, pt[1], 0) = 0; temp3 = dAM/x*( C_YI_M1(rightCell, pt[0], 1)  C_YI_M1(leftCell, pt[0], 1) )/2/h + dAM *( C_YI_M1(rightCell, pt[0], 1)2*C_YI_M1(c, pt[0], 1)+C_YI_M1(leftCell, pt[0], 1) )/h/h + dAM*( C_YI_M1(aboveCell, pt[0], 1)2*C_YI_M1(c, pt[0], 1)+C_YI_M1(belowCell, pt[0], 1) )/h/h + 6*(1epsilon)/dP*kG*( C_YI_M1(c, pt[0], 1)C_YI_M1(c, pt[1], 1) )// + (1epsilon)*epsilonS*kR*C_YI_M1(c, t, 1) + C_YI_M1(c, pt[0], 1)/deltaT  uX*( C_YI_M1(rightCell, pt[0], 1)C_YI_M1(leftCell, pt[0], 1) )/2/h  uX*C_YI_M1(c, pt[0], 1)/x  uY*( C_YI_M1(aboveCell, pt[0], 1)C_YI_M1(belowCell, pt[0], 1) )/2/h; temp3 *= deltaT; if(temp1 > 0 && temp1 < 1) C_YI(c, pt[0], 1) = temp3; else C_YI(c, pt[0], 1) = 0; temp4 = 6/dP*kG*( C_YI_M1(c, pt[0], 1)C_YI_M1(c, pt[1], 1) ) + epsilonS*kR*C_YI_M1(c, pt[1], 1) + C_YI_M1(c, pt[1], 1)/deltaT; temp3 *= deltaT; if(temp1 > 0 && temp1 < 1) C_YI(c, pt[1], 1) = temp4; else C_YI(c, pt[1], 1) = 0; } } end_c_loop(c, t) } } DEFINE_VR_RATE(user_rate, c, t, r, mole_weight, species_mf, rate, rr_t) { if(Data_Valid_P() ) { Thread **pt = THREAD_SUB_THREADS(t); *rate = kR * epsilonS * C_YI(c, pt[1], 1); } else *rate = 0; *rr_t = *rate; } Even if I remove all the functions and just keep the DEFINE_VR_RATE function, an error occured in 81st loop.. Thanks in advance 
A question!
Dear all,
I have defined a DEFINE_EXECUTE_AT_END to calculate species mass fraction near the wall and I save it in a file. after 101 iterations, Fluent quits with no warning or errors! I was wondering if anybody has observed the same problem. Thanks, Gholam 
segmentation violation
Hi everyone,
I have a same your problem. I found that the main reason is the array that we declare by our self, such as xx[100]. This problem may be fixed by using the function as following xx=(real *)malloc(size * sizeof(real)); 
Thread necromancy..
I am getting the access violation error on initialisation unfortunately the links above to university.fluent.com no longer work, they redirect to a useless ANSYS page :mad:
What can I do to my case or mesh to prevent this happening? Cheers. 
All times are GMT 4. The time now is 16:33. 