Advanced User Defined Function (UDF) Tutorials [PDF]

  • 0 0 0
  • Gefällt Ihnen dieses papier und der download? Sie können Ihre eigene PDF-Datei in wenigen Minuten kostenlos online veröffentlichen! Anmelden
Datei wird geladen, bitte warten...
Zitiervorschau

Advanced User Defined Function (UDF) Tutorials 1. Position Dependent Porous Media 2. Sinusoidal Wall Temperature Variation 3. Temperature Dependent Viscosity 4. UDFs for a User Defined Scalar 5. Modeling Uniform Fluidization in a Two Dimensional Fluidized Bed 6. Calculation of Flow Uniformity 7. Modeling the Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF 8. Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating

Membrane

Position Dependent Porous Media 1. Introduction The purpose of this tutorial is to illustrate the modeling of a position dependent porous plug in a two dimensional channel flow with the help of a user-defined function (UDF). This tutorial demonstrates how to do the following: • Compile the UDF. • Use UDF for specifying the source terms. • Postprocess the resulting data.

2. Prerequisites This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tutorial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some steps in the setup and solution procedure will not be shown explicitly. For more details about user-defined functions (UDF) refer to the ANSYS Fluent UDF Manual.

3. Problem Description The problem considered in this tutorial is shown schematically in Figure 1: Problem Schematic (p. 1) Figure 1: Problem Schematic

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

1

Position Dependent Porous Media The domain is divided into two fluid zones. In the fluid-2 cell zone, an X-momentum source term is included for each cell using UDF. This source term models the effect of a porous plug on the flow in the X-direction and is given by:

where C = 100 is a model constant. Equation source terms are added using the DEFINE_SOURCE macro. The finite-volume solver of ANSYS Fluent expects the source term to be linearized according to the following convention:

where the superscript * represents the value at the previous iteration. B (called dS[eqn]} in the UDF macro) can be coded explicitly by using currently known value of φ, and the entire S is returned by DEFINE_SOURCE. For the simple source of X-momentum equation in this problem,

For more details, examine the source code (porous plug.c) as shown in the Appendix (p. 9).

4. Preparation 1.

Copy the files (porous_plug.msh.gz and porous_plug.c) to the working folder.

2.

Use Fluent Launcher to start the 2D version of ANSYS Fluent.

3.

Enable Double-Precision in the Options list.

4.

Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.

Note The path to the .bat fie which is required to compile the UDF will be displayed as soon as you enable Setup Compilation Environment for UDF. If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default, click the Show More Options button to view the additional settings.

2

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

5. Setup and Solution 5.1. Mesh •

Read the mesh file (porous_plug.msh.gz). File → Read → Mesh...

Note As the mesh file is read, ANSYS Fluent will report the progress in the console. Figure 2: Mesh Display

5.2. General Settings 1.

Retain the default solver settings. General

2.

Check the mesh. General → Check

Note ANSYS Fluent will perform various checks on the mesh and will report the progress in the console. Ensure that the reported minimum volume is a positive number.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

3

Position Dependent Porous Media

5.3. Models •

Select the k-epsilon turbulence model. Models →

Viscous → Edit...

Note You will use the default fluid properties of air for this problem. Hence, you need not make any changes to the material properties.

5.4. Compile the UDF Note The UDF can be compiled as well as interpreted. In this tutorial, use the compiled option. Compile the UDF (porous plug.c). Define → User-Defined → Functions → Compiled...

1.

Click the Add... button in the Source Files section to open the Select File dialog.

2.

Select the file porous_plug.c.

3.

Click Build.

Note A Warning dialog box will appear, warning you to make sure that the UDF source files are in the same folder that contains the case and data files. Click OK to close the Warning dialog box. You can view the compilation history in the log file that is saved in your working folder. 4. 4

Click Load to load the library. Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

5.5. Cell Zone Conditions Set the cell zone conditions for the fluid-2. Cell Zone Conditions →

fluid-2 → Edit...

1.

Enable Source Terms and then click the Source Terms tab.

2.

Click Edit... for X Momentum to open the X Momentum sources dialog box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

5

Position Dependent Porous Media

3.

a.

Enter 1 for Number of X Momentum sources.

b.

Select udf xmom_source::libudf from the drop-down lists.

c.

Click OK to close the X Momentum sources dialog box.

Click OK to close the Fluid dialog box.

5.6. Boundary Conditions 1.

Set the boundary conditions for velocity-inlet-1. Boundary Conditions →

6

velocity-inlet-1 → Edit...

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

2.

a.

Enter 1 m/s for Velocity Magnitude.

b.

Select Intensity and Hydraulic Diameter from the Specification Method drop-down list in the Turbulence group box.

c.

Retain 5 % for Turbulent Intensity and enter 4 m for Hydraulic Diameter.

d.

Retain the default values for the other parameters.

e.

Click OK to close the Velocity Inlet dialog box.

Set the boundary conditions for pressure-outlet-1. Boundary Conditions →

pressure-outlet-1 → Edit...

a.

Retain 0 for Gauge Pressure.

b.

Retain the selection of Intensity and Viscosity Ratio from the Specification Method drop-down list in the Turbulence group box.

c.

Retain 5 % for Backflow Turbulent Intensity and 10 for Backflow Turbulent Viscosity Ratio.

d.

Retain the default values for the other parameters.

e.

Click OK to close the Pressure Outlet dialog box.

5.7. Solution 1.

Initialize the solution. Solution Initialization → Initialize

Note Hybrid Initialization is the default Initialization Method in ANSYS Fluent. Refer to the section 28.11 Hybrid Initialization, in the ANSYS Fluent User's Guide.

2.

Save the initial case file (porous_plug.cas.gz). File → Write → Case...

3.

Start the calculation for 100 iterations. Run Calculation → Calculate

Note The solution converges in approximately 33 iterations.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

7

Position Dependent Porous Media Figure 3: Scaled Residuals

4.

Save the data file (porous_plug.dat.gz). File → Write → Data...

5.8. Postprocessing 1.

Display the pressure contours. Graphics and Animations →

8

Contours → Set Up...

a.

Enable Filled in the Options list.

b.

Select Pressure... and Static Pressure from Contours of drop-down list.

c.

Click Display (Figure 4: Pressure Contours (p. 9)) and close the Contours dialog box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution Figure 4: Pressure Contours

2.

Display the velocity vectors contours. Graphics and Animations →

Vectors → Set Up...

Figure 5: Velocity Vectors

5.9. Appendix The contents of the UDF source code are as follows:

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

9

Position Dependent Porous Media /*******************************************************************/ /* */ /* Position-Dependent Porous Media */ /* */ /*******************************************************************/ #include "udf.h" DEFINE_SOURCE(xmom_source, cell, thread, dS, eqn) { const real c2=100.0; real x[ND_ND]; real con, source; C_CENTROID(x, cell, thread); con = c2*0.5*C_R(cell, thread)*x[1]; source = - con*fabs(C_U(cell, thread))*C_U(cell, thread); dS[eqn] = - 2.*con*fabs(C_U(cell, thread)); return source; }

5.10. Results Figure 4: Pressure Contours (p. 9) shows that fluid-2 is causing pressure drop in the system and thus acting as a porous plug. Figure 5: Velocity Vectors (p. 9) shows that the fluid flows preferentially near the bottom of the channel due to the effect of the source term on the axial momentum of the fluid.

5.11. Summary This tutorial demonstrated the use of UDF for specifying source terms. User-defined source terms can be useful for introducing additional physics into the simulation, and can usually be modeled as sources or sinks of mass, momentum, energy, species etc.

Note When you are comfortable with the present exercise, you can try modifying the UDF to specify momentum sources for both the X and Y momentum equations. The present UDF can be copied and suitably modified for the Y momentum equation. Both functions will then reside in the UDF file, and be accessible to the solver upon compilation.

10

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Sinusoidal Wall Temperature Variation 1. Introduction This tutorial examines fluid flow through a two dimensional channel, where one wall of the channel has user-defined temperature profile applied to it. The purpose of this tutorial is to demonstrate the ability of ANSYS Fluent to use user-defined functions (UDFs) to specify a position-dependent variable on the wall boundary condition. This tutorial demonstrates how to do the following: • Interpret the UDF. • Use UDF for specifying the profiles on boundaries. • Postprocess the resulting data.

2. Prerequisites This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tutorial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some steps in the setup and solution procedure will not be shown explicitly. For more details about user-defined functions (UDF) refer to the ANSYS Fluent UDF Manual.

3. Problem Description The problem considered in this tutorial is shown schematically in Figure 1: Problem Schematic (p. 2). Air at 300 K enters a 2D channel which has an insulated upper wall and a heated lower wall. The temperature on the lower wall varies sinusoidally with x-position according to:

The calculation will be performed assuming steady state, incompressible, and laminar flow in the channel.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

1

Sinusoidal Wall Temperature Variation Figure 1: Problem Schematic

4. Preparation 1.

Copy the files (channel.msh.gz and wallprof.c) to the working folder.

2.

Use Fluent Launcher to start the 2D version of ANSYS Fluent.

3.

Enable Double-Precision in the Options list.

4.

Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.

Note The path to the .bat fie which is required to compile the UDF will be displayed as soon as you enable Setup Compilation Environment for UDF. If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default, click the Show More Options button to view the additional settings.

5. Setup and Solution 5.1. Mesh Read the mesh file (channel.msh.gz). File → Read → Mesh...

Note As the mesh file is read, ANSYS Fluent will report the progress in the console.

2

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution Figure 2: Mesh Display

5.2. General Settings 1.

Retain the default solver settings. General

2.

Check the mesh. General → Check

Note ANSYS Fluent will perform various checks on the mesh and will report the progress in the console. Ensure that the reported minimum volume is a positive number.

5.3. Models Enable energy equation. Models →

Energy → Edit...

Note You will use the default fluid properties of air for this problem. Hence, you need not make any changes to the material properties.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

3

Sinusoidal Wall Temperature Variation

5.4. User-Defined Functions Note The UDF can be compiled as well as interpreted. In this tutorial, you will use the interpreted option. Interpret the UDF. Define → User-Defined → Functions → Interpreted...

1.

Click on the Browse... button.

2.

Select the source file (wallprof.c) in the Select File dialog box.

3.

Specify the C preprocessor to be used in the CPP Command Name field.

Note If you want to use the C preprocessor that ANSYS Fluent. has supplied, you can enable the Use Contributed CPP option.

4.

Retain the default value of 10000 for Stack Size.

Note The Stack Size should be 10000 unless the number of local variables in your function causes the stack to overflow. Its value should be set to a number that is greater than the number of local variables used.

5.

Click Interpret and close the Interpreted UDFs dialog box.

5.5. Boundary Conditions 1.

4

Set the boundary conditions for wall-1. Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution Boundary Conditions →

2.

wall-1 → Edit...

a.

Click the Thermal tab and select Temperature from the Thermal Conditions list.

b.

Select udf temperature_profile from the Temperature drop-down list.

c.

Retain the default values for the other parameters.

d.

Click OK to close the Wall dialog box.

Set the boundary conditions for velocity-inlet-1. Boundary Conditions →

velocity-inlet-1 → Edit...

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

5

Sinusoidal Wall Temperature Variation

a.

Select Components from the Velocity Specification Method drop-down list.

b.

Enter 1 m/s for X-Velocity.

c.

Click OK to close the Velocity Inlet dialog box.

5.6. Solution 1.

Change the Absolute Criteria for continuity to 0.0001. Monitors → Residuals → Edit...

2.

6

Initialize the solution.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution Solution Initialization → Initialize

Note Hybrid Initialization is the default Initialization Method in ANSYS Fluent. Refer to the section 28.11 Hybrid Initialization, in the ANSYS Fluent User's Guide.

3.

Save the initial case file (channel.cas.gz). File → Write → Case...

4.

Start the calculation for 100 iterations. Run Calculation → Calculate

Note The solution converges in approximately 47 iterations. Figure 3: Scaled Residuals

5.

Save the data file (channel.dat.gz). File → Write → Data...

5.7. Postprocessing Display the filled contours of static temperature. Graphics and Animations →

Contours → Set Up...

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

7

Sinusoidal Wall Temperature Variation 1.

Enable Filled in the Options list.

2.

Select Temperature... and Static Temperature from Contours of drop-down list.

3.

Click Display (Figure 4: Contours of Static Temperature (p. 8)) and close the Contours dialog box. Figure 4: Contours of Static Temperature

5.8. Appendix The contents of the UDF source code are as follows: /*******************************************************************/ /* */ /* User-Defined Functions for sinusoidal temperature profile */ /* */ /*******************************************************************/ include "udf.h" #define PI 3.141592654 DEFINE_PROFILE(temperature_profile, thread, position) { real r[3]; /* this will hold the position vector */ real x; face_t f; if (!Data_Valid_P()) return; begin_f_loop(f, thread) { F_CENTROID(r,f,thread); x = r[0]; F_PROFILE(f, thread, position) = 300.+100.*sin(PI*x/0.005); } end_f_loop(f, thread) }

8

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

5.9. Results The contour plot in Figure 4: Contours of Static Temperature (p. 8) shows that the temperature on the wall and in the fluid reaches a peak at the center of the channel due to the peak in the prescribed wall temperature.

5.10. Summary This tutorial demonstrated the use of UDF for specifying profiles on boundaries. You can apply this approach to the other boundary condition types such as pressure and velocity inlets, and pressure outlets. When you are comfortable with this problem, try modifying the UDF to specify heat flux rather than temperature. • Replace the following line in the udf code with the specified heat flux expression. temp = 300. + 100. * sin(pi * x/0.005) • Change the boundary condition type. • Hook the new profile to the wall boundary before running the new case.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

9

10

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Temperature Dependent Viscosity 1. Introduction This tutorial examines the flow of liquid metal through a two dimensional channel. The viscosity of the liquid metal is modeled as a function of the temperature using a user-defined function (UDF). This tutorial demonstrates how to do the following: • Interpret the UDF. • Use UDF for specifying the user-defined property. • Postprocess the resulting data.

2. Prerequisites This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tutorial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some steps in the setup and solution procedure will not be shown explicitly. For more details about user-defined functions (UDF) refer to the ANSYS Fluent UDF Manual.

3. Problem Description The problem considered in this tutorial is shown schematically in Figure 1: Problem Schematic (p. 1). As the symmetry condition is imposed at the centerline, only half the channel is modeled. The wall of the channel is split into two parts: wall-2, which has a temperature of 280 K and wall-3, which has a temperature of 290 K. The temperature-dependent viscosity of the liquid metal will respond to this change in wall temperature. Figure 1: Problem Schematic

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

1

Temperature Dependent Viscosity

Strategy The function cell_viscosity is defined on a cell using DEFINE_PROPERTY. Two real variables are introduced: • temp = the value of C_T (cell, thread). • mu = laminar viscosity (computed by the function). The value of the temperature is checked and based upon its range, the appropriate value of mu is computed. At the end of the function, the computed value for mu is returned to the solver. The molecular viscosity of the liquid metal will be defined as a function of temperature which is given as follows:

where, T = temperature of the fluid (K) µ = molecular viscosity of the fluid (kg/m-s).

4. Preparation 1.

Copy the files (user-vis.msh.gz and viscosity.c) to the working folder.

2.

Use Fluent Launcher to start the 2D version of ANSYS Fluent.

3.

Enable Double-Precision in the Options list.

4.

Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.

Note The path to the .bat fie which is required to compile the UDF will be displayed as soon as you enable Setup Compilation Environment for UDF. If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default, click the Show More Options button to view the additional settings.

5. Setup and Solution 5.1. Mesh Read the mesh file (user-vis.msh.gz).

2

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution File → Read → Mesh...

Note As the mesh file is read, ANSYS Fluent will report the progress in the console. Figure 2: Mesh Display

5.2. General Settings 1.

Retain the default solver settings. General

2.

Check the mesh. General → Check

Note ANSYS Fluent will perform various checks on the mesh and will report the progress in the console. Ensure that the reported minimum volume is a positive number.

5.3. Models Enable energy equation. Models →

Energy → Edit...

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

3

Temperature Dependent Viscosity

5.4. Interpret the UDF Interpret the UDF. Define → User-Defined → Functions → Interpreted...

1.

Click on the Browse... button.

2.

Select the source file (viscosity.c) in the Select File dialog box.

3.

Specify the C preprocessor to be used in the CPP Command Name field.

Note If you want to use the C preprocessor that ANSYS Fluent has supplied, you can enable the Use Contributed CPP option.

4.

Retain the default value of 10000 for Stack Size.

Note The Stack Size should be 10000 unless the number of local variables in your function causes the stack to overflow. Its value should be set to a number that is greater than the number of local variables used.

5.

Click Interpret and close the Interpreted UDFs dialog box.

5.5. Materials Modify the fluid material. Materials →

4

Fluid → Create/Edit...

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

1.

Enter liquid_metal for Name.

2.

Enter 8000 kg/m3 for Density.

3.

Enter 680 j/kg-k for Cp (Specific Heat).

4.

Enter 30 w/m-k for Thermal Conductivity.

5.

Select user-defined from the Viscosity drop-down list and click OK to close User-Defined Functions dialog box.

Note A Question dialog box opens, asking whether to overwrite air. Click Yes.

6.

Click Change/Create and close Create/Edit Materials dialog box.

5.6. Boundary Conditions 1.

Set the boundary conditions for wall-2. Boundary Conditions →

wall-2 → Edit...

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

5

Temperature Dependent Viscosity

2.

a.

Click the Thermal tab and select Temperature from the Thermal Conditions list.

b.

Enter 280 for Temperature.

c.

Retain the default values for the other parameters.

d.

Click OK to close the Wall dialog box.

Set the boundary conditions for wall-3. Boundary Conditions →

3.

a.

Click the Thermal tab and select Temperature from the Thermal Conditions list.

b.

Enter 290 for Temperature.

c.

Retain the default values for the other parameters.

d.

Click OK to close the Wall dialog box.

Set the boundary conditions for velocity-inlet-6. Boundary Conditions →

6

wall-3 → Edit...

velocity-inlet-6 → Edit...

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

4.

a.

Select Components from the Velocity Specification Method drop-down list.

b.

Enter 0.001 m/s for X-Velocity.

c.

Click the Thermal tab and enter 290 for Temperature.

d.

Click OK to close the Velocity Inlet dialog box.

Set the boundary conditions for pressure-outlet-7. Boundary Conditions →

pressure-outlet-7 → Edit...

a.

Click the Thermal tab and enter 290 for Temperature.

b.

Click OK to close the Velocity Inlet dialog box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

7

Temperature Dependent Viscosity

5.7. Solution 1.

Initialize the flow field from velocity-inlet-6. Solution Initialization

2.

a.

Select Standard Initialization from the Initialization Methods group box.

b.

Select velocity-inlet-6 from the Compute from drop-down list.

c.

Click Initialize.

Save the initial case file (temp-vis.cas.gz). File → Write → Case...

3.

Start the calculation for 300 iterations. Run Calculation → Calculate

Note The solution converges in approximately 215 iterations. Figure 3: Scaled Residuals

4.

Save the data file (temp-vis.dat.gz). File → Write → Data...

8

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

5.8. Postprocessing Display the filled contours of molecular viscosity.. Graphics and Animations →

Contours → Set Up...

1.

Enable Filled in the Options list.

2.

Select Properties... and Molecular Viscosity from Contours of drop-down list.

3.

Click Display (Figure 4: Contours of Molecular Viscosity (p. 9)) and close the Contours dialog box. Figure 4: Contours of Molecular Viscosity

5.9. Appendix The UDF (viscosity.c) is used to specify the temperature-dependent molecular viscosity in each cell. You can open the UDF in a separate editor and view its contents to understand the structure and function. The contents of the UDF file are as follows: /*******************************************************************/ /* */ /* User-Defined Function for temperature-dependent viscosity */ /* */ /*******************************************************************/ #include "udf.h"

DEFINE_PROPERTY(user_vis, cell, thread) { real temp, mu;

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

9

Temperature Dependent Viscosity temp = C_T(cell, thread); { /* If the temperature is high, use a small, constant viscosity */ if (temp > 288.) mu = 5.5e-3; /* Otherwise, use a profile to get higher viscosity values */ else if (temp >= 286. ) mu = 143.2135 - 0.49725 * temp; else mu = 1.0; } return mu; }

The above equations are applied to each and every cell which is associated to the thread (in this case a fluid zone). This UDF will be called from the Create/Edit Materials dialog box where the user-defined is specified for Viscosity.

5.10. Results Figure 4: Contours of Molecular Viscosity (p. 9) shows that when the warmer fluid enters the channel from the left and encounters the cooler wall further on, its viscosity increases according to the userdefined viscosity relation.

5.11. Summary This tutorial demonstrated the use of UDFs for specifying a user-defined property.

Important This capability is available only for viscosity and thermal conductivity (density and specific heat cannot be specified through UDFs).

Note When you are comfortable with this exercise, you can try modifying the UDF to specify temperature-dependent thermal conductivity. You can copy the source code for the viscosity UDF and change the appropriate lines to calculate thermal conductivity. You need to access the thermal conductivity UDF in the Create/Edit Materials dialog box in the same way as viscosity.

10

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

UDFs for a User-Defined Scalar 1. Introduction ANSYS Fluent solves the transport equation for a user-defined scalar (UDS) in the same way as it solves the transport equation for a scalar in the core equations, such as a species mass fraction. The UDS capability can be used to implement a wide range of physical models in magneto-hydrodynamics, electromagnetics, and more. In this tutorial you will learn to solve a general scalar diffusion equation with the possible types of boundary condition (BC) at the boundary (or a part of the boundary) of the domain.

The possible types of boundary conditions are as follows: • Dirichlet BC: Φ = D0 • Neumann BC: — Γ(∂Φ/∂n) = q0 • Mixed BC: — Γ(∂Φ/∂n) = hC( Φ – Φ∞) Here, D0, q0, hC, and Φ∞ are constant values. This tutorial demonstrates how to do the following: • Set the user defined scalar values. • Compile the UDF. • Postprocess the resulting data.

2. Prerequisites This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tutorial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some steps in the setup and solution procedure will not be shown explicitly. For more details about user-defined functions (UDF) refer to the ANSYS Fluent UDF Manual.

3. Problem Description As shown in the problem illustration, the problem is a 2D rectangle, with constant flux, constant value, and mixed boundary conditions along the boundary edges.

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

1

UDFs for a User-Defined Scalar For the problem, Γ = 0.162 W/(m K) Cp = Specific heat of the material [1650 J/(kg K)] Φ∞ = 550oC hC = 20 W/(m2K) Figure 1: Problem Schematic

4. Preparation 1.

Copy the files (laplace.msh.gz, mixedbc.c, and transientMixedBC.c) to the working folder.

2.

Use Fluent Launcher to start the 2D version of ANSYS Fluent.

3.

Enable Double-Precision in the Options list.

2

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution 4.

Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.

Note The path to the .bat fie which is required to compile the UDF will be displayed as soon as you enable Setup Compilation Environment for UDF. If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default, click the Show More Options button to view the additional settings.

5. Setup and Solution 5.1. Mesh •

Read the mesh file (laplace.msh.gz). File → Read → Mesh...

Note As the mesh file is read, ANSYS Fluent will report the progress in the console. Figure 2: Mesh Display

5.2. General Settings 1.

Retain the default solver settings. General

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

3

UDFs for a User-Defined Scalar 2.

Check the mesh. General → Check

Note ANSYS Fluent will perform various checks on the mesh and will report the progress in the console. Ensure that the reported minimum volume is a positive number.

5.3. User-Defined Functions 1.

Set the UDS value. Define → User-Defined → Scalars...

a.

Enter 1 for Number of User-Defined Scalars.

b.

Select none from Flux Function drop-down list.

c.

Click OK to close User-Defined Scalars dialog box.

Note Click OK in the Information dialog box that appears informing you of the change in the material properties or methods.

2.

Compile the UDF (mixedbc.c). Define → User-Defined → Functions → Compiled...

1.

Click the Add... button in the Source Files section to open the Select File dialog.

2.

Select the file mixedbc.c.

4

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution 3.

Click Build.

Note A Warning dialog box will appear, warning you to make sure that the UDF source files are in the same folder that contains the case and data files. Click OK to close the Warning dialog box. You can view the compilation history in the log file that is saved in your working folder. 4.

Click Load to load the library.

5.4. Materials Materials →

air → Create/Edit...

Create a new material (maple).

1.

Retain the default values for Density and Viscosity.

2.

Click Edit... for UDS Diffusivity and enter 0.162 for the Coefficient and close the UDS Diffusion Coefficients dialog box..

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

5

UDFs for a User-Defined Scalar

3.

Enter maple for the Name.

4.

Click Change/Create.

Note A Question dialog box appears, asking you whether to overwrite air. Click Yes.

5.

Close the Create/Edit Materials dialog box.

5.5. Boundary Conditions 1.

Set the boundary conditions for topwall. Boundary Conditions →

2.

a.

Click the UDS tab.

b.

Select Specified Value from the User Scalar 0 drop-down list in the User-Defined Scalar Boundary Condition group box.

c.

Enter 80 for UDS Scalar 0 in the User-Defined Scalar Boundary Value group box.

d.

Click OK to close the Wall dialog box.

Set the boundary conditions for leftwall. Boundary Conditions → a.

6

topwall → Edit...

leftwall → Edit...

Click the UDS tab.

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

3.

b.

Ensure that Specified Value is selected from the User Scalar 0 drop-down list in the User-Defined Scalar Boundary Condition group box.

c.

Retain 0 for UDS Scalar 0 in the User-Defined Scalar Boundary Value group box.

d.

Click OK to close the Wall dialog box.

Set the boundary conditions for rightwall. Boundary Conditions →

4.

rightwall → Edit...

a.

Click the UDS tab and select Specified Value from the User Scalar 0 drop-down list in the UserDefined Scalar Boundary Condition group box.

b.

Select udf scalarMixedBC::libudf from the User Scalar 0 drop-down list in the User-Defined Scalar Boundary Value group box.

c.

Click OK to close the Wall dialog box.

Set the similar boundary conditions for bottomwall as set for rightwall.

Note The following equation gives mixed boundary condition for rightwall and bottomwall.

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

7

UDFs for a User-Defined Scalar where, Γ = UDS diffusivity [0.162] hC = 20 Φ∞ = 550

5.6. Solution for Steady-State Solver 1.

Deselect the Flow equation. Solution Controls → Equations...

2.

Disable Check Convergence for uds-0. Monitors →

3.

Residuals → Edit...

Define a point monitor. Surface → Point...

4.

a.

Retain 0.025 for x0 (m) and 0.05 for y0 (m).

b.

Enter middlepoint for the Name.

c.

Click Create and close Point Surface dialog box.

Enable the plotting of the point monitor. Monitors (Surface Monitors) → Create...

8

a.

Enable Plot and Write.

b.

Retain the selection of Iteration from the X Axis and Get Data Every drop-down lists. Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

5.

c.

Select Sum from the Report Type drop-down list.

d.

Select User Defined Scalars... and Scalar-0 from the Field Variable drop-down lists.

e.

Select middlepoint from the Surfaces list.

f.

Click OK to close the Surface Monitor dialog box.

Initialize the solution. Solution Initialization → Initialize

Note Hybrid Initialization is the default Initialization Method in ANSYS Fluent. Refer to the section 28.11 Hybrid Initialization, in the ANSYS Fluent User's Guide.

6.

Save the initial case file (laplace.cas.gz). File → Write → Case...

7.

Start the calculation for 50 iterations. Run Calculation → Calculate

Note As the value of Φ remains constant after 40 iterations (Figure 3: Scaled Residuals (p. 9) and Figure 4: Monitor Plot (p. 10)), you can consider that the solution is converged. Figure 3: Scaled Residuals

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

9

UDFs for a User-Defined Scalar Figure 4: Monitor Plot

8.

Save the data file (laplace.dat.gz). File → Write → Data...

5.7. Postprocessing •

Display the contours of Φ. Graphics and Animations →

10

Contours → Set Up...

a.

Select User Defined Scalars... and Scalar-0 from the Contours of drop-down lists.

b.

Click Display and close the Contours dialog box.

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution Figure 5: Contours of Φ

Since the problem is partially set up in the steady case, here only the unique steps for the setup of the unsteady solver are mentioned.

5.8. Unsteady UDS Solver The unsteady diffusion problem represented by equation shown in Appendix B: Unsteady Solver (p. 17), over the same rectangular domain is solved by a first-order implicit formulation. The boundary condition is also unchanged. The initial condition is Φ = 80 through the domain. 1.

Read the case file laplace.cas.gz. File → Read → Case...

2.

Enable the transient solver. General →

3.

Transient

Compile the UDF (transientMixedBC.c). Define → User-Defined → Functions → Compiled... a.

Click Add... and select the source file, transientMixedBC.c.

b.

Enter libudf1 for the Library Name.

c.

Click Build to build the library.

Note A Warning dialog box opens, asking you to ensure that the UDF source files are in the same folder that contains the case and data files. Click OK.

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

11

UDFs for a User-Defined Scalar d. 4.

Click Load to load the newly created UDF library.

Select first-order unsteady UDF. Define → User-Defined → Scalars...

5.

a.

Retain Number of User-Defined Scalars to 1.

b.

Retain the selection of none from Flux Function drop-down list.

c.

Select unst1stOrder::libudf1 from Unsteady Function drop-down list.

d.

Click OK to close User-Defined Scalars dialog box.

Initialize the solution by setting User Scalar 0 to 80. Solution Initialization → Initialize

6.

Enter 10 for Autosave Every (Time Steps). Calculation Activities

7.

Set the time-stepping parameters. Run Calculation

8.

a.

Enter 0.1 s for Time Step Size.

b.

Enter 200 for Number of Time Steps.

c.

Enter 40 for Max Iterations/Time Step.

d.

Click Calculate.

Display the contours of Φ at t = 1 s. a.

Read the data file (laplace-1-00010.dat). File → Read → Data...

b.

Select User Defined Scalars... and Scalar-0 from the Contours of drop-down lists. Graphics and Animations →

c.

12

Contours → Set Up...

Click Display (Figure 6: Contours of Φ at t = 1 s (p. 13) ).

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution Figure 6: Contours of Φ at t = 1 s

9.

Similarly, display contours of at t = 3 s, t = 4 s, and t = 5 s by reading appropriate data files.

Note The diffusion of Φ into the domain due to high Φ∞ in the ambient is clearly visible via the mixed (convective) boundary condition. Figure 7: Contours of Φ at t = 3 s

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

13

UDFs for a User-Defined Scalar Figure 8: Contours of Φ at t = 4 s

Figure 9: Contours of Φ at t = 5s

6. Appendix A: Steady-State Solver Consider a steady-state scalar equation with constant Γ and zero source term (SΦ = 0) as follows: — ∇ . (Γ∇Φ) = 0 This is the Laplace's equation. Solving the Laplaces's equation using the ANSYS Fluent UDS solver does not necessarily require user-defined functions (UDFs). You can activate the UDS from the graphical user interface. ANSYS Fluent UDS provides only Dirichlet and Neumann conditions for the boundaries. Hence, you need to use the UDF to apply the mixed boundary condition for the UDS equation. 14

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Appendix A: Steady-State Solver

Formulation of the Mixed Boundary Condition Figure 10: Mixed Boundary Condition

For a generic cell c0 adjacent to the boundary, the diffusive flux across the boundary face f of the cell is expressed as follows:

Using the mid-point rule of surface integral, the diffusive flux can be approximated as:

In ANSYS Fluent, the diffusive flux is approximated in two parts: 1. The primary gradient is evaluated implicitly along the line connecting the cell centroid c0 to the centroid face f. 2. It is corrected by a secondary gradient (or cross diffusion) term evaluated explicitly by the gradient obtained from the previous iteration (

).

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

15

UDFs for a User-Defined Scalar

ANSYS Fluent provides you with two macros: • BOUNDARY_FACE_GEOMETRY(f, t, A, ds, es, A_by_es, dr0): a macro which defines the necessary geometrical variables of the cell. • BOUNDARY_SECONDARY_GRADIENT_SOURCE(source, SV_UDSI_G(i), dG, es, A_by_es, k): a macro which calculates the secondary gradient term in the above equation. If you designate the secondary gradient term in the above equation as β0, and Abe, equations can be written as:

Φf can be expressed as follows:

The mixed boundary condition for the UDS is ready to be specified by boundary profile Φf in the equation above through the UDF macro DEFINED_PROFILE().

UDF Code The UDF code for steady state is as follows: /***************************************************************************************/ /* Implementation of the mixed boundary condition for a UDS (or multiple): */ /* q = hC ( phi - PHI_inf) */ /***************************************************************************************/ #include "udf.h" #include "sg.h" /* needed for the boundary and secondary gradient macros */ /*=====================================================================================*/ #define CP 1650.0 /* heat capacity for maple in (J/kg K) */ #define HTC 20.0 /* heat transfer coefficient for the problem */ #define TINF 550 /* ambient temperature of the problem */ /*=====================================================================================*/ /* Names of the user-defined scalar to be used */ enum { phi1, N_REQUIRED_UDS };

16

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

as

Appendix B: Unsteady Solver DEFINE_PROFILE(scalarMixedBC, thread, nv) { /*constants must be specified correctly for the mixed BC */ real hC, PHI1_inf; /* ====================== */ face_t f; real A[ND_ND], dG[ND_ND], dr0[ND_ND], es[ND_ND], dr, A_by_es; real Af; real beta0, gamma; real temp1, temp2; Thread *t0=thread->t0; hC=HTC; PHI1_inf=TINF; begin_f_loop(f, thread) { /* identify the cell thread adjecent to the face thread f */ cell_t c0 = F_C0(f, thread); BOUNDARY_FACE_GEOMETRY(f, thread, A, dr, es, A_by_es, dr0); Af=NV_MAG(A); gamma=C_UDST_DIFF(c0, t0, phi1); if (NULLP(T_STORAGE_R_NV(t0, SV_UDST_G(phi1)))) beta0=0; /*if gradient is not allocated and stored yet, bypass the following macro (it happens when case/data files are being read */ else BOUNDARY_SECONDARY_GRADIENT_SOURCE(beta0, SV_UDSI_G(phi1), dG, es, A_by_es, gamma); /* temporary variables used in the profile expression */ temp1=gamma*A_by_es/dr; temp2=hC*Af; F_PROFILE(f, thread, nv) = (temp1*C_UDSI(c0, t0, phi1)- beta0 + temp2*PHI1_inf)/(temp2 + temp1); } end_f_loop(f, thread) } }

7. Appendix B: Unsteady Solver The unsteady user-defined scalar equation is as follows:

It has to be solved with the same boundary conditions and given initial condition. When the transient term is ∂(ρΦ)/∂t, ANSYS Fluent can readily handle this unsteady UDS term when you enable the unsteady solver (either first or second-order). But if the transient term of the user's equation is not the same as the given form, you must supply the unsteady term through the DEFINE_UDS_UNSTEADY() macro. For example, in the above equation, c is a variable. For an unsteady heat conduction problem in dimensional form it represents ρcp of the solid material.

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

17

UDFs for a User-Defined Scalar

First-Order Unsteady Formulation In finite-volume methods, the transient term is first approximated by first or second-order finite-difference expression, then integrated with respect to the cell volume. The ANSYS Fluent solver expects this transient term to be moved to the right-hand side of the governing equation and included in the discretized equation as a source term. The first-order finite-difference backward differencing approximation gives:

where, Φn = the value of Φ at the current time level Φn-1 = the value at the previous time level ∆t = the time-step size Hence,

where, ∆V = the volume of each individual cell Apu = the coefficient multiplying n (the implicit part) Su = the explicit part (because it is expressed by known values at the previous time-step) You can rewrite the volume integral of the unsteady term as:

and it is ready to be coded in the unsteady macro DEFINE_UDS_UNSTEADY().

UDF Code The UDF code for unsteady solver is as follows:

18

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Further Improvements /**************************************************************************************/ /* Implementation of */ /* */ /* the unsteady term for the user-defined scalar (1st-order) */ /* */ /**************************************************************************************/ DEFINE_UDS_UNSTEADY(unst1stOrder, c, t, i, apu, su) { /* if the unsteady term is different from the default term: d(rho*phi) ---------dt this macro is used to specify the appropriate unsteady term

*/

real volume, cp=CP, deltaTime=CURRENT_TIMESTEP; volume=C_VOLUME(c, t); /* the transient term is moved to the RHS of the equation and is split into two parts---check the FVM algorithm for detail. First-order backward differencing is implemented below:

*/

*apu = -cp*volume/deltaTime; *su = cp*volume*C_UDSI_M1(c, t, i)/deltaTile; }

Note Before compiling the source code, add the program fragment to the code given in Appendix A: Steady-State Solver (p. 14). The complete UDF is in transientMixedBC.c.

8. Further Improvements It can be shown that the following finite-difference backward differencing approximation to ∂Φ/∂t is second-order accurate in time:

It involves the values of Φ at three different time levels: Φn,Φn-1, and Φn-2. You can use the first-order implicit UDF code in the appendix as a useful guide to come up with your own second-order implicit unsteady UDF code. A few hints for the exercise: • In the first step of unsteady simulation (n = 1), Φn–2 is not available yet (Φn-1 condition). Therefore you can use the first-order formulation in this step in order to advance to the second time step (n = 2). • Φn–2 is represented by C_UDSI_M2(c, t, i) for each cell. • The transient term is moved to the right hand side of the equation as a source term. Hence, remember to get the signs right. • Select second-order unsteady formulation before starting the iteration.

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

19

UDFs for a User-Defined Scalar

Non-Constant Source Term You can implement a non-constant source term in the equation. The macro, DEFINE_SOURCE (name, c, t, dS, eqn) is called to represent SΦ. The finite-volume solver of ANSYS Fluent expects the source term to be linearized according to the following convention:

where, * = Value at the previous iteration A = source B = dS[eqn] A and B can be coded explicitly by using currently known value of Φ. The general UDF for all variables is DEFINE_SOURCE(). To use it for a UDS (Φ), you need to hook it up in the boundary condition dialog box to the cell zone where Φ is be solved. There are various ways to linearize a source term, but the general requirement is that B (the slope) should be non-positive to enhance convergence of the iterative solution process. The convergence is better with more negative slope.

9. Summary In this tutorial, you modeled the UDS scalar diffusion equation by using UDFs in ANSYS Fluent. Some details of the finite-volume method used by the solver were carefully discussed when implementing terms in the governing equation and BC. However, treatment of the advective term∇. general flux vector), is not covered here.

20

Release 16.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Φ(

is the

Modeling Uniform Fluidization in 2D Fluidized Bed 1. Introduction The prediction of pressure drop in a uniformly fluidized bed is a problem of long standing interest in the process industry. The Eulerian models in ANSYS Fluent provide an important modeling tool for studying dense phase particulate flow involving complex inter-phase momentum transfer. Despite rigorous mathematical modeling of the associated physics, the drag laws used in the model continue to be semi-empirical in nature. Therefore, it is crucial to use a drag law that correctly predicts the incipient or minimum fluidization conditions where the bed of particles is essentially in a state of suspension as a result of the balance between interfacial drag and body forces. The purpose of this tutorial is to study the hydrodynamics and bubble formation in a fluidized bed over a period of time. It also demonstrates how to customize a drag law for granular gas-solid flow. This tutorial demonstrates how to do the following: • Customize a drag law for granular gas-solid flow. • Use the Eulerian models to predict the pressure drop in an uniformly fluidized bed. • Solve the case using appropriate solver settings. • Postprocess the resulting data.

2. Prerequisites This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tutorial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some steps in the setup and solution procedure will not be shown explicitly. This tutorial will not cover the mechanics of using the Eulerian models. It will focus on the application of these models. For more information refer to Section 25.5 Setting Up the Eulerian Model in the ANSYS Fluent User's Guide. For information about user-defined functions (UDF) refer to the ANSYS Fluent UDF Manual.

3. Problem Description One of the drag laws in ANSYS Fluent is the Syamlal-O'Brien drag law. This law works for a large variety of problems, but has to be tuned properly for predicting the minimum fluidization conditions accurately. The default Syamlal-O'brien drag law is as follows: The fluid-solid exchange coefficient is

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

1

Modeling Uniform Fluidization in 2D Fluidized Bed

where υr,s is the terminal velocity coefficient for the solid phase.

with A = αl4.14 and B = 0.8 αl1.28 for α ≤ 0:85 and with B = αl2.65 2 for α ≥ 0:85 Figure 1: Problem Schematic

The default constants of 0.8 and 2.65 predict a minimum fluidization of 21 cm/s. The experimentally observed minimum fluidization for this particular case is 8 cm/s. Therefore, by changing the constants we can tune the drag law to predict minimum fluidization at 8 cm/s. After some mathematical manipu-

2

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution lation, these constants come out to be 0.281632 and 9.07696 respectively. Therefore, these values have to be used to predict the correct bed behavior and are passed to the code through user-defined functions. The problem considered is a 1m x 0.15m fluidized bed as shown in Figure 1: Problem Schematic (p. 2). The inlet air enters in at 0.25 m/s and the top is modeled as a outflow. The bed is packed with granular solids at 0.55 volume fraction (close to packing).

4. Preparation 1.

Copy the files (bp.msh.gz and bp_drag.c) to the working folder.

2.

Use Fluent Launcher to start the 2D version of ANSYS Fluent.

3.

Enable Double-Precision in the Options list.

4.

Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.

Note The path to the .bat fie which is required to compile the UDF will be displayed as soon as you enable Setup Compilation Environment for UDF. If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default, click the Show More Options button to view the additional settings.

5. Setup and Solution Note All entries in setting up this case are in SI units, unless otherwise specified.

5.1. Mesh Read the mesh file (bp.msh.gz). File → Read → Mesh...

Note As the mesh file is read, ANSYS Fluent will report the progress in the console.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

3

Modeling Uniform Fluidization in 2D Fluidized Bed Figure 2: Mesh Display

5.2. General Settings 1.

Enable the transient solver by selecting Transient from the Time list. General →

2.

Transient

Check the mesh. General → Check

Note ANSYS Fluent will perform various checks on the mesh and will report the progress in the console. Ensure that the reported minimum volume is a positive number.

5.3. Models Select the Eulerian multiphase model. Models →

Multiphase → Edit...

1.

Select Eulerain from the Model list.

2.

Retain the default settings and click OK to close the Multiphase Model dialog box.

5.4. Materials 1.

4

Modify the properties for air.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution Materials →

2.

air → Create/Edit...

a.

Enter 1.2 kg/m3 for Density.

b.

Enter 1.8e-05 kg/m-s for Viscosity.

c.

Click Change/Create.

Define a material called solids.

a.

Enter solids for Name.

b.

Enter 2600 kg/m3 for Density and 1.7894e-05 kg/m-s for Viscosity.

c.

Click Change/Create.

Note A Question dialog box will appear asking if you want to overwrite air. Click No.

3.

Close the Create/Edit Materials dialog box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

5

Modeling Uniform Fluidization in 2D Fluidized Bed

5.5. Compile the UDF Note The UDF contains two arguments s_col and f_col. These refer to the indices of the phases appearing in the second and first columns of the table in the interaction dialog box respectively. Therefore in this case s_col refers to the index of gas phase which is 0 and f_col refers to the index for solids which is equal to 1. Define → User-Defined → Functions → Compiled...

1.

Click the Add... button in the Source Files section to open the Select File dialog.

2.

Select the file bp_drag.c.

3.

Enter lib_drag for Library Name.

4.

Click Build.

Note A Warning dialog box will appear, warning you to make sure that the UDF source files are in the same folder that contains the case and data files. Click OK to close the Warning dialog box. You can view the compilation history in the log file that is saved in your working folder. 5.

Click Load to load the library.

5.6. Phases 1.

Define primary phase. Phases →

6

phase-1 → Edit...

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

2.

a.

Enter gas for Name.

b.

Ensure air is selected from the Phase Material drop-down list.

c.

Click OK to close the Primary Phase dialog box.

Define secondary phase. Phases →

phase-2 → Edit...

a.

Enter solid for Name.

b.

Select solids from the Phase Material drop-down list. Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

7

Modeling Uniform Fluidization in 2D Fluidized Bed c.

Enable Granular.

d.

Enter 0.0003 m for Diameter, and select syamlal-obrien from the Granular Viscosity dropdown list.

e.

Retain the default values for the other parameters.

f.

Click OK to close the Secondary Phase dialog box.

Note Check the column numbers where the two phases appear in the Phase Interaction dialog box. In this case solid and gas appear in the first and second columns respectively. These columns are used to specify the phase indices in the argument list for the UDF.

3.

Set the drag coefficient. Phases → Interaction...

Click the Interaction... button to open the Phase Interaction dialog box. a.

In the Drag tab, select user-defined from the drop-down list in the Drag Coefficient group box.

i. 8

Ensure that custom_drag_syam::lib drag is selected. Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution ii. b.

Click OK to close the User-Defined Functions dialog box.

Click OK to close the Phase Interaction dialog box.

5.7. Boundary Conditions Set the boundary conditions for vinlet zone. Boundary Conditions →

1.

2.

vinlet

Select gas from the Phase drop-down list and click Edit.... a.

Select Components from the Velocity Specification Method drop-down list.

b.

Enter 0.25 m/s for Y-Velocity.

c.

Click OK to close the Velocity Inlet dialog box.

Select solid from the Phase drop-down list and click the Edit... button to open the Velocity Inlet dialog box. a.

Click the Multiphase tab.

b.

Ensure that Volume Fraction is 0.

c.

Click OK to close the Velocity Inlet dialog box.

5.8. Operating Conditions Boundary Conditions → Operating Conditions...

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

9

Modeling Uniform Fluidization in 2D Fluidized Bed

1.

Enable Gravity and enter -9.81 m/s2 for Gravitational Acceleration in the Y direction.

2.

Enable Specified Operating Density, and enter 1.2 kg/m3 for Operating Density.

3.

Click OK to close the Operating Conditions dialog box.

5.9. Solution 1.

Mark a region for adaption. Adapt → Region...

10

a.

Enter 0.15 m for X Max and Y Max in the Input Coordinates group box.

b.

Click Mark to mark the cells for refinement. Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution c.

Close the Region Adaption dialog box.

Note You can display and manipulate the generated adaption registers using the Manage... button in the Region Adaption dialog box.

2.

Set the solution control parameters. Solution Controls

3.

a.

Enter 0.5 for Pressure in the Under-Relaxation Factors group box.

b.

Enter 0.2 for Momentum.

c.

Enter 0.4 for Volume Fraction.

Initialize the flow with default values. Solution Initialization → Initialize

4.

Patch the solids volume fraction for hexahedron-r0. Solution Initialization → Patch...

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

11

Modeling Uniform Fluidization in 2D Fluidized Bed

a.

Select solid from the Phase drop-down list.

b.

Select Volume Fraction from the Variable list.

c.

Enter 0.55 for the Value.

d.

Select hexahedron-r0 from the Registers to Patch list.

Note If you wish to patch a constant value, enter that value in the Value field. If you want to patch a previously-defined field function, enable the Use Field Function option and select the appropriate function in the Field Function list.

5.

e.

Click Patch.

f.

Close the Patch dialog box.

Enable autosaving of the data files for every 100 time steps. Calculation Activities

6.

Set up commands for animation. Calculation Activities (Execute Commands) → Create/Edit...

12

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

7.

a.

Set 3 for Defined Commands.

b.

Enable Active for all the commands.

c.

Set 10 for Every for all the commands.

d.

Select Time Step from the When drop-down list for all.

e.

Enter /display/set-window 2 for command-1.

f.

Enter /display/contour/solid/vof 0 0.53 for command-2.

g.

Enter /display/hardcopy "vof-solids-%t.tiff" for command-3.

h.

Click OK to close the Execute Commands dialog box.

Set the graphics hardcopy format. File → Save Picture...

8.

9.

a.

Select TIFF from the Format list.

b.

Select Color from the Coloring list.

c.

Click Apply and close the Save Picture dialog box.

Set up the contours display. a.

Enable Filled from the Options group box.

b.

Select Phases... and Volume Fraction from the Contours of drop-down lists.

c.

Select solid from the Phase drop-down list.

d.

Click Display and close the Contours dialog box.

Save the initial case file (bp.cas.gz). Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

13

Modeling Uniform Fluidization in 2D Fluidized Bed File → Write → Case... 10. Start the calculation. Run Calculation

a.

Enter 0.001 for Time Step Size.

b.

Enter 1400 for Number of Time Steps.

c.

Enable Extrapolate Variables.

d.

Click Calculate.

11. Save the data file (bp.dat.gz). File → Write → Data...

5.10. Postprocessing 1.

Display contours of volume fraction. a.

14

Read the data file for the 200th time step (bp-1-00200.dat).

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution File → Read → Data... b.

Display filled contours of volume fraction for solid, at 0.2 sec (Figure 3: Contours of Volume Fraction of solid (t = 0.2 s) (p. 15)). Graphics and Animations

Contours → Set Up...

Figure 3: Contours of Volume Fraction of solid (t = 0.2 s)

c.

Similarly display contours at 0.9 sec (Figure 4: Contours of Volume Fraction of solid (t = 0.9 s) (p. 15)), and 1.4 sec (Figure 5: Contours of Volume Fraction of solid (t = 1.4 s) (p. 16)). Figure 4: Contours of Volume Fraction of solid (t = 0.9 s)

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

15

Modeling Uniform Fluidization in 2D Fluidized Bed Figure 5: Contours of Volume Fraction of solid (t = 1.4 s)

2.

View the animation for the fluidization process using the .tiff files.

5.11. Results Typically, the constants set to 0.8 and 2.65 in the default Syamlal-O'Brien drag law have to be modified to balance the interfacial drag with the weight of the bed at minimum fluidization. If this is not done, the correct bubbling pattern will not be predicted, leading to incorrect predictions of pressure drop which is the most important objective of such simulations.

16

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Calculation of Flow Uniformity 1. Introduction The purpose of this tutorial is to provide guidelines and recommendations for setting up and solving a flow uniformity problem with the help of a user-defined function (UDF). This tutorial demonstrates how to do the following: • Modify the UDF for a specific case. • Use the UDF to calculate the flow uniformity indexes for steady-state flow.

2. Prerequisites This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tutorial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some steps in the setup and solution procedure will not be shown explicitly. For more details about user-defined functions (UDF) refer to the ANSYS Fluent UDF Manual.

3. Problem Description The problem considers a 3D flow passage. A schematic of the problem is shown in Figure 1: Problem Schematic (p. 2). There are two flow inlets and an outlet. The postprocessing planes (post-01, post02, post-03, and post-04) have already been created with the mesh.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

1

Calculation of Flow Uniformity Figure 1: Problem Schematic

4. Preparation 1.

Copy the files (flow-uniformity.msh.gz, cat-general.c, and input.txt) to the working folder.

2.

Use Fluent Launcher to start the 3D version of ANSYS Fluent.

3.

Enable Double-Precision in the Options list.

4.

Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.

Note The path to the .bat fie which is required to compile the UDF will be displayed as soon as you enable Setup Compilation Environment for UDF. If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default, click the Show More Options button to view the additional settings.

5. Setup and Solution 5.1. Mesh Read the mesh file (flow-uniformity.msh.gz).

2

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution File → Read → Mesh...

Note As the mesh file is read, ANSYS Fluent will report the progress in the console. Figure 2: Mesh Display

5.2. General Settings 1.

Retain the default solver settings. General

2.

Check the mesh. General → Check

Note ANSYS Fluent will perform various checks on the mesh and will report the progress in the console. Ensure that the reported minimum volume is a positive number.

3.

Scale the mesh to centimeters. General → Scale... a.

Select cm from Mesh Was Created In drop-down list.

b.

Click Scale and close Scale Mesh dialog box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

3

Calculation of Flow Uniformity

5.3. Models Select the k-epsilon turbulence model. Models →

Viscous → Edit...

Note You will use the default fluid properties of air for this problem. Hence, you need not make any changes to the material properties.

5.4. Boundary Conditions 1.

Set the boundary conditions for vel-in-large. Boundary Conditions →

4

vel-in-large → Edit...

a.

Retain selection of Magnitude, Normal to Boundary from the Velocity Specification Method drop-down list.

b.

Enter 0.5 m/s for Velocity Magnitude.

c.

Select Intensity and Hydraulic Diameter from the Specification Method drop-down list.

d.

Retain 5 % for Turbulent Intensity.

e.

Enter 0.06 m for Hydraulic Diameter.

f.

Click OK to close the Velocity Inlet dialog box. Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution 2.

Set the boundary conditions for vel-in-small. Boundary Conditions →

3.

vel-in-small → Edit...

a.

Retain selection of Magnitude, Normal to Boundary from the Velocity Specification Method drop-down list.

b.

Enter 2 m/s for Velocity Magnitude.

c.

Select Intensity and Hydraulic Diameter from the Specification Method drop-down list.

d.

Retain 5 % for Turbulent Intensity.

e.

Enter 0.02 m for Hydraulic Diameter.

f.

Click OK to close the Velocity Inlet dialog box.

Set the boundary conditions for press-out. Boundary Conditions →

press-out → Edit...

a.

Retain selection of Normal to Boundary from the Backflow Direction Specification Method drop-down list.

b.

Select Intensity and Hydraulic Diameter from the Specification Method drop-down list.

c.

Retain 5 % Backflow Turbulent Intensity.

d.

Enter 0.06 m for Backflow Hydraulic Diameter.

e.

Click OK to close the Pressure Outlet dialog box.

5.5. Solution 1.

Initialize the flow field from vel-in-large. Solution Initialization

2.

a.

Select Standard Initialization from the Initialization Methods group box.

b.

Select vel-in-large from the Compute from drop-down list.

c.

Click Initialize.

Save the initial case file (flow-1.cas.gz). File → Write → Case...

3.

Start the calculation for 150 iterations.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

5

Calculation of Flow Uniformity Run Calculation → Calculate

Note The solution will converge in approximately 100 iterations.

4.

Save the data file (flow-1.dat.gz). File → Write → Data...

5.6. Postprocessing 1.

Display the filled contours of velocity magnitude. Graphics and Animations →

Contours → Set Up...

a.

Enable Filled in the Options list.

b.

Select Velocity... and Velocity Magnitude from Contours of drop-down list.

c.

Select post-01, post-02, post-03, and post-04 from the Surfaces list.

d.

Enable Draw Mesh in the Options group box.

Note The Mesh Display dialog box will open.

e. 2.

i.

Enable Edges and disable Faces in the Options group box.

ii.

Select all the surfaces except the default-interior ones from the Surfaces list.

iii.

Click Display and close Mesh Display dialog box.

Click Display and close the Contours dialog box.

Manipulate the display using the Scene Description dialog box. Graphics and Animations → Scene...

6

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

a.

Select the surfaces wall, press-out, vel-in-large, vel-in-small, wall:014, wall:016, wall:017, under the list of Names in the Scene Description dialog box.

b.

Click Display... in the Geometry Attributes group box to open the Display Properties dialog box.

i.

Enable Lighting in the Visibility group box.

ii.

Disable Edges, Lines, and Nodes in the Visibility group box.

iii.

Enable Outer Faces in the Visibility group box.

iv.

Set the sliders for Red, Green, and Blue to 255 in the Colors group box.

v.

Set the slider for Transparency to 80.

vi.

Click Apply and close the Display Properties dialog box (Figure 3: Contours of Velocity Magnitude (p. 8)). Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

7

Calculation of Flow Uniformity Figure 3: Contours of Velocity Magnitude

c. 3.

Close Scene Description dialog box.

Display velocity vectors (see Figure 4). Figure 4: Velocity Vectors Colored by Velocity Magnitude

4.

8

Calculate the flow uniformity.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution a.

Set up the input file (input.txt).

Note The input file (input.txt) has to be processed before executing the UDF. For the details about the input file, see Appendix A: Details of the Input File (p. 10).

b.

Set the Number of User-Defined Memory Locations to 4. Define → User-Defined → Memory...

c.

Save the case file (flow.cas.gz). File → Write → Case...

d.

Compile the UDF (mixedbc.c). Define → User-Defined → Functions → Compiled...

i.

Click the Add... button in the Source Files section to open the Select File dialog.

ii.

Select the file cat-general.c.

Note For details about the UDF file (cat-general.c), refer to Appendix B: Contents of UDF (p. 11).

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

9

Calculation of Flow Uniformity iii.

Click Build.

Note A Warning dialog box will appear, warning you to make sure that the UDF source files are in the same folder that contains the case and data files. Click OK to close the Warning dialog box. You can view the compilation history in the log file that is saved in your working folder. iv. e.

Click Load to load the library.

Execute the UDF. Define → User-Defined → Execute on Demand...

f.

i.

Select Uniform_steady::libudf from the Execute On Demand drop-down list.

ii.

Click Execute.

The output on the screen and in the file are shown in Appendix C: Output of UDF (p. 15). The UDF reads the input file (input.txt) and generates the output file (output.txt) automatically in each simulation. The parameters of the output are explained in Appendix D: General Structure of UDF (p. 16). If you want to preserve the old results, rename the output.txt file. Otherwise the data for the next run will be appended to the old file.

6. Appendix A: Details of the Input File • The first line is the number of postprocessing faces. You can define more than one face zones for flow uniformity calculation. • Each line after the first line has the parameters of a face-zone. They are defined in the following order: – POST_BOUNDARY_ZONE_ID – POST_CELL_ZONE_ ID_1 – POST_CELL_ZONE_ ID_2 – L_XX – L_YX – L_ZX – L_XY 10

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Appendix B: Contents of UDF – L_YY – L_ZY Further detailed description of the parameters is given as follows: 1. POST_BOUNDARY_ZONE_ID is the ID of the face zone. 2. POST_CELL_ZONE_ ID_1 and POST_CELL_ZONE_ ID_2 are the IDs of two adjacent cell zones of the postprocessing face zone. They are the same if the face zone is inside a cell zone. 3. L_XX, L_YX, L_ZX are the direction cosines of the x-axis of the local coordinate. The UDF uses a local coordinate for each face zone to compute the flow uniformity. The local x-axis will be the major axis, and local y-axis will be the minor axis. You should define the direction of longer length as x-axis, and the other direction in the same plane as y-axis. 4. L_XY, L_YY, L_ZY are the direction cosines of the y-axis of the local coordinate. The UDF uses a local coordinate for each face zone to compute the flow uniformity. The local x-axis will be the major axis, and local y-axis will be the minor axis. You should define the direction of longer length as x-axis, and the other direction in the same plane as y-axis. • The definition of the direction cosines may affect the eccentricity because it reflects the local flow distribution on the plane. The gamma does not depend on the direction cosines.

7. Appendix B: Contents of UDF The contents of the UDF file are as follows: #include "udf.h" int ncount; int npost; /*You need to modify these three lines*/ int POST_BOUNDARY_ZONE_ID[50]; int POST_CELL_ZONE_ID_1[50]; int POST_CELL_ZONE_ID_2[50]; float L_XX[50]; float L_YX[50]; float L_ZX[50]; float L_XY[50]; float L_YY[50]; float L_ZY[50]; float L_XZ[50]; float L_YZ[50]; float L_ZZ[50];

static void read_input() { int i=0; FILE *fpin; if((fpin=fopen("input.txt","r"))==NULL) { printf("Input file does not exist!"); } fscanf(fpin, "%d",&npost); for(i=0;i vmax) { vmax=vmag; f_vmax=f; } } end_f_loop(f,tf) vavg/=A_tot; vratio=vmax/vavg; F_CENTROID(x_vmax_global,f_vmax,tf); x_vmax= NVD_DOT(x_vmax_global,L_XX[flag],L_YX[flag],L_ZX[flag]); y_vmax= NVD_DOT(x_vmax_global,L_XY[flag],L_YY[flag],L_ZY[flag]); eccent_x=2.0*(x_vmax-x_mid)/L_major; eccent_y=2.0*(y_vmax-y_mid)/L_minor; eccent=sqrt(eccent_x*eccent_x+eccent_y*eccent_y); Message("Eccentricity information:\n"); Message("(x_vmax, y_vmax) = (%f, %f) [m]\n", x_vmax, y_vmax); Message("eccentricity = (%f, %f) -> %f \n\n",eccent_x, eccent_y, eccent); Message("vmax = %f m/s occurs at face %d\n", vmax, f_vmax);

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

13

Calculation of Flow Uniformity Message("vratio = %f\n", vratio); /* uniformity, gamma calculations */ v_35=0.35*vmax; v_65=0.65*vmax; a_35=0.0; a_65=0.0; gamma=0.0; begin_f_loop(f,tf) { F_AREA(A_face_vec,f,tf); A_face_mag=NV_MAG(A_face_vec); c0=F_C0(f,tf); c1=F_C1(f,tf); vmag=0.5*(C_UDMI(c0,tc0,3)+C_UDMI(c1,tc1,3)); if(vmag >= v_35) a_35+=A_face_mag; if(vmag >= v_65) a_65+=A_face_mag; gamma+=ABS(vmag-vavg)*A_face_mag; } end_f_loop(f,tf) gamma=1.0-gamma/(2.*vavg*A_tot); unif_35=a_35/A_tot*100; unif_65=a_65/A_tot*100; Message("uniformity index = %f/%f\n",unif_65,unif_35); Message("gamma = %f\n",gamma); fprintf(fp, "post%d %9.3f %9.3f %9.3f %9.3f %9.3f %9.3f \n", flag, eccent, gamma, unif_35, unif_65, vratio, vmax); fclose(fp); } static void set_udm(int flag) { /* NOTE: THIS ROUTINE REQUIRES ALLOCATION OF */ /* 4 USER DEFINED MEMORY LOCATIONS IN FLUENT */ #define #define #define #define

X_PRIME 0 Y_PRIME 1 Z_PRIME 2 V_MAG 3

float xc[ND_ND]; Thread *tc1,*tc2; cell_t c; Domain *domain; domain = Get_Domain(1); tc1=Lookup_Thread(domain, POST_CELL_ZONE_ID_1[flag]); tc2=Lookup_Thread(domain, POST_CELL_ZONE_ID_2[flag]); begin_c_loop(c,tc1) { C_CENTROID(xc,c,tc1); C_UDMI(c,tc1,X_PRIME)=NVD_DOT(xc,L_XX[flag],L_YX[flag],L_ZX[flag]); C_UDMI(c,tc1,Y_PRIME)=NVD_DOT(xc,L_XY[flag],L_YY[flag],L_ZY[flag]); C_UDMI(c,tc1,Z_PRIME)=NVD_DOT(xc,L_XZ[flag],L_YZ[flag],L_ZZ[flag]); C_UDMI(c,tc1,V_MAG)=sqrt(C_VMAG2(c,tc1)); } end_c_loop(c,tc1) if(POST_CELL_ZONE_ID_1[flag] != POST_CELL_ZONE_ID_2[flag]) { begin_c_loop(c,tc2) { C_CENTROID(xc,c,tc2); C_UDMI(c,tc2,X_PRIME)=NVD_DOT(xc,L_XX[flag],L_YX[flag],L_ZX[flag]); C_UDMI(c,tc2,Y_PRIME)=NVD_DOT(xc,L_XY[flag],L_YY[flag],L_ZY[flag]); C_UDMI(c,tc2,Z_PRIME)=NVD_DOT(xc,L_XZ[flag],L_YZ[flag],L_ZZ[flag]); C_UDMI(c,tc2,V_MAG)=sqrt(C_VMAG2(c,tc2));

14

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Appendix C: Output of UDF } end_c_loop(c,tc2) } }

DEFINE_ON_DEMAND(Uniform_steady) { int i=0; read_input(); init_udm(); for(i=0; i 0.119455 vmax = 1.904786 m/s occurs at face 356 vratio = 2.436113 uniformity index = 15.249242/46.124355 gamma = 0.790568 ================================================================ post-1 ================================================================ Geometry information: (x_min, x_mid, x_max) = (-0.030000, 0.000000, 0.030000) [m] (y_min, y_mid, y_max) = (-0.030000, 0.000000, 0.030000) [m] (L_major, L_minor) = (0.060000, 0.060000) [m] Eccentricity information: (x_vmax, y_vmax) = (-0.000981, -0.008046) [m] eccentricity = (-0.032702, -0.268192) -> 0.270179 vmax = 1.717937 m/s occurs at face 354 vratio = 2.208650 uniformity index = 20.263460/58.617546 gamma = 0.795331 ================================================================ post-2 Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

15

Calculation of Flow Uniformity ================================================================ Geometry information: (x_min, x_mid, x_max) = (-0.044035, -0.029980, -0.015925) [m] (y_min, y_mid, y_max) = (-0.010000, -0.000000, 0.009999) [m] (L_major, L_minor) = (0.028110, 0.019999) [m] Eccentricity information: (x_vmax, y_vmax) = (-0.019842, -0.002659) [m] eccentricity = (0.721307, -0.265830) -> 0.768732 vmax = 2.292925 m/s occurs at face 52 vratio = 1.112993 uniformity index = 98.425621/100.000000 gamma = 0.958206 ================================================================ post-3 ================================================================ Geometry information: (x_min, x_mid, x_max) = (-0.030000, 0.000000, 0.030000) [m] (y_min, y_mid, y_max) = (-0.030000, 0.000000, 0.030000) [m] (L_major, L_minor) = (0.060000, 0.060000) [m] Eccentricity information: (x_vmax, y_vmax) = (-0.004882, 0.003414) [m] eccentricity = (-0.162746, 0.113784) -> 0.198577 vmax = 2.078881 m/s occurs at face 411 vratio = 2.651827 uniformity index = 13.180047/36.439743 gamma = 0.787329

Output in a file: post-face post0 post1 post2 post3

eccent 0.119 0.270 0.769 0.199

gamma 0.791 0.795 0.958 0.787

unif_35 46.124 58.618 100.000 36.440

unif_65 15.249 20.263 98.426 13.180

vratio 2.436 2.209 1.113 2.652

vmax 1.905 1.718 2.293 2.079

9. Appendix D: General Structure of UDF The UDF can be used for uniform steady-state analysis. It is used as a compiled UDF. There are three subroutines, init_udm, set_udm, and cat_post in the UDF. You need to set four user-defined memory locations, in which udm-0, udm-1, and udm-2 store the coordinates, and udm-3 stores velocity. The functions of the subroutines are as follows: • init_udm: It is used to initialize the user-defined memory. • set_udm: It computes the local coordinate in the selected cell zones based on the directional cosines provided by users. It stores the local coordinates in udm-0, udm-1, and udm-2, and velocity magnitude of the selected cell zones in udm-3. • cat_post: Compute flow parameter for the postprocessing faces.

16

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Appendix D: General Structure of UDF

Calculation of Flow Parameters: Figure 5: Postprocessing Face

1. Calculation of geometric parameters of the postprocessing face. a. Length of major and minor axes: L_major = x_max — x_min L_minor = y_max — y_min

(1) (2)

where, L_major = length of major axis L_minor = length of minor axis x_max = maximum x coordinate y_max = maximum y coordinate x_min = minimum x coordinate y_min = minimum y coordinate b. Center of the zone:

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

17

Calculation of Flow Uniformity

2. Calculation of velocity index (eccentricity). Compute the location (x and y coordinates) of the maximum velocity and the distance between this location and the center of the face. Find the maximum velocity and velocity ratio. Eccentricity (ε) is defined as:

Velocity ratio ( ν_ratio) can be defined as the ratio of the maximum velocity to the average velocity.

3. Calculation of ow uniformity. Compute the uniformity index (area based), gamma, and vel_space. The uniformity index is based on these reference velocities: ν_65 (65% of the maximum velocity) and ν_35 (35% of the maximum velocity). The uniformity is defined as:

where, A_65 = the area of which velocity is higher than ν_65 18

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Summary A_35 = the area of which velocity is higher than ν_35 Gamma is defined as,

4. Output parameters. a. On the screen: The parameters of the output on the screen can be explained as follows: • (x_max, y_max) = Location of the maximum velocity • eccentricity = (ε_x, ε_y) ⇒ ε • vmax = maximum velocity • vratio = ν_ratio • uniformity index = φ_65/φ_35 • gamma = γ b. In the output file: The parameters in the output fie can be explained as follows: • time = flow time • eccent = ε • gamma = γ • unif_35 = φ_35 • unif_65 = φ_65 • vmax = maximum velocity

10. Summary In this tutorial, a flow uniformity problem was set up and solved for a steady state flow with the help of UDF

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

19

20

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF 1. Introduction The purpose of this tutorial is to include a user-defined scalar equation (sediment concentration) in the calculation process. With the help of the user-defined functions (UDFs), a Boussinesq-like approximation is considered. The buoyancy effects due to density gradients are accounted for by a gravity source term in the vertical (axial) momentum equation. The damping effect of stratification on turbulence is introduced by means of source terms in the transport equations of turbulence kinetic energy (k) and its rate of dissipation (e). A rheology function is also considered to account for the increased viscosity of highly concentrated sludge mixtures. This tutorial demonstrates how to do the following: • Define an unsteady case with appropriate settings. • Compile and link a compiled UDF. • Set up qualitative and quantitative convergence monitors. • Conduct alphanumeric and graphic postprocessing.

2. Prerequisites This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tutorial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some steps in the setup and solution procedure will not be shown explicitly. Some knowledge of UDF structure, compilation and linking is desired. For more details about userdefined functions (UDF) refer to the ANSYS Fluent UDF Manual.

3. Problem Description The problem considered is a circular, center-feed secondary clarifier with inclined bottom and central sludge withdrawal. The central inlet includes two baffles: a vertical inlet baffle that forces the inflow to enter the tank at a relatively low position; and a horizontal deflection plate that prevents short circuiting from the inlet to the sludge withdrawal. Axisymmetry is assumed, and the flow and settling processes are modelled in a radial section on a two-dimensional grid (References (p. 22)).

4. Preparation 1.

Copy the files (clarifier.msh.gz and clarifier.c) to the working folder.

2.

Use Fluent Launcher to start the 2D version of ANSYS Fluent.

3.

Enable Double-Precision in the Options list. Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

1

Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF 4.

Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.

Note The path to the .bat fie which is required to compile the UDF will be displayed as soon as you enable Setup Compilation Environment for UDF. If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default, click the Show More Options button to view the additional settings.

5. Setup and Solution 5.1. Mesh 1.

Read the mesh file (clarifier.msh.gz). File → Read → Mesh...

Note As the mesh file is read, ANSYS Fluent will report the progress in the console.

2.

Orient the view with the camera tool. Display → Views...

2

a.

Click the Camera... button to open the Camera Parameters dialog box.

b.

Select Up Vector from the Camera drop-down list.

c.

Set X, Y, Z to -1, 0, 0.

d.

Click Apply and close the Camera Parameters dialog box.

e.

Close the Views dialog box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution Figure 1: Mesh Display

5.2. General Settings Define solver settings. General 1.

Enable Transient.

2.

Select Axisymmetric from the 2D Space list.

3.

Translate the mesh using the following TUI command. /mesh/translate 0 2.45e-16

Note If you check in the Scale Mesh dialog box you will notice that Ymin value is negative. For an axisymmetric problem this results in an error while checking the mesh. The axis of rotation must be the X-axis and the mesh must lie on or above the y=0 line. .

4.

Check the mesh. General → Check

Note ANSYS Fluent will perform various checks on the mesh and will report the progress in the console. Ensure that the reported minimum volume is a positive number.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

3

Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF

5.3. Models Select the k-epsilon turbulence model. Models →

Viscous → Edit...

Retain the default selection of Standard Wall Functions from the Near-Wall Treatment list and close the Viscous Model dialog box.

Note Based on Reynolds number calculation at the inlet, the flow is expected to be turbulent, so an appropriate turbulence model is required.

5.4. Compile the UDF Compile the UDF (clarifier.c). Define → User-Defined → Functions → Compiled...

1.

Click the Add... button in the Source Files section to open the Select File dialog.

2.

Select the file clarifier.c and click OK in the Select File dialog box.

3.

Enter sedimentation in the Library Name text entry box.

4.

Click Build to compile the UDF code.

Note A Warning dialog box will appear, warning you to make sure that the UDF source files are in the same folder that contains the case and data files. Click OK to close the Warning dialog box. All related files following the compilation will be stored in the sedimentation folder. You can view the compilation history in the log file that is saved in your working folder.

4

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution 5.

Click Load so that all the macros are available in the graphical user interface. For more details regarding the resolved system of equations, refer to Appendix B: Compiling the UDF (p. 21).

5.5. User-Defined Scalars Note Besides the continuity, momentum, and turbulence transport equation, a new passive scalar equation is defined to determine local particle concentration. Although the standard GUI does not allow the direct activation of the concentration equation, you can introduce the computation of a general transport equation, whose terms are adapted to yield the final sediment concentration equation. 1.

Enable the user defined scalar. Define → User-Defined → Scalars...

2.

a.

Increase the Number of User-Defined Scalars to 1.

b.

Select settling_flux::sedimentation from the Flux Function drop-down list.

c.

Retain the selection of default from the Unsteady Function drop-down list.

Click OK to close the User-Defined Scalars dialog box.

Note ANSYS Fluent displays an Information dialog box informing that available material properties or methods have changed. Click OK in the Information dialog box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

5

Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF

5.6. User-Defined Memory Note A user-defined memory (UDM) is a customized variable defined within the UDF code. UDMs can store any expression combining flow variables and user constants. They are easily accessed and can be used for postprocessing (contours, vectors, XY plots, etc.). In this tutorial, five UDMs have been defined to store quantities as shown in the following table: Table 1: UDM

Description

0

Settling Velocity

1

UDS Diffusion Coefficient

2

Gravity Source Term

3

Turbulence Kinetic Rate Source Term

4

Turbulence Dissipation Rate Source Term

Define → User-Defined → Memory...

1.

Increase the Number of User-Defined Memory Locations to 5.

2.

Click OK to close the User-Defined Memory dialog box.

5.7. Materials Materials → Edit...

Note The Create/Edit Materials dialog box for air opens. 1.

Select user-defined from the UDS Diffusivity drop-down list.

2.

Select turbulent_diff::sedimentation and click OK to close the User-Defined Functions dialog box.

6

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

3.

Click Change/Create.

4.

Import the water-liquid material from the Fluent Database.

5.

Enter 1000 kg/m3 for Density.

6.

Select user-defined from the Viscosity drop-down list and select viscosity::sedimentation in the Userdefined Functions dialog box.

7.

Select user-defined from the UDS Diusivity drop-down list and select turbulent_diff::sedimentation in the User-Defined Functions dialog box.

8.

Click Change/Create and close the Materials dialog box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

7

Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF

5.8. Cell Zone Conditions Cell Zone Conditions →

fluid → Edit...

1.

Select water-liquid from the Material Name drop-down list.

2.

Enable Source Terms.

3.

Click on the Source Terms tab.

8

a.

Click the Edit... button next to Axial Momentum to open the Axial Momentum sources dialog box.

b.

Set the Number of Axial Momentum sources to 1.

c.

Select udf X_mom_src::sedimentation from the drop-down list.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution d.

Click OK to close the Axial Momentum sources dialog box.

4.

Similarly, enable the UDF source term udf turb_k_source::sedimentation for Turbulent Kinetic Energy.

5.

Also enable udf turb_e_source::sedimentation for Turbulent Dissipation Rate.

6.

Click OK to close the Fluid dialog box.

5.9. Boundary Conditions 1.

Set the boundary conditions for inlet. Boundary Conditions →

inlet → Edit...

a.

Retain selection of Magnitude, Normal to Boundary from the Velocity Specification Method drop-down list.

b.

Enter 0.019 m/s for Velocity Magnitude.

c.

Select Intensity and Hydraulic Diameter from the Specification Method drop-down list.

d.

Retain 5 % for Turbulent Intensity.

e.

Enter 5.6 m for Hydraulic Diameter.

f.

Click the UDS tab and select Specified Value from the User Scalar 0 drop-down list.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

9

Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF

2.

g.

Enter 3.2 for User Scalar 0.

h.

Click OK to close the Velocity Inlet dialog box.

Set the boundary conditions for outlet-top. Boundary Conditions →

3.

10

outlet-top → Edit...

a.

Retain selection of Magnitude, Normal to Boundary from the Velocity Specification Method drop-down list.

b.

Enter -0.04 m/s for Velocity Magnitude.

c.

Select Intensity and Hydraulic Diameter from the Specification Method drop-down list.

d.

Retain 5 % for Turbulent Intensity.

e.

Enter 0.02 m for Hydraulic Diameter.

f.

Retain the default parameters in the UDS tab.

g.

Click OK to close the Velocity Inlet dialog box.

Set the boundary conditions for outlet_bottom.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution Boundary Conditions →

4.

outlet_bottom → Edit...

a.

Retain selection of Normal to Boundary from the Backflow Direction Specification Method drop-down list.

b.

Select Intensity and Hydraulic Diameter from the Specification Method drop-down list.

c.

Retain 5 % Backflow Turbulent Intensity.

d.

Enter 3.2 m for Backflow Hydraulic Diameter.

e.

Retain the default parameters in the UDS tab.

f.

Click OK to close the Pressure Outlet dialog box.

Retain the default settings for other zones.

5.10. Solution 1.

Define the solution control parameters. Solution Methods

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

11

Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF

2.

a.

Select Green-Gauss Cell Based from the Gradient drop-down list.

b.

Select PRESTO! from the Pressure drop-down list.

c.

Select QUICK for all the other parameters.

d.

Select Second Order Implicit from the Transient Formulation drop-down list.

Define a surface monitor. Monitors (Surface Monitors) → Edit...

12

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

3.

a.

Enable Plot and Write.

b.

Select Flow Time from the X Axis drop-down list.

c.

Select Time Step from Get Data Every drop-down list.

d.

Select Flow Rate from the Report Type drop-down list .

e.

Select User Defined Scalars... and Scalar-0 from the Field Variable drop-down lists.

f.

Select outlet_bottom from the Surfaces selection list.

g.

Click OK to close the Surface Monitor dialog box.

Initialize the flow field. Solution Initialization

4.

a.

Select Standard Initialization from the Initialization Methods group box.

b.

Select all-zones from the Compute from drop-down list.

c.

Click Initialize.

Save the case and data files (clarifier-t=0.cas/dat.gz). File → Write → Case & Data... Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

13

Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF 5.

Run the calculations. Run Calculation → Calculate 1.

Enter 10 for Time Step Size and 7300 for Number of Time Steps.

2.

Click Calculate.

Note The hydraulic residence time (hrt = ratio of volume to flow rate) of the sedimentation tank is approximately 7300 seconds. It is assumed that the steady-state solution is achieved for 10 times the hrt (conservative estimation). The size of the time step size is a compromise between numerical stability and computational time. A time step of 10 seconds is chosen which yields a total number of 7300 time steps to reach a steady-state solution. The outcome of the simulation is the steady-state clarifier behavior and intermediate time-dependent information will be neglected.

6.

Save the case and data files (clarifier-steady.cas/dat.gz). File → Write → Case & Data...

5.11. Postprocessing 1.

Display contours of particle concentration, User Scalar 0. Graphics and Animations →

Contours → Set Up...

Figure 2: Contours of Particle Concentration

14

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution 2.

Display velocity vectors colored by velocity magnitude. Graphics and Animations →

Vectors → Set Up...

a.

Increase Scale to 5 to improve vector viewing.

b.

Click Display and close the Vectors dialog box.

Figure 3: Velocity Vectors

3.

Display contours of settling velocity, User Memory 0. Graphics and Animations →

Contours → Set Up...

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

15

Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF Figure 4: Contours of Settling Velocity

4.

Create an isosurface at the radial coordinate, y=4 m. Surface → Iso-Surface...

5.

16

a.

Select Mesh... and Y-Coordinate from the Surface of Constant drop-down lists.

b.

Enter 4 for Iso-Values and y=4 for New Surface Name.

c.

Click Create and close the Iso-Surface dialog box.

Create two custom field functions.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution Define → Custom-Field Functions...

a.

Click the - button on the keypad in the dialog box.

b.

Select Mesh... and X-Coordinate from the Field Functions drop-down lists.

c.

Click the Select button and enter x-in in the New Function Name text entry box.

d.

Click Define.

e.

Similarly, create the second custom field function, mgl-1.

f.

i.

Select User Defined Scalars... and Scalar-0 from the Field Functions drop-down list and click Select.

ii.

Click the X button on the keypad in the dialog box.

iii.

Enter 1000 using the keypad.

iv.

Enter mgl-1 for the New Function Name and click Define.

Close the Custom Field Function Calculator dialog box. Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

17

Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF 6.

Create an XY plot to display concentration profiles at a radial position. Plots →

18

XY Plot → Set Up...

a.

In the list of Options disable Position on X Axis and ensure that only Node Values is enabled.

b.

Select Custom Field Functions.... and x-in0 from the Y Axis Function drop-down lists.

c.

Select User Defined Scalars.... and Scalar-0 from the X Axis Function drop-down lists.

d.

Select y=4 from the list of Surfaces.

e.

Click Plot.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution Figure 5: Concentration Profile at y = 4 m

7.

Modify the number format. Display → Colormap...

Note Changing the number format (type and precision) eases results interpretation for a nontechnical audience.

a.

Select general from the Type drop-down list.

b.

Enter 4 for Precision.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

19

Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF c. 8.

Click Apply and close the Colormap dialog box.

Display concentration contours in mg/l units (Custom Field Function and mgl-1). Figure 6: Contours of Particle Concentration (mg/l)

6. Appendix A: Parameters The loading conditions for this reference case can be found on the publication in References (p. 22). For simplicity, some key parameters are summarized in the following table: Table 2: Parameter

Description

Value

Uin

Inflow Velocity

0.019 m/s

Cin

Inflow Particle Concentration

3.2 kg/m3

R

Recycle Ratio

0.86

ρp

Dry Particle Density

1450 kg/m3

ρw

Clear Water Density

1000 kg/m3

σc

Schmidt Number

0.7

US0

Reference Settling Velocity

0.005 m/s

RH

Floc Settling Parameter

0.7 m3/kg

RP

Colloidal Settling Parameter

5 m3/kg

CMIN

Nonsettleable Concentration

0.01 kg/m3

USMAX

Maximum Settling Velocity

0.002 m/s

20

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Appendix B: Compiling the UDF

7. Appendix B: Compiling the UDF The resolved system of equations is shown below. Some slight modifications are conducted on the general form of the transport equations to account for the complex physics of the clarification process. The sedimentation-related terms are marked and associated with the corresponding UDF macros. The contents of the UDF file are as follows: 1. Continuity Equation:

2. X-Momentum Equation:

where,

: DEFINE_SOURCE(X_mom_src,c,tc,ds,eqn) 3. Y-Momentum Equation:

4. Turbulent Kinetic Energy (k) Equation:

where, Gb: DEFINE_SOURCE (turb_k_source,c,tc,ds,eqn)

Gb = 5. Turbulent Dissipation Rate (ε) Equation:

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

21

Modeling Effect of Sedimentation Concentration in a Secondary Clarifier using a UDF

where, C3εGb: DEFINE_SOURCE(turb_e_source,c,tc,,ds,eqn) 6. Concentration Equation (Passive Scalar Equation):

where,

: DEFINE_UDS_FLUX(settling_flux,f,tf,i)

: DEFINE_DIFFUSIVITY(turbulent_diff,f,tf,i)

8. References Computing Shear Flow and Sludge Blanket in Secondary Clariers Djamel Lakehal, Peter Krebs, Johan Krijgsman, Wolfgang Rodi

22

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating Membrane 1. Introduction The purpose of this tutorial is to illustrate how to use a user-defined function (UDF) to control the dynamic mesh of a generic flow device with a rotating blade and a flexible oscillating membrane. The motion of the rotating blade and the oscillating membrane have a large amplitude which requires the use of local remeshing. The rotation of the blade, the oscillation of the membrane, and the sliding of the nodes along the top wall of the housing are defined and controlled by means of a UDF that utilizes the three macros specific to the dynamic mesh model. This tutorial demonstrates how to do the following: • Set up the dynamic mesh (DM) model for this problem. • Use the three DM-specific macros in a UDF to control the dynamic mesh. • Preview the dynamic mesh before starting the flow computation.

2. Prerequisites This tutorial is written with the assumption that you have completed Tutorial 1 from ANSYS Fluent Tutorial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some steps in the setup and solution procedure will not be shown explicitly. Some knowledge of UDF structure, compilation and linking is desired. For more details about userdefined functions (UDF) refer to the ANSYS Fluent UDF Manual.

3. Problem Description A generic flow device with a flexible oscillating membrane beneath it is shown in Figure 1: Problem Schematic (p. 2). The valve radius is 0.1 m.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

1

Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating Membrane Figure 1: Problem Schematic

4. Preparation 1.

Copy the files (butterfly-flex.msh.gz and butterfly-flex.c) to the working folder.

2.

Use Fluent Launcher to start the 2D version of ANSYS Fluent.

3.

Enable Double-Precision in the Options list.

4.

Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.

Note The path to the .bat fie which is required to compile the UDF will be displayed as soon as you enable Setup Compilation Environment for UDF. If the UDF Compiler tab does not appear in the Fluent Launcher dialog box by default, click the Show More Options button to view the additional settings.

5. Setup and Solution 5.1. Mesh Read the mesh file (butterfly-flex.msh.gz).

2

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution File → Read → Mesh...

Note As the mesh file is read, ANSYS Fluent will report the progress in the console.

5.2. General Settings 1.

Define solver settings. General →

2.

Transient

Check the mesh. General → Check

Note ANSYS Fluent will perform various checks on the mesh and will report the progress in the console. Ensure that the reported minimum volume is a positive number.

3.

Display the mesh. General → Display a.

b.

Click Colors.... i.

Select Color by ID from the Options list in the Mesh Colors dialog box.

ii.

Click Close.

Click Display and close Mesh Display dialog box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

3

Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating Membrane Figure 2: Mesh Display

5.3. Compile the UDF •

Compile the UDF (butterfly-flex.c). Define → User-Defined → Functions → Compiled...

4

a.

Click the Add... button in the Source Files section to open the Select File dialog.

b.

Select the file butterfly-flex.c

c.

Enter libudf-flex in the Library Name text entry box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution d.

Click Build.

Note A Warning dialog box will appear, warning you to make sure that the UDF source files are in the same folder that contains the case and data files. Click OK to close the Warning dialog box. You can view the compilation history in the log file that is saved in your working folder. e.

Click Load to load the newly created UDF library so that all the macros are available in the graphical user interface.

5.4. Dynamic Mesh Setup The mesh is controlled using a combination of local remeshing with sizing functions and spring smoothing. 1.

Enable dynamic mesh motion and specify the associated parameters. Dynamic Mesh a.

Enable Dynamic Mesh and Remeshing.

Note The dialog box expands to show relevant inputs.

b.

Click Settings... to open Mesh Method Settings dialog box.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

5

Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating Membrane

i.

Click Smoothing tab and enter 0.3 for the Spring Constant Factor.

ii.

Retain the default settings for other parameters.

iii.

Click Remeshing tab and specify the parameters as given in the following table: Table 1:

6

Parameter

Value

Minimum Length Scale (m)

0.00236

Maximum Length Scale (m)

0.02

Maximum Cell Skewness

0.65

Size Remeshing Interval

1

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution

c. 2.

Click OK to close the Mesh Method Settings dialog box.

Specify the wall-butterfly zone as a rigid body. Dynamic Mesh (Dynamic Mesh Zones) → Create/Edit...

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

7

Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating Membrane

a.

Select wall-butterfly from Zone Names drop-down list

b.

Retain the default selection of Rigid Body in the Type group box.

c.

Select butterfly_flex_UDF::libudf-flex from the Motion UDF/Profile drop-down list.

d.

Retain the Center of Gravity Location as (0,0).

Note The valve motion is defined about its center of gravity (CG) located at (0,0). This is important in the case of rotation.

8

e.

In the Meshing Options tab, specify a value of 0.002 m for Cell Height.

f.

Click Create.

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Setup and Solution 3.

Specify the wall-top zone as a deforming zone.

Note The objective is to allow all nodes located on the top wall to slide along that wall as the tip of the valve moves past it. Thus define a horizontal line and set wall-top zone as a deforming zone. a.

Select wall-top from the Zone Names drop-down list.

b.

Select Deforming in the Type list.

c.

Click the Geometry Definition tab.

d.

4.

i.

Select user-defined from the Definition drop-down list.

ii.

Select plane::libudf-flex from the Geometry UDF drop-down list.

Click the Meshing Options tab. i.

Disable Remeshing in the Methods list.

ii.

Retain the default values for other parameters.

iii.

Click Create.

Specify the membrane zone as a dynamic zone. a.

Select membrane from the Zone Names drop-down list.

b.

Select User-Defined from the Type list.

c.

In the Motion Attributes tab select moving_arc::libudf-flex from the Mesh Motion UDF dropdown list.

Note The motion of membrane and membrane-shadow wall is governed by the function moving_arc from the UDF.

5.

d.

Click Create.

e.

Similarly, define the membrane-shadow zone as a dynamic zone.

f.

Close the Dynamic Mesh Zones dialog box.

Save the case file (membrane-moving-init.cas.gz). File → Write → Case...

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

9

Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating Membrane

5.5. Mesh Motion Preview Specify the parameters for the mesh motion. Dynamic Mesh (Dynamic Mesh Zones) → Preview Mesh Motion

1.

Enter 0.005 for Time Step Size.

2.

Enter 313 for the Number of Time Steps.

3.

Click Preview.

Note The valve will move through 90 degrees and assume the position shown in Figure 3: Mesh Display After Mesh Motion (p. 10). Figure 3: Mesh Display After Mesh Motion

10

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Appendix

6. Appendix /*********************************************************************/ /* UDF to compute the orientation of a rotating valve, based on a specified rotational speed. Christoph Hiemcke, Fluent Inc., butterlfy_flex_UDF dt cg_vel cg_omega time dtime

= = = = = =

12 Feb 2004

name shown in Fluent GUI thread cg velocity (global) angular velocity (global) current time time step

*/ /*********************************************************************/ #include "udf.h" #define #define

omega R

1.0 0.109

/* rotational speed, rad/sec /* radius of the arc, meters

*/ */

DEFINE_CG_MOTION(butterfly_flex_UDF, dt, cg_vel, cg_omega, time, dtime) { cg_vel[0] = 0.0; cg_vel[1] = 0.0; cg_vel[2] = 0.0; cg_omega[0] = 0.0; cg_omega[1] = 0.0; cg_omega[2] = omega; } /***********************************************************************/ /* UDF to define a horizontal plane. One will thus be able to project boundary nodes upon this plane. */ /***********************************************************************/ DEFINE_GEOM(plane, domain, dt, position) { position[1] = R; } /***********************************************************************/ /* UDF to define a wall that is initially a circular arc, but then oscillates sinusoidally with time. alpha = angle that dictates the motion of the arc; theta = angle that corresponds to the position of the rotating valve */ /***********************************************************************/ DEFINE_GRID_MOTION(moving_arc, domain, dt, time, dtime) { Thread *tf = DT_THREAD (dt); face_t f; Node *node_p; real alpha, theta, x, ymag, yfull, y; int n; /* Set/activate the deforming flag on adjacent cell zone, which /* means that the cells adjacent to the deforming wall will also be /* deformed, in order to avoid skewness. SET_DEFORMING_THREAD_FLAG (THREAD_T0 (tf));

*/ */ */

/* Compute the angles: alpha = omega * CURRENT_TIME;

*/

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

11

Using a UDF to Control the Dynamic Mesh of a Flexible Oscillating Membrane theta = 2.0 * alpha + 3.0 * M_PI / 2.0; /* /* /* /*

Loop over the deforming boundary zone's faces; inner loop loops over all nodes of a given face; Thus, since one node can belong to several faces, one must guard against operating on a given node more than once:

*/ */ */ */

begin_f_loop (f, tf) { f_node_loop (f, tf, n) { node_p = F_NODE (f, tf, n); /* Update the current node only if it has not been /* previously visited: */ if (NODE_POS_NEED_UPDATE (node_p)) { /* Set flag to indicate that the current node's /* position has been updated, so that it will not be */ /* updated during a future pass through the loop: NODE_POS_UPDATED (node_p);

*/

*/ */

x = NODE_X (node_p); ymag = sqrt (R*R - x*x) + 0.03; yfull = ymag - 0.1; y = - 0.1 + yfull * sin(theta); NODE_Y (node_p) = y; } } } end_f_loop (f, tf); } /*********************************************************************/ /* */ /* End of the UDF. */ /* */ /*********************************************************************/

Note The first section (under DEFINE_CG_MOTION) prescribes a constant angular rotation about the z-axis, and is used to spin the valve. The second section (under DEFINE_GEOM) defines a line at y = R = 0.109 m; this line is coincident with the top wall of the housing and guides the nodes as they slide along the top wall. The third section (under DEFINE_GRID_MOTION) controls the motion of the nodes belonging to the membrane. The initial shape of the membrane is that of a circular arc, and then it moves up and down harmonically.

7. Summary In this tutorial you modeled an oscillating membrane in a generic flow device with a rotating blade using the DM model in ANSYS Fluent. The local remeshing scheme was used to define the mesh motion. DM specific macros of a UDF were used to govern the rotational motion of the blade, deformation of the membrane, and the sliding of the nodes on the top wall of the housing.

12

Release 15.0 - © SAS IP, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.