|
[Sponsors] |
Fluent UDFs crash at initialization/run with temperature & species macros |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
December 21, 2022, 13:16 |
Fluent UDFs crash at initialization/run with temperature & species macros
|
#1 |
New Member
Andrew
Join Date: Dec 2022
Posts: 29
Rep Power: 3 |
Hi, I am simulating a multiphase flow of boiling/evaporating salt water using the Eulerian model. I have written a UDF to vary the saturation pressures/temperatures with the salinity (nacl is included as one of the mixture species) using 2D interpolation.
I can compile, load and hook my UDFs without error, but initialization causes Fluent to crash with a segmentation violation. The error is mentions "SIGSEGV", and then closes after printing the following: ========================================= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES RANK 3 PID 16448 RUNNING AT DESKTOP-TTQLM5V EXIT STATUS: -1 (ffffffff) ========================================= I believe I've traced the problem to the macros for cell temperature (C_T(c,t)) and species mass fraction (C_YI(c,t,i)). When I replace these functions with constant values, I can initialize without crashing. Similar posts have mentioned that trying to access C_T at initialization when it is not yet defined will cause this error. However, I have tried initializing first without hooking the UDF, then enabling it, and beginning the calculation, but the crash still occurs in this case, so I don't think this strategy will fix the issue. I've copied my UDF below. The "pressure_data" array, which stores all the saturation pressure values, is inputted as a 1D array and adjusted for proper access later, because Fluent seemed to have a problem with a multidimensional array. My UDF for saturation temperatures is largely the same, just with different data. Any suggestions would be greatly appreciated. Thank you! _______________________ #include <udf.h> DEFINE_PROPERTY(saturation_pressure,c,t) { real sat_p; // real x, y, x1, x2, y1, y2, f11, f12, f21, f22, a, b, term1, term2, term3, term4; int ix1, ix2, iy1, iy2; int i = 0; real temp_data[13] = {0,10,20,30,40,50,60,70,80,90,100,110,120}; real salinity_data[13] = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120}; real pressure_data[169] = { 0.611,0.608,0.605,0.602,0.598,0.594,0.59,0.586,0.5 82,0.577,0.572,0.567,0.562, 1.228,1.222,1.216,1.209,1.202,1.194,1.186,1.177,1. 168,1.159,1.149,1.139,1.129, 2.339,2.328,2.316,2.303,2.289,2.274,2.259,2.242,2. 225,2.207,2.189,2.17,2.149, 4.246,4.226,4.204,4.18,4.155,4.129,4.101,4.071,4.0 4,4.008,3.974,3.939,3.902, 7.383,7.348,7.31,7.269,7.226,7.179,7.131,7.079,7.0 25,6.969,6.91,6.849,6.786, 12.35,12.291,12.227,12.159,12.086,12.009,11.927,11 .841,11.751,11.656,11.558,11.456,11.35, 19.944,19.849,19.746,19.635,19.518,19.393,19.261,1 9.122,18.976,18.824,18.665,18.5,18.329, 31.198,31.049,30.888,30.715,30.531,30.336,30.129,2 9.912,29.684,29.446,29.198,28.94,28.672, 47.412,47.185,46.941,46.678,46.399,46.102,45.788,4 5.457,45.111,44.749,44.372,43.98,43.573, 70.18,69.845,69.483,69.095,68.681,68.241,67.776,67 .287,66.775,66.239,65.681,65.1,64.499, 101.419,100.934,100.411,99.85,99.252,98.616,97.945 ,97.239,96.498,95.723,94.916,94.078,93.208, 143.384,142.699,141.96,141.166,140.32,139.422,138. 473,137.474,136.426,135.332,134.191,133.005,131.77 6, 198.685,197.736,196.712,195.613,194.44,193.195,191 .88,190.496,189.045,187.528,185.947,184.304,182.60 1, }; x = C_T(c, t) - 273.15; // Temperature - K to C y = C_YI(c, t, 1)* pow(10, 3); // Species mass fraction - kg/kg to g/kg // identify neighboring values // identify neighboring values for (i = 0; i < 13; i++) { // check within range of data if (x<temp_data[0]){ x = temp_data[0]; } else if (x>temp_data[12]){ x = temp_data[12]; } // first, evaluate temperature boundaries (x) a = x - temp_data[i]; // in case of direct match if (a==0) { if (x==temp_data[12]){ x1 = temp_data[i-1]; x2 = temp_data[i]; ix1 = i-1; ix2 = i; } else{ x1 = temp_data[i]; x2 = temp_data[i+1]; ix1 = i; ix2 = i+1; } } // if within 10 of value else if (a>0 && a <10) { x1 = temp_data[i]; x2 = temp_data[i+1]; ix1 = i; ix2 = i+1; } //****** now, repeat for y // check within range of data if (y<salinity_data[0]){ y = salinity_data[0]; } else if (y>salinity_data[12]){ y = salinity_data[12]; } // first, evaluate temperature boundaries (y) b = y - salinity_data[i]; // in case of direct match if (b==0) { if (y==salinity_data[12]){ y1 = salinity_data[i-1]; y2 = salinity_data[i]; iy1 = i-1; iy2 = i; } else{ y1 = salinity_data[i]; y2 = salinity_data[i+1]; iy1 = i; iy2 = i+1; } } // if within 10 of value else if (b>0 && b <10) { y1 = salinity_data[i]; y2 = salinity_data[i+1]; iy1 = i; iy2 = i+1; } } //printf("x1=%f,loc=%d,x2=%f,loc=%d,y1=%f,loc=%d,y2= %f,loc=%d, \n",x1,ix1,x2,ix2,y1,iy1,y2,iy2); f11 = pressure_data[(ix1) * 13 + iy1]; f12 = pressure_data[(ix1) * 13 + iy2]; f21 = pressure_data[(ix2) * 13 + iy1]; f22 = pressure_data[(ix2) * 13 + iy2]; term1 = f11*(x2-x)*(y2-y); term2 = f21*(x-x1)*(y2-y); term3 = f12*(x2-x)*(y-y1); term4 = f22*(x-x1)*(y-y1); sat_p = (term1+term2+term3+term4)/((x2-x1)*(y2-y1)); sat_p = sat_p*pow(10,3); // conversion to Pascals for export Message("Sat P is %g\n", sat_p); return sat_p; } |
|
December 22, 2022, 11:22 |
|
#2 |
New Member
Andrew
Join Date: Dec 2022
Posts: 29
Rep Power: 3 |
Adding some relevant information from my troubleshooting:
I am using both the species mass transfer model (to simulate concentration-driven evaporation) and the evaporation-condensation (Lee) model (to simulate boiling/condensation past the saturation conditions). The species model requires a UDF in terms of saturation pressure, and the Lee model requires a UDF in terms of saturation temperature. I found that the saturation pressure UDF works without issue, using only the macros C_T and C_YI as inputs from the calculation. But, the saturation temperature UDF is still causing segmentation violations. It can access C_P without issue, but both C_T and C_YI cause segmentation violations. The only remaining problem now is to stop the C_YI macro from crashing the saturation temperature UDF. Will update if I find a solution. |
|
December 22, 2022, 17:14 |
|
#3 |
New Member
Andrew
Join Date: Dec 2022
Posts: 29
Rep Power: 3 |
One more update from troubleshooting:
C_YI(c,t,i) takes the thread t as an argument, which is obtained from the DEFINE_PROPERTY call. For a multiphase case, I believe it needs either the mixture thread or the phase-level thread (not sure which). I am guessing that the thread passed by DEFINE_PROPERTY when used in the Lee model's saturation temperature call is not the correct thread for the species mass fraction macro C_YI. This may also explain why my other UDF, which also uses the C_YI call, does not cause an error and obtains the proper data - it probably obtains the proper thread from DEFINE_PROPERTY when used within the Species Mass Transfer function. I'm still unsure how to determine which type of thread is actually required for C_YI in Eulerian multiphase, and how to obtain this thread if it is not passed by DEFINE_PROPERTY. Any input is greatly appreciated, thanks. |
|
December 27, 2022, 17:01 |
|
#4 |
New Member
Andrew
Join Date: Dec 2022
Posts: 29
Rep Power: 3 |
I have found the solution:
For multiphase w/ Eulerian and species models, I believe the macros C_YI, C_P and C_T all require the phase-level thread pointer (subthread). For a DEFINE_PROPERTY UDF, the "species mass transfer" mechanism will pass cell c and phase-level thread pointer t. These are the correct inputs for the above mentioned macros. However, the "evaporation-condensation" mechanism (Lee model) will pass cell c and mixture-level thread pointer t. To obtain the phase-level thread pointer within the UDF for the Lee model, I used the following code: int phase_domain_index = 0; // primary phase index is 0 Thread* subthread = THREAD_SUB_THREAD(t, phase_domain_index); // t has to be the mixture-level thread Then, I simply modified this UDF, replacing the macro inputs of t with the subthread obtained by the above code. Hope this will be helpful for someone else down the line! |
|
Tags |
crash, eulerian, fluent, multiphase, udf |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[openSmoke] libOpenSMOKE | Tobi | OpenFOAM Community Contributions | 562 | January 25, 2023 10:21 |
Evaporation condensation below saturation temperature in FLUENT | user321 | Fluent Multiphase | 1 | January 29, 2020 06:41 |
Can't Get Temperature distribution in Solids in Fluent (Pipe cooling) | Bobby Charlton | FLUENT | 0 | December 31, 2019 20:07 |
[ANSYS Meshing] Fluent Conjugate heat transfer: Temperature at a small fluid region exceed limit | RPjack | ANSYS Meshing & Geometry | 1 | June 20, 2019 08:11 |
Increasing temperature in species transport | ssamton | FLUENT | 2 | February 28, 2012 21:37 |