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 |
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! |
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; } |
Quote:
|
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?
|
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. |
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! |
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 |
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 |
Quote:
Thanks, Best regards |
Quote:
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 |
Hi there, hope everyone here is doing good! I have a small doubt in udf.
Quote:
Thanks in advance, have a good day! |
All times are GMT -4. The time now is 12:47. |