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

Writing UDF for heat source term

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By Floyd

Reply
 
LinkBack Thread Tools 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: 7
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: 7
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: 7
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 likes 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: 7
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: 7
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: 7
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: 7
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: 7
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: 7
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: 7
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

Reply

Thread Tools
Display Modes

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 On
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 5 June 21, 2013 05:39
UDF Source Term Christian FLUENT 4 August 1, 2009 05:53
The source term of UDF summer FLUENT 0 August 24, 2006 17:44
HELP! adding a mass source to VOF eqn. by UDF??? ROOZBEH FLUENT 4 May 29, 2003 09:54
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 23:02.