Description of AdjointShapeOptimizationFoam and how to implement new cost functions

Similar documents
Rhie-Chow interpolation in OpenFOAM 1

INDUSTRIAL APPLICATION OF CONTINUOUS ADJOINT FLOW SOLVERS FOR THE OPTIMIZATION OF AUTOMOTIVE EXHAUST SYSTEMS. C. Hinterberger, M.

OpenFOAM selected solver

Pressure-velocity correction method Finite Volume solution of Navier-Stokes equations Exercise: Finish solving the Navier Stokes equations

AN UNCERTAINTY ESTIMATION EXAMPLE FOR BACKWARD FACING STEP CFD SIMULATION. Abstract

RANS turbulence treatment for continuous adjoint optimization

Tutorial for the heated pipe with constant fluid properties in STAR-CCM+

Stratified scavenging in two-stroke engines using OpenFOAM

Large Scale Fluid-Structure Interaction by coupling OpenFOAM with external codes

Lecture 2: Fundamentals 2/3: Navier-Stokes Equation + Basics of Discretization

Boundary Conditions - Inlet

CHAPTER 7 NUMERICAL MODELLING OF A SPIRAL HEAT EXCHANGER USING CFD TECHNIQUE

On the transient modelling of impinging jets heat transfer. A practical approach

How to implement your own turbulence model(1/3)

Micro-Scale CFD Modeling of Packed-Beds

Differential relations for fluid flow

This chapter focuses on the study of the numerical approximation of threedimensional

Turbulent Boundary Layers & Turbulence Models. Lecture 09

How to implement your own turbulence model (1/3)

Calculating equation coefficients

Computation of turbulent Prandtl number for mixed convection around a heated cylinder

studies Maryse Page Hydro-Québec, Research Institute Håkan Nilsson Chalmers University of Technology Omar Bounous Chalmers University of Technology

Coupled calculations in OpenFOAM -

CFDOFAIRFLOWINHYDROPOWERGENERATORS FOR CONVECTIVE COOLING, USING OPENFOAM

viscousheatingsolver Martin Becker

Basic Fluid Mechanics

Boundary layer flows The logarithmic law of the wall Mixing length model for turbulent viscosity

CHARACTERISTIC OF VORTEX IN A MIXING LAYER FORMED AT NOZZLE PITZDAILY USING OPENFOAM

Computation of Unsteady Flows With Moving Grids

Unsteady Rotor-Stator Simulation of the U9 Kaplan Turbine Model

Keywords - Gas Turbine, Exhaust Diffuser, Annular Diffuser, CFD, Numerical Simulations.

Publication 97/2. An Introduction to Turbulence Models. Lars Davidson, lada

A Thorough Description Of How Wall Functions Are Implemented In OpenFOAM

Predictionof discharge coefficient of Venturimeter at low Reynolds numbers by analytical and CFD Method

V (r,t) = i ˆ u( x, y,z,t) + ˆ j v( x, y,z,t) + k ˆ w( x, y, z,t)

Simplified flow around a propeller for the course CFD with OpenSource Software

SOE3213/4: CFD Lecture 3

MAE 598 Project #1 Jeremiah Dwight

Conservation of Angular Momentum

Draft Tube calculations using OpenFOAM-1.5dev and validation with FLINDT data

Development of adjoint-based optimization methods for ducted flows in vehicles

( ) Notes. Fluid mechanics. Inviscid Euler model. Lagrangian viewpoint. " = " x,t,#, #

TOPOLOGY OPTIMIZATION OF NAVIER-STOKES FLOW IN MICROFLUIDICS

The effect of geometric parameters on the head loss factor in headers

Numerical Optimization Algorithms

Game Physics. Game and Media Technology Master Program - Utrecht University. Dr. Nicolas Pronost

Level Set-based Topology Optimization Method for Viscous Flow Using Lattice Boltzmann Method

Numerical Simulation of the Hagemann Entrainment Experiments

This section develops numerically and analytically the geometric optimisation of

International Journal of Scientific & Engineering Research, Volume 6, Issue 5, May ISSN

GENERALISATION OF THE TWO-SCALE MOMENTUM THEORY FOR COUPLED WIND TURBINE/FARM OPTIMISATION

INTRODUCCION AL ANALISIS DE ELEMENTO FINITO (CAE / FEA)

Fluid-Structure Interaction Problems using SU2 and External Finite-Element Solvers

DEVELOPED LAMINAR FLOW IN PIPE USING COMPUTATIONAL FLUID DYNAMICS M.

FEniCS Course. Lecture 6: Incompressible Navier Stokes. Contributors Anders Logg André Massing

CFD with OpenSource software A course at Chalmers University of Technology Taught by HÅKAN NILSSON. Project work: intersettlingfoam

Development of a consistent and conservative Eulerian - Eulerian algorithm for multiphase flows

A numerical investigation of tip clearance flow in Kaplan water turbines

OpenFOAM SIMULATION OF THE FLOW IN THE HÖLLEFORSEN DRAFT TUBE MODEL

Transient Thermal Flow and Thermal Stress Analysis Coupled NASTRAN and SC/Tetra

Evaluation of OpenFOAM for CFD of turbulent flow in

Computational Fluid Dynamics

CFD with OpenSource software

Process Chemistry Toolbox - Mixing

vector H. If O is the point about which moments are desired, the angular moment about O is given:

Basic Fluid Mechanics

A NUMERICAL ANALYSIS OF COMBUSTION PROCESS IN AN AXISYMMETRIC COMBUSTION CHAMBER

Turbulence Modeling of Air Flow in the Heat Accumulator Layer

report: Computational Fluid Dynamics Modelling of the Vortex Ventilator MK4 Rev 2 Ventrite International

Homework 4 in 5C1212; Part A: Incompressible Navier- Stokes, Finite Volume Methods

Prediction of Performance Characteristics of Orifice Plate Assembly for Non-Standard Conditions Using CFD

Magnetic induction and electric potential solvers for incompressible MHD flows

COMPUTATIONAL FLUID DYNAMIC ANALYSIS ON THE EFFECT OF PARTICLES DENSITY AND BODY DIAMETER IN A TANGENTIAL INLET CYCLONE HEAT EXCHANGER

Hybrid RANS/LES simulations of a cavitating flow in Venturi

Description and validation of the rotordisksource class for propeller performance estimation

Enhancement of Heat Transfer Effectiveness of Plate-pin fin heat sinks With Central hole and Staggered positioning of Pin fins

Initial and Boundary Conditions

A Simplified Numerical Analysis for the Performance Evaluation of Intercooler

CFD analysis of the transient flow in a low-oil concentration hydrocyclone

Viscoelastic Fluid Simulation with OpenFOAM

150A Review Session 2/13/2014 Fluid Statics. Pressure acts in all directions, normal to the surrounding surfaces

EXAMPLE 115 NON-ISOTHERMAL FLOW IN A SINGLE SCREW EXTRUDER DESCRIPTION KEYWORDS FILENAMES. Example 115

Prepared by: Simanto. Date: Sunday, August 17, 2014

ECE580 Fall 2015 Solution to Midterm Exam 1 October 23, Please leave fractions as fractions, but simplify them, etc.

1 Exercise: Linear, incompressible Stokes flow with FE

Drag Coefficient of Tall Building by CFD Method using ANSYS

2Dimensional CFD Simulation of Gas Fired Furnace during Heat Treatment Process

Solving PDEs with OpenFOAM

Description of poroussimplefoam and adding the Brinkmann model to the porous models Developed for OpenFOAM-2.2.x

Tutorial for the supercritical pressure pipe with STAR-CCM+

Fluid Dynamics Exercises and questions for the course

Simulating Drag Crisis for a Sphere Using Skin Friction Boundary Conditions

JMBC Computational Fluid Dynamics I Exercises by A.E.P. Veldman

A Two-Fluid/DQMOM Methodology For Condensation In Bubbly Flow

ABSTRACT I. INTRODUCTION

Analysis of the Cooling Design in Electrical Transformer

Angular momentum equation

CFD in Heat Transfer Equipment Professor Bengt Sunden Division of Heat Transfer Department of Energy Sciences Lund University

ABSTRACT I. INTRODUCTION

Constrained optimization

Transcription:

Description of AdjointShapeOptimizationFoam and how to implement new cost functions A project work in the course CFD with OpenSource software, taught by Håkan Nilsson. Chalmers University of Technology, Gothenburg, Sweden December 10, 2013 December 10, 2013 1 /

Overview Introduction Theory Implementation Modifications Results December 10, 2013 2 /

Introduction Optimization in CFD Increased importance Optimization algorithm - Simplex - Evolution Strategies - Gradient based -... Demanding - Number of variables - Constraints December 10, 2013 3 /

Introduction Adjoint approach Gradient based method Tool to compute sensitivity w.r.t. design variables Well behaved objective function Large number of design variables Constraints, number of functions December 10, 2013 4 /

Optimization problem Objective function minimize J = J(v, p, α) (1) such that (v )v + p (2νD(v)) + αv = 0, (2) v = 0. (3) Gerneral cost function Incompressible, steady state RANS equation Porosity α Topology optimization December 10, 2013 5 /

Optimization problem Lagrangian relaxation minimize L := J + Lagrange multipliers, (u, q) A penalty to violate the constraints Adjoint velocity, u, and pressure, q No physical meaning Ω (u, q)rdω. (4) December 10, 2013 6 /

Optimization problem Variations w.r.t. flow and design variables δl = δ α L + δ v L + δ p L, (5) δ v L + δ p L = 0. (6) Total variation. Choose adjoint variables so that the variation with respect to flow variables vanishes. 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. Approximations needed to arrive at the adjoint equations. - Forzen turbulence. - Ducted flow specialization. Integration by parts to arrive at volume contribution and boundary contribution. December 10, 2013 7 /

Resulting equations Sensitivity Expression for cell i V i the cell volume. L α i = u i v i V i, (7) Equation of the adjoint variables and an expression for the sensitivity of L with respect to the porosity of each cell December 10, 2013 8 /

Resulting equations Adjoint equations 2D(u)v = q + (2νD(u)) αu J Ω v, (8) u = J Ω p. (9) Contribution from volumetric part of the cost function, J Ω. December 10, 2013 9 /

Resulting equations Adjoint boundary conditions Wall and inlet boundary conditions Outlet boundary conditions u t = 0, (10) u n = J Ω p, (11) n q = 0. (12) q = u v + u n v n + ν(n )u n + J Γ v n, (13) 0 = v n u t + ν(n )u t + J Γ v t. (14) December 10, 2013 10 /

Resulting equations Adjoint boundary conditions Wall Inlet Outlet v No-slip Prescribed value Zero gradient p Zero gradient Zero gradient p = 0 Table: Boundary conditions for the primal quantities v and p. Only valid for specific primal boundary condition. Contribution from both the volume and boundary part of the cost function, J Ω and J Γ respectively. Eq. 13 and 14 used to calculate the adjoint pressure and tangential part of the adjoint velocity at the outlet. December 10, 2013 11 /

Resulting equations Summary of the theory Introducing a Lagrange relaxation, with multipliers u and q. Choice of adjoint variables gives adjoint equations and an expression for the sensititivity. Lengthy derivations. Approximations and requirements to ensure a valid method. If the cost function satisfies J ω = 0 the dependence of J enters the solver only through the boundary conditions. The optimization problem reduces to solving two flow equations, the primal and the adjoint. When the sensitivity is calculated an algorithm is needed to update the porosity. December 10, 2013 12 /

Steepest descent algorithm Steepest descent p k = f(x k ), (15) α n+1 = α n u i v i V i δ. (16) General search direction in the opposite direction of the gradient of the objective function. Considering a linear problem a minimum will be found for small enough steps in the search direction. Using the sensitivity, L/ α to update. The step length δ. An optimization problem of its own. Under relaxation and limits in the final implementation. December 10, 2013 13 /

Solver Solution procedure Main-loop Update the porosity Steepest descent Solve the primal system (v, p) Solve the adjoint system (u, q) Frozen tubulence Convergence assessment End time or convergence condition Converged End Figure 1: Block scheme of the solution procedure used in. December 10, 2013 14 /

Solver $FOAM SOLVERS/incompressible/ /.C Let us study the implementation together, trying to identify the underlying theory we have covered so far. In the order it is implemented in the code. Porosity update - Implementation of the steepest descent using under relaxation. - Correct? The primal pressure-velocity SIMPLE corrector - How is the sink term implemented? The adjoint pressure-velocity SIMPLE corrector - Is the current implementation done for objective functions with volumteric contribution (J Ω 0)? December 10, 2013 15 /

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( alpha + lambda (Ua & U), zeroalpha ), alphamax ) alpha ) ; Listing 1: file.c α n+1 = α n (1 γ) + γmin (max ((α n + u i v i V i δ).0), α max ), (17) December 10, 2013 16 /

Solver Porosity update However the there seems to be an incorrect sign in the steepest descent implementation. The correct eq. and implementation should be α n+1 = α n (1 γ) + γmin (max ((α n u i v i V i δ), 0), α max ). (18) 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( alpha lambda (Ua & U), zeroalpha ), alphamax ) alpha ) ; Listing 2: file.c December 10, 2013 17 /

Solver Primal SIMPLE loop 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 ( phi, 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 ( alpha, U) 110 ) ; 111 112 UEqn ( ). r e l a x ( ) ; 113 114 s o l v e (UEqn ( ) == f v c : : grad ( p ) ) ; Listing 3: file.c December 10, 2013 18 /

Solver Primal SIMPLE loop fvm::sp(alpha, U) Implicit implementation of the extra source term. December 10, 2013 19 /

Solver Adjoint SIMPLE loop 156 // A d j o i n t Momentum p r e d i c t o r 157 158 volvectorfield adjointtransposeconvection ( ( fvc : : grad (Ua) & U ) ) ; 159 // v o l V e c t o r F i e l d a d j o i n t T r a n s p o s e C o n v e c t i o n 160 // ( 161 // fvc : : reconstruct 162 // ( 163 // mesh. magsf ( ) ( f v c : : sngrad (Ua) & f v c : : i n t e r p o l a t e (U) ) 164 // ) 165 // ) ; 166 167 z e r o C e l l s ( a d j o i n t T r a n s p o s e C o n v e c t i o n, i n l e t C e l l s ) ; 168 169 tmp<f v V e c t o r M a t r i x > UaEqn 170 ( 171 fvm : : d i v ( phi, Ua) 172 a d j o i n t T r a n s p o s e C o n v e c t i o n 173 + t u r b u l e n c e >d i v D e v R e f f (Ua) 174 + fvm : : Sp ( alpha, Ua) 175 ) ; 176 177 UaEqn ( ). r e l a x ( ) ; 178 179 s o l v e ( UaEqn ( ) == f v c : : grad ( pa ) ) ; Listing 4: file.c December 10, 2013 20 /

Solver Adjoint SIMPLE loop Similar to the primal system. No additional terms containing information about the cost function, i.e. current implementation treats cost functions of the type J Γ = 0 December 10, 2013 21 /

Boundary conditions of the adjoint variables Adjoint boundary conditions 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. December 10, 2013 22 /

Boundary conditions of the adjoint variables Power dissipation J := Only boundary contribution. Γ (p + 1 2 v2 )v n dγ. (19) Energy loss, due to pressure drop and kinetic energy. December 10, 2013 23 /

Boundary conditions of the adjoint variables Inlet boundary conditions u t = 0, (20) u n = J Ω p, (21) n q = 0. (22) u t = { 0, u n = n q = 0. 0 at wall, v n at inlet, (23) December 10, 2013 24 /

Boundary conditions of the adjoint variables Inlet boundary conditions Use existing conditions - Prescribed value - No slip - Zero-gradient Could be useful to implement a inlet boundary condition for the adjoint velocity, if the velocity profile of the primal velocity at the inlet is not easily described. December 10, 2013 25 /

Boundary conditions of the adjoint variables Outlet boundary conditions q = u v + u n v n + ν(n )u n + J Γ v n, (24) 0 = v n u t + ν(n )u t + J Γ v t. (25) { q = u v + u n v n + ν(n )u n 1 2 v2 v 2 n, 0 = v n (u t v t ) + ν(n )u t. (26) December 10, 2013 26 /

Boundary conditions of the adjoint variables Outlet boundary conditions Use eq. 26 to prescribe a value to the adjoint pressure Use eq. 26 to prescribe a value to the tangential component of the adjoint velocity u t = ν u neigh,t v p,n v p,t v p,n + ν, (27) December 10, 2013 27 /

Boundary conditions of the adjoint variables Implementation of pressure condition 86 // Member F u n c t i o n s // 87 88 void Foam : : adjointoutletpressurefvpatchscalarfield : : updatecoeffs ( ) 89 { 90 i f ( updated ( ) ) 91 { 92 return ; 93 } 94 95 const fvspatchfield <scalar>& phip = 96 patch ( ). lookuppatchfield <s u r f a c e S c a l a r F i e l d, s c a l a r >("phi" ) ; 97 98 const fvspatchfield <scalar>& phiap = 99 patch ( ). lookuppatchfield <s u r f a c e S c a l a r F i e l d, s c a l a r >("phia" ) ; 100 101 const f v P a t c h F i e l d <v e c t o r >& Up = 102 patch ( ). lookuppatchfield <v o l V e c t o r F i e l d, vector >("U" ) ; 103 104 const f v P a t c h F i e l d <v e c t o r >& Uap = 105 patch ( ). lookuppatchfield <v o l V e c t o r F i e l d, vector >("Ua" ) ; 106 107 operator==((phiap /patch ( ). magsf ( ) 1.0) phip /patch ( ). magsf ( ) + (Up & Uap ) ) ; 108 109 fixedvaluefvpatchscalarfield : : updatecoeffs ( ) ; 110 } Listing 5: file adjointoutletpressurefvpatchscalarfield.c December 10, 2013 28 /

Boundary conditions of the adjoint variables Implementation of velocity condition 83 // Member F u n c t i o n s // 84 85 // Update the coefficients associated with the patch f i e l d 86 void Foam : : adjointoutletvelocityfvpatchvectorfield : : updatecoeffs ( ) 87 { 88 i f ( updated ( ) ) 89 { 90 return ; 91 } 92 93 const fvspatchfield <scalar>& phiap = 94 patch ( ). lookuppatchfield <s u r f a c e S c a l a r F i e l d, s c a l a r >("phia" ) ; 95 96 const f v P a t c h F i e l d <v e c t o r >& Up = 97 patch ( ). lookuppatchfield <v o l V e c t o r F i e l d, vector >("U" ) ; 98 99 s c a l a r F i e l d Un(mag( patch ( ). n f ( ) & Up ) ) ; 100 vectorfield UtHat ( (Up patch ( ). nf ( ) Un ) / (Un + SMALL ) ) ; 101 102 v e c t o r F i e l d Uan ( patch ( ). nf ( ) ( patch ( ). n f ( ) & p a t c h I n t e r n a l F i e l d ( ) ) ) ; 103 104 vectorfield : : operator=(phiap patch ( ). Sf ( ) / sqr ( patch ( ). magsf ( ) ) + UtHat ) ; 105 // vectorfield : : operator=(uan + UtHat ) ; 106 107 fixedvaluefvpatchvectorfield : : updatecoeffs ( ) ; 108 } Listing 6: file adjointoutletvelocityfvpatchvectorfield.c December 10, 2013 29 /

Boundary conditions of the adjoint variables Analyzing the implementation Listing 5 gives an implementation of the pressure condition according to compare to q = (u n 1)v n + u v. (28) q = u v + u n v n + ν(n )u n 1 2 v2 v 2 n, (29) Listing 6 gives an implementation of the velocity condition according to compare to u p,t = v p v p,n u p,n + SMALL. (30) u t = ν u neigh,t v p,n v p,t v p,n + ν, (31) December 10, 2013 30 /

Boundary conditions of the adjoint variables Analyzing the theory Not equal to the theory. Another cost function, total pressure loss. Approximations or derivations done makes the cost function hard to identify. December 10, 2013 31 /

Analyzing the theory Changing the sign of the steepest descent implementation. Implementing the cost functions according to derived equations. December 10, 2013 32 /

Adjoint pressure boundary condition Similar to the existing implementation A few additional terms - Velocity in the neighbouring node - Effective viscosity const scalarfield& deltainv = patch ( ). deltacoeffs ( ) ; // distance ˆ( 1) between patch and neighbouring node. // create the object needed to get the v i s c o u s i t y : const incompressible : : RASModel& rasmodel = db ( ). lookupobject<incompressible : : RASModel>("RASProperties" ) ; // n u e f f from the t u r u l e n c e model, rasmodel : s c a l a r F i e l d n u e f f = rasmodel. n u E f f ( ) ( ). b o u n d a r y F i e l d ( ) [ patch ( ). i n d e x ( ) ] ; // Neighbouring node s v e l o c i t y ( normal component ) : s c a l a r F i e l d Uaneigh n = (Uap. p a t c h I n t e r n a l F i e l d ( ) & patch ( ). nf ( ) ) ; Listing 7: file myadjointoutletvelocityfvpatchvectorfield.c December 10, 2013 33 /

Adjoint velocity boundary condition Vector fields instead of scalar fields // patchinternalfield to get the adjoint v e l o c i t y of neighbouring node. vectorfield Uaneigh = Uap. patchinternalfield ( ) ; // I t s tangential and normal components vectorfield Uaneigh n = ( Uaneigh & normal ) normal ; v e c t o r F i e l d Uaneigh t = Uaneigh Uaneigh n ; Listing 8: file myadjointoutletvelocityfvpatchvectorfield.c December 10, 2013 34 /

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. Wall Inlet Outlet u Prescribed value, 0 Prescribed value, u n = v n adjointoutletvelocitypower q Zero gradient Zero gradient adjointoutletpressurepower December 10, 2013 35 /

Power dissipation pitzdaily porosity field December 10, 2013 36 /

Power dissipation pitzdaily value of the objective function 0.006 valueobjfunc.xy 0.005 0.004 J 0.003 0.002 0.001 0 0 500 1000 1500 2000 2500 3000 Iteration step December 10, 2013 37 /

Power dissipation pitzdaily value of the objective function, without porosity update 0.006 valueobjfunc.xy 0.005 0.004 J 0.003 0.002 0.001 0 0 500 1000 1500 2000 2500 3000 Iteration step December 10, 2013 38 /

Power dissipation Pipe bend example December 10, 2013 39 /

Power dissipation Thank you for listening! Questions December 10, 2013 /