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

Writing UDF for heat source term

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By Floyd

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 12, 2010, 06:07
Default Writing UDF for heat source term
  #1
New Member
 
Floyd
Join Date: Jun 2010
Posts: 9
Rep Power: 15
Floyd is on a distinguished road
Dear all,

I am new to UDF and need to write some codes for a time dependent heat source term in DEFINE_SOURCE Macros. However, I don't see there is any time argument in the DEFINE_SOURCE Macros. I hope some nice persons could give me some idea of how to write codes for time dependent source term.

With thanks & regards,
Floyd
Floyd is offline   Reply With Quote

Old   June 12, 2010, 22:42
Default
  #2
Member
 
Hongjin Wang
Join Date: Mar 2010
Posts: 37
Rep Power: 16
sosososo1114 is on a distinguished road
FLUENT provides a macro called CURRENT_TIME to return the real current flow time in seconds, and another one called CURRENT_TIMESTEP to return the physical current time step size. I think you may need this two macros. For details, please google the udf manual..
Good luck!
sosososo1114 is offline   Reply With Quote

Old   June 13, 2010, 09:03
Default
  #3
New Member
 
Floyd
Join Date: Jun 2010
Posts: 9
Rep Power: 15
Floyd is on a distinguished road
Thanks for your reply,

That's the code I am using in my simulation. I don't know what I should do with the argument "cell" and "thread". Is it fine to leave them if I only need to write a time dependent source term within a solid?

/************************************************** *********************
UDF for time dependent volumetric heat generation of 18650 cell
************************************************** **********************/
#include "udf.h"
#define C1 -8.0e3 //define constant term
#define C2 4.0e-6
#define C3 -0.0042
#define C4 2.3582
DEFINE_SOURCE(heat_gen,cell,thread,dS,eqn)
{

real source;
real time;
time = CURRENT_TIME; //taking time value;

source = C1*pow(time,3)+C2*pow(time,2)-time*C3+C4; //time dependent heat source;
dS[eqn] = 0;
return source;

}
Olds88 and hfs1995 like this.
Floyd is offline   Reply With Quote

Old   June 13, 2010, 22:13
Default
  #4
Member
 
Hongjin Wang
Join Date: Mar 2010
Posts: 37
Rep Power: 16
sosososo1114 is on a distinguished road
Quote:
Originally Posted by Floyd View Post
Thanks for your reply,

That's the code I am using in my simulation. I don't know what I should do with the argument "cell" and "thread". Is it fine to leave them if I only need to write a time dependent source term within a solid?

/************************************************** *********************
UDF for time dependent volumetric heat generation of 18650 cell
************************************************** **********************/
#include "udf.h"
#define C1 -8.0e3 //define constant term
#define C2 4.0e-6
#define C3 -0.0042
#define C4 2.3582
DEFINE_SOURCE(heat_gen,cell,thread,dS,eqn)
{

real source;
real time;
time = CURRENT_TIME; //taking time value;

source = C1*pow(time,3)+C2*pow(time,2)-time*C3+C4; //time dependent heat source;
dS[eqn] = 0;
return source;

}
Judging from your codes, it seems that the heat sources in your case only depends on the time flow. That is to say, with above codes, every cell in your solid zone will have the same heat source generate at the same time. If that is what you want, your code is right. And your have to do noting with cell or with thread. But if you want your heat source varies through spaces, you need to use these two augments. In other word, cell and thread indicates the coordinates of a mesh cell.
sosososo1114 is offline   Reply With Quote

Old   June 14, 2010, 01:46
Default
  #5
New Member
 
Floyd
Join Date: Jun 2010
Posts: 9
Rep Power: 15
Floyd is on a distinguished road
Thanks for your help again! Yes, what I want was just to create a heat source which is increasing with time only. I sucessfully interpreted, compiled and hooked the code into fluent. however, I got another problem. The residuals of energy didn't converged and was growing when I ran the calculation. What possible factor could make this happen?
Floyd is offline   Reply With Quote

Old   June 14, 2010, 09:59
Default
  #6
Member
 
Hongjin Wang
Join Date: Mar 2010
Posts: 37
Rep Power: 16
sosososo1114 is on a distinguished road
Hi,
The residuals may get more difficulities in convergence in the cases with UDF defined sources than those without sources do. Maybe your time step is to large for your case. But I have not seen your case. Hence I am not sure what exactly goes wrong. But you can try this way:

first, run the case without UDF sources hooked at steady model to see whether the residuals will converge. If it will not, there might be some problems with your grids. Check your meshes.

If it will, hook the UDF to your zones and Key "0" into time step in the iteration pannel. If the residuals still get divergent, chang (usually decrease ) the time step size. Run iteration till they converge.
Then, type other number rather than 0 in the time step, run again.
Ps: although the initial condition does nothing with the results theoriticaly, a suitable one will reduce the iteration numbers.

Besides, note the iteration numbers of each time step. your case may just not run enough iterations.
Or maybe the convergency conditions are too strick.
sosososo1114 is offline   Reply With Quote

Old   June 15, 2010, 09:50
Default
  #7
New Member
 
Floyd
Join Date: Jun 2010
Posts: 9
Rep Power: 15
Floyd is on a distinguished road
Hi Hongjin!

I really appreciated your help, I followed your instructions and now trying on my simulation. I am actually working on a simulation of temperature changes of a battery which is generating heat along time under natural convection. It sounds pretty simple case. what kind of advise you may give me in doing a case like this? Thank you very much!
Floyd is offline   Reply With Quote

Old   June 18, 2010, 01:20
Default
  #8
Member
 
Hongjin Wang
Join Date: Mar 2010
Posts: 37
Rep Power: 16
sosososo1114 is on a distinguished road
Sorry Floyd, I did not see your reply untill now. I have not done such a case. So I might not give your more detailed suggestions. Yet I know there are a lot of studies about the battery and you might find what you want. I am sorry.


Regards,
Hongjin Wang
sosososo1114 is offline   Reply With Quote

Old   June 18, 2010, 05:51
Default
  #9
New Member
 
Floyd
Join Date: Jun 2010
Posts: 9
Rep Power: 15
Floyd is on a distinguished road
It's Ok! you've been so nice to help me out. I 'll try to dig out the rest. Thank you very much!

Regards,
Floyd
Floyd is offline   Reply With Quote

Old   October 15, 2010, 07:50
Default
  #10
New Member
 
samt
Join Date: Jan 2010
Posts: 13
Rep Power: 16
tumble is on a distinguished road
Quote:
Originally Posted by sosososo1114 View Post
Judging from your codes, it seems that the heat sources in your case only depends on the time flow. That is to say, with above codes, every cell in your solid zone will have the same heat source generate at the same time. If that is what you want, your code is right. And your have to do noting with cell or with thread. But if you want your heat source varies through spaces, you need to use these two augments. In other word, cell and thread indicates the coordinates of a mesh cell.
I am new to UDF, I want to write a UDF from a source term which varies with time and space ; can you help me to write codes adequate for a source term moving in a solid.
Thanks,
Best regards
tumble is offline   Reply With Quote

Old   June 18, 2018, 21:23
Default
  #11
New Member
 
Edwin P
Join Date: Jun 2018
Posts: 13
Rep Power: 7
intied is on a distinguished road
Quote:
Originally Posted by Floyd View Post
It's Ok! you've been so nice to help me out. I 'll try to dig out the rest. Thank you very much!

Regards,
Floyd

Hi Floyd
I have the same problem as you. I write a similar UDF for the source term. It compiles but does not converge. Did you solve that problem?
Regards
intied is offline   Reply With Quote

Old   July 3, 2021, 02:56
Default Hi there, hope everyone here is doing good! I have a small doubt in udf.
  #12
New Member
 
Sangeeth
Join Date: Jun 2021
Posts: 3
Rep Power: 4
sangeeth_30 is on a distinguished road
Quote:
Originally Posted by sosososo1114 View Post
Judging from your codes, it seems that the heat sources in your case only depends on the time flow. That is to say, with above codes, every cell in your solid zone will have the same heat source generate at the same time. If that is what you want, your code is right. And your have to do noting with cell or with thread. But if you want your heat source varies through spaces, you need to use these two augments. In other word, cell and thread indicates the coordinates of a mesh cell.
Hi guys, hope everyone is doing good! In my case the heat source is moving with a constant speed in a 2d plane in x-direction. The width and height of the heat source remains constant. And the Heat Source for a cell inside the heat source region = k(constant) * (volume of cell that is inside the heat source region). How to find the volume of each and every cell that is inside the heat source to use it in the above formula.
Thanks in advance, have a good day!
sangeeth_30 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
Problem of SOURCE term gradient in UDS wind Fluent UDF and Scheme Programming 6 December 1, 2022 14:21
HELP! adding a mass source to VOF eqn. by UDF??? ROOZBEH FLUENT 5 December 3, 2016 17:53
UDF Source Term Christian FLUENT 4 August 1, 2009 05:53
The source term of UDF summer FLUENT 0 August 24, 2006 17:44
UDFs for Scalar Eqn - Fluid/Solid HT Greg Perkins FLUENT 0 October 11, 2000 03:43


All times are GMT -4. The time now is 03:10.