5.4. Expression Examples

The following are a few examples that demonstrate why or where you may want to use an expression and how you would do so for these situations.

5.4.1. Parabolic Inflow Profile

The following example shows you how to define a parabolic inlet profile for laminar pipe flow, as shown in Figure 5.9: Contours of Velocity - Parabolic Inflow. In this example, the pipe is centered in the X and Z directions and the pipe axis is aligned to the Y-direction.

Figure 5.9: Contours of Velocity - Parabolic Inflow

Contours of Velocity - Parabolic Inflow

The expression for defining the parabolic inflow shown in Figure 5.9: Contours of Velocity - Parabolic Inflow is Equation 5–1,

(5–1)

Where is the velocity at the axis, is the radius of the pipe, and is the local radial coordinate.

To fully define this example:

  1. Create a named expression for the maximum velocity called umax.

     Setup Named Expressions  New...

    1. Enter umax for the Name.

    2. Enter 0.2 [m/s] for the Definition and click OK.

  2. Create an expression for the radius of the pipe.

    1. Open the Expressions dialog box by right-clicking Named Expressions in the outline view tree and selecting New....

    2. Enter Radius for the Name.

    3. Enter sqrt(Area(["in"])/PI) for the Definition. "in" is the name of the inlet boundary. PI is the expression constant for Pi.

    4. Click OK to create the named expression.

  3. Create an expression for the local radial profile.

    1. Open the Expressions dialog box and enter radius for the Name.

    2. Enter sqrt(x**2+z**2) for the Definition. This expression uses the square root mathematical expression operator.

    3. Click OK to create the named expression.

  4. Create an expression for the inlet velocity profile. This expression combines the other expressions you created.

    1. Open the Expressions dialog box and enter uprofile for the Name.

    2. Enter umax*(1- (radius/Radius)**2) for the Definition. You can use the Expressions drop-down to the right of the Definition box to add named expressions to your expression definition as an alternative to typing the names manually.

    3. Click OK to create the named expression.

  5. Assign uprofile to the velocity inlet.

     Setup Boundary Conditions Inlet in Edit...

    You can group the boundary conditions by type to organize the boundaries and reduce the size of the list. This can be accomplished by right-clicking Boundary Conditions in the tree and selecting Group By> Zone Type.

    1. Select expression from the drop-down to the right of Velocity Magnitude.

    2. Enter uprofile in the Velocity Magnitude field and click OK.

5.4.2. Time-Varied Parabolic Inflow

The following example shows you how to define a parabolic inlet profile for laminar pipe flow that varies over time (a sine function with a period of 10 seconds). The velocity profile in this example is the same as for Parabolic Inflow Profile except it is for a transient simulation because the velocity varies over time. Figure 5.10: Parabolic Inflow Velocity Over Time plots the area weighted average of the velocity magnitude over 10 seconds.

Figure 5.10: Parabolic Inflow Velocity Over Time

Parabolic Inflow Velocity Over Time

To create an expression for this time-varied velocity profile:

  1. Define all of the named expressions as described in Parabolic Inflow Profile.

  2. Create an expression for omega.

     Setup Named Expressions  New...

    1. Enter omega for the Name.

    2. Enter 2*PI / (10[s]) for the Definition and click OK.

  3. Create an expression for the velocity profile that varies over time.

    1. Open the Expressions dialog box and enter uprofile_transient for the Name.

    2. Enter uprofile*(sin(omega*Time)*0.1 + 1) for the Definition and click OK.

  4. Assign uprofile_transient to the velocity inlet.

     Setup Boundary Conditions Inlet in Edit...

    You can group the boundary conditions by type to organize the boundaries and reduce the size of the list. This can be accomplished by right-clicking Boundary Conditions in the tree and selecting Group By> Zone Type.

    1. Select expression from the drop-down to the right of Velocity Magnitude.

    2. Enter uprofile_transient in the Velocity Magnitude field and click OK.

5.4.3. Controlled Outlet Temperature

The following example shows you how to drive the maximum temperature at the outlet to a target temperature by varying the inlet temperature. For this scenario, a pipe with laminar flow has a part of the wall that is heated to 350 Kelvin and a target outlet temperature of 320 Kelvin (Figure 5.11: Pipe Geometry Colored by ID (Heated Wall is Green) shows the portion of the wall that is heated). A controller turns on every 10th iteration (steady-state case) and adjusts the inlet temperature according to Equation 5–2. In the other iterations, the controller leaves the temperature unchanged. This is achieved by using the conditional statement given in Equation 5–3. Figure 5.12: Contours of Temperature (outlet is closest) shows the developed temperature profile for this case.

(5–2)

(5–3)

is the formula used to adjust the inlet temperature, is the current inlet temperature, is the target temperature for the outlet, which is set to 320 Kelvin, is the maximum temperature at the outlet, and is a relaxation factor.

Figure 5.11: Pipe Geometry Colored by ID (Heated Wall is Green)

Pipe Geometry Colored by ID (Heated Wall is Green)

Figure 5.12: Contours of Temperature (outlet is closest)

Contours of Temperature (outlet is closest)

Figure 5.13: Plots of Inlet Temperature, Average Outlet Temperature, and Maximum Outlet Temperature

Plots of Inlet Temperature, Average Outlet Temperature, and Maximum Outlet Temperature

The following steps show how to create the expressions used in this example:

  1. Create a named expression for the initial temperature, called TStart.

     Setup Named Expressions  New...

    1. Enter TStart for the Name.

    2. Enter 300 [K] for the Definition and click OK.

  2. Create an expression for the target temperature for the outlet, called TTarget, and set it equal to 320 [K]. Use the same process that you used to create TStart.

  3. Create an expression for the maximum temperature that occurs at the outlet, called TMaxOut. In this expression you will be using a function to determine the maximum temperature.

    1. Click the Functions drop-down and select ReductionMaximum.

    2. Enter StaticTemperature for the first field of the function and ["out"] for the location. The total expression should appear as Maximum(StaticTemperature, ["out"]).

  4. Create an expression for the current inlet temperature, called TInCurrent, and set it equal to Average(StaticTemperature, ["in"], Weight=None). Use a similar process to what you used to create TMaxOut, but with selecting the Average function instead.

  5. Create an expression for the relaxation factor, called relax, and set it equal to 0.9.

  6. Create an expression for adjusting the inlet temperature, called TAdjust, and set it equal to TInCurrent + (TTarget - TMaxOut)*relax.

  7. Create an expression for the inlet temperature, which will be called TIn, and set it equal to IF(iter<5, TStart, IF(mod(iter+1, 10)==0, TAdjust, TInCurrent)). Use a similar process to what you used to create TMaxOut, but with selecting the IF conditional function instead.

  8. Assign TIn to the inlet.

     Setup Boundary Conditions Inlet in Edit...

    1. Select expression from the drop-down to the right of Temperature.

    2. Enter TIn in the Temperature field and click OK.

5.4.4. Computing Forces with Parameterized Angle of Attack

The following example shows you how to setup to use dot(), vector(), moment(), and force() expression operations in Ansys Fluent. Six expressions are defined: AOA, dragForce, flowDir, liftForce, moment, and totalForce.

To begin, define the angle of attack expression as an input parameter.

  1. Open the Expression dialog box.

     Setup Named Expressions  New...

    Note that the dialog box appears as Parameter Expression because the setup is already completed and Use as Input Parameter is enabled.

  2. Enter AOA as the Name.

  3. Enter 5[deg] in the Definition field.

  4. Enable Use as Input Parameter.

  5. Click OK to create the angle of attack input parameter expression.

Define the flow direction.

  1. Open the Expression dialog box.

     Setup Named Expressions  New...

  2. Enter flowDir as the Name.

  3. Enter vector(cos(AOA), sin(AOA), 0.0) in the Definition field.


    Note:  You select expressions that you have already defined, such as AOA from the Expressions drop-down list on the right-hand side of the dialog box.


  4. Click OK to create the expression for the flow direction.

Define the total force.

  1. Open the Expression dialog box.

     Setup Named Expressions  New...

  2. Enter totalForce as the Name.

  3. Enter Force(['wall-top', 'wall-bottom']) in the Definition field.

  4. Click OK to create the expression for the total force.

Define the moment about the centroid of the airfoil.

  1. Open the Expression dialog box.

     Setup Named Expressions  New...

  2. Enter moment as the Name.

  3. Enter Moment(Centroid(['fluid-16'], ['wall-top', 'wall-bottom']).mag in the Definition field.

  4. Enable Use as Output Parameter to use the moment as an output parameter.

  5. Click OK to create the expression for the total force.

Define the lift force normal to the flow.

  1. Open the Expression dialog box.

     Setup Named Expressions  New...

  2. Enter liftForce as the Name.

  3. Enter dot(totalForce, vector(-flowDir.y, flowdir.x, 0)) in the Definition field.


    Note:  You select expressions that you have already defined, such as totalForce from the Expressions drop-down list on the right-hand side of the dialog box.


  4. Enable Use as Output Parameter to use the lift force as an output parameter.

  5. Click OK to create the expression for the lift force.

Define the drag force.

  1. Open the Expression dialog box.

     Setup Named Expressions  New...

  2. Enter dragForce as the Name.

  3. Enter dot(totalForce, flowDir) in the Definition field.


    Note:  You select expressions that you have already defined, such as totalForce from the Expressions drop-down list on the right-hand side of the dialog box.


  4. Enable Use as Output Parameter to use the drag force as an output parameter.

  5. Click OK to create the expression for the total force.

Now that these expressions are defined, you can include them in expression report definitions for monitoring and judging convergence.