CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Problem reading external text data

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Ahmed A. Serageldin

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 28, 2020, 23:03
Default Problem reading external text data
  #1
New Member
 
Ahmed Awwad
Join Date: Feb 2018
Posts: 21
Rep Power: 8
Ahmed A. Serageldin is on a distinguished road
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
}
Ahmed A. Serageldin is offline   Reply With Quote

Old   November 29, 2020, 03:35
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
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?
pakk is offline   Reply With Quote

Old   November 29, 2020, 04:34
Default
  #3
New Member
 
Ahmed Awwad
Join Date: Feb 2018
Posts: 21
Rep Power: 8
Ahmed A. Serageldin is on a distinguished road
Quote:
Originally Posted by pakk View Post
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?
I used m to calculate qhp at the end of UDF
Ahmed A. Serageldin is offline   Reply With Quote

Old   November 29, 2020, 04:44
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by Ahmed A. Serageldin View Post
I used m to calculate qhp at the end of UDF
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.
pakk is offline   Reply With Quote

Old   November 29, 2020, 22:23
Default
  #5
New Member
 
Ahmed Awwad
Join Date: Feb 2018
Posts: 21
Rep Power: 8
Ahmed A. Serageldin is on a distinguished road
Quote:
Originally Posted by pakk View Post
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.
Thank you so much, your advice is very useful and solve my problem
pakk likes this.
Ahmed A. Serageldin is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[swak4Foam] swakExpression not writing to log alexfells OpenFOAM Community Contributions 3 March 16, 2020 18:19
What‘s wrong with my cvg case? WUJT CONVERGE 8 October 13, 2017 12:19
[Commercial meshers] Problem converting fluent mesh vinz OpenFOAM Meshing & Mesh Conversion 28 October 12, 2015 06:37
Tecplot360 problem for reading OpenFOAM data maysmech OpenFOAM Post-Processing 5 April 13, 2011 15:37
[Commercial meshers] FluentMesh conversion problem waynezw0618 OpenFOAM Meshing & Mesh Conversion 12 November 30, 2006 23:12


All times are GMT -4. The time now is 06:53.