CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   udf for heat generation rate (https://www.cfd-online.com/Forums/fluent-udf/83435-udf-heat-generation-rate.html)

hosseinr May 27, 2013 04:07

source energy
 
hi
Where is my problem udf?
#include "udf.h"

DEFINE_SR_RATE(my_rate,f,t,r,mw,yi,rr)
{
real y_ch4 = yi[0];
real y_h2o = yi[1];
real y_h2 = yi[2];
real y_co = yi[3];
real y_co2 = yi[4];
real y_o2 = yi[6];
real y_n2 = yi[5];
real K1, K2, K3, K4, T_w, TP ,Nsum , K_C1, K_C2, K_C3, K_C4, K_C5, K_C6, QR , keq2 , keq3 , keq4;
real r1,T_WALL,A, r2 ,r3, r4, k3,k4, min=0, max=1e+5, k1, k2;
Thread *t0 = THREAD_T0(t);
cell_t c0 = F_C0(f,t);
y_ch4 *= 1/mw[0];
y_h2o *= 1/mw[1];
y_h2 *= 1/mw[2];
y_co *= 1/mw[3];
y_co2 *= 1/mw[4];
y_o2 *= 1/mw[6];
y_n2 *= 1/mw[5];
Nsum = y_ch4 + y_h2o + y_h2 + y_co + y_co2 + y_n2 + y_o2 ;
y_ch4 *= 1/Nsum;
y_h2o *= 1/Nsum;
y_h2 *= 1/Nsum;
y_co *= 1/Nsum;
y_co2 *= 1/Nsum;
y_o2 *= 1/Nsum;
y_n2 *= 1/Nsum;
T_w = F_T(f,t);
begin_c_loop(c0,t0)
{
T_WALL = C_T(c0,t0);
C_UDSI(c0,t0,0) = T_WALL;
}
end_c_loop(c0,t0)
/* ki( Kmol*m^-2*s ) */
K1 = KO_1*exp(-E1/(R*T_w))*aa;
K2 = KO_2*exp(-E2/(R*T_w))*aa;
K3 = KO_3*exp(-E3/(R*T_w))*aa;
K4 = KO_4*exp(-E4/(R*T_w))*aa;
K_C1 = K_CO1*exp((-AH1)/(R*T_w));
K_C2 = K_CO2*exp((-AH2)/(R*T_w));
K_C3 = K_CO3*exp((-AH3)/(R*T_w));
K_C4 = K_CO4*exp((-AH4)/(R*T_w));
K_C5 = K_CO5*exp((-AH5)/(R*T_w));
K_C6 = K_CO6*exp((-AH6)/(R*T_w));
/* TP( bar ) */
TP = C_P(c0,t0)/ad;
keq2 = (ab)*exp(ac/T_w);
keq3 = (ae)*exp(af/T_w);
keq4 = (ag)*exp(ah/T_w);
QR = 1+(K_C4*(TP*y_co))+(K_C5*(TP*y_h2))+(K_C3*(TP*y_ch 4))+((K_C6*(TP*y_h2o))/(TP*y_h2));
/* rr (Kmol*m^-2*s)*/
if (STREQ(r->name, "reaction-1"))
{
r1 = k1*(((TP*y_ch4)*pow(TP*y_o2,.5))/pow((1+(K_C1*(TP*y_ch4))+(K_C2*pow(TP*y_o2,.5))),2 ));
if(r1<min)
{
*rr = min;
}
else if (r1 > min && r1 < max)
*rr = r1;
else if (r1 > max){
*rr = max;
}
}
else if (STREQ(r->name, "reaction-2")){
r2=((k2/pow(TP*y_h2,2.5))*(((TP*y_ch4)*(TP*y_h2o))-((pow(TP*y_h2,3)*(TP*y_co))/(keq2)))/(pow(QR,2)));
if(r2 < min)
{
*rr = min;
}
else if (r2 > min && r2 < max)
*rr = r2;
else if (r2 > max){
*rr = max;
}
}
else if (STREQ(r->name, "reaction-3"))
{
r3=((k3/(TP*y_h2))*(((TP*y_co)*(TP*y_h2o))-(((TP*y_h2)*(TP*y_co2))/(keq3)))/(pow(QR,2)));
if(r3 < min)
{
*rr = min;
}
else if (r3 > min && r3 < max)
*rr = r3;
else if (r3 > max){
*rr = max;
}
}
else if (STREQ(r->name, "reaction-4")){
r4=((k4/pow(TP*y_h2,3.5))*(((TP*y_ch4)*pow(TP*y_h2o,2))-(((pow(TP*y_h2,4))*(TP*y_co2))/(keq4)))/(pow(QR,2)));
if(r4 < min)
{
*rr = min;
}
else if (r4 > min && r4 < max)
*rr = r4;
else if (r4 > max){
*rr = max;
}
}
}
DEFINE_ON_DEMAND(copy_uds_to_udm)
{
Domain* d = Get_Domain(1);
Thread* t;
cell_t c;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
Thread* t0;
cell_t c0;
{
C_UDMI(c0,t0,0) =C_UDSI(c0,t0,0);
}
end_c_loop(c,t)
}
return;
}

DEFINE_SOURCE(energy,c,t,dS,eqn)
{


real source;
source = C_UDMI(c0,t0,0);
dS[eqn] = 0;

return source;
}

student_231 October 18, 2015 12:08

Quote:

Originally Posted by ComputerGuy (Post 288729)
Sarah,

Is "x" in your function the x-coordinate of the cell? If so, try the following un-checked code.

Code:

#include "udf.h"
#include "math.h"

DEFINE_SOURCE(energy_source,c,t,dS,eqn)
{
  real x[ND_ND];
  real source;
  C_CENTROID(x,c,t);
  source = sin(0.3*x[0]);
  dS[eqn] = 0.3*cos(0.3*x[0]);
  return source;
}

The source in this case is actually the sine function, and the derivative (dS) is the cosine function. If your heat generation rate is actually the cosine function as you've listed it, the code is:

Code:

#include "udf.h"
#include "math.h"

DEFINE_SOURCE(energy_source,c,t,dS,eqn)
{
  real x[ND_ND];
  real source;
  C_CENTROID(x,c,t);
  source = 0.3*cos(0.3*x[0]);
  dS[eqn] = -0.09*sin(0.3*x[0]);
  return source;
}

ComputerGuy

i also need help ... i am just a beginner with fluent... i have to model a rod with 5mm radius and extended in z direction upto 1 m .. i want to write a udf for heat generation rate as a sine function varying along z direction (maximum at the centre and zero at the edges...) can any one help me with... i'll be thankful...

brunoc October 20, 2015 10:25

What have you done so far? Do you have a geometry? Mesh? Base models? Did you take a look at the tutorials?

maziyarghani August 12, 2017 05:05

Quote:

Originally Posted by ComputerGuy (Post 288956)
Sarah,

I think everything looks right, except for the first line. Try this:

Code:

DEFINE_PROFILE(porosity_profile,t,i)
{
real x[ND_ND];
real y;
cell_t c;
begin_c_loop(c,t)
{
C_CENTROID(x,c,t);
y=x[1];
if((y==1.) || (y==1.85))
{
F_PROFILE(c,t,i)=0.39;
}
if ((y>1.) && (y<=1.425))
{
F_PROFILE(c,t,i)=0.39*(1.+1.05*exp(-100.*(y-1.)/0.06));
}
if ((y>1.425) && (y<1.85))
{
F_PROFILE(c,t,i)=0.39*(1.+1.05*exp(-100.*(1.85-y)/0.06));
}
C_UDMI(c,t,0)=F_PROFILE(c,t,i);
}

By doing it this way, you'll write the value of porosity into a user defined memory location (which you also have to enable in Fluent, by the way). I have never seen C_POR(c,t), and cannot find it in the documentation, and thus I figured this is a safe way of referencing the cell porosity. I don't do a whole lot of UDF coding in porous regions, so perhaps you've discovered a keyword I don't know.

Let us know if this works for you!

ComputerGuy

Dear ComputerGuy
I should write an udf for my photovoltaic cell project to relate heat generation rate(output power) to photovoltaic cell's temperature actually I wanna consider this correlation Pel=a(1-b)Tc.I.SCR.A in which all the parameters are constant except Tc
how can I write its udf code?
In fact I have written no udf code yet.

maziyarghani August 12, 2017 05:10

Quote:

Originally Posted by ComputerGuy (Post 288956)
Sarah,

I think everything looks right, except for the first line. Try this:

Code:

DEFINE_PROFILE(porosity_profile,t,i)
{
real x[ND_ND];
real y;
cell_t c;
begin_c_loop(c,t)
{
C_CENTROID(x,c,t);
y=x[1];
if((y==1.) || (y==1.85))
{
F_PROFILE(c,t,i)=0.39;
}
if ((y>1.) && (y<=1.425))
{
F_PROFILE(c,t,i)=0.39*(1.+1.05*exp(-100.*(y-1.)/0.06));
}
if ((y>1.425) && (y<1.85))
{
F_PROFILE(c,t,i)=0.39*(1.+1.05*exp(-100.*(1.85-y)/0.06));
}
C_UDMI(c,t,0)=F_PROFILE(c,t,i);
}

By doing it this way, you'll write the value of porosity into a user defined memory location (which you also have to enable in Fluent, by the way). I have never seen C_POR(c,t), and cannot find it in the documentation, and thus I figured this is a safe way of referencing the cell porosity. I don't do a whole lot of UDF coding in porous regions, so perhaps you've discovered a keyword I don't know.

Let us know if this works for you!

ComputerGuy

Dear ComputerGuy
I should write an udf for my photovoltaic cell project to relate heat generation rate(output power) to photovoltaic cell's temperature actually I wanna consider this correlation Pel=a(1-b)Tc.I.SCR.A in which all the parameters are constant except Tc
how can I write its udf code?
In fact I have written no udf code yet.

chauhan November 25, 2019 23:44

Varying heat generation rate
 
Hello,


I am trying to simulate 3D thermal analysis of a physical domain. In the domain, on a surface, heat is being removed by jet impingement of fluid from an orifice plate 150 mm above it.

Since multiple jet impingement problems are unstable and difficult to converge, I take alternate approach.

I would provide convective boundary condition on the wall surface (exposed to jet practically). There would be heat loss from the surface. Now this heat I want to provide as heat source in the fluid volume above it. So the logic is as follows:
1) Estimate the heat from the surface (imposed with convective boundary condition) with every iteration
2) Provide this estimated heat as heat source for the fluid above the wall, with every iteration.


P.S. - I would be deleting a cell layer above this surface in fluid domain, in order to impose convective boundary condition.


Has anybody experienced such problem/issue in Fluent. It would be appreciable if anybody can share the logic and approach to write the UDF for above explained problem.


Thank you

AlexanderZ November 26, 2019 03:31

how are you going to apply heat source to fluid above the wall
if you want to delete cell layer above surface in fluid domain?

chauhan November 26, 2019 03:43

Quote:

Originally Posted by AlexanderZ (Post 750723)
how are you going to apply heat source to fluid above the wall
if you want to delete cell layer above surface in fluid domain?




As said, I am going to delete a cell from fluid regime. There are more than 6 layers of cells in the fluid regime. I will delete one, at the bottom surface, in order to give boundary condition of convection.

AlexanderZ November 26, 2019 23:27

I don't catch your idea. Make a sketch

To make volumetric heat source in UDF you can use DEFINE_SOURCE macro
more information and examples are in Ansys Fluent Customization manual

chauhan November 29, 2019 01:24

1 Attachment(s)
Quote:

Originally Posted by AlexanderZ (Post 750832)
I don't catch your idea. Make a sketch

To make volumetric heat source in UDF you can use DEFINE_SOURCE macro
more information and examples are in Ansys Fluent Customization manual


I have elaborated and explained the issue in the attachment. Please let me know if it is helpful.

AlexanderZ December 1, 2019 20:59

zones R and I should have mesh

use Define_profile macro to apply surface heat flux on A boundary, same for C boundary

good examples you can find in Ansys Fluent Customization manual

chauhan December 4, 2019 00:40

Quote:

Originally Posted by AlexanderZ (Post 751196)
zones R and I should have mesh

use Define_profile macro to apply surface heat flux on A boundary, same for C boundary

good examples you can find in Ansys Fluent Customization manual




Thank you so much Alexander for your response.

I understand that, with every iteration I need to write/save heat/heat flux value on surface A into a table (may be CSV) and the same could be read in order to impose heat flux/heat on surface C.


Is this possible? However, I will go through the manual and try to find out some way out.
Again thank you so much for the response and support.

AlexanderZ December 4, 2019 22:51

you can read/write from file if it is needed.

amanv December 5, 2022 08:45

1 Attachment(s)
Hi, I am currently trying to create a UDF for a source term to input into ANSYS FLUENT. I am modeling heat generation within a Li-ion cell and have the current charging profile. The heat generated within the cell is modeled with the equation q = I^2*R where I is current, R is internal resistance and q is the heat generation.

I have this current charging profile which varies over time. The internal resistance value is constant throughout the charging. I would like to know how to write a UDF such that the current changes with time according to this curve (attached image) .

Any help would be appreciated! thanks in advance


All times are GMT -4. The time now is 22:58.