CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Creating a UDF for heat generation given data points (https://www.cfd-online.com/Forums/fluent-udf/246454-creating-udf-heat-generation-given-data-points.html)

amanv December 5, 2022 06:09

Creating a UDF for heat generation given data points
 
1 Attachment(s)
Hi, I am currently trying to create a UDF for a source term to input into ANSYS FLUENT. I am modeling heat generation within a Li-ion cell and have the current charging profile. The heat generated within the cell is modeled with the equation q = I^2*R where I is current, R is internal resistance and q is the heat generation.

I have this current charging profile which varies over time. The internal resistance value is constant throughout the charging. I would like to know how to write a UDF such that the current changes with time according to this curve (attached image) .

luzikato December 5, 2022 06:45

To add a source term, I think it's pretty obvious that we should use DEFINE_SOURCE macro. And for the given data points you can convert these values to a polynomial equation that varies along the timestep. What about the constant values? I suggest you implement a boolean that checks the current timestep. If the current timestep is below 500 ms then use constant source value and then after the timestep above 500 ms then return the source value calculated from the polynomial.

I understand the polynomial itself won't give you the exact value as in your sample data. But I think it would be still pretty valid.

amanv December 5, 2022 08:12

Quote:

Originally Posted by luzikato (Post 840595)
To add a source term, I think it's pretty obvious that we should use DEFINE_SOURCE macro. And for the given data points you can convert these values to a polynomial equation that varies along the timestep. What about the constant values? I suggest you implement a boolean that checks the current timestep. If the current timestep is below 500 ms then use constant source value and then after the timestep above 500 ms then return the source value calculated from the polynomial.

I understand the polynomial itself won't give you the exact value as in your sample data. But I think it would be still pretty valid.

Hi luzikato, thanks for your reply!

I'm not sure what you mean by "implement a boolean". How can this be done?

luzikato December 5, 2022 09:05

According to your provided data points, you can't use a polynomial to define the whole curve because the inconsistency of the curve (the source value from 0 ms to 500 ms is almost constant). So, I was thinking to use polynomial only for the source value from 500 ms and so on. And for below 500 ms, you can use the constant amount of heat source. What would I do to achieve this is something like this:

Code:

if (t == 500) {
        source = 4.199; // Constant value from 0 ms to 500 ms
}
else {
        source == x; // The x value should be your polynomial function from >500 ms until 2400 ms.
}

Of course, you have to add DEFINE_SOURCE macro above. But I think I will leave it to you.

amanv December 5, 2022 12:54

Thank you luzikato!

I have attempted it and have got the following. Does this seem correct or am i making a mistake? The constant values were obtained from a curve-fitting program.

#include "udf.h"
#define C1 -5E-08 //define constant term
#define C2 0.0003
#define C3 -0.5805
#define C4 428.16
#define C5 4.194E-9

DEFINE_SOURCE(heat_gen_cell,cell,thread,dS,eqn)
{

real source;
real time;
time = CURRENT_TIME; //taking time value;
if (time == 500) {
source = 4.199; // Constant value from 0 ms to 500 ms
}
else {
source == C1 * pow(time, 3) + C2 * pow(time, 2) + C3 * pow(time, 1) + C4 ; // The x value should be your polynomial function from >500 ms until 2400 ms.
}

dS[eqn] = 0;
return source;
}

luzikato December 9, 2022 07:32

Hi! Sorry for the late reply. The codes seem alright to me. Have you tried inserting it to your case?

AlexanderZ December 12, 2022 00:43

UDF uses UNITS in SI
500 ms = 0.5 sec not 500


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