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

How to write a UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 25, 2012, 07:06
Default How to write a UDF
  #1
New Member
 
Balaji
Join Date: Jun 2011
Posts: 9
Rep Power: 14
balaji is on a distinguished road
Dear all,

I need to write a UDF for pressure inlet boundary condition where i knew 10 data points of time vs pressure. Can someone help me in detailing the procedure to write such a UDF.

Thanks in advance
balaji is offline   Reply With Quote

Old   June 26, 2012, 13:08
Default
  #2
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
Assuming you want to interpolate the pressure linearly between the discrete values, something like this might do the trick

Code:
#include "udf.h"

DEFINE_PROFILE(pressure_profile,t,i)
{
    real tn[10];
    real pn[10];
    face_t f;
    int n;
    real time=RP_Get_Real("flow-time");

    tn[1]=2;
    tn[2]=3;
    //...and so on, here you may enter your data points

    pn[1]=4;
    pn[2]=7;
    //...and so on


    begin_f_loop(f,t)
    {
        for(n=10;n>0;n=n-1)
        {
            if(tn[n]<time)
            {
                F_PROFILE(f,t,i)=pn[n]+(time-tn[n])/(tn[n+1]-tn[n])*(pn[n+1]-pn[n]);
            }
        }
    }
    end_f_loop(f,t)
}
I didn't actually try this, so no guarantee. But it is sure something to start from.
flotus1 is offline   Reply With Quote

Old   June 26, 2012, 21:33
Default
  #3
New Member
 
Balaji
Join Date: Jun 2011
Posts: 9
Rep Power: 14
balaji is on a distinguished road
Thanks Alexander,

will try your suggestion and post whether it worked for me or not.

Thanks for your timely support

Balaji
balaji is offline   Reply With Quote

Old   June 27, 2012, 01:25
Default
  #4
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
Sorry I just found a little mistake:

Code:
#include "udf.h"

DEFINE_PROFILE(pressure_profile,t,i)
{
    real tn[10];
    real pn[10];
    face_t f;
    int n;
    real time=RP_Get_Real("flow-time");

    tn[1]=2;
    tn[2]=3;
    //...and so on, here you may enter your data points

    pn[1]=4;
    pn[2]=7;
    //...and so on


    begin_f_loop(f,t)
    {
        n=1;
        while(tn[n]<=time)
        {
            F_PROFILE(f,t,i)=pn[n]+(time-tn[n])/(tn[n+1]-tn[n])*(pn[n+1]-pn[n]);
            n++;
        }
    }
    end_f_loop(f,t)
}
flotus1 is offline   Reply With Quote

Old   June 27, 2012, 09:00
Default
  #5
New Member
 
Balaji
Join Date: Jun 2011
Posts: 9
Rep Power: 14
balaji is on a distinguished road
Thanks Alexander

I have solved the problem using your help.

Thanks Saeed

For your help anyways i have solved the problem
balaji 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
HOW to write udf for motion of piston and displacer? mani.rajendiran Fluent UDF and Scheme Programming 0 March 13, 2012 00:22
Fluent write UDF for calculating My, Mz and Fz davesmith_01 FLUENT 1 November 20, 2011 21:20
how write UDF lnjxhl FLUENT 3 March 3, 2010 08:32
how to write a 3D linear temperature of UDF venus FLUENT 1 October 28, 2008 02:46
UDF to read and write data Mcgregor FLUENT 4 June 9, 2003 13:21


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