CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Writing UDF for heat source term (https://www.cfd-online.com/Forums/fluent/77087-writing-udf-heat-source-term.html)

Floyd June 12, 2010 06:07

Writing UDF for heat source term
 
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

sosososo1114 June 12, 2010 22:42

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!

Floyd June 13, 2010 09:03

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;

}

sosososo1114 June 13, 2010 22:13

Quote:

Originally Posted by Floyd (Post 262804)
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.

Floyd June 14, 2010 01:46

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?

sosososo1114 June 14, 2010 09:59

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. :D
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.

Floyd June 15, 2010 09:50

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!

sosososo1114 June 18, 2010 01:20

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

Floyd June 18, 2010 05:51

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

tumble October 15, 2010 07:50

Quote:

Originally Posted by sosososo1114 (Post 262835)
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

intied June 18, 2018 21:23

Quote:

Originally Posted by Floyd (Post 263547)
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

sangeeth_30 July 3, 2021 02:56

Hi there, hope everyone here is doing good! I have a small doubt in udf.
 
Quote:

Originally Posted by sosososo1114 (Post 262835)
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!


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