CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

udf for heat generation rate

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 27, 2013, 04:07
Default source energy
  #41
New Member
 
hossein
Join Date: May 2013
Posts: 1
Rep Power: 0
hosseinr is on a distinguished road
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;
}
hosseinr is offline   Reply With Quote

Old   October 18, 2015, 12:08
Default
  #42
New Member
 
HSA
Join Date: Oct 2015
Posts: 2
Rep Power: 0
student_231 is on a distinguished road
Quote:
Originally Posted by ComputerGuy View Post
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...

Last edited by student_231; October 18, 2015 at 12:09. Reason: mistake
student_231 is offline   Reply With Quote

Old   October 20, 2015, 10:25
Default
  #43
Senior Member
 
Bruno
Join Date: Mar 2009
Location: Brazil
Posts: 277
Rep Power: 21
brunoc is on a distinguished road
What have you done so far? Do you have a geometry? Mesh? Base models? Did you take a look at the tutorials?
brunoc is offline   Reply With Quote

Old   August 12, 2017, 05:05
Default
  #44
New Member
 
maziyar ghanikolahloo
Join Date: Jan 2017
Posts: 5
Rep Power: 9
maziyarghani is on a distinguished road
Quote:
Originally Posted by ComputerGuy View Post
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 is offline   Reply With Quote

Old   August 12, 2017, 05:10
Default
  #45
New Member
 
maziyar ghanikolahloo
Join Date: Jan 2017
Posts: 5
Rep Power: 9
maziyarghani is on a distinguished road
Quote:
Originally Posted by ComputerGuy View Post
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 is offline   Reply With Quote

Old   November 25, 2019, 23:44
Default Varying heat generation rate
  #46
New Member
 
Amit Chauhan
Join Date: May 2010
Location: Chennai, India
Posts: 18
Rep Power: 15
chauhan is on a distinguished road
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
chauhan is offline   Reply With Quote

Old   November 26, 2019, 03:31
Default
  #47
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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?
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   November 26, 2019, 03:43
Default
  #48
New Member
 
Amit Chauhan
Join Date: May 2010
Location: Chennai, India
Posts: 18
Rep Power: 15
chauhan is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
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.
chauhan is offline   Reply With Quote

Old   November 26, 2019, 23:27
Default
  #49
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   November 29, 2019, 01:24
Default
  #50
New Member
 
Amit Chauhan
Join Date: May 2010
Location: Chennai, India
Posts: 18
Rep Power: 15
chauhan is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
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.
Attached Files
File Type: pdf varying heat generation issue_1.pdf (151.5 KB, 12 views)
chauhan is offline   Reply With Quote

Old   December 1, 2019, 20:59
Default
  #51
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   December 4, 2019, 00:40
Default
  #52
New Member
 
Amit Chauhan
Join Date: May 2010
Location: Chennai, India
Posts: 18
Rep Power: 15
chauhan is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
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.
chauhan is offline   Reply With Quote

Old   December 4, 2019, 22:51
Default
  #53
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you can read/write from file if it is needed.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   December 5, 2022, 08:45
Default
  #54
New Member
 
Aman
Join Date: Dec 2022
Posts: 5
Rep Power: 3
amanv is on a distinguished road
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
Attached Images
File Type: jpg Screenshot_20221205_110515.jpg (103.5 KB, 2 views)
amanv is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF to measure Mass Flow Rate a.lynchy Fluent UDF and Scheme Programming 31 October 4, 2018 14:10
strain rate in UDF Paulina FLUENT 11 November 20, 2014 03:06
UDF for critical strain rate to extinction Birute Bunkute FLUENT 1 March 25, 2010 15:40
surface reaction rate with udf yellow-stuff FLUENT 4 January 29, 2010 12:53
heat generation rate w/m3 in 2D Laszlo FLUENT 1 May 6, 2004 11:58


All times are GMT -4. The time now is 08:55.