|
[Sponsors] |
Creating a UDF for heat generation given data points |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
December 5, 2022, 07:09 |
Creating a UDF for heat generation given data points
|
#1 |
New Member
Aman
Join Date: Dec 2022
Posts: 5
Rep Power: 4 |
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) . |
|
December 5, 2022, 07:45 |
|
#2 |
New Member
Anas Nur Fauzan
Join Date: Oct 2019
Posts: 18
Rep Power: 7 |
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. |
|
December 5, 2022, 09:12 |
|
#3 | |
New Member
Aman
Join Date: Dec 2022
Posts: 5
Rep Power: 4 |
Quote:
I'm not sure what you mean by "implement a boolean". How can this be done? |
||
December 5, 2022, 10:05 |
|
#4 |
New Member
Anas Nur Fauzan
Join Date: Oct 2019
Posts: 18
Rep Power: 7 |
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. } |
|
December 5, 2022, 13:54 |
|
#5 |
New Member
Aman
Join Date: Dec 2022
Posts: 5
Rep Power: 4 |
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; } |
|
December 9, 2022, 08:32 |
|
#6 |
New Member
Anas Nur Fauzan
Join Date: Oct 2019
Posts: 18
Rep Power: 7 |
Hi! Sorry for the late reply. The codes seem alright to me. Have you tried inserting it to your case?
|
|
December 12, 2022, 01:43 |
|
#7 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
UDF uses UNITS in SI
500 ms = 0.5 sec not 500
__________________
best regards ****************************** press LIKE if this message was helpful |
|
Tags |
ansys 2021 r2, fluent - udf, udf and programming |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF DPM_BC with F_UDMI not storing data | balki | Fluent UDF and Scheme Programming | 3 | June 6, 2016 23:10 |
[snappyHexMesh] crash sHM | H25E | OpenFOAM Meshing & Mesh Conversion | 11 | November 10, 2014 12:27 |
Possible Bug in pimpleFoam (or createPatch) (or fluent3DMeshToFoam) | cfdonline2mohsen | OpenFOAM | 3 | October 21, 2013 10:28 |
Problem in running ICEM grid in Openfoam | Tarak | OpenFOAM | 6 | September 9, 2011 18:51 |
XYZ (ASCII format) data points into GAMBIT | Neil | FLUENT | 1 | August 7, 2007 10:24 |