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

calculate integral in UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 2, 2012, 09:13
Default calculate integral in UDF
  #1
New Member
 
Yu-Pei Chen
Join Date: Jun 2011
Posts: 26
Rep Power: 15
ypchen is on a distinguished road
Hi, everybody.
My case has a heat flux cross the wall, and it's not a constant value.
The value is calculated by integrating the domain from z1 to z2, the variable in the integral is temperature (function of z), others are just some constants.
I wanna calculate the integral in UDF.
I have a idea by using "TRAPEZOIDAL RULE", but I don't now how to do it. Does anyone knows how to calculate integral in UDF or how to apply TRAPEZOIDAL RULE ??
thank you very much !
ypchen is offline   Reply With Quote

Old   January 2, 2012, 10:22
Default
  #2
Member
 
Join Date: Nov 2011
Location: Czech Republic
Posts: 97
Rep Power: 15
Sixkillers is on a distinguished road
Hi! You have two options how to solve this problem:

1) Write your own integration method (as you proposed)
2) Link your UDF against some numerical library (e.g. GSL) and use it inside your code.

If you are fine with number 1) and you don't need such robust integration routine. Here is my implementation of Gauss–Kronrod quadrature formula, which I use in my UDFs. It requires 15 function evaluation and its accuracy is comparable with trapezoidal rule when integration interval is divided into 100 parts.

PHP Code:
static const real nodes[7] =
{
    
0.991455371120813,
    
0.949107912342759,
    
0.864864423359769,
    
0.741531185599394,
    
0.586087235467691,
    
0.405845151377397,
    
0.207784955007898
};

static const 
real weights[8] =
{
    
0.022935322010529,
    
0.063092092629979,
    
0.104790010322250,
    
0.140653259715525,
    
0.169004726639267,
    
0.190350578064785,
    
0.204432940075298,
    
0.209482141084728
};

real gk15(real (*fce)(real), real areal b)
{
    
real trans1 = (b-a)/2.0;
    
real trans2 = (a+b)/2.0;

    
real integral 0.0;

    
int i;
    for(
07i++)
    {
        
integral += weights[i]*((*fce)(trans1*nodes[i] + trans2) + (*fce)(trans1*(-nodes[i]) + trans2));
    }

    
integral += weights[7]*(*fce)(trans2);

    return 
trans1*integral;

So you just have to pass pointer to your function, lower and upper integration limit (e.g. gk15(&myFun,0,10)).
Sixkillers is offline   Reply With Quote

Old   January 3, 2012, 10:14
Default
  #3
New Member
 
Yu-Pei Chen
Join Date: Jun 2011
Posts: 26
Rep Power: 15
ypchen is on a distinguished road
Thank for your reply, sixlillers.
Actually, I wanna calculate the heat flux at a cylinder wall, I need to get the temperature data near the wall so that I can calculate the temperature difference, so I have one more question : how do I get temperature data near the wall and how to use it in the UDF that you gave me to calculate the integral.
thank you ! ypchen
ypchen is offline   Reply With Quote

Old   January 3, 2012, 17:25
Default
  #4
Member
 
Join Date: Nov 2011
Location: Czech Republic
Posts: 97
Rep Power: 15
Sixkillers is on a distinguished road
Well I thought you need compute an integral of a scalar function (one variable). Fluent can compute surface integral by demand after simulation (Results -> Reports -> Surface Integrals) or you can setup a surface monitor, which will compute your desired integral and write its value to a file after each time step and then you will have to read it from your UDF.
Sixkillers is offline   Reply With Quote

Old   January 4, 2012, 08:53
Default Hi Six KIllers
  #5
New Member
 
Join Date: Dec 2011
Posts: 11
Rep Power: 15
saksham.pachar is on a distinguished road
I have a Problem in defining udf For Spanwise Average Nussel Number Along Flow

I have the .cas, .dat, and tecplot layout in my mail.
kindly give me your , so that I can mail them the entire problem.

Is it Possible to Integrate in Fluent

I can Plot h*X/k along z at a line along the flow on the bottom wall.
But there can be a lot of lines along the breadth.
I dont want to use excel.

Secondly i want the contours of Nussel no on the bottom plate, which I am able to show in Fluent, But I also want to show, the number along the contour, So that i can identify which contour is for which number

, how to calculate Nussel Number, and average Nussel Number In Tecplot, By Specifying Equations is also welcome
saksham.pachar 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
Drag coefficient, DPM. jorge poyatos FLUENT 14 January 20, 2012 14:41
UDF for Heat Exchanger model francois louw FLUENT 2 July 16, 2010 03:21
How to calculate the mass flow rate with UDF ? HP FLUENT 0 January 10, 2005 20:38
DEFINE_DPM_OUTPUT macro UDF HELP Puneet FLUENT 3 November 28, 2003 11:55
DEFINE_GEOM UDF Problems Pat FLUENT 0 August 14, 2003 14:16


All times are GMT -4. The time now is 21:57.