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

map outlet boundary profile as an inlet condition using UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 18, 2014, 20:21
Default map outlet boundary profile as an inlet condition using UDF
  #1
Senior Member
 
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21
Daniel_Khazaei will become famous soon enough
Hello to all

I have a channel with arbitrary cross section and I need a fully developed velocity profile for the inlet.

I know that I can use write/read profile options in fluent, however I need to manipulate data as I need to know u/u_mean ratio for the cross section in fully developed condition.

Then I use the calculated ratio for the real transient boundary condition in my UDF.

So I have created a straight channel with the same cross section. Then I have used write profile option for velocity magnitude at the outlet.

After that, I have manually calculated velocity ratio.

I have two different input file:

1) mean transient velocity magnitude

2) velocity ratio

At the end, I need to apply transient fully developed velocity profile for the inlet. Here is the code:

Code:
#include "udf.h"

int size = 0;
real radius = 0.0;
float u_mean[1201];
float *u_ratio;

DEFINE_ON_DEMAND(readUmean)
{
    #if !RP_HOST
    int i = 0;
    FILE *fp_read;
    
    for (i=0;i<1201;i++)
    {
        u_mean[i] = 0.0;
    }
    
    fp_read = fopen("mean_velocity.txt","r");
    
    if (fp_read!=NULL)
    {
        Message("\nReading file");
        for (i=0;i<1201;i++)
        {
            fscanf(fp_read, "%f\n", &u_mean[i]);
        }
        Message("\nEnd of Reading file");
        Message("\n");
    }
    else
    {
        Message("\nError opening file");
        Message("\n");
        exit(EXIT_FAILURE);
    }
    fclose(fp_read);
    Message("First mean velocity: %.9f", u_mean[0]);
    Message("\n");
    #endif
}

DEFINE_ON_DEMAND(readUratio)
{
    #if !RP_HOST
    int j = 0;
    FILE *fp;
    Domain *d;
    Thread *t;
    d = Get_Domain(1);
    t = Lookup_Thread(d,11);
    
    size = THREAD_N_ELEMENTS_INT(t);
    u_ratio = (float *)malloc(size * sizeof(float));
    
    for (j=0;j<size;j++)
    {
        u_ratio[j] = 0.0;
    }
    
    fp = fopen("outlet_velocity_ratio.txt","r");
    
    if (fp!=NULL)
    {
        Message("\nReading file");
        for (j=0;j<size;j++)
        {
            fscanf(fp, "%f\n", &u_ratio[j]);
        }
        Message("\nEnd of Reading file");
        Message("\n");
    }
    else
    {
        Message("\nError opening file");
        Message("\n");
        exit(EXIT_FAILURE);
    }
    fclose(fp);
    Message("First ratio: %.9f", u_ratio[0]);
    Message("\n");
    #endif
}

DEFINE_PROFILE(z_velocity_unsteady,thread_unsteady,index_unsteady)
{
    #if !RP_HOST
    real current_time;
    real steady_offset;
    int counter;
    face_t f_unsteady;
    
    steady_offset = 4.0; //steady-state time
    current_time = CURRENT_TIME;
    
    counter = (current_time - steady_offset) / CURRENT_TIMESTEP;

    begin_f_loop(f_unsteady,thread_unsteady)
    {
        F_PROFILE(f_unsteady,thread_unsteady,index_unsteady) = u_mean[counter]*u_ratio[f_unsteady];
    }
    end_f_loop(f_unsteady,thread_unsteady)
    #endif
}

DEFINE_PROFILE(z_velocity_steady,thread_steady,index_steady)
{
    #if !RP_HOST
    face_t f_steady;

    begin_f_loop(f_steady,thread_steady)
    {
        F_PROFILE(f_steady,thread_steady,index_steady) = u_mean[0]*u_ratio[f_steady];
    }
    end_f_loop(f_steady,thread_steady)
    #endif
}
The problem is inconsistent order between faces in the thread and velocity ratio file which results in disordered velocity distribution at the inlet as you can see in the attached pictures.

I know the problem is here, when I use f_steady for the array index which means the written data and current face indexing is inconsistent:

Code:
F_PROFILE(f_steady,thread_steady,index_steady) = u_mean[0]*u_ratio[f_steady];
Attached Images
File Type: jpg correct_one.JPG (25.6 KB, 21 views)
File Type: jpg result.JPG (30.9 KB, 19 views)
Daniel_Khazaei is offline   Reply With Quote

Old   December 19, 2014, 04:34
Default
  #2
Senior Member
 
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21
Daniel_Khazaei will become famous soon enough
To further illustrate the problem, I want to know whether it is possible to do the following in a udf:

1) I have a file containing x,y,z and velocity magnitude for the outlet of a straight tube.

2) I want to map this velocity at the inlet of another case using a UDF ( I know I can read the profile using fluent itself but I need to do the same thing in my UDF)
Daniel_Khazaei is offline   Reply With Quote

Old   June 20, 2016, 12:53
Default
  #3
New Member
 
Join Date: May 2012
Posts: 2
Rep Power: 0
spoink is on a distinguished road
Hi,

have you achieved any success? If yes, I would highly appreciate if you could explain your final workflow.

Thanks in advance!
spoink 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
Problem with assigned inlet velocity profile as a boundary condition Ozgur_ FLUENT 5 August 25, 2015 05:58
Time dependant pressure boundary condition yosuke1984 OpenFOAM Verification & Validation 3 May 6, 2015 07:16
Pressure Inlet Boundary Condition Profile arapha FLUENT 0 April 4, 2011 17:23
Inlet and outlet boundary condition David Baker FLUENT 3 June 22, 2005 01:42
what the result is negatif pressure at inlet chong chee nan FLUENT 0 December 29, 2001 06:13


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