|
[Sponsors] |
November 29, 2020, 00:03 |
Problem reading external text data
|
#1 |
New Member
Ahmed Awwad
Join Date: Feb 2018
Posts: 21
Rep Power: 8 |
I write a UDF to read data of two variables (building load and flowrate), I saved data for each variable in a separate text file. Then by using Define_IN_Demand macros to open and read each one. Then these data are used to calculate inlet conditions by using DEFINE_PROFILE macro as shown here, then I compiled the UDF successfully and hooked the profile then start the simulation and after 1 iteration I got this error " Reversed flow on 1407 faces (56.3% area) of pressure-outlet 37.
Stabilizing temperature to enhance linear solver robustness. Stabilizing temperature using GMRES to enhance linear solver robustness. Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Divergence detected in AMG solver: temperature Error at host: floating point exception ===============Message from the Cortex Process================================ Compute processes interrupted. Processing can be resumed. ================================================== ============================ Error: floating point exception Error Object: #f" But when I read only building data from text file and considering flow rate as constant there is no error and the simulation completed without any error. Please help me to solve this problem UDF used #include "udf.h" #define cp 4182 real Q[87600]; real m[87600]; real avetempa=279.65; DEFINE_ON_DEMAND(read_buildingdata) { int i; float b; FILE *rfile; /* declare a FILE pointer */ #if RP_HOST host_to_node_sync_file("test1.dat"); #endif #if RP_NODE host_to_node_sync_file("/"); #endif rfile = fopen("buildingdata.txt", "r"); /* open file for reading */ #if RP_HOST Message("buildingdata file opened\n"); #endif for (i=0;i<87600;i++) { fscanf(rfile, "%f\n", &b); /* that supposes one value per line */ Q[i]=b; } fclose(rfile); #if RP_HOST Message("buildingdata file closed\n"); #endif } DEFINE_ON_DEMAND(read_flowdata) { int ii; float d; FILE *rfile1; /* declare a FILE pointer */ #if RP_HOST host_to_node_sync_file("test2.dat"); #endif #if RP_NODE host_to_node_sync_file("/"); #endif rfile1 = fopen("flowratedata.txt", "r"); /* open file for reading */ #if RP_HOST Message("flowrate file opened\n"); #endif for (ii=0;ii<87600;ii++) { fscanf(rfile1, "%f\n", &d); /* that supposes one value per line */ m[ii]=d; } fclose(rfile1); #if RP_HOST Message("flowrate file closed\n"); #endif } /* Defining outlet temperature.*/ DEFINE_ADJUST(average_exit_temp,domain) { real tempa=0.0; real totalarea=0.0; int ID1 = 43;//'108; /* the outlet boundary condition identifier*/ int ktt=N_TIME-1; #if !RP_HOST face_t f1; real A[ND_ND]; Thread *outlet_thread = Lookup_Thread(domain,ID1); begin_f_loop(f1,outlet_thread) { if PRINCIPAL_FACE_P(f1,outlet_thread) { F_AREA(A,f1,outlet_thread); totalarea +=NV_MAG(A); tempa +=NV_MAG(A)*F_T(f1,outlet_thread); } } end_f_loop(f1,outlet_thread) #if RP_NODE tempa = PRF_GRSUM1(tempa); totalarea = PRF_GRSUM1(totalarea); #endif avetempa= tempa/totalarea; if(ktt==0) avetempa=283.45; # endif node_to_host_real_1(avetempa); #if RP_HOST /*Message("average temperature : %f K q7=%f\n",avetempa,Q[ktt]);*/ #endif } DEFINE_PROFILE(Inlettemp,thread,pos) { face_t f; real x[ND_ND],btt; real ftime = CURRENT_TIME; int k_time=N_TIME; real qheat=Q[k_time-1]; real COP; real qhp; real m; real w; if(qheat<0) COP=3.6857+0.1*(avetempa-273.15); else COP=9.4867-0.158*(avetempa-273.15); if(qheat<0) qhp=(qheat-(qheat/COP))/(m*cp*60); else qhp=(qheat+(qheat/COP))/(m*cp*60); #if RP_NODE begin_f_loop(f, thread) { if PRINCIPAL_FACE_P(f,thread) { if(ftime<3600) btt=283.45; else btt = avetempa +(qhp); F_PROFILE(f, thread, pos) =btt; } } end_f_loop(f, thread) #endif } |
|
November 29, 2020, 04:35 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
You read mass flow from the file, but you never use it anywhere... Or at least after reading the code three times, I can not see where it is used.
You do use an uninitialized m in your define_profile. So I guess the m should refer to the value from the file, or not? |
|
November 29, 2020, 05:34 |
|
#3 |
New Member
Ahmed Awwad
Join Date: Feb 2018
Posts: 21
Rep Power: 8 |
I used m to calculate qhp at the end of UDF
|
|
November 29, 2020, 05:44 |
|
#4 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
No, you don't.
Maybe you want to, but there you redefine m ("real m") and never tell Fluent what m is. You have to find out which face you are in, which index of your array m that corresponds to, and then refer to that value. |
|
November 29, 2020, 23:23 |
|
#5 |
New Member
Ahmed Awwad
Join Date: Feb 2018
Posts: 21
Rep Power: 8 |
Thank you so much, your advice is very useful and solve my problem
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] swakExpression not writing to log | alexfells | OpenFOAM Community Contributions | 3 | March 16, 2020 19:19 |
What‘s wrong with my cvg case? | WUJT | CONVERGE | 8 | October 13, 2017 13:19 |
[Commercial meshers] Problem converting fluent mesh | vinz | OpenFOAM Meshing & Mesh Conversion | 28 | October 12, 2015 07:37 |
Tecplot360 problem for reading OpenFOAM data | maysmech | OpenFOAM Post-Processing | 5 | April 13, 2011 16:37 |
[Commercial meshers] FluentMesh conversion problem | waynezw0618 | OpenFOAM Meshing & Mesh Conversion | 12 | December 1, 2006 00:12 |