UDF for energy source term
in my heat transfer model i want to write a udf for the energy source term
S y = - density * dH\dt where H= the total enthalpy , t= time my udf is ; #include "udf.h" #define dens 800.0 DEFINE_SOURCE(heat source,cell,thread,dS,eqn) { real source ; source= - C_H-G(cell,thread)*dens ; dS [eqn] =0 ; return source ; } can any one help me to , i dont know if the cell enthaly gredient is equal to the chane of enthalpy with time? |
im waiting for ur help???
|
No, the gradient is a spacial derivative. Besides, it is a vector. You need a time derivative, which YOU have to provide.
|
yes u are right
but how can i write the dh/dt? |
I did this before. I don't have access to it right now, but here is the idea (I AM NOT SURE OF THE EXACT SYNTAX, I just write it roughly by memory):
1- compute/store H in a UDM with a "Adjust" UDF 2- then derive it in your Source UDF, something like that (first order in that example): time_step = "macro for time step goes here"; dHdt = (UDM(0) - UDM_M1(0)) / time_step; // suppose you put H in UDM(0) For what I remember, it was not that easy to implement, but the idea is there. Among all, make sure to understand exactly when "Adjust" is executed. This line: dS [eqn] =0 ; can be a problem. Make sure to understand what it means, look at UDF guide. You may need to derive your source term to ever converge (depend on your problem). I always derive my source term, it is either safer or downright necessary (numerically). Keep motivation high, this problem will be challenging if you are beginner, but it is feasible. |
Quote:
Make sure you enable a user-defined memory location... Also, I'm assuming you want the density at the current time step, not the average density between the two timesteps (current and previous). Also, enthalpy has a spatial gradient (x/y/z), but you want the gradient w.r.t. time. This is a crude approximation of a derivative. Ideally, you should do some higher order approximations. Finally: there is an "if" statement in there to ensure that, at the beginning of the simulation where you have no derivative information, no source term is calculated. --ComputerGuy Code:
#include "udf.h" |
Quote:
Code:
Keep in mind that dS[eqn]=0 could lead to convergence problem, but it is ok to try it first like that. Otherwise, ComputerGuy is right, DEFINE_SOURCE should looks similar to that. |
Quote:
ComputerGuy Code:
|
Yes, that's it ComputerGuy! :)
Only left is the special case of the very first time step and the whole thing is adressed. |
Quote:
engloly: Let us know if these work ComputerGuy |
Still one detail, the UDM should be initialized so that during the first time step there is a value for it.
|
Energy source term does not work!
Dear all,
I wrote a udf for energy equation, but I think it depends on the magnitude of sigma_r.:confused::confused: For sigma_r equal to 3e-1, udf works well :cool:, but if you change it to 3e-3, udf doesn't work. :eek: can anybody help me? UDF code: #include "udf.h" #define PI 3.14159265 #define ei 40e-3 #define sigma_r 3e-3 #define sigma_t 0.5e-6 #define t0 0 DEFINE_SOURCE(Energy_source, c, ct, dS, eqn) { real source; real pos[ND_ND]; real centre[ND_ND]; real flow_time; real r; NV_D(centre,=,0.8,0,0); /* Set a vector */ flow_time = CURRENT_TIME; /* Special Fluent macro */ C_CENTROID(pos,c,ct); NV_VV(pos,=,pos,-,centre); /* Vector arithmetic */ r = NV_MAG(pos); source = (ei/(4*pow(PI,2)*pow(sigma_r,3)*sigma_t))*exp(-0.5*pow((flow_time-t0)/sigma_t,2))*exp(-0.5*pow(r/sigma_r,2)); dS[eqn] = 0; return source; } |
All times are GMT -4. The time now is 13:05. |