8.2.1. Boundary Conditions

This section contains two applications of boundary condition UDFs.

8.2.1.1. Parabolic Velocity Inlet Profile in an Elbow Duct

Consider the elbow duct illustrated in Figure 8.10: The Mesh for the Elbow Duct Example. The domain has a velocity inlet on the left side, and a pressure outlet at the top of the right side.

Figure 8.10:  The Mesh for the Elbow Duct Example

The Mesh for the Elbow Duct Example

A flow field in which a constant x velocity is applied at the inlet will be compared with one where a parabolic x velocity profile is applied. While the application of a profile using a piecewise-linear profile is available with the boundary profiles option, the specification of a polynomial can be accomplished only by a user-defined function.

The results of a constant velocity (of 0.1 m/sec) at the inlet are shown in Figure 8.11: Velocity Magnitude Contours for a Constant Inlet x Velocity and Figure 8.12: Velocity Vectors for a Constant Inlet x Velocity. The consistent profile is seen to develop as the flow passes through the duct.

Figure 8.11:  Velocity Magnitude Contours for a Constant Inlet x Velocity

Velocity Magnitude Contours for a Constant Inlet x Velocity

Figure 8.12:  Velocity Vectors for a Constant Inlet x Velocity

Velocity Vectors for a Constant Inlet x Velocity

Now suppose that you want to impose a non-uniform x velocity to the duct inlet, which has a parabolic shape. The velocity is 0 m/s at the walls of the inlet and 0.1 m/s at the center.

A UDF is used to introduce this parabolic profile at the inlet. The C source code (vprofile.c) is shown below. The function makes use of ANSYS Fluent-supplied solver functions that are described in Face Macros.

The UDF, named inlet_x_velocity, is defined using DEFINE_PROFILE and has two arguments: thread and position. Thread is a pointer to the face’s thread, and position is an integer that is a numerical label for the variable being set within each loop.

The function begins by declaring variable f as a face_t data type. A one-dimensional array x and variable y are declared as real data types. A looping macro is then used to loop over each face in the zone to create a profile, or an array of data. Within each loop, F_CENTROID outputs the value of the face centroid (array x) for the face with index f that is on the thread pointed to by thread. The y coordinate stored in x[1] is assigned to variable y, and is then used to calculate the x velocity. This value is then assigned to F_PROFILE, which uses the integer position (passed to it by the solver based on your selection of the UDF as the boundary condition for x velocity in the Velocity Inlet dialog box) to set the x velocity face value in memory.

/***********************************************************************
   vprofile.c 
  UDF for specifying steady-state velocity profile boundary condition
 ************************************************************************/
 
 #include "udf.h"
 
 DEFINE_PROFILE(inlet_x_velocity, thread, position)
 {
    real x[ND_ND]; /* this will hold the position vector */
    real y, h;
    face_t f;
    h = 0.016; /* inlet height in m */
    begin_f_loop(f,thread)
      {
        F_CENTROID(x, f, thread);
        y = 2.*(x[1]-0.5*h)/h; /* non-dimensional y coordinate */
        F_PROFILE(f, thread, position) = 0.1*(1.0-y*y);
      }
    end_f_loop(f, thread)
 } 

To make use of this UDF in ANSYS Fluent, you will first need to interpret (or compile) the function, and then hook it to ANSYS Fluent using the graphical user interface. Follow the procedure for interpreting source files using the Interpreted UDFs dialog box (Interpreting a UDF Source File Using the Interpreted UDFs Dialog Box), or compiling source files using the Compiled UDFs dialog box (Compiling a UDF Using the GUI).

To hook the UDF to ANSYS Fluent as the velocity boundary condition for the zone of choice, open the Velocity Inlet dialog box and click the Momentum tab (Figure 8.13: The Velocity Inlet Dialog Box).

 Setup →   Boundary Conditions →   velocity-inlet → Edit...

Figure 8.13:  The Velocity Inlet Dialog Box

The Velocity Inlet Dialog Box

In the X-Velocity drop-down list, select udf inlet_x_velocity, the name that was given to the function above (with udf preceding it). Click OK to accept the new boundary condition and close the dialog box. Your user-defined profile will be used in the subsequent solution calculation.

After the solution is initialized and run to convergence, a revised velocity field is obtained as shown in Figure 8.14: Velocity Magnitude Contours for a Parabolic Inlet x Velocity and Figure 8.15: Velocity Vectors for a Parabolic Inlet x Velocity. The velocity field shows a maximum at the center of the inlet, which drops to zero at the walls.

Figure 8.14:  Velocity Magnitude Contours for a Parabolic Inlet x Velocity

Velocity Magnitude Contours for a Parabolic Inlet x Velocity

Figure 8.15:  Velocity Vectors for a Parabolic Inlet x Velocity

Velocity Vectors for a Parabolic Inlet x Velocity

8.2.1.2. Transient Pressure Outlet Profile for Flow in a Tube

In this example, a temporally periodic pressure boundary condition will be applied to the outlet of a tube using a UDF. The pressure has the form

The tube is assumed to be filled with air, with a fixed total pressure at the inlet. The pressure of the air fluctuates at the outlet about an equilibrium value () of 101325 Pa, with an amplitude of 5 Pa and a frequency of 10 rad/s.

The source file listing for the UDF that describes the transient outlet profile is shown below. The function, named unsteady_pressure, is defined using the DEFINE_PROFILE macro. The utility CURRENT_TIME is used to look up the real flow time, which is assigned to the variable t. (See Time-Dependent Macros for details on CURRENT_TIME).

/**********************************************************************
   unsteady.c 
  UDF for specifying a transient pressure profile boundary condition
 ***********************************************************************/
 
 #include "udf.h"
 
 DEFINE_PROFILE(unsteady_pressure, thread, position)
 {
    face_t f;
    real t = CURRENT_TIME;
    begin_f_loop(f, thread)
      {
        F_PROFILE(f, thread, position) = 101325.0 + 5.0*sin(10.*t);
      }
    end_f_loop(f, thread)
   
 } 

Before you can interpret or compile the UDF, you must specify a transient flow calculation in the General task page. Then, follow the procedure for interpreting source files using the Interpreted UDFs dialog box (Interpreting a UDF Source File Using the Interpreted UDFs Dialog Box), or compiling source files using the Compiled UDFs dialog box (Compiling a UDF Using the GUI).

The sinusoidal pressure boundary condition defined by the UDF can now be hooked to the outlet zone. In the Pressure Outlet dialog box (Figure 8.16: The Pressure Outlet Dialog Box), simply select the name of the UDF given in this example with the word udf preceding it (udf unsteady_pressure) from the Gauge Pressure drop-down list. Click OK to accept the new boundary condition and close the dialog box. Your user-defined profile will be used in the subsequent solution calculation.

 Setup →   Boundary Conditions →   pressure-outlet-5 → Edit...

Figure 8.16:  The Pressure Outlet Dialog Box

The Pressure Outlet Dialog Box

The time-stepping parameters are set in the Run Calculation task page (Figure 8.17: The Run Calculation Task Page).

 Solution →   Run Calculation

Figure 8.17:  The Run Calculation Task Page

The Run Calculation Task Page

In this example, a Time Step Size of 0.0314 s is used so that 20 time steps will complete a full period of oscillation in the outlet velocity. The Profile Update Interval is set to 1 so that the pressure will be updated every iteration. After 300 time steps (or 15 periods) are complete, you can examine the pressure and velocity magnitude across the pressure outlet.

To collect this information during the calculation, open the Surface Monitor dialog box (Figure 8.18: The Surface Monitor Dialog Box) before beginning the calculation.

 Solution → Monitors → Surface New...

Figure 8.18:  The Surface Monitor Dialog Box

The Surface Monitor Dialog Box

The Surface Monitor dialog box will display the default settings. You can rename the surface monitor by entering monitor-1 in the Name field. Then set the parameters in the Options group box. Enable Print to Console to see the changing values of the selected quantity in the console. Enable Plot so that the selected quantity will be plotted as the calculation proceeds. Enable Write so that the information will be written to a file, which will be given the name you enter in the File Name field (monitor-1.out). Select Flow Time from the X Axis drop-down list, and select Time Step in the drop-down list under Get Data Every.

Next, select Area-Weighted Average from the Report Type drop-down list. In the drop-down lists under Field Variable, select Pressure... and Static Pressure. Finally, select pressure-outlet-5 in the Surfaces selection list and click OK

In a similar manner, you can set up a second monitor to capture the velocity magnitude fluctuations in the pressure outlet.

After the first time step has been completed, the monitors should appear in the chosen plot windows. Alternatively, you can read the files by opening the File XY Plot dialog box (Figure 8.19: The File XY Plot Dialog Box).

 Results → Plots → File  Edit...

Figure 8.19:  The File XY Plot Dialog Box

The File XY Plot Dialog Box

You can read an output file by clicking Add... and selecting it in the Select File dialog box that opens and clicking OK. Then click the Plot button in the File XY Plot dialog box to obtain plots like those shown in Figure 8.20: Average Static Pressure at the Pressure Outlet and Figure 8.21: Average Velocity Magnitude at the Pressure Outlet.

Figure 8.20: Average Static Pressure at the Pressure Outlet nicely illustrates that the pressure oscillates around the equilibrium value, 101325 Pa, with an amplitude of 5 Pa, as expected.

Figure 8.20:  Average Static Pressure at the Pressure Outlet

Average Static Pressure at the Pressure Outlet

Figure 8.21:  Average Velocity Magnitude at the Pressure Outlet

Average Velocity Magnitude at the Pressure Outlet


Release 18.2 - © ANSYS, Inc. All rights reserved.