Professional Documents
Culture Documents
User Defined Functions: Fluent Software Training TRN-99-003
User Defined Functions: Fluent Software Training TRN-99-003
TRN-99-003
Introduction
u What is a User Defined Function?
l A UDF is a routine (programmed by the user) written in C which can be
dynamically linked with the solver.
n Standard C functions
s e.g., trigonometric, exponential, control blocks, do-loops, file i/o, etc.
n Pre-Defined Macros
s Allows access to field variable, material property, and cell geometry data.
UDF Basics
u UDF’s assigns values (e.g., boundary data,
source terms) to individual cells and cell faces
in fluid and boundary zones.
l In a UDF, zones are referred to as threads.
l A looping macro is used to access individual
cells belonging to a thread.
n e.g., a face-loop macro visits 563 faces
on face zone 3 (velocity-inlet).
s Position of each face is available
to calculate and assign spatially
varying properties.
n Thread and variable references are
automatically passed to UDF when
assigned to boundary in GUI.
u Values returned to the solver by UDFs must be in SI units.
u(y) = 20 [ 1 - (y/0.0745)2]
y=0
Macros
u Macros are pre-defined (Fluent) functions:
l Allows definition of UDF functionality and function name (DEFINE_ macro)
l Allows access to field variables, cell information, looping capabilities, etc.
u Macros are defined in header files.
l The udf.h header file must be included in your source code.
n #include “udf.h”
l The header files must be accessible in your path.
n Typically stored in Fluent.Inc/src/ directory.
l Other “.h” header files may need to be included.
n Depends upon relevant variables and macros needed in your UDF, e.g.,
s dpm.h for DPM variable access
DEFINE Macros
u Any UDF you write must begin with a DEFINE macro:
l 14 general purpose macros and 10 DPM-related macros (not listed):
DEFINE_ADJUST(name,domain); general purpose UDF called every iteration
DEFINE_INIT(name,domain); UDF used to initialize field variables
DEFINE_ON_DEMAND(name); defines an ‘execute-on-demand’ function
DEFINE_RW_FILE(name,face,thread,index); customize reads/writes to case/data files
DEFINE_PROFILE(name,thread,index); defines boundary profiles
DEFINE_SOURCE(name,cell,thread,dS,index); defines source terms
DEFINE_HEAT_FLUX(name,face,thread,c0,t0,cid,cir); defines heat flux
DEFINE_PROPERTY(name,cell,thread); defines material properties
DEFINE_DIFFUSIVITY(name,cell,thread,index); defines UDS and species diffusivities
DEFINE_UDS_FLUX(name,face,thread,index); defines UDS flux terms
DEFINE_UDS_UNSTEADY(name,face,thread,index); defines UDS transient terms
DEFINE_SR_RATE(name,face,thread,r,mw,yi,rr); defines surface reaction rates
DEFINE_VR_RATE(name,cell,thread,r,mw,yi,rr,rr_t); defines vol. reaction rates
DEFINE_SCAT_PHASE_FUNC(name,cell,face); defines scattering phase function for DOM
thread_loop_c(t, d){} loop that steps through all cell threads in domain
thread_loop_f(t, d){} loop that steps through all face threads in domain
begin_c_loop(c, t){} end_c_loop(c, t) loop that steps through all cells in a thread
begin_f_loop(f, t){} end_f_loop(f, t) loop that steps through all faces in a thread
u Face field variables are only available when using the segregated
solver and generally, only at exterior boundaries.
F_R(f,t); density
F_P(f,t); pressure
F_U(f,t); u-velocity
F_V(f,t); v-velocity
F_W(f,t); w-velocity
F_T(f,t); temperature
F_H(f,t); enthalpy
F_K(f,t); turbulent KE
F_D(f,t); tke dissipation
F_YI(f,t,i); species mass fraction
F_UDSI(f,t,i); UDS scalars
F_UDMI(f,t,i); UDM scalars
Supporting UDF’s
u Because UDF’s can be very complicated, Fluent Inc. does not assume
responsibility for the accuracy or stability of solutions obtained using
UDFs that are user-generated.
l Support will be limited to guidance related to communication between a
UDF and the FLUENT solver.
l Other aspects of the UDF development process that include conceptual
function design, implementation (writing C code), compilation and
debugging of C source code, execution of the UDF, and function design
verification will remain the responsibility of the UDF author.
n Consulting option
Outline
u Definitions; Examples of flow regimes
u Description of multiphase models in FLUENT 5 and FLUENT 4.5
u How to choose the correct model for your application
u Summary and guidelines
Definitions
u Multiphase flow is simultaneous flow of
l Matters with different phases( i.e. gas, liquid or solid).
l Matters with different chemical substances but with the same phase (i.e.
liquid-liquid like oil-water).
Flow Regimes
u Multiphase flow can be classified by the
following regimes:
l Bubbly flow: Discrete gaseous or fluid
bubbles in a continuous fluid
l Droplet flow: Discrete fluid droplets in a
continuous gas
slug flow bubbly flow droplet
l Particle-laden flow: Discrete solid flow particle-laden
particles in a continuous fluid flow
l Slug flow: Large bubbles (nearly filling
cross-section) in a continuous fluid
l Annular flow: Continuous fluid along
walls, gas in center
l Stratified/free-surface flow: Immiscible annular flow free-surface flow
fluids separated by a clearly-defined
interface
Flow Regimes
u User must know a priori what the flow field looks like:
l Flow regime,
n bubbly flow , slug flow, etc.
s Model one flow regime at a time.
Multiphase Models
u Four models for multiphase flows currently available in structured
FLUENT 4.5
l Lagrangian dispersed phase model (DPM)
u Unstructured FLUENT 5
l Lagrangian dispersed phase model (DPM)
l Cavitation Model
l temperature gradients
l user defined
u Two-Way Coupling
l Fluid phase influences particulate phase via drag and turbulence transfer.
continuous phase
flow field calculation
water
water
air
air
Mass Transfer
u Evaporation/Condensation.
l For liquid temperatures ≥ saturation temperature, evaporation rate:
rvα l ρ l (Tl − Tsat )
m& v =
Tsat
l For vapor temperatures ≤ saturation temperature, condensation rate:
rlα v ρ v (Tsat − Tv )
m& l =
Tsat
l User specifies saturation temperature and, if desired, “time relaxation
parameters” rl and rv . (Wen Ho Lee (1979))
u Unidirectional mass transfer, r is constant
m& 12 = rα 2 ρ1
u User Defined Subroutine for mass transfer
Courtesy of
Fuller Company
ASMM
u Solves for the momentum and the continuity equations of the mixture.
u Solves for the transport of volume fraction of secondary phase.
u Uses an algebraic relation to calculate the slip velocity between phases.
u It can be used for steady and unsteady flow.
r r
urel = a τ p
r
r r r r ∂um
a = ( g − (u m ⋅ ∇um + ))
∂t
( ρ m − ρ p )d p2
τp = f drag
18µ f
is the drag function
f drag
Oil-Water Separation
Courtesy of
Arco Exploration & Production Technology
Dr. Martin de Tezanos Pinto
27 © Fluent Inc. 2/20/01
Fluent Software Training
TRN-99-003
dR 2( p v − p ) 3 ρ vα v 2( p v − p )
= m& =
dt 3ρ l R 3ρ l
u Needs improvement:
l ability to predict collapse of cavity bubbles
n Needs to solve for enthalpy equation and thermodynamic properties
n Solve for change of bubble size
Cavitation model
VOF Model
Volume Fraction
u Assumes that each control volume contains just one phase (or the
interface between phases).
l For volume fraction of kth fluid, three conditions are possible:
n εk = 0 if cell is empty (of the kth fluid)
n εk = 1 if cell is full (of the kth fluid)
n 0 < εk < 1 if cell contains the interface between the fluids
u Tracking of interface(s) between phases is accomplished by solution of
a volume fraction continuity equation for each phase:
∂ε k ∂ε k
+ uj = Sε k
∂t ∂ xi
Mass transfer between phases can be modeled by using a user-defined
subroutine to specify a nonzero value for Sεk .
l Multiple interfaces can be simulated
l Can not resolve details of the interface smaller than the mesh size
VOF
u Solves one set of momentum equations for all fluids.
∂ ∂ ∂P ∂ ∂u i ∂u j
( ρu j ) + ( ρu i u j ) = − + µ( + ) + ρg j + F j
∂t ∂x i ∂ x j ∂ xi ∂x j ∂xi
Surface Tension
u Cylinder of water (5 x 1 cm) is surrounded by air in no gravity
u Surface is initially perturbed so that the diameter is 5% larger on ends
u The disturbance at the surface grows because of surface tension
Wall Adhesion
u Wall adhesion is modeled by specification of contact angle that fluid
makes with wall.
l Large contact angle (> 90°) is applied to water at bottom of container in
zero-gravity field.
l An obtuse angle, as measured in water, will form at walls.
l As water tries to satisfy contact angle condition, it detaches from bottom
and moves slowly upward, forming a bubble.
s Evaporators lFlotation
s Scrubbers lAeration
Eulerian For large bubbles either use Vof or modify the Drag
law. Ignores bubble coalescence or interaction.
All Values VOF Bubbles should span across several cells.Applicable
to separated flows: free surface flows, annular flows,
liquid films, stratified flows.
ASMM Only one solid size. More efficient than DPM. For
liquid-solid applications can be used for higher
volume fraction of solids but well below packing
limit.
All values Eulerian Solve in a transient manner..
Granular
40 © Fluent Inc. 2/20/01
Fluent Software Training
TRN-99-003
Solution Guidelines
u All multiphase calculations:
l Start with a single-phase calculation to establish broad flow patterns.
u Eulerian multiphase calculations:
l Use COPY-PHASE-VELOCITIES to copy primary phase velocities to
secondary phases.
l Patch secondary volume fraction(s) as an initial condition.
l For a single outflow, use OUTLET rather than PRESSURE-INLET; for
multiple outflow boundaries, must use PRESSURE-INLET for each.
l For circulating fluidized beds, avoid symmetry planes. (They promote
unphysical cluster formation.)
l Set the “false time step for underrelaxation” to 0.001
l Set normalizing density equal to physical density
l Compute a transient solution
Summary
u Modeling multiphase flows is very complex, due to interdependence of
many variables.
u Accuracy of results directly related to appropriateness of model you
choose:
l For most applications with low volume fraction of particles, droplets, or
bubbles, use ASMM or DPM model .
l For particle-laden flows, Eulerian granular multiphase model is best.
l For separated gas-liquid flows (stratified, free-surface, etc.) VOF model is
best.
l For general, complex gas-liquid flows involving multiple flow regimes:
n Select aspect of flow that is of most interest.
n Choose model that is most appropriate.
n Accuracy of results will not be as good as for others, since selected
physical model will be valid only for some flow regimes.
Conservation equations
u Conservation of mass
∂ r n
α q ρ q + ∇ ⋅ α q ρ q u q = ∑ m& pq
∂t p =1
u Conservation of momentum
∂ r r r v
α q ρ q uq + ∇ ⋅ (α q ρ q uq ⊗ uq ) = −α q ∇P + ∇ ⋅ α qτ q + α q ρq Fq +
∂t n r
∑ pq
( R + m& u
pq pq
)
u Conservation of enthalpy p =1
∂ r dpq r r
(α q ρq hq ) + ∇ ⋅ (α q ρ quq hq ) = −α q + τ k : ∇uq − ∇.qq + sq +
∂t dt
n
∑ (Qpq + m& pq hpq )
p =1
Constitutive Equations
r
u Frictional Flow (∇u s = 0)
l Particles are in enduring contact and momentum transfer is through
friction
l Stresses from soil mechanics, Schaeffer (1987)
u Description of frictional viscosity
Ps sin ϕ
µ s , frict =
2 I2
u Lift Force: Caused by the shearing effect of the fluid onto the particle
Drew and Lahey (1990).
r r r
K k , fs = C Lα s ρ f (u f − u s ) × (∇ × u f )
l Lift force usually insignificant compared to drag force except when the
phases separate quickly and near boundaries
∂ v µ kt
α k ρ k kk + ∇ ⋅ α k ρ k u k k k = ∇ ⋅ (ν k + ∇k k ) + Gk − α k ρ k ε k + Π k
∂t k σk k
∂ v µkt ε
α k ρk ε k + ∇ ⋅α k ρk uk ε k = ∇ ⋅ (ν k + ∇ε k ) + k {cε 1Gk − cε 2α k ρk ε k } + Πε
∂t k σε kk k
14 300
12 250
Syamlal-O'Brien Syamlal-O'Brien
10
Schuh et al. 200 Schuh et al.
8 Arastoopour
Gidaspow A
f Gidaspow A
Gidaspow B f 150
6 Arastoopour
Gidaspow B
Wen and Yu 100 WenandYu
4
Di Felice Di Felice
2 50
0 0
0.010.06 0.12 0.17 0.23 0.280.34 0.39 0.45 0.5 0.56 0.01 0.07 0.13 0.19 0.25 0.31 0.37 0.43 0.49 0.55
Solids volume fraction
Solids volume fraction
Implicit/Full
Implicit/FullElimination
Elimination TDMA
TDMACoupled
Coupled
Algorithm
Algorithmv4.5
v4.5 Algorithm
Algorithmv4.5
v4.5
u Solution!
l Consider a two phase liquid (primary) and solid (secondary)
n liquid has two species L1, L2
n solid has two species s1,s2
l Reactions within each phase i.e. (L1-->L2) and (s1-->s2) can be set up as
usual through GUI (like in single phase)
l For heterogeneous reaction e.g. (L1+0.5L2-->0.2s1+s2)
GOOD LUCK!!
Particle size
Descriptive terms Size range Example
Coarse solid 5 - 100 mm coal
Granular solid 0.3 - 5 mm sugar
Coarse powder 100-300 µm salt, sand
Fine powder 10-100 µm FCC catalyst
Super fine powder 1-10 µm face powder
Ultra fine powder ~1 µm paint pigments
Nano Particles ~1e-3 µm molecules
u i = u i + u 'i
where u ' i is derived from the local turbulence parameters:
u 'i = ς 2k
3
and ς is a normally distributed random number
u Mass flow rates and exchange source terms for each injection are
divided equally among the multiple stochastic tracks.
Cloud Tracking
u The particle cloud model uses statistical methods to trace the turbulent
dispersion of particles about a mean trajectory. The mean trajectory is
calculated from the ensemble average of the equations of motion for
the particles represented in the cloud. The distribution of particles
inside the cloud is represented by a Gaussian probability density
function.
Flow regimes
Combustion Modeling
in FLUENT
Outline
u Applications
u Overview of Combustion Modeling Capabilities
u Chemical Kinetics
u Gas Phase Combustion Models
u Discrete Phase Models
u Pollutant Models
u Combustion Simulation Guidelines
Applications
u Wide range of homogeneous
and heterogeneous reacting
flows
l Furnaces
Temperature in a gas furnace
l Boilers
l Process heaters
l Gas turbines
l Rocket engines
u Predictions of: CO2 mass fraction
l Flow field and mixing
characteristics
l Temperature field
l Species concentrations
l Particulates and pollutants Stream function
s Laminar flamelet
n Progress variable
s Zimont model
Rj = ∑R
k
jk
u Requires:
l List of species and their properties
l List of reactions and reaction rates
u FLUENT V5 provides this info in a mixture material database.
u Chemical mechanisms and physical properties for the most common
fuels are provided in database.
u If you have different chemistry, you can:
l Create new mixtures.
l Modify properties/reactions of existing mixtures.
1
p(V )∆V = lim
T→∞ T
∑τ
i
i
∂ ∂ ∂ ν t ∂c
( ρ c ) + ( ρ u c ) = ρ + Rc 0≤ c≤1
∂t ∂x i ∂x i Sc t ∂x i
i
NOx Models
u NOx consists of mostly nitric oxide (NO).
l Precursor for smog
l Contributes to acid rain
l Causes ozone depletion
u Three mechanisms included in FLUENT for NOx production:
l Thermal NOx - Zeldovich mechanism (oxidation of atmospheric N)
n Most significant at high temperatures
l Prompt NOx - empirical mechanisms by De Soete, Williams, etc.
n Contribution is in general small
n Significant at fuel rich zones
l Fuel NOx - Empirical mechanisms by De Soete, Williams, etc.
n Predominant in coal flames where fuel-bound nitrogen is high and
temperature is generally low.
u NOx reburn chemistry (V5)
l NO can be reduced in fuel rich zones by reaction with hydrocarbons
25 © Fluent Inc. 2/20/01
Fluent Software Training
TRN-99-003
u Turbulence
l Start with standard k-ε model
l Switch to RNG k-ε , Realizable k-ε or RSM to obtain better agreement
with data and/or to analyze sensitivity to the turbulence model
u Judging Convergence
l Residuals should be less than 10-3 except for T, P-1 and species, which
should be less than 10-6
l The mass and energy flux reports must balance
l Monitor variables of interest (e.g. mean temperature at the outlet)
l Ensure contour plots of field variables are smooth, realistic and steady
Concluding Remarks
u FLUENT V5 is the code of choice for combustion modeling.
l Outstanding set of physical models