...

Chapter 6 CFX Expression Language CEL

by user

on
Category:

physics

131

views

Report

Comments

Transcript

Chapter 6 CFX Expression Language CEL
Chapter 11
CFX Expression Language
(CEL)
Introduction to CFX
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
11-1
April 28, 2009
Inventory #002598
CFX Expression Language
CEL
Training Manual
• CEL - CFX Expression Language
– Allows the user to create equations (can be functions of
solution/system variables) that can be used in CFX-Pre and CFD-Post
• Example:
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
11-2
April 28, 2009
Inventory #002598
CFX Expression Language
CEL Rules
Training Manual
• The syntax rules are the same as those for conventional arithmetic.
Operators are written as:
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
^ (exponentiation)
• Variables and expressions are case sensitive (example: t vs. T)
• Expressions must be dimensionally consistent for addition and subtraction
operations (example: 1.0 [mm] + 0.45 [yds] is OK)
– You cannot add values with inconsistent dimensions
• Fractional and decimal powers are allowed (example: a^(1/2) + 1.0^0.5)
• Units of expressions are not declared – they are the result of units in the
expression (example: a [kg m^-3] * b [m s^-1] has units of [kg m^-2 s^-1]
• Some constants are also available in CEL for use in expressions:
–
–
–
–
e
g
pi
R
Constant: 2.7182818
Acceleration due to gravity: 9.806 [m s^-2]
Constant: 3.1415927
Universal Gas Constant: 8314.5 [m^2 s^-2 K^-1]
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
11-3
April 28, 2009
Inventory #002598
CFX Expression Language
Built In Functions
Training Manual
• Numerical functions and operators are also available in CEL
– Right-click when creating expressions for a complete list
– Custom functions with User Fortran can also be created
Function
sin(x)
cos(x)
tan(x) ***
asin(x)
acos(x)
atan(x)
exp(x)
loge(x)
log10(x)
abs(x)
sqrt(x)
if(test, res1, res2)*
min(x,y) ****
max(x,y) ****
step(x) *
Operand’s Dimensions [x]
Angle
Angle
Angle
Dimensionless
Dimensionless
Dimensionless
Dimensionless
Dimensionless
Dimensionless
Any
Any
Any
Any
Any
Dimensionless
Operand’s Values
Any
Any
Any
-1 x 1
-1 x 1
Any
Any
0<x
0<x
Any
0 x
Any
Any
Any
Any
Result’s Dimensions
Dimensionless
Dimensionless
Dimensionless
Angle
Angle
Angle
Dimensionless
Dimensionless
Dimensionless
[x]
[x]^0.5
Any (res1 and res2 must have the same dimensions)
[x]
[x]
Dimensionless
*if functions contain a test, and two result outcomes. The first outcome, res1 will be returned if test evaluates to true. If test evaluates to false, res2 is
returned. Consider the following example, where we wish to set volume fraction to 1 when X is greater than 1 [m], and 0 if X is less than 1 [m]:
if (x>1[m], 1, 0)
In this case, if the result is precisely equal to 1[m], the result is (res1+res2)/2
**step(x) is 0 for negative x, 1 for positive x and 0.5 for x=0.
*** note that tan(x) is undefined for np/2 where n=1, 3, 5 .. .
**** both x and y must have the same dimensions.
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
11-4
April 28, 2009
Inventory #002598
CFX Expression Language
Solver Variables
Training Manual
• Solver variables are available for use in any expression
• Below is a partial list of the available system variables:
– When creating expressions, right-click to access a full list
x
y
z
r
theta
t
u
v
w
p
ke
ed
T
sstrnr
density
rNoDim
viscosity
Cp
cond
AV name
mf
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
Direction 1 in Reference Coordinate Frame
Direction 2 in Reference Coordinate Frame
Direction 3 in Reference Coordinate Frame
Radial spatial location, r = (x^2+y^2)^0.5
Angle, arctan(y/x)
Time
Velocity in the x coordinate direction
Velocity in the y coordinate direction
Velocity in the z coordinate direction
(absolute) Pressure
Turbulent kinetic energy
Turbulent eddy dissipation
Temperature
Shear strain rate
Density
Non-dimensional radius (rotating frame only)
Dynamic Viscosity
Specific Heat Capacity at Constant Pressure
Thermal Conductivity
Additional Variable name
Mass Fraction
11-5
Depending on your
physics, some
variables will not be
valid – e.g. you need
to solver heat transfer
to use T
April 28, 2009
Inventory #002598
CFX Expression Language
How To Create Expressions
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
Training Manual
11-6
April 28, 2009
Inventory #002598
CFX Expression Language
How To Create Expressions
Training Manual
To add more
expressions
(similar method in
CFD-Post)
Right-click in the
Definition window
to access
Variables,
Constants,
Functions,
Locators and
existing
Expressions
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
11-7
April 28, 2009
Inventory #002598
CFX Expression Language
CEL in CFX-Pre: Example 1
Training Manual
• Creating a variable viscosity
– Viscosity of a shear thickening fluid:
  K n1
where  is the shear strain rate
Solver Variable and Expression Name are both
accessed via the right mouse button
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
11-8
April 28, 2009
Inventory #002598
CFX Expression Language
CEL in CFX-Pre: Example 1
Training Manual
• Alternatively, an expression can be entered directly into a field
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
11-9
April 28, 2009
Inventory #002598
CFX Expression Language
CEL in CFX-Pre: Example 2
Training Manual
• Using an “if” Function
– Set inlet temperature to 300 K for the first 19 iterations then raise it to
320 K after 20 iterations
Solver variable
accessed with the right
mouse button
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
Note: On the 21st iteration
inlet temp = 310 K
11-10
April 28, 2009
Inventory #002598
CFX Expression Language
User Functions
Training Manual
• You can also define your own 1-D linear, or 3-D cloud of points
interpolation functions
Import
data
points or
add
manually
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
11-11
April 28, 2009
Inventory #002598
CFX Expression Language
User Functions: Example
Training Manual
• Example: Having the timestep change
with iteration number as shown here
Iteration Number is
dimensionless
Timestep size is in seconds
Continued on next
slide...
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
11-12
April 28, 2009
Inventory #002598
CFX Expression Language
User Functions: Example
Training Manual
• Example: Having the timestep change
with iteration number as shown here
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
11-13
April 28, 2009
Inventory #002598
CFX Expression Language
Integrated Quantities
Training Manual
• Integrated quantities can be used in expressions to evaluate variables over
some location
– Examples:
– Calculate the area average of Cp on an isosurface: areaAve(Cp)@iso1
– Mass flow of particular fluid through a locator: oil.massFlow()@slice1
• Available in CFX-Pre and CFD-Post
– Usage is more strict in CFX-Pre
• E.g. the argument supplied to the function must be a variable, not an expression
• “@<locator>” syntax must always supply a named location used in the
physics definition
– A boundary condition name, a domain name, a monitor point name, etc.
• To reference general mesh regions use the syntax [email protected]:<name>”
• Phases/components can be referenced using:
[<phase name>.][<component name>.]<function>@<locator>
– E.g. Air.Nitrogen.massFlow()@outlet
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
11-14
April 28, 2009
Inventory #002598
CFX Expression Language
Integrated Quantities
Training Manual
• Some functions allow an x, y or z operator:
– area_x()@boundary gives the area projected in the x-direction
– force_z()@wall gives the z component of the force on the wall
– See documentation for a full list
• These functions also allow an optional coordinate frame:
– force_z_MyCoord()@wall gives the z component of the force on the wall using the
coordinate frame “MyCoord”
• Each function requires either 0 or 1 arguments
– areaAve requires 1 argument: areaAve(Temperature)@Wall
– massFlow requires 0 arguments: massFlow()@Inlet
• Return value units depend on the argument units
– areaAve(Temperature)@Wall will return a value with units of Temperature
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
11-15
April 28, 2009
Inventory #002598
CFX Expression Language
Integrated Quantities
Training Manual
• Below is a partial list of functions
– See documentation for a complete list
– Right-clicking when creating an expression will show most functions
Function Name and Syntax
<required> [<optional>]
area( )@<Location>
area_x( )@<Location>
area_y( )@<Location>
area_z( )@<Location>
areaAve(<var>)@<Location>
areaInt(<var>)@<Location>
ave(<var>)@<Location>
[<Fluid>.]force( )@<Location>
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
Operation
Valid <Location>
Area of a boundary or
Any 2D region (e.g., boundary
interface.
or interface)
The (signed) component of the
normal area vector in the local
x, y or z direction.
Any 2D region (e.g., a
boundary or interface)
Area-weighted average of <var> Any 2D region (e.g., a
on a boundary.
boundary or interface)
Area-weighted integral of <var> Any 2D region (e.g., a
on a boundary.
boundary or interface)
Arithmetic average of <var>
Any 3D region (e.g., domain or
within a domain or subdomain. subdomain)
The magnitude of the force
vector on a boundary.
Any 2D region (e.g., a wall)
11-16
April 28, 2009
Inventory #002598
CFX Expression Language
Integrated Quantities
Function Name and Syntax
<required> [<optional>]
[<Fluid>.]force_x( )@<Location>
[<Fluid>.]force_y( )@<Location>
[<Fluid>.]force_z( )@<Location>
inside()@<Location>
mass()@<Location>
massAve(<var>)@<Location>
massInt(<var>)@<Location>
[<Fluid>.]massFlow()@<Location>
[<Fluid>.]massFlowAve(<var>)
@<Location>
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
Training Manual
Operation
Valid <Location>
The (signed) component of the
force vector in the local x, y
or z direction.
Any 2D region (e.g., a wall)
Any 2D or 3D named subregion of the physical location
Similar to the subdomain
variable, but allows a specific on which the expression is
2D or 3D location to be given. evaluated.
The total mass within a domain
or subdomain. This is fluid
Any 3D region (e.g., domain or
dependent.
subdomain)
Mass-weighted average of
<var> on a domain or
Any 3D region (e.g., domain or
subdomain.
subdomain)
The mass-weighted integration
of <var> within a domain or
Any 3D region (e.g., domain or
subdomain
subdomain)
Any fluid surfaces (e.g., Inlets,
Outlets, Openings and fluidMass flow through a boundary. fluid interfaces)
Any fluid surfaces (e.g., Inlets,
Mass flow weighted average of Outlets, Openings and fluid<var> on a boundary.
fluid interfaces)
11-17
April 28, 2009
Inventory #002598
CFX Expression Language
Integrated Quantities
Function Name and Syntax
<required> [<optional>]
Training Manual
Operation
Valid <Location>
[<Fluid>.]massFlowInt(<var>)
@<Location>
Any fluid surfaces (e.g., Inlets,
Outlets, Openings and fluidfluid interfaces)
Any fluid surfaces (e.g., Inlets,
Mass flow weighted integration Outlets, Openings and fluidof <var> on a boundary.
fluid interfaces)
maxVal(<var>)@<Location>
Maximum Value of <var>
Any 3D region (e.g., domain or
within a domain or subdomain. subdomain)
[<Fluid>.]massFlowAveAbs(<var>)
@<Location>
minVal(<var>)@<Location>
probe(<var>)@<Location>
rmsAve(<var>)@<Location>
sum(<var>)@<Location>
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
Absolute mass flow weighted
average of <var> on a
boundary.
Minimum Value of <var> within
a domain or subdomain.
Returns the value of the
specified variable on the
specified Point locator.
RMS average of <var> within a
domain.
Sum of <var> over all domain
or subdomain vertices.
11-18
Any 3D region (e.g., domain or
subdomain)
Any point object (e.g., a
Source Point or Cartesian
Monitor Point)
Any 3D region (e.g., domain or
subdomain)
Any 3D region (e.g., domain or
subdomain)
April 28, 2009
Inventory #002598
CFX Expression Language
Useful Functions
Training Manual
• The inside() function returns 1 when inside the specified location and
0 when outside
– Useful to limit the scope of a function to a subdomain or boundary
• The step() function return 1 when the argument is positive and 0
when the argument is negative
– Useful as an on-off switch
– if() function can also be used as a switch
• areaAve() and massFlowAve() are used to evaluate the average of a
quantity on a location
– areaAve() is an area-weighted average. It is usually used on wall
boundaries and when the quantity is not “carried with the flow”, e.g.
Pressure at an outlet, Temperature on a wall
– massFlowAve() is an average weighted by the local mass flow. It is
usually used to evaluate quantities that are “carried with the flow”, e.g.
Temperature at an outlet
ANSYS, Inc. Proprietary
© 2009 ANSYS, Inc. All rights reserved.
11-19
April 28, 2009
Inventory #002598
Fly UP