Sunteți pe pagina 1din 17

2008 International

ANSYS Conference
Training Manual

Customizing CFX
Workshop 1:
Setting an Inlet Velocity Profile with User Fortran

ANSYS, Inc. Proprietary


2008 ANSYS, Inc. All rights reserved.

W1-1

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Overview

Training Manual

Step with parabolic inlet velocity profile


This could easily be set up using just CEL (no Fortran), but it
will illustrate the basic steps involved in setting up and using
a User CEL Function in CFX-Pre

ANSYS, Inc. Proprietary


2008 ANSYS, Inc. All rights reserved.

W1-2

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Opening an Existing Case File

Training Manual

1. Start by opening the CFX


case file backstep.cfx in
CFX-Pre

Examine the inlet boundary


condition
The problem is set as planar
2D with one element in the zdirection and symmetry
planes on the high and low zfaces
There are walls located at
the high and low y-faces
above and below the inlet
The velocity profile will
therefore be set up in the ydirection. The y-bounds for
the inlet face are from
-0.05 [m] to +0.05 [m]

ANSYS, Inc. Proprietary


2008 ANSYS, Inc. All rights reserved.

W1-3

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

CEL Option

Training Manual

The current setting for the normal speed


at an inlet is a constant value which
would be appropriate for turbulent or
undeveloped flow
For laminar flow, a velocity profile which
varied with wall distance would be
observed once the flow developed
This could easily be done using CEL by
setting the Normal Speed to the
expression:
0.001 [m/s]*(1.0 (y/ybound)^2)

where ybound is set to 0.05 [m] (the


y bound of the symmetrically located
inlet face)
We will see how to implement the same
condition using User CEL Fortran

ANSYS, Inc. Proprietary


2008 ANSYS, Inc. All rights reserved.

W1-4

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Using a Template Routine

Training Manual

User CEL Routines are always


called with the same arguments
and will have similar structures
with some common elements

Rather than creating a Fortran


routine from scratch, you can
make use of the various
templates provided in the
/examples folder of the CFX
installation directory

There are additional examples in


the /UserFortran subfolder of the
/examples directory

2. Copy the ucf_template.F file in


the /examples folder to your
working directory
ANSYS, Inc. Proprietary
2008 ANSYS, Inc. All rights reserved.

W1-5

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Basic Features in ucf_template.F

Training Manual

#include "cfx5ext.h"
This include statement is always required
dllexport(ucf_template)
The dllexport line uses the subroutine name in lower case
SUBROUTINE UCF_TEMPLATE (
& NLOC, NRET, NARG, RET, ARGS, CRESLT, CZ,DZ,IZ,LZ,RZ )
CC
CD User routine: template for user CEL function
CC
CC -------------------CC
Input
CC -------------------CC
The solver will always know the locale
CC NLOC
- size of current locale
for the call and NLOC, the number of
CC NRET
- number of components in result
locations in the current locale
CC NARG
- number of arguments in call
CC ARGS() - (NLOC,NARG) argument values
Currently, NRET is always 1
CC
CC -------------------NARG is the number of variables which
CC
Modified
CC -------------------are passed to the routine to evaluate the
CC
return variable
CC Stacks possibly.
CC
ARGS() is the array where the input
CC -------------------arguments are stored
CC
Output
CC -------------------RET() is the array where the return values
CC
CC RET() - (NLOC,NRET) return values
are stored
CC CRESLT - 'GOOD' for success
ANSYS, Inc. Proprietary
2008 ANSYS, Inc. All rights reserved.

W1-6

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Creating Your Own Routine


3.
4.

Training Manual

Copy the template to a file named ucf_velocity.F


Change the name of the routine to uservelfunc and modify both the name of the
SUBROUTINE and the dllexport line
#include "cfx5ext.h"
dllexport(uservelfunc)
SUBROUTINE USERVELFUNC (
&

NLOC, NRET, NARG, RET, ARGS, CRESLT, CZ,DZ,IZ,LZ,RZ )

We will be passing three parameters/variables to the user routine: parameters


vmax and ybound and the spatial variable y:
vmax = args(1,1)
ybound = args(1,2)
y = args(i,3) where i = 1 to NLOC

5.

See the following slide for the required FORTRAN statements for the variable
assignments and the computation of the return value. After implementing these
statements, save the modified routine ucf_velocity.F

ANSYS, Inc. Proprietary


2008 ANSYS, Inc. All rights reserved.

W1-7

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

ucf_velocity.F

Training Manual

C -----------------------------C
Argument list
C -----------------------------INTEGER NLOC,NARG,NRET
CHARACTER CRESLT*(*)
REAL ARGS(NLOC,NARG), RET(NLOC,NRET)
INTEGER IZ(*)
CHARACTER CZ(*)*(1)
DOUBLE PRECISION DZ(*)
LOGICAL LZ(*)
REAL RZ(*)
C -----------------------------C
Local Variables
C -----------------------------REAL VMAX, YBOUND, Y
INTEGER I
C --------------------------C
Executable Statements
C --------------------------C
C Define parameters vmax and ybound from the input arguments
C
VMAX = ARGS(1,1)
YBOUND = ARGS(1,2)
C
C Loop over Y from 1 to NLOC and compute the normal speed in RET:
DO 10 I = 1,NLOC
Y = ARGS(I,3)
RET(I,1) = VMAX*(1.0 - Y**2/YBOUND**2)
10
CONTINUE
END
ANSYS, Inc. Proprietary
2008 ANSYS, Inc. All rights reserved.

W1-8

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Fortran Compilers

Training Manual

In order to compile and link


FORTRAN, you will need the
necessary software installed
on your machine
The tables at right show the standard
requirements for Windows and Linux
You run the cfx5mkext command to
compile the FORTRAN and build the
dynamic link libraries from the CFX
command prompt which you access
via Tools/Command Line from the
CFX-Launcher
For a typical Windows FORTRAN
installation, you should type ifortvars
from the CFX command line before
executing cfx5mkext
ANSYS, Inc. Proprietary
2008 ANSYS, Inc. All rights reserved.

W1-9

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Compiling the User Routine

Training Manual

6. From the CFX Launcher, make


sure that the directory is set to
your working directory and click
Tools > Command Line
7. From the CFX command
line issue the command:
ifortvars

followed by:
cfx5mkext ucf_velocity.F

This compiles the code


and creates the needed
libraries

ANSYS, Inc. Proprietary


2008 ANSYS, Inc. All rights reserved.

W1-10

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Setting Up the User Function in CFX-Pre

Training Manual

The set-up in CFX-Pre needs to


be modified to account for the
existence of a user routine and
the User CEL Function which calls
that routine

8. Click on the User Routine icon and


name the routine uservelocity
9. Set the following:

Option = User CEL Function


Calling Name = uservelfunc

This is the name given to the subroutine

Library Name = ucf_velocity

This is the name of the library created by


cfx5mkext (here the default name
applies, which is the name of the Fortran
file you compiled with cfx5mkext)

10. Set the Library Path to the folder where the Fortran source file
resides and click Ok
ANSYS, Inc. Proprietary
2008 ANSYS, Inc. All rights reserved.

W1-11

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Creating a User CEL Function

Training Manual

You now need to create the


user routine which will call
the user function you just defined

11. Click on the User Function icon


and name the function
normalspeed
12. Set the following:

Option = User Function


User Routine Name = uservelocity
Argument Units = m/s, m, m

These units correspond to vmax,


ybound, and y, respectively

13. Set the Result Units to m/s and


click Ok to complete the definition
of the User Routine
ANSYS, Inc. Proprietary
2008 ANSYS, Inc. All rights reserved.

W1-12

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Creating Expressions for Vmax and ybound

You can pass either expressions


or variables to a User Routine

In this case, we will pass two


expressions as parameters
(vmax and ybound) and one
spatial variable (y)

Training Manual

14. Click on the Expressions entry in


the Outline view in CFX-Pre,
then right-click and select Insert
Expression. Create the following
expressions:
vmax
ybound

ANSYS, Inc. Proprietary


2008 ANSYS, Inc. All rights reserved.

0.001 [m/s]
0.05 [m]

W1-13

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Using the CEL Function

Training Manual

Once the CEL function is defined, it


can be used like any other system
function on any form which accepts
an expression

15. Edit the inlet boundary condition.


Click on the Expression toggle next
the entry box for Normal Speed
and enter the expression:
normalspeed(vmax,ybound,y)
(Note that the arguments include
both expressions and variables
which is permissible)
16. Click Ok to apply the change

ANSYS, Inc. Proprietary


2008 ANSYS, Inc. All rights reserved.

W1-14

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Writing the Definition File

Training Manual

17. Write the CFX Solver File and


run the job.

Once the solver has started,


browse the top of the output file
and note the user functions and
user routines added in the
LIBRARY: section

ANSYS, Inc. Proprietary


2008 ANSYS, Inc. All rights reserved.

W1-15

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Monitoring the Run

ANSYS, Inc. Proprietary


2008 ANSYS, Inc. All rights reserved.

Training Manual

W1-16

August 26, 2008


Inventory #002568

Workshop 1: Inlet Velocity Profile

Results

ANSYS, Inc. Proprietary


2008 ANSYS, Inc. All rights reserved.

Training Manual

W1-17

August 26, 2008


Inventory #002568

S-ar putea să vă placă și