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

Creating a UDF for heat generation given data points

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By luzikato
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 5, 2022, 07:09
Default Creating a UDF for heat generation given data points
  #1
New Member
 
Aman
Join Date: Dec 2022
Posts: 5
Rep Power: 4
amanv is on a distinguished road
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) .
Attached Images
File Type: jpg Screenshot_20221205_110515.jpg (103.5 KB, 29 views)
amanv is offline   Reply With Quote

Old   December 5, 2022, 07:45
Default
  #2
New Member
 
Anas Nur Fauzan
Join Date: Oct 2019
Posts: 18
Rep Power: 7
luzikato is on a distinguished road
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.
luzikato is offline   Reply With Quote

Old   December 5, 2022, 09:12
Default
  #3
New Member
 
Aman
Join Date: Dec 2022
Posts: 5
Rep Power: 4
amanv is on a distinguished road
Quote:
Originally Posted by luzikato View Post
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?
amanv is offline   Reply With Quote

Old   December 5, 2022, 10:05
Default
  #4
New Member
 
Anas Nur Fauzan
Join Date: Oct 2019
Posts: 18
Rep Power: 7
luzikato is on a distinguished road
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.
luzikato is offline   Reply With Quote

Old   December 5, 2022, 13:54
Default
  #5
New Member
 
Aman
Join Date: Dec 2022
Posts: 5
Rep Power: 4
amanv is on a distinguished road
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;
}
amanv is offline   Reply With Quote

Old   December 9, 2022, 08:32
Default
  #6
New Member
 
Anas Nur Fauzan
Join Date: Oct 2019
Posts: 18
Rep Power: 7
luzikato is on a distinguished road
Hi! Sorry for the late reply. The codes seem alright to me. Have you tried inserting it to your case?
amanv likes this.
luzikato is offline   Reply With Quote

Old   December 12, 2022, 01:43
Default
  #7
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
UDF uses UNITS in SI
500 ms = 0.5 sec not 500
amanv likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Reply

Tags
ansys 2021 r2, fluent - udf, udf and programming


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 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


All times are GMT -4. The time now is 12:08.