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 Members List Search Today's Posts Mark Forums Read

Like Tree3Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 28, 2010, 17:33
Default udf for heat generation rate
  #1
Member
 
sarah
Join Date: Aug 2010
Posts: 42
Rep Power: 15
sarah l is on a distinguished road
hi every body
I am supposed to write a udf for heat generation rate which is a cosine function
#include"udf.h"
DEFINE_SOURCE(energy_source,c,t,ds,eqn)

{
real x;
ds[eqn]=0.3*cos(0.3*x);
return sin(0.3*x) ;
}
but there are some errors! any one can help me to modidfy it. thanks
hariehkr and jose_zola like this.
sarah l is offline   Reply With Quote

Old   December 28, 2010, 19:23
Default
  #2
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
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

Last edited by ComputerGuy; December 28, 2010 at 19:27. Reason: added additional code
ComputerGuy is offline   Reply With Quote

Old   December 29, 2010, 12:08
Default
  #3
Member
 
sarah
Join Date: Aug 2010
Posts: 42
Rep Power: 15
sarah l is on a distinguished road
ComputerGuy
I am really thankful of you for your response , but X is the height of my geometry (of course its better to use y instead of x , I did mistake to type x!) my geometry its here:

Heat generation rate is a cosine function of y (height) :
source =5.958*sin(pi *y/11)+1.866
So
ds= 5.958*pi /11*cos(pi* y/11)
I am grateful if you help me to write a udf for it .
Best regards
sarah l is offline   Reply With Quote

Old   December 29, 2010, 12:14
Default
  #4
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
Sarah,

I have given you the code you need to make your function work. Instead of x[0], which returns the "x" component of the geometry, you'll need to use x[1], which returns the "y" component.

The only other thing is changing the source=.... and dS[eqn]=.... to the heat generation function and its derivative.

ComputerGuy
ComputerGuy is offline   Reply With Quote

Old   December 29, 2010, 13:11
Default
  #5
Member
 
sarah
Join Date: Aug 2010
Posts: 42
Rep Power: 15
sarah l is on a distinguished road
Dear ComputerGuy
I am new in udf so there is some thing that I don't know about them , such as ND could you explain me about ND , why you define x[ND_ND] ?
thanks
Sarah
sarah l is offline   Reply With Quote

Old   December 29, 2010, 14:25
Default
  #6
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
Sarah,

You should read through the Fluent UDF manual. However, from the Fluent 6.3 UDF manual (Fluent, Inc., September 11, 2006), page 3-26:

"The constant ND_ND is de ned as 2 for RP 2D (FLUENT 2D) and RP 3D (FLUENT 3D). It can be used when you want to build a 2 x2 matrix in 2D and a 3 x3 matrix in 3D. When you use ND_ND, your UDF will work for both 2D and 3D cases, without requiring any modi cations."

Thus, when I defined "real x[ND_ND]," I was making x a position vector with dimension ND, where n is the number of dimensions in your simulation.

x[0] would be the x component
x[1] would be the y component
x[2] would be the z component

The manual has extremely thorough examples -- go through it.

ComputerGuy
ComputerGuy is offline   Reply With Quote

Old   December 30, 2010, 11:36
Default Hello Computer Guy
  #7
New Member
 
masters
Join Date: Sep 2010
Posts: 5
Rep Power: 15
manohar is on a distinguished road
My problem is also related to heat generation in the energy eqn..

In my model Qg(heat generation) is proportional to exponential function of temperature and time gradient of new variable (dC/dt)
Initial condition of C is specified i.e t=0,C=0
My aim is to calculate a C at different times..
Is this possible in fluent to include the new variable in the fluent UDF...
I have written the UDF for the exponential function of temperature but how to include dc/dt is still a question for me..
manohar is offline   Reply With Quote

Old   December 30, 2010, 14:14
Default
  #8
Member
 
sarah
Join Date: Aug 2010
Posts: 42
Rep Power: 15
sarah l is on a distinguished road
Dear ComputerGuy
Yes , you are right , I have read this manual and its so good but there is not any theme about porosity , really in my project I have to define porosity as a function of x and I don’t know how to write a udf for it , everybody who I asked them , say: its impossible or very hard by fluent 6.3.26!
Could you help me about this issue ?of course I am really thankful of you for your great help about heat generation rate .
Best regards
Sarah
sarah l is offline   Reply With Quote

Old   December 30, 2010, 23:49
Default
  #9
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
Manohar,

Is C a scalar? Is it a property of the fluid which travels with the fluid (like species mass fraction, for example)? Or, is it something about the cell which simply changes with time?

For example, if you wanted to track the change in temperature in a cell such that you approximate dT/dt (or dC/dt in your case), there are macros which allow you to access the previous time step of a given cell. The previous temperature in a cell may be accessed by:
Code:
 
C_T_M1(c,t);
Many of the variables of the previous time step can be accessed in this way. Have a look at the UDF manual, section 3.2.3 (Fluent 6.3) for more information. With this, it should be very simply to approximate a derivative.

If you can't find your answer there, or if Fluent doesn't automatically track what you're looking for, you could always create a few User-Defined Memory Locations to track values from a previous time step.

That is, assume C_UDMI(cell,thread,2) is the current value of C and C_UDMI(cell,thread,1) is the previous value:

\frac{\partial C}{\partial t}\approx \frac{C \textunderscore UDMI(cell,thread,2))-C \textunderscore UDMI(cell,thread,1))}{PREVIOUS \textunderscore TIMESTEP}

If you're looking for a "value" or "property" of the fluid which will move with a fluid parcel (advect, diffuse, etc.), look into User-Defined Scalars.

If you provide a little more information, especially the functional form of your equation and what you're trying to track (i.e., what is C), perhaps you'll be able to get more help.

ComputerGuy

Quote:
Originally Posted by manohar View Post
My problem is also related to heat generation in the energy eqn..

In my model Qg(heat generation) is proportional to exponential function of temperature and time gradient of new variable (dC/dt)
Initial condition of C is specified i.e t=0,C=0
My aim is to calculate a C at different times..
Is this possible in fluent to include the new variable in the fluent UDF...
I have written the UDF for the exponential function of temperature but how to include dc/dt is still a question for me..
ComputerGuy is offline   Reply With Quote

Old   December 30, 2010, 23:57
Default
  #10
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
Sarah,

If you can write an equation (or an algorithm) for porosity as a function of geometric position, you can write a UDF for it. It's not that hard. The trick is that as opposed to DEFINE_SOURCE for energy, you must use a DEFINE_PROFILE UDF. Set the region you're interested in to a porous zone, code the DEFINE_PROFILE UDF, compile or interpret the UDF, then load the UDF into the porosity drop-down menu.

Let me know if you need further assistance!

ComputerGuy


Quote:
Originally Posted by sarah l View Post
Dear ComputerGuy
Yes , you are right , I have read this manual and its so good but there is not any theme about porosity , really in my project I have to define porosity as a function of x and I don’t know how to write a udf for it , everybody who I asked them , say: its impossible or very hard by fluent 6.3.26!
Could you help me about this issue ?of course I am really thankful of you for your great help about heat generation rate .
Best regards
Sarah
ComputerGuy is offline   Reply With Quote

Old   December 31, 2010, 11:56
Default Hello Computer Guy
  #11
New Member
 
masters
Join Date: Sep 2010
Posts: 5
Rep Power: 15
manohar is on a distinguished road
My model is related due to absorption(Where gas is getting absorbed by solid).
I am solving energy equation(Unsteady) for the cylindrical model
In my model
Qg = exp(-const/T)*dc/dt ----(1)
where dc/dt = (pg - Peq)/peq*(some constant) ----(2)
where pg =constant= 3 bar
peq is a function of Temperature(T).
C is concentration of gas in the solid
My aim is to find to find T and C for different time.
I can substitute (2) eqn in (1) eqn and total heat source will be in function of temperature but finding C by means of temperature will be a long procedure.
Is there any way to find both C and T parallel by writing UDF??
manohar is offline   Reply With Quote

Old   December 31, 2010, 12:38
Default
  #12
Member
 
sarah
Join Date: Aug 2010
Posts: 42
Rep Power: 15
sarah l is on a distinguished road
Dear ComputerGuy
Thank you It is very kind of you . well I have written an equation for porosity , Its here :
Porosity= 0.39*(1+1.05*exp(-100*(y-1)/0.06)) 1 < y<1.425
Porosity= 0.39*(1+1.05*exp(-100*(1.85-y)/0.06)) 1.425<y<1.85
y=1 , y=1.85 porosity =0.39
And I have written a udf for it :


#include "udf.h"

DEFINE_PROFILE(porosity_profile,t,i)
{
real x[ND_ND];
real y;
cell_t c;

begin_c_loop(c,t)
{

y=x[1];
if(1<y<1.425)
F_PROFILE(c,t,i)=0.39*(1+1.05*exp(-100*(y-1)/0.06));
else if(1.425<y<1.85)
F_PROFILE(c,t,i)=0.39*(1+1.05*exp(-100*(1.85-y)/0.06));
}
end_c_loop(c,t)
}

is it corresponding to the equation of porosity? And when we use udf for porosity so we have to write a udf for viscous resistance and inertial resistance as well , so should we interpereted and hook udfs respectively ?, It means we should first hook porosity_udf then viscous resistance_udf and inertial resistance_udf , isn’t it ?
I should also thank you since your advices help me in my project so far .
Best regards
Sarah
sarah l is offline   Reply With Quote

Old   December 31, 2010, 12:41
Default
  #13
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
Manohar,

If I understand correctly:
  1. Heat is being generated by the absorbtion of a gas into a solid.
  2. The heat generation rate depends on the temperature, as well as the difference in pressure of the gas from its equilibrium value (vapor pressure).
  3. The vapor pressure is a function of temperature, and is therefore time dependent.
  4. You want an expression for, or an output of, both T and C
My suggestions would be the following:
  1. Have Fluent monitor and output the temperature as a function of flow time (not iteration); this can be volume averaged, mass averaged, etc. You need to decide where you want to monitor the temperature, because there appears to be a transient, spatially dependent thermal behavior in your system. Thus, your choice of location may change your expression for T as a function of time.
  2. Have Fluent monitor and output Peq. Better yet, set up a custom field fuction which is \frac{(P_{g} - P_{eq})*(some constant)}{P_{eq}} From there, you could very easily numerically integrate the result (which is dC/dt) and come up with an answer for C. If that doesn't suit you, regress the data (i.e., fit a curve through it), develop an expression which approximates dC/dt, and analytically integrate that.
Many times problems of this sort don't have a nice analytical solution. If they did, we probably wouldn't be using Fluent to solve them.

ComputerGuy

Last edited by ComputerGuy; January 1, 2011 at 03:03.
ComputerGuy is offline   Reply With Quote

Old   December 31, 2010, 13:05
Default
  #14
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
Sarah,

Your UDF was basically correct, although didn't address the case where y=1 or y=1.85. You also need to assign a vector to x, which I did with the C_CENTROID command. I've changed it below:

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));
  }
 }
 end_c_loop(c,t)
}
See also: http://my.fit.edu/itresources/manual...udf/node42.htm

Examples 5 and 6 show the usage of both F_PROFILE and C_PROFILE for defining porosity. You can do the same for viscous and inertial resistances, using basically the same code as above, but modified with the appropriate values.

ComputerGuy


Quote:
Originally Posted by sarah l View Post
Dear ComputerGuy
Thank you It is very kind of you . well I have written an equation for porosity , Its here :
Porosity= 0.39*(1+1.05*exp(-100*(y-1)/0.06)) 1 < y<1.425
Porosity= 0.39*(1+1.05*exp(-100*(1.85-y)/0.06)) 1.425<y<1.85
y=1 , y=1.85 porosity =0.39
And I have written a udf for it :


#include "udf.h"

DEFINE_PROFILE(porosity_profile,t,i)
{
real x[ND_ND];
real y;
cell_t c;

begin_c_loop(c,t)
{

y=x[1];
if(1<y<1.425)
F_PROFILE(c,t,i)=0.39*(1+1.05*exp(-100*(y-1)/0.06));
else if(1.425<y<1.85)
F_PROFILE(c,t,i)=0.39*(1+1.05*exp(-100*(1.85-y)/0.06));
}
end_c_loop(c,t)
}

is it corresponding to the equation of porosity? And when we use udf for porosity so we have to write a udf for viscous resistance and inertial resistance as well , so should we interpereted and hook udfs respectively ?, It means we should first hook porosity_udf then viscous resistance_udf and inertial resistance_udf , isn’t it ?
I should also thank you since your advices help me in my project so far .
Best regards
Sarah
ComputerGuy is offline   Reply With Quote

Old   December 31, 2010, 14:36
Default
  #15
Member
 
sarah
Join Date: Aug 2010
Posts: 42
Rep Power: 15
sarah l is on a distinguished road
Dear ComputerGuy
Thank you for modification of my code , but now I have faced a funny problem! While I interpreting a udf , previous udf would be removed , for example , in my case ,first I interpreted and hooked udf of energy _source and then udf of porosity but I saw energy_source udf has been removed , what should I do till fluent accepts many udfs not only one . thanks
Best regards
Sarah
sarah l is offline   Reply With Quote

Old   December 31, 2010, 14:55
Default
  #16
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
Sarah,

Put all the UDF's in the same .c file. For instance:

#include "udf.h"

DEFINE_SOURCE()
{}

DEFINE_PROFILE()
{}

etc..

All of the appropriate functions will be available in the drop-down lists.

ComputerGuy
ComputerGuy is offline   Reply With Quote

Old   December 31, 2010, 18:36
Default
  #17
Member
 
sarah
Join Date: Aug 2010
Posts: 42
Rep Power: 15
sarah l is on a distinguished road
Dear ComputerGuy
Thank you so much! , however there is still a question for me , you declared that I use the same code which written for porosity for viscous and inertial resistances , but It is too hard since in my project these are defined as:
C1= (Dp^2 *porosity^3)/(150(1-porosity)^3)
C2=(3.5*(1-porosity))/(Dp*porosity^3))



So can I write a udf for them like this:
#include "udf.h"
DEFINE_PROFILE(inertial_res,t,i)

{
cell_t c;
begin_c_loop(c,t)
{
F_PROFILE(c,t,i) = 3.5*(1 - C_POR(c,t))
/(d_p*pow(C_POR(c,t),3));
}
end_c_loop(c,t)
}
C_POR(c,t) is porosity , so I have to modify porosity code of course I don’t know how do it! Could you help me?
Thanks
Sarah
sarah l is offline   Reply With Quote

Old   December 31, 2010, 19:52
Default
  #18
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
Sarah,

You need to use a similar format to the porosity function I wrote, not the same one.


Short of writing all the UDF's for you, here's what I'd suggest:
  1. Enable a user-defined memory location
  2. In your DEFINE_PROFILE function for porosity (already written below in this thread), also write the porosity to the C_UDMI(c,t,0)
  3. Create two new functions: one for C1 and one for C2 (DEFINE_PROFILEs)
  4. Using the definitions you've just written, define C1 and C2, but instead of using C_POR, which I didn't know existed as a built-in definition, you could simply use C_UDMI(c,t,0), because C_UDMI(c,t,0) now represents the porosity in the cell.
Are you trying to simulate a packed bed? If so, have you read the Fluent manual (specificially, look at equation 7.19-15 and 7.19-16) for the Ergun and Blake-Kozeny equations.

Regards,
ComputerGuy
ComputerGuy is offline   Reply With Quote

Old   January 1, 2011, 00:03
Default
  #19
Member
 
sarah
Join Date: Aug 2010
Posts: 42
Rep Power: 15
sarah l is on a distinguished road
Dear computerGuy
Yes , I am supposed to simulate a packed bed and I’ve read Fluent manual which related to porous media modeling , I ‘ve taken your advices and wrote this code:
#define C_UDMI(c,t,0) F_PROFILE(c,t,i)
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));
}

}

end_c_loop(c,t)
}
// inertial resistance udf .


DEFINE_PROFILE(inertial_res,t,i)

{
cell_t c;
begin_c_loop(c,t)
{
F_PROFILE(c,t,i) = 3.5*(1 - C_UDMI(c,t,0))
/(0.06*pow(C_UDMI(c,t,0),3));
}
end_c_loop(c,t)
}
//viscous resistance udf .

DEFINE_PROFILE(viscous_res,t,i)
{
cell_t c;
begin_c_loop(c,t)
{
F_PROFILE(c,t,i) = 150*pow((1 - C_UDMI(c,t,0)),2)
/(0.0036*pow(C_UDMI(c,t,0),3));
}
end_c_loop(c,t)
}


Is it correct? Of course I could hook it to fluent like porosity code which I had written my self but you modified it , really you suggested to enable a user-defined memory location, why?

Best regards
Sarah
sarah l is offline   Reply With Quote

Old   January 1, 2011, 00:23
Default
  #20
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
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
piyupant likes this.
ComputerGuy is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 15:10
strain rate in UDF Paulina FLUENT 11 November 20, 2014 04:06
UDF for critical strain rate to extinction Birute Bunkute FLUENT 1 March 25, 2010 16:40
surface reaction rate with udf yellow-stuff FLUENT 4 January 29, 2010 13:53
heat generation rate w/m3 in 2D Laszlo FLUENT 1 May 6, 2004 12:58


All times are GMT -4. The time now is 04:06.