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/)
-   -   How to write a UDF (https://www.cfd-online.com/Forums/fluent-udf/103729-how-write-udf.html)

balaji June 25, 2012 07:06

How to write a UDF
 
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

flotus1 June 26, 2012 13:08

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.

balaji June 26, 2012 21:33

Thanks Alexander,

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

Thanks for your timely support

Balaji

flotus1 June 27, 2012 01:25

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)
}


balaji June 27, 2012 09:00

Thanks Alexander

I have solved the problem using your help.

Thanks Saeed

For your help anyways i have solved the problem


All times are GMT -4. The time now is 02:46.