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

Calculation of Physiological Equivalent Temperature Index using UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 4, 2023, 18:06
Lightbulb Calculation of Physiological Equivalent Temperature Index using UDF
  #1
New Member
 
Moe
Join Date: Jul 2021
Posts: 14
Rep Power: 4
shadymody is on a distinguished road
Hey everyone,

I was trying to create an output variable in Fluent that will calculate the Physiological Equivalent Temperature. i will use it to create contours later

I tried to use ChatGPT to get help as I don't have experience with coding

I got the following code
Code:
#include "udf.h"

// Declare a global variable to store the physiological equivalent temperature
real physiological_equivalent_temperature[THREAD_MAX][THREAD_MAX];

// Define a UDF to calculate the physiological equivalent temperature at each time step for all cells in the domain
DEFINE_ON_DEMAND(calculate_physiological_equivalent_temperature_all)
{
int i, j;
real air_temperature; // in Celsius
real relative_humidity; // in %
real wind_speed; // in m/s

// Loop over all threads in the domain
for (i = 0; i < THREAD_MAX; i++)
{
// Loop over all cells in the thread
for (j = 0; j < THREAD_MAX; j++)
{
// Read the air temperature, relative humidity, and wind speed from the Fluent simulation
air_temperature = C_T(cell_center, i, j);
relative_humidity = C_HUMIDITY(cell_center, i, j);
wind_speed = C_V(cell_center, i, j);

  // Calculate the physiological equivalent temperature using the formula:
  // PET = -2.7 + 0.66 * air_temperature + 0.39 * relative_humidity * (0.5 * air_temperature - 10.5) + 0.29 * wind_speed
  physiological_equivalent_temperature[i][j] = -2.7 + 0.66 * air_temperature + 0.39 * relative_humidity * (0.5 * air_temperature - 10.5) + 0.29 * wind_speed;
}
}
}

// Define a UDF to output the physiological equivalent temperature to a file for all cells in the domain
DEFINE_DPM_OUTPUT_VAR(write_physiological_equivalent_temperature_all, f, t, i)
{
int i, j;

// Loop over all threads in the domain
for (i = 0; i < THREAD_MAX; i++)
{
// Loop over all cells in the thread
for (j = 0; j < THREAD_MAX; j++)
{
// Write the value of the physiological equivalent temperature for the cell to the output file
fprintf(f, "%f\n", physiological_equivalent_temperature[i][j]);
}
}
}
when I insert this into fluent I get some errors..
but from my understanding, this is not the correct way of creating c_loop

Can anyone please help me fix this code?

thanks in advance
shadymody is offline   Reply With Quote

Old   January 8, 2023, 14:37
Default
  #2
New Member
 
Andrew
Join Date: Dec 2022
Posts: 29
Rep Power: 3
andrew-c is on a distinguished road
First off, I'd recommend reading the fluent UDF manual if you haven't already. Even if you're not familiar with C/C++, it's got some good examples and describes the necessary functions very clearly. If you read up on some of the functions you're trying to use here, it will likely help you debug.

For example - the C_T macro should only take two arguments, not three. Also, in many cases, UDFs are unable to be used with 2D arrays (not sure why, I ran into this problem recently). In addition, writing the PET to an output file will not be done with a fprintf function (this prints to the console window). There are a few ways to do this; try reading about "user defined scalar" values and how to use them.

Try taking a look at this link for an example of the define_on_demand function:
https://www.afs.enea.it/project/nept...udf/node28.htm

If you provide more details about error codes, it will help us help you as well.
andrew-c is offline   Reply With Quote

Reply

Tags
fluent, output, thermal comfort, udf, user defined


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 of saturation temperature stanlee8 Fluent UDF and Scheme Programming 8 June 27, 2021 07:12
Saturation temperature UDF for evaporation-condensation obiscolly50 Fluent UDF and Scheme Programming 1 June 20, 2021 10:08
Help with unsteady calculation with source/sink UDF RobV Fluent UDF and Scheme Programming 3 March 10, 2016 03:45
Calculation of the Governing Equations Mihail CFX 7 September 7, 2014 06:27
Sequential calculation of Temperature and mass tra J.W.Ryu FLUENT 7 June 18, 2002 07:12


All times are GMT -4. The time now is 11:39.