Description of AdjointShapeOptimizationFoam
and how to implement new cost functions
Ulf Nilsson
Overview
I Introduction
I Theory
I Implementation
I Modifications
I Results
Introduction
Optimization in CFD
I Increased importance
I Optimization algorithm
- Simplex
- Evolution Strategies
- Gradient based
- ...
I Demanding
- Number of variables
- Constraints
Introduction
Adjoint approach
Optimization problem
Objective function
Optimization problem
Lagrangian relaxation
Z
minimize L := J + (u, q)RdΩ. (4)
Ω
Optimization problem
δL = δα L + δv L + δp L, (5)
δv L + δp L = 0. (6)
I Total variation.
I Choose adjoint variables so that the variation with respect to flow
variables vanishes.
I Equation of the adjoint variables and an expression for the sensitivity
of L with respect to the porosity of each cell, derivations out of the
scope of the project.
I Approximations needed to arrive at the adjoint equations.
- Forzen turbulence.
- Ducted flow specialization.
I Integration by parts to arrive at volume contribution and boundary
contribution.
Ulf Nilsson adjointShapeOptimizationFoam December 10, 2013 7 / 40
Overview Introduction Theory Implementation Modifications Results
Resulting equations
Sensitivity
∂L
= ui · vi Vi , (7)
∂αi
I Expression for cell i
I Vi the cell volume.
I Equation of the adjoint variables and an expression for the sensitivity
of L with respect to the porosity of each cell
Resulting equations
Adjoint equations
∂JΩ
−2D(u)v = −∇q + ∇ · (2νD(u)) − αu − , (8)
∂v
∂JΩ
∇·u= . (9)
∂p
Resulting equations
ut = 0, (10)
∂JΩ
un = − , (11)
∂p
n · ∇q = 0. (12)
Resulting equations
Resulting equations
Steepest descent
αn+1 = αn − ui · vi Vi δ. (16)
Solver
Solution procedure
Main-loop
Solve the
primal system
(v, p)
“Frozen tubulence”
Update the Solve the
porosity adjoint system
Steepest descent (u, q)
Convergence
assessment Converged
End
End time or
convergence condition
Solver
$FOAM SOLVERS/incompressible/
adjointShapeOptimizationFoam/
adjointShapeOptimizationFoam.C
Solver
Porosity update
94 a l p h a +=
95 mesh . f i e l d R e l a x a t i o n F a c t o r ( " alpha " )
96 ∗ ( min ( max ( a l p h a + lambda ∗ ( Ua & U) , z e r o A l p h a ) , alphaMax ) − a l p h a ) ;
Listing 1: file adjointShapeOptimizationFoam.C
Solver
Porosity update
94 a l p h a +=
95 mesh . f i e l d R e l a x a t i o n F a c t o r ( " alpha " )
96 ∗ ( min ( max ( a l p h a − lambda ∗ ( Ua & U) , z e r o A l p h a ) , alphaMax ) − a l p h a ) ;
Listing 2: file adjointShapeOptimizationFoam.C
Solver
103 // Momentum p r e d i c t o r
104
105 tmp<f v V e c t o r M a t r i x > UEqn
106 (
107 fvm : : d i v ( p h i , U)
108 + t u r b u l e n c e −>d i v D e v R e f f (U)
109 + fvm : : Sp ( a l p h a , U)
110 );
111
112 UEqn ( ) . r e l a x ( ) ;
113
114 s o l v e ( UEqn ( ) == −f v c : : g r a d ( p ) ) ;
Listing 3: file adjointShapeOptimizationFoam.C
Solver
Solver
Solver
The bad results when the sign in the steepest descent algorithm is
changed indicates additional problems with the current solver. Since the
actual solver seems to agree with the theory, what remains to be examined
is the boundary conditions.
First the boundary condition for a specific cost function need to be
calculated.
Power dissipation
1
Z
J := − (p + v 2 )v · n dΓ. (19)
2
Γ
ut = 0, (20)
∂JΩ
un = − , (21)
∂p
n · ∇q = 0. (22)
ut =(
0,
0 at wall,
un = (23)
vn at inlet,
n · ∇q = 0.
∂JΓ
q = u · v + un vn + ν(n · ∇)un + , (24)
∂vn
∂JΓ
0 = vn ut + ν(n · ∇)ut + . (25)
∂vt
(
q = u · v + un vn + ν(n · ∇)un − 21 v 2 − vn2 ,
(26)
0 = vn (ut − vt ) + ν(n · ∇)ut .
ν
−∆ uneigh,t − vp,n vp,t
ut = ν , (27)
vp,n + ∆
// c r e a t e t h e o b j e c t n e e d e d t o g e t t h e v i s c o u s i t y :
const i n c o m p r e s s i b l e : : RASModel& r a s M o d e l =
db ( ) . l o o k u p O b j e c t <i n c o m p r e s s i b l e : : RASModel>(" RASProperties " ) ;
// n u e f f from t h e t u r u l e n c e model , r a s M o d e l :
s c a l a r F i e l d n u e f f = rasModel . nuEff ( ) ( ) . boundaryField ( ) [ patch ( ) . index ( ) ] ;
// N e i g h b o u r i n g node ’ s v e l o c i t y ( n o r m a l component ) :
s c a l a r F i e l d U a n e i g h n = ( Uap . p a t c h I n t e r n a l F i e l d ( ) & p a t c h ( ) . n f ( ) ) ;
Listing 7: file myAdjointOutletVelocityFvPatchVectorField.C
Case settings
The boundary conditions of the primal and adjoint variables are set
according to the table below. More detailed information and m4 script of
the “box” example case can be found in the provided files.
Power dissipation
Power dissipation
0.006
”valueObjFunc.xy”
0.005
0.004
0.003
J
0.002
0.001
0
0 500 1000 1500 2000 2500 3000
Iteration step
Power dissipation
0.006
”valueObjFunc.xy”
0.005
0.004
0.003
J
0.002
0.001
0
0 500 1000 1500 2000 2500 3000
Iteration step
Power dissipation
Power dissipation
Questions