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

UDF for heat flux Bc

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 3, 2023, 09:21
Default UDF for heat flux Bc
  #1
New Member
 
Mohammadreza Tohidi
Join Date: Jul 2023
Posts: 4
Rep Power: 3
Reza_th is on a distinguished road
Dear friends
I wrote a UDF for one of my walls and this UDF will calculate the heat flux based on my simulation condition.

The code compiled corectly in fluent by when I run the simulation i have the error of Error: floating point exception

can someone review my code and help me through this?


Thanks




#include "udf.h"

real T_inf_BC2 = 273.15;
real h_BC2 = -2000.0;
real h_BC3 = 10; // Typical value we used
real m_snow_initial = 0.0005; // Constant initial value for mass of snow per unit area [Kg/m^2]
real ice_density = 917; // Density of ice [kg/m³] - Typical value @ standard atmospheric pressure and 0 degrees Celsius
real Boltzmann = 5.67 * 10e-8; //[W/m²·K⁴]
real hif = 334000; // Heat of fusion of snow [J/kg]
real dt = 300; // Time step length [s]
real A = 0.009;//Aprx area of each cell [m^2]
real K = 0.1;
int cell = 1560; // Total number of cell on the surface

DEFINE_PROFILE(heat_flux_bc, thread, position)
{
real x[ND_ND];
real flux;
real time = CURRENT_TIME;
real flow_time = RP_Get_Real("flow-time");
static real m_snow_time_step = 0;
real snow_fall_rate;
real ambient_temperature;
real m_snow;
real h_snow;
real m_dot_melt;
real T_snow;
real h_BC1 = (K / h_snow * A);
static int i = 1;
int J = 0;

face_t f;
real T_wall;

FILE* file;
char line[256];

file = fopen("C:/Users/MOTOH/Desktop/file.txt", "r");
if (file == NULL)
{
Message("Error: Unable to open file.\n");
return;
}

while (fgets(line, sizeof(line), file) != NULL)
{
real file_time;
real ambient_temperature_file;
real snow_fall_rate_file;
sscanf(line, "%lf, %lf, %lf",
&file_time, &ambient_temperature_file, &snow_fall_rate_file);

ambient_temperature = ambient_temperature_file;
snow_fall_rate = snow_fall_rate_file;

if (time >= file_time)
{
break;
}
}

fclose(file);

begin_f_loop(f, thread)
{
F_CENTROID(x, f, thread);
T_wall = C_T(f, thread);

if (T_wall < 273.15)
{
if (i == 1)
{
m_snow = m_snow_initial;
h_snow = m_snow / (ice_density * A);
T_snow = ambient_temperature;
flux = (h_BC1 * (T_wall - T_snow));
m_snow_time_step = m_snow + (snow_fall_rate * dt);
}
else
{
m_snow = m_snow_time_step;
h_snow = m_snow / (ice_density * A);
T_snow = ambient_temperature;
flux = (h_BC1 * (T_wall - T_snow));
m_snow_time_step = m_snow + (snow_fall_rate * dt);
}
}
else
{
if (m_snow_time_step == 0)
{
flux = h_BC3 * (T_wall - ambient_temperature);
}
else
{
m_snow = m_snow_time_step;
h_snow = m_snow / (ice_density * A);
real q_cond_snow = (h_BC1 * (T_wall - T_snow));
flux = (h_BC2 * (T_wall - T_inf_BC2));
real q_melt = flux - q_cond_snow;
m_dot_melt = q_melt / hif;
m_snow_time_step = m_snow + ((snow_fall_rate - m_dot_melt) * dt);
}
}
if (m_snow_time_step == 0.0)
{
J++;
}
F_PROFILE(f, thread, position) = -flux;
}
end_f_loop(f, thread)

i++;

Message("Percentage of area free of snow: %.2f%%\n", (J / cell) * 100.0);
Reza_th is offline   Reply With Quote

Old   October 5, 2023, 04:31
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
at least one variable is not defined

for instance
real h_BC1 = (K / h_snow * A);
h_snow is not defined

read compilation log
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ 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
UDF for heat flux at membrane in membrane distillation process yacarioca FLUENT 0 March 10, 2021 00:58
UDF for reading radiative heat flux ssa_cfd Fluent UDF and Scheme Programming 1 December 14, 2020 01:53
uds flux - drift velocity - udf johnwinter Fluent UDF and Scheme Programming 3 November 25, 2017 05:07
UDF for UDS flux gyf135 Fluent UDF and Scheme Programming 0 October 13, 2015 21:02
UDF Mass flux computing Carlo FLUENT 6 November 23, 2014 22:59


All times are GMT -4. The time now is 14:59.