precision and sensitivity analysis of the numerical

42
Implementation of the Numerical Jacobian in SU2 Precision and Sensitivity Analysis of the Numerical Jacobian implementation in the SU2 Open-Source Suite for Multiphysics Simulation and Design Supervisor: Paolo Francesco Barbante Supervisor: Luca Formaggia Jos´ e Yuri Villafan Matr. 883536 Academic Year 2018-2019

Upload: others

Post on 26-Apr-2022

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Precision and Sensitivity Analysis of the Numerical

Implementation of the Numerical

Jacobian in SU2

Precision and Sensitivity Analysis of the

Numerical Jacobian implementation in the SU2

Open-Source Suite for Multiphysics Simulation

and Design

Supervisor: Paolo Francesco BarbanteSupervisor: Luca Formaggia

Jose Yuri Villafan Matr. 883536

Academic Year 2018-2019

Page 2: Precision and Sensitivity Analysis of the Numerical

Abstract

Computational analysis tools are a staple in the Multiphysics Simula-tion and Design community, and the availability of open-source programsenhances the quantity and quality of data at researchers’ disposal.

SU2 Suite’s objective is to offer a broad array of numerical methods tobe used in numerical analysis of computational fluid dynamics problems.It does so by implementing diverse software tools written in C++ that canbe used in the simulation and analysis of the aforementioned problems.

The objective of this report is to introduce the effectiveness and short-comings of the computation in both analytical and numerical ways of theJacobian matrices for steady Euler compressible problems.

First, a brief introduction to the SU2 Suite will be presented, in orderto make the reader acquainted with such a powerful tool. Then, a seriesof analysis, introduced by related theoretical aspects, will be presented.

The focus of the report will be the introduction of the numerical com-putation of the Jacobian matrix in CFD problems. Analysis regarding itseffectiveness will be carried out, with particular consideration to its intro-duction in the ROE numerical scheme for compressible Euler problems.

2

Page 3: Precision and Sensitivity Analysis of the Numerical

Contents

1 SU2, the Open-Source CFD Code 51.1 SU2 workflow . . . . . . . . . . . . . . . . . . . . . . . . . . 51.2 CGeometry, CSolver and CNumerics classes . . . . . . . . . 7

2 Modeling 102.1 Newton-Raphson method . . . . . . . . . . . . . . . . . . . 112.2 Numerical Jacobian . . . . . . . . . . . . . . . . . . . . . . 122.3 Implementation issues . . . . . . . . . . . . . . . . . . . . . 132.4 Backtracking line search . . . . . . . . . . . . . . . . . . . . 16

3 Analysis 183.1 Test case . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.2 Configuration file . . . . . . . . . . . . . . . . . . . . . . . . 193.3 Analysis and Results . . . . . . . . . . . . . . . . . . . . . . 21

3.3.1 Precision analysis . . . . . . . . . . . . . . . . . . . . 213.3.2 Sensitivity of the solution w.r.t. the perturbation δ . 243.3.3 Sensitivity of the solution w.r.t. the CFL condition . 263.3.4 Analysis of the Jacobians condition number w.r.t.

the CFL condition . . . . . . . . . . . . . . . . . . . 293.3.5 Backtracking line search method . . . . . . . . . . . 31

4 C++ code 344.1 Jacobian implementation . . . . . . . . . . . . . . . . . . . 354.2 Backtracking line search implementation . . . . . . . . . . . 38

5 Conclusion 415.1 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415.2 Topics for further study . . . . . . . . . . . . . . . . . . . . 41

A Bibliography 42

List of Figures

1 SU2 classes collaboration diagram. . . . . . . . . . . . . . . . . . 62 Solver classes inheritance diagram. . . . . . . . . . . . . . . . . . 83 Analytical solution (spatial discretization: ROE method) of the

NACA 0012 airfoil QuickStart test case. . . . . . . . . . . . . . . 194 Analytical solution (spatial discretization: AUSM method, FWD

differences) of the NACA 0012 airfoil QuickStart test case. . . . 235 Analytical solution (spatial discretization: AUSM method, CEN

differences) of the NACA 0012 airfoil QuickStart test case. . . . 236 log10 residual of ρ as function of δ. . . . . . . . . . . . . . . . . . 247 log10 residual of ρE as function of δ. . . . . . . . . . . . . . . . . 258 Lift coefficient as function of δ. . . . . . . . . . . . . . . . . . . . 259 Drag coefficient as function of δ. . . . . . . . . . . . . . . . . . . 2610 log10 residual of ρ as function of CFL. . . . . . . . . . . . . . . . 27

3

Page 4: Precision and Sensitivity Analysis of the Numerical

11 log10 residual of ρE as function of CFL. . . . . . . . . . . . . . . 2712 Lift coefficient as function of CFL. . . . . . . . . . . . . . . . . . 2813 Drag coefficient as function of CFL. . . . . . . . . . . . . . . . . 2814 Jacobians condition number at CFL=1.6. . . . . . . . . . . . . . 2915 Jacobians condition number at CFL=1.9. . . . . . . . . . . . . . 3016 Jacobians condition number at CFL=2.2. . . . . . . . . . . . . . 3017 Jacobians condition number at CFL=1.9, with Backtracking Line

Search. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3118 Jacobians condition number at CFL=2.2, with Backtracking Line

Search. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3219 log10 residual of ρ as function of CFL, with Backtracking Line

Search. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3320 Drag coefficient as function of CFL, with Backtracking Line Search. 33

List of Algorithms

1 Newton’s method . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 Armijo’s algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 16

4

Page 5: Precision and Sensitivity Analysis of the Numerical

1 SU2, the Open-Source CFD Code

SU2 is a suite of open-source software tools written in C++ for the numericalsolution of partial differential equations (PDE) and performing PDE constrainedoptimization (cfr. [1] for an in-depth guide).

The primary applications are computational fluid dynamics and aerodynamicshape optimization, but has been extended to treat more general equations suchas electrodynamics and chemically reacting flows.

SU2 has been developed to solve multiphysics analysis and optimization tasksusing unstructured mesh topologies. Its unique architecture is well suited forextensibility to treat partial-differential-equation-based problems not initiallyenvisioned. The common framework adopted enables the rapid implementa-tion of new physics packages that can be tightly coupled to form a powerfulensemble of analysis tools to address complex problems facing many engineer-ing communities. The framework is able to solve both the flow and adjointsystems of equations to provide a high-fidelity predictive capability and sen-sitivity information. That information can be used for optimal shape designusing a gradient-based framework, goal-oriented adaptive mesh refinement, oruncertainty quantification.

SU2 framework allows the use of the Message Passing Interface (MPI) andAutomatic Differentiation (CoDiPack), while accepting model and simulationparameters in a text file.

1.1 SU2 workflow

The objective of this section is to introduce the C++ class structure of SU2 at ahigh level. The class descriptions below focus on the structure within SU2 CFD(the main component of SU2), but many of the classes are also used in the othermodules.

At the highest level, SU2 CFD has a driver class, CDriver, that controlsthe solution of a multiphysics simulation. The CDriver class is responsiblefor instantiating all of the geometry, physics packages, and numerical methodsneeded to solve a particular problem. The CDriver class within SU2 CFDinstantiates many classes, including the following:

CConfig - Reads and stores the problem configuration, including all op-tions and settings from the input file (extension .cfg).

COutput - Writes the output of the simulation in a user-specified format(Paraview, Tecplot, CGNS, comma-separated values, etc.).

CIntegration - Solves the particular governing equations by calling thechild classes CMultiGridIntegration, CSingleGridIntegration. Thisis used for both multigrid or single-grid calculations, and it connects thesubclasses CGeometry, CSolver, and CNumerics for performing inte-gration in time and space.

5

Page 6: Precision and Sensitivity Analysis of the Numerical

CIteration - Classes that complete an iteration of a single physics pack-age, e.g., fluid or structure.

Maximizing the flexibility of the code was a fundamental driver for the designof the class architecture, and an overview of the collaboration diagram of allclasses within SU2 CFD is shown below.

Figure 1: SU2 classes collaboration diagram.

The core capabilities of the computational tool are embedded within theCGeometry, CSolver, and CNumerics classes that manage the geometry,the main solver functionality (definition of the terms in the PDE), and thenumerical methods, respectively. In the next subsection, these three classes willbe discussed.

6

Page 7: Precision and Sensitivity Analysis of the Numerical

1.2 CGeometry, CSolver and CNumerics classes

The CGeometry class reads and processes the input mesh file (extension .su2),and it includes several child classes, such as:

CPhysicalGeometry - Constructs the dual mesh structure from the pri-mal mesh.

CMultiGridGeometry - If multigrid is requested, this class automat-ically creates consecutively coarser meshes from the original input meshusing a control volume agglomeration procedure. These coarse grid levelsare then used for multigrid calculations.

CPrimalGrid and CDualGrid - Two classes that are used for definingthe geometrical characteristics of the primal and dual grids.

In the CSolver class, the solution procedure is defined. Each child class ofCSolver represents a solver for a particular set of governing equations. Thesesolver classes contain subroutines with instructions for computing each spatialterm of the PDE, e.g., loops over the mesh edges to compute convective andviscous fluxes, loops over the mesh nodes to compute source terms, and routinesfor imposing various boundary condition types for the PDE.

One or more of these child classes will be instantiated depending on thedesired physics, and several examples are:

CEulerSolver - For the Euler equations (compressible or incompressible).

CTurbSolver - For a turbulence model.

CAdjEulerSolver - For the adjoint equations of the Euler equations.

The solver classes call the CVariable class for storing unknowns and othervariables pertinent to the PDE at each mesh node, several classes in CNumer-ics in order to specify a spatial discretization of the governing equations, and,if necessary, container classes for holding the matrices and vectors needed bylinear solvers. In general, these classes can be briefly described as follows:

CVariable - Used to store variables at every point in the grid, such as theconservative variables (unknowns of the PDE). Depending on the systemof equations being solved, CVariable instantiates a certain child class andstores a set of variables particular to that problem at each grid node.

CSysMatrix - Stores values for the Jacobians of fluxes and source termsin a sparse matrix structure for implicit calculations. It includes vari-ous methods for solving a linear system, including Krylov methods suchas GMRES and BiCGSTAB, in addition to several preconditioning tech-niques, such as Jacobi, LU-SGS, or line implicit preconditioning.

CSysVector - Holds and manipulates vectors needed by the linear solversin combination with CSysMatrix to store the sparse matrix representa-tion of the Jacobian.

7

Page 8: Precision and Sensitivity Analysis of the Numerical

Figure 2: Solver classes inheritance diagram.

The CNumerics class discretizes each system of governing equations usingthe numerical schemes specified in the input file. There are several child classesthat provide a wide range of discretization techniques for convective fluxes,viscous fluxes, and any source terms that might be present in a given PDE.

For example, during a single iteration of an implicit calculation, methods inthe CNumerics classes would compute the flux contributions and Jacobians ateach node (using the variables stored in the CVariable class). These flux andJacobian values are transferred back to the CSolver class, and the CSolverclass calls routines within CSysMatrix in order to solve the resulting linearsystem of equations for the solution update. The table below shows a list of thevarious capabilities in the CNumerics class.

8

Page 9: Precision and Sensitivity Analysis of the Numerical

Parent Class: CNumerics

Roe’s Scheme Average Gradient Piecewise Constant Source

JST Scheme Galerkin Thermal Non-Equilibrium Source

AUSM Scheme Average Gradient Corrected Gravity Source

HLLC Scheme Electrical Source

CUSP Scheme Turbulence Source

Lax-Friedrich Scheme Transition Source

Roe-Turkel for low Mach Axisymmetric Source

Steger-Warming Scheme Rotational Frame Source

Free Surface Source

Table 1: CNumerics child classes

The numerical methods that compute the flux contributions and Jacobiansof the convective fluxes are in the leftmost columm. Among those, highlightedin blue, are the ones where the numerical computation of the Jacobian has beenimplemented.

All those methods define a numerical approximation of the Jacobian, exceptROE scheme. The latter is an exact scheme, and computationally more expen-sive than most other flux schemes, especially because of its matrix dissipationterm. However, when used in combination with implicit time stepping, its fluxJacobian can be easily computed analitically and this results in a quite effi-cient algorithm. In turn ROE scheme benefits least from a numerical Jacobianimplementation in terms of computation time, analysis shows.

The Steger-Warming scheme belongs to the ‘flux vector splitting’ family andrelies on the fact that the inviscid flux vector is homogeneous in the vectorof conservative variables. Euler equations satisfy this property but there areimportant examples, such as the shallow water equations, that do not. Thehomogeneity property may however be circumvented so as to be able to applythe FVS approach, see [2].

The Roe-Turkel scheme is a correction of the Roe scheme, which uses thepreconditioning of Turkel, and leads to an improvement of the solution. Indeed,at low Mach number, the Roe scheme presents an excess of artificial viscosity.It is also shown in [3] that for the Roe-Turkel scheme the convergence of thenumerical solution towards the exact solution depends only on the mesh sizeparameter whereas that of the Roe scheme depends on the ratio between meshsize parameter and Mach number.

9

Page 10: Precision and Sensitivity Analysis of the Numerical

2 Modeling

The flexible class structure of SU2 has been designed to solve problems definedon a domain Ω ⊂ R3, delimited by disconnected boundaries. In particular,the PDE system resulting from physical modeling of a fluid-dynamics problemshould have the following structure:

∂tU +∇·Fc −∇·Fv = S in Ω, t > 0 (1)

with appropriate boundary and temporal conditions that will be problem-dependent. In this general framework, U represents the vector of state variables,Fc(U) are the convective fluxes, Fv(U) are the viscous (diffusive) fluxes andS(U) is a generic source term.

The procedure involved in solving the aforementioned problems, in case offluids (CFD problems), is usually as follows (see [4]):

1. Discretization of the system of partial differential equations (PDEs) inspace to get a system of ordinary differential equations (ODEs);

2. Use of a time integration method to solve the system of ODEs over time.After discretization of the PDEs, we usually end up with a stiff system1

of ODEs, which is best integrated by an implicit integration scheme;

3. Use of an iterative method to solve the implicit scheme;

4. Within this iterative method, a linear system of equations will typicallyneed to be solved.

The third step is the relevant one in regards to this project, but first, let usbriefly describe how to get there.

When integrating in space the system of PDE’s in (1), we obtain the followingsystem of conservation laws:

d

dt

ˆ

Ω

UdΩ +

ˆ

Ω

∇·FcdΩ −ˆ

Ω

∇·FvdΩ =

ˆ

Ω

SdΩ

that can be written as:

R(U) =d

dt

ˆ

Ω

UdΩ +z

Σ

(Fc − Fv)(P)·ndΣ−ˆ

Ω

S(P)dΩ = 0

where U are the conservative variables and P = P(U) are the variables inwhich the solution is stored and updated, e.g. primitive, natural, conservative.

The time discretized expression for the residual R(U) depends on the choiceof the scheme for the time integration, e.g. Backward Euler, Crank-Nicolson.

1A ‘stiff equation’ is a differential equation for which certain numerical methods for solvingthe equation are numerically unstable, unless the step size is taken to be extremely small.

10

Page 11: Precision and Sensitivity Analysis of the Numerical

2.1 Newton-Raphson method

In order to complete a single step in the implicit integration scheme, we needto solve

R(U) = 0 (2)

R =

R1

R2

...Rn

, U =

U1

U2

...Un

where R(U) is a non-linear function of U ∈ Rn. The most successful tech-

niques for solving nonlinear problems are based on Newton’s method.A way of deriving Newton’s method for a non linear problem is to perform

a Taylor expansion in time around R(U), from which we get:

R(Un+1) = 0⇒ R(Un+1) = R(Un) +∂R

∂U |Un

4Un = 0

Starting with an initial guess U0, the Newton iteration is as follows:

Uk+1 = Uk +4Uk (3)

∂R

∂U |Uk

4Uk = −R(Uk) (4)

where ∂R∂U is the Jacobian of R:

∂R

∂U=

∂R1

∂U1

∂R1

∂U2· · · ∂R1

∂Un∂R2

∂U1

∂R2

∂U2· · · ∂R2

∂Un

......

. . ....

∂Rn

∂U1

∂Rn

∂U2· · · ∂Rn

∂Un

.In order to do the Newton iteration the linear system (4) needs to be solved

and get 4Uk.

Algorithm 1 Newton’s method

1: Choose a small ε and set U0 = 0;2: for k = 0, 1, 2, . . . do

3: Assemble the Jacobian matrix ∂R∂U

kand the residual vector −R(Uk)

4: Solve the linear system (4)5: Set Uk+1 = Uk +4Uk

6: if ‖4Uk‖ < ε then7: Stop8: end if9: end for

11

Page 12: Precision and Sensitivity Analysis of the Numerical

In an unsteady case, as shown in Algorithm (1), the iteration is terminatedat stage k if the correction 4Uk is small. Another alternative would be to stopwhen the residual −R(Uk) is small, since this would indicate that the equationis well satisfied by the computed solution Uk.

In a steady case, where time accuracy is not required, the solution at the newtime step Un+1 can be directly set equal to Uk+1 after one Newton subiteration.

The problem is reduced to solving a large system of linear equations, butbefore that, the Jacobian needs to be computed.

2.2 Numerical Jacobian

A crucial ingredient for the overall performance of an implicit solver is thecalculation of the flux jacobian terms to be included in the matrix of the linearsystem to solve:

∂R

∂U |Uk

= JT + JR.

Two contributions to the jacobian matrix can be identified, namely JT cor-responding to the time-dependent part of the equation and JR related to thediscretization of the spatial part (convective and diffusive fluxes, source term).Their expression depend on the choice of the time stepping method.

As it will be explained in detail later, it is possible to choose the kind oftime stepping method to be used by SU2 in the configuration file. The followingmethods are available:

RUNGE-KUTTA EXPLICIT

EULER IMPLICIT

EULER EXPLICIT

The analytical jacobian of the space terms JR incorporates two distinct contri-butions: one during a loop over all faces (boundary and internal ones) in order toassemble the contribution from the convective and diffusive fluxes, another oneduring a global loop over cells to calculate also the source term contributions.

The jacobian term can be computed numerically, by approximating eachpartial derivative by means of a forward finite difference formula. In our case,the jacobian of the residual R with respect to the k component of the updatevariables P can be expressed as follows (see [5]):

(∂R

∂Pm

)k

· −→1 k ≈R(Pm + εk ·

−→1 k

)−R (Pm)

εk(5)

where k = 1 . . . Neq, and the index m depends on the degree of freedom inthe computational stencil whose corresponding P variables are perturbed.

12

Page 13: Precision and Sensitivity Analysis of the Numerical

When looping over the faces to assemble the fluxes, the following choice form holds:

m =

left, right on internal faces

left on boundary faces

This means that on the boundary face, only the (left) internal state is per-turbed, while the (right) ghost state is recomputed to satisfy the numericalboundary condition for the given perturbed internal state, allowing us not toinclude entries for the ghost states in the jacobian matrix.

In the case of the source term jacobian, however, since the discretizationis based only on the cell centered state, only that one is perturbed and thecontribution from the neighbor states is completely neglected.

The perturbation εk is defined as:

εk = δ sign (Pm,k) max (|Pm,k|, uuserk ) (6)

where δ ≤ 10−5 and uuserk is a user defined value whose magnitude shouldbe of the order of the corresponding update variable Pk.

2.3 Implementation issues

It is known that numerical differentiation is an unstable procedure prone totruncation and subtractive cancellation errors [6]. Decreasing the step size εkwill reduce the truncation error. Unfortunately a smaller step has the oppositeeffect on the cancellation error. Selecting the optimal step size for a certainproblem is computationally expensive and the benefits achieved are not justifi-able as the effect of small errors in the values of the elements of the Jacobianmatrix is minor. Moreover, there is no strong evidence for the sensitivity of thesolution w.r.t. δ from the analysis that have been carried out in the developmentof this project (see section 3.3.2 for details). For this reason, the sizing of thefinite difference step is not attempted and a constant increment size is used inevaluating the gradient. Furthermore, to allow for the flexibility to adjust tothe specific problem characteristics, the individual size of each parameter stepcan be adjusted by the user as previously seen.

Calculation of the numerical approximation of the Jacobian matrix requiresn2 and 2n2 model evaluations for the forward difference case and for centraldifferences. To alleviate the computational burden, forward differences are al-ways used except when they become unreliable. This usually happens when thesolution is small, or when the difference in the values of the function is smallrelative to the step size, which happens very often in the benchmark test case.In both cases, the central difference formula is used instead:

(∂R

∂Pm

)k

· −→1 k ≈R(Pm + εk ·

−→1 k

)−R

(Pm − εk ·

−→1 k

)2εk

. (7)

13

Page 14: Precision and Sensitivity Analysis of the Numerical

Finally, a first-order Broyden update scheme could be implemented and thenumber of model function computations reduced in the calculation of the ap-proximate Jacobian at the iteration as follows:

Ji4xi = ri

Ji+1 = Ji +(ri+1 − ri − Ji4xi)4xTi

‖4xi‖2.

This scheme would require only n functional evaluation and can be used upto n times in sequence after each evaluation of the Jacobian matrix by forward orcentral differences. A note of caution is due here: for highly nonlinear or poorlyconditioned models, the errors that would be encountered in using the Broydenupdate scheme could cause larger parameter deviation which could result in thetrapping of the solution at a local minimum (see [6]).

On a different note, as we have seen at the beginning of section 2.1, theJacobian must be evaluated w.r.t. the vector of conservative variables U. Hencethe evaluation of ∂R/∂U has been separated into

∂R

∂U=∂R

∂P

∂P

∂U

allowing for a simpler implementation in terms of C++ code. All that isrequired to be known is P = P(U) and its Jacobian,

∂P

∂U=

−vxρ

1ρ 0 0 0

−vyρ 0 1ρ 0 0

−vzρ 0 0 1ρ 0

v2x+v2y+v2z2cv

Rgas − vxcvRgas −vycvRgas −vzcvRgasRgas

cv1 0 0 0 0

which is exact for a compressible Euler problem; P = [vx, vy, vz, P, ρ]

and U = [ρ, ρvx, ρvy, ρvz, ρE] are the vectors of primitive and conservativevariables respectively.

Particular attention has to be paid to the update of the primitive variablesP while computing ∂R/∂P, since the perturbation of the n-th primitive variablewould affect the non-perturbed ones and hence the evaluation of the residualR. In particular, variations in the velocity, pressure and density, affect thetemperature and the enthalpy.

14

Page 15: Precision and Sensitivity Analysis of the Numerical

The following is a snippet of the code in the implementation of the numericalJacobian in ‘numerics structure.cpp’ after the perturbation of the n-th variable:

2352 sign = (0>P[iVar ]? -1:1);

2353 epsk = delta * sign * max(fabs(P[iVar]), user_pert[iVar ]);

2354 P_pert[iVar] = P[iVar] + epsk;

23552356 su2double sq_vel = 0.0;

2357 for (iDim = 0; iDim < nDim; iDim ++)

2358 sq_vel += P_pert[iDim +1] * P_pert[iDim +1];

23592360 P_pert [0] = P_pert[nDim +1] / (P_pert[nDim +2] * Gas_Constant );

2361 P_pert[nDim +3] = P_pert[nDim +1] * Gamma

2362 / (P_pert[nDim +2] * Gamma_Minus_One)

2363 + 0.5 * sq_vel;

Ppert is the vector of perturbed primitive variables.Ppert[0] and Ppert[nDim + 3] represent the temperature and the total en-

thalpy, nDim = 2, 3 is the dimension of Ω.It is important to state the P and Ppert vectors implemented in the SU2

framework store all the following fluid’s properties:

[φ, vx, vy, vz, P, ρ, e, νL, νE , κ, cp]

where:

φ is the temperature

vx, vy, vz are the velocities in the x, y and z direction

P is the pressure

ρ is the density

e is the enthalpy

νL and νE are the Laminar and Eddy viscosity

κ is the Thermal conductivity

cp is the specific heat at constant pressure

while only the vector [vx, vy, vz, P, ρ] is of immediate interest towards thecomputation of the Jacobian, since the conservative variables U are expressedas a function of those elements.

The variables δ and userpert have been added to the SU2 configurationoptions and are called:

NUMERICAL JACOBIAN PERTURBATION (δ)

USER PERTURBATION (userpert)

15

Page 16: Precision and Sensitivity Analysis of the Numerical

2.4 Backtracking line search

The Newton method requires the Jacobian in order to search for zeros, andis very sensitive w.r.t. the computation of the latter. Strictly speaking, anymethod that replaces the exact Jacobian with an approximation is a quasi-Newton method. In hindsight, the implementation of the analytical computationof the Jacobian transforms the procedure described up to now, from a Newtonmethod, to a quasi-Newton method.

Using an approximation of the Jacobian has given rise to a loss of convergencefor CFL numbers higher than 2. It will all be described in detail in the analysischapter.

In this subsection a backtracking line search method will be introduced. Suchmethod has been implemented in order to recover convergence in the tests thathave been carried out.

In (unconstrained) minimization, a backtracking line search, a search schemebased on the Armijo–Goldstein condition, is a line search method to determinethe maximum amount to move along a given search direction. It involves startingwith a relatively large estimate of the step size for movement along the searchdirection, and iteratively shrinking the step size (i.e., ”backtracking”) until adecrease of the objective function is observed that adequately corresponds to thedecrease that is expected, based on the local gradient of the objective function[7].

Given a starting position x and a search direction p, the task of a line searchis to determine a step size α > 0 that adequately reduces the objective functionf : Rn → R.

Based on a selected control parameter c ∈ (0, 1), the Armijo–Goldstein condi-tion tests whether a step-wise movement from a current position x to a modifiedposition x +αp achieves an adequately corresponding decrease in the objectivefunction. The condition is fulfilled if

f (x + αp) ≤ f(x) + αcpT∇f(x).

This condition, when used appropriately as part of a line search, can ensurethat the step size is not excessively large. However, this condition is not sufficienton its own to ensure that the step size is nearly optimal, since any value of αthat is sufficiently small will satisfy the condition.

Thus, the backtracking line search strategy starts with a relatively large stepsize, and repeatedly shrinks it by a factor τ ∈ (0, 1) until the Armijo–Goldsteincondition is fulfilled.

Algorithm 2 Armijo’s algorithm

1: Choose α0 > 0, τ ∈ (0, 1), c ∈ (0, 1) and set t = −cpT∇f(x);2: while f(x)− f (x + αjp) < αjt do3: Increment j4: Set αj = ταj−1

5: end while6: Return αj as the solution.

16

Page 17: Precision and Sensitivity Analysis of the Numerical

Armijo used c = τ = 1/2 in a paper he published in 1966 (see [8]).The algorithm that has been implemented to recover convergence uses αoc =

1 and τ = 1/2. The respective variables have been added to the SU2 configurationoptions and are called:

RELAXATION FACTOR FLOW (αoc)

BACKTRACKING COEFF (1/τ)

The condition check was not implemented since the Newton iteration is runinside the Multigrid iteration in the SU2 framework, and the job of settingαj = ταj−1 was left to the latter in order not to increase the computationload. Indeed, it is usually undesirable to devote substantial resources to findinga value of α to precisely minimize f . This is because the computing resourcesneeded to find a more precise minimum along one particular direction couldinstead be employed to identify a better search direction. Once an improvedstarting point has been identified by the line search, another subsequent linesearch will ordinarily be performed in a new direction. The goal, then, is just toidentify a value of α that provides a reasonable amount of improvement in theobjective function, rather than to find the actual minimizing value of α. Strictlyspeaking, the code relies on the Multigrid iteration to update the value of αj .

Analysis shows that convergence is recovered for some CFL at which therewas no convergence or it was slow without backtracking line search.

There are still CFL numbers (>2.3) that do not allow convergence in thebenchmark test case.

17

Page 18: Precision and Sensitivity Analysis of the Numerical

3 Analysis

In this section the benchmark test case and the analysis that have been carriedout will be described.

3.1 Test case

The SU2 framework provides many test cases, that are available for downloadat their GitHub [10], and one that is already included in the SU2 source calledQuickStart.

QuickStart is a tutorial for the SU2 software suite. That tutorial is intendedto demonstrate some of the key features of the analysis and design tools and itrequires only the SU2 CFD tool from the SU2 suite. Its goal is to make the userfamiliar with performing the flow and continuous adjoint simulation of external,inviscid flow around a 2D geometry in the following setup:

Steady, 2D, Euler and Continuous Adjoint Euler equations

Multigrid

A numerical scheme for spatial discretization of choice

Euler implicit time integration

Euler Wall and Farfield boundary conditions

The specific geometry chosen for the tutorial is the NACA 0012 airfoil. It isone of the four-digit wing sections developed by the National Advisory Com-mitte for Aeonautics (NACA), and it is a widely used geometry for many CFDtest cases. The numbering system is such that the first number indicates themaximum camber (in percent of chord), the second shows the location of themaximum camber (in tens of percent of chord) and the last two digits indicatethe maximum thickness (in percent of chord). The reader is invited to see [9]for more information about airfoil sections.

This problem will solve the Euler equations on the NACA 0012 airfoil at anangle of attack of 1.25 degrees, using air with the following freestream conditions:

Pressure = 101, 325 Pa

Temperature = 273.15 K

Mach number = 0.8

The aim is to find the flow solution and the adjoint solution with respect to anobjective function defined as the drag on the airfoil. We will focus only on thedirect problem.

Two files are needed as input to the code: a configuration file describing theoptions for the particular problem, and the corresponding computational meshfile. The files are in the SU2/QuickStart/ directory.

18

Page 19: Precision and Sensitivity Analysis of the Numerical

Figure 3: Analytical solution (spatial discretization: ROE method) of the NACA0012 airfoil QuickStart test case.

3.2 Configuration file

Aside from the mesh, the only other file required to run the SU2 CFD solverdetails the configuration options. The configuration file (extension .cfg) definesthe problem, including all options for the numerical methods, flow conditions,multigrid, and also specifies the names of the input mesh and output files.

The main settings will be shown in the following:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% SU2 configuration file %% Case description: Transonic inviscid flow around a NACA0012 airfoil %% Author: Thomas D. Economon %% Institution: Stanford University %% Date: 2014.06.11 %% File Version 6.2.0 "Falcon" %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% ------------- DIRECT, ADJOINT, AND LINEARIZED PROBLEM DEFINITION ------------%%% Physical governing equations (EULER, NAVIER_STOKES,% WAVE_EQUATION, HEAT_EQUATION, FEM_ELASTICITY,% POISSON_EQUATION)PHYSICAL_PROBLEM= EULER%% Mathematical problem (DIRECT, CONTINUOUS_ADJOINT)MATH_PROBLEM= DIRECT%% Restart solution (NO, YES)RESTART_SOL= NO

...

19

Page 20: Precision and Sensitivity Analysis of the Numerical

% ------------- COMMON PARAMETERS TO DEFINE THE NUMERICAL METHOD --------------%%% Courant-Friedrichs-Lewy condition of the finest gridCFL_NUMBER= 2.0%% Number of total iterationsEXT_ITER= 250

...

% -------------------------- MULTIGRID PARAMETERS -----------------------------%%% Multi-Grid Levels (0 = no multi-grid)MGLEVEL= 3

...

% -------------------- FLOW NUMERICAL METHOD DEFINITION -----------------------%%% Convective numerical method (JST, LAX-FRIEDRICH, CUSP, ROE, AUSM, HLLC,% TURKEL_PREC, MSW)CONV_NUM_METHOD_FLOW= ROE%% Time discretization (RUNGE-KUTTA_EXPLICIT, EULER_IMPLICIT, EULER_EXPLICIT)TIME_DISCRE_FLOW= EULER_IMPLICIT

...

% ------------------------- INPUT/OUTPUT INFORMATION --------------------------%% Mesh input fileMESH_FILENAME= mesh_NACA0012_inv.su2%% Output file convergence history (w/o extension)CONV_FILENAME= history%% Output file flow (w/o extension) variablesVOLUME_FLOW_FILENAME= flow

A new block that contains all relevant information about the computationof the numerical Jacobian must be added to the configuration file:

% ------------- NUMERICAL JACOBIAN BLOCK -------------------------------------%%% Automatic Differentiation (YES, NO)AUTO_DIFF= NO%% Computation of the Jacobian matrices in a numerical wayNUMERICAL_JACOBIAN_CONVECTIVE= YESNUMERICAL_JACOBIAN_VISCOUS= NONUMERICAL_JACOBIAN_SOURCE= NO%% Perturbation used in the computation (default = 1e-7)NUMERICAL_JACOBIAN_PERTURBATION= 1E-7% User defined perturbation used in the computation (default = 1e-15)USER_PERTURBATION= (1E-15, 1E-15, 1E-15, 1E-15, 1E-15)%% Backtracking parametersRELAXATION_FACTOR_FLOW= 1.0BACKTRACKING_COEFF= 2.0

20

Page 21: Precision and Sensitivity Analysis of the Numerical

3.3 Analysis and Results

The following analysis were performed on the aforementioned QuickStart testcase in order to establish correctness and precision of the numerical Jacobian:

1. Precision of the numerical Jacobian w.r.t. the analytical one when theResidual is a quadratic function;

2. Sensitivity of the solution (residuals, Jacobians, Drag and Lift coefficients)w.r.t. the perturbation δ;

3. Sensitivity of the solution (residuals, Jacobians, Drag and Lift coefficients)w.r.t. the CFL condition;

4. Analysis of the condition number of the Jacobians to test convergencew.r.t. the CFL condition;

5. All above analysis were repeated with Backtracking line search.

3.3.1 Precision analysis

In order to verify the correctness of the implementation of the numerical Jaco-bian in SU2 a very simple test can be run. The Jacobian can be evaluated onboth quadratic and cubic Residuals, and its precision verified with the followingtheorems:

Theorem Forward formula of order O(h).Assume that f ∈ C2[a, b] and that x+ h, x ∈ [a, b].

Then f ′(x) ≈ f(x+h)−f(x)h and ∃ c = c(x) ∈ [a, b] s.t. truncation error

τ(f, h) = −hf”(c)2 = O(h).

Theorem Centered formula of order O(h2).Assume that f ∈ C3[a, b] and that x− h, x+ h, x ∈ [a, b].

Then f ′(x) ≈ f(x+h)−f(x−h)2h and ∃ c = c(x) ∈ [a, b] s.t. truncation error

τ(f, h) = −h2f(3)(c)

6 = O(h2).

We deduce that when using the centered formula, the error should be 0 in caseof a quadratic Residual whose third derivative is null.

The following Residuals have been tested:

Quadratic Residual R =

v2x + vxvy + vxP + vxρvxvy + v2

y + vyP + vyρvxP + vyP + P 2 + Pρvxρ+ vyρ+ Pρ+ ρ2

Cubic Residual R =

2v3x + v2

xvy + v2xP + v2

xρ+ vxv2y + vxP

2 + vxρ2

2v3y + v2

yvx + v2yP + v2

yρ+ vyv2x + vyP

2 + vyρ2

2P 3 + P 2vx + P 2vy + P 2ρ+ Pv2x + Pv2

y + Pρ2

2ρ3 + ρ2vx + ρ2vy + ρ2P + ρv2x + ρv2

y + ρP 2

21

Page 22: Precision and Sensitivity Analysis of the Numerical

Furthermore, the numerical Jacobian has been computed in MatLab as well,as means of providing a comparison with the numerical Jacobian computed inC++.

Forward finite differences:

Errors Ana vs. C++ Ana vs. MatLab C++ vs. MatLab

Quadratic Residual 1.92743e+ 0 1.15266e+ 1 1.27415e+ 1Cubic Residual 1.93140e+ 5 4.00999e+ 6 1.87600e+ 6

Relative Errors Ana vs. C++ Ana vs. MatLab

Quadratic Residual 6.00567e− 6 3.59156e− 5Cubic Residual 2.89981e− 6 6.02060e− 5

Centered finite differences:

Errors Ana vs. C++ Ana vs. MatLab C++ vs. MatLab

Quadratic Residual 1.92694e+ 0 1.29129e+ 1 1.40061e+ 1Cubic Residual 3.35318e+ 4 1.28941e+ 6 1.28574e+ 6

Relative Errors Ana vs. C++ Ana vs. MatLab

Quadratic Residual 6.00416e− 6 4.02354e− 5Cubic Residual 5.03447e− 7 1.93592e− 5

We see that the centered formula shows an improvement w.r.t. the forwardformula in case of a cubic Residual. In CFD problems the Residuals are far morecomplex, and a 4-th order centered scheme would be preferable. For instance:

f ′(x) ≈ −f(x+ 2h) + 8 f(x+ h)− 8 f(x− h) + f(x− 2h)

12h.

There are trade-offs associated with using a higher order formula. In theexample above four evaluations of the Residual would be required per node,increasing computation times up to 1s per global iteration (with Multigrid).

The main driver of the comparison analysis between forward and centeredformulas were the solution plots. Some showed far from predictable results.

22

Page 23: Precision and Sensitivity Analysis of the Numerical

For instance, if using forward differences, one can notice that too muchdissipation is being introduced. The shockwave is no more, and there seems tobe some kind of turbulence at the end of the airfoil.

Figure 4: Analytical solution (spatial discretization: AUSM method, FWD dif-ferences) of the NACA 0012 airfoil QuickStart test case.

Whereas, if using central differences, which does not add artificial dissipationat all, the shockwave is recovered:

Figure 5: Analytical solution (spatial discretization: AUSM method, CEN dif-ferences) of the NACA 0012 airfoil QuickStart test case.

23

Page 24: Precision and Sensitivity Analysis of the Numerical

From now on, only the results obtained with a central finite difference for-mula will be shown.

3.3.2 Sensitivity of the solution w.r.t. the perturbation δ

In this subsection was studied how the perturbation δ would affect the solutionand its residuals, the Jacobian matrices and the Drag and Lift coefficients. Thefollowing plots will show the development of the aforementioned variables as afunction of the number of iterations. The analysis were carried out with thefollowing settings:

CFL NUMBER= 1.3

EXT ITER= 250

CONV NUM METHOD FLOW= ROENUM (numerical jacobian imple-mentation of ROE scheme)

Figure 6: log10 residual of ρ as function of δ.

24

Page 25: Precision and Sensitivity Analysis of the Numerical

Figure 7: log10 residual of ρE as function of δ.

Figure 8: Lift coefficient as function of δ.

25

Page 26: Precision and Sensitivity Analysis of the Numerical

Figure 9: Drag coefficient as function of δ.

As it was previously stated in section 2.3, there is no strong evidence forthe sensitivity of the solution w.r.t. δ. For that reason, the sizing of the finitedifference step was not attempted and a constant increment size was used inevaluating the gradient from this time forward. Moreover, all plots show thatthe numerical computation of the Jacobian is in agreement with the analyticalcomputation of the same.

3.3.3 Sensitivity of the solution w.r.t. the CFL condition

Once the correctness of the numerical Jacobian with centered finite differencesimplementation was assessed, the focus of the analysis shifted to the sensitivityof the solution w.r.t. the CFL condition and how much the latter affected theresiduals, the Jacobians, and the Drag and Lift coefficients.

The following analysis was carried out with a fixed δ = 1e− 10.

NUMERICAL JACOBIAN PERTURBATION= 1E-10

Knowing in advance that the sheer computation of the Jacobian in a numericalway would mean that a quasi-Newton method was being used, it was expectedthat there would be loss of rate of convergence for some CFL numbers. Thefollowing plots show so:

26

Page 27: Precision and Sensitivity Analysis of the Numerical

Figure 10: log10 residual of ρ as function of CFL.

Figure 11: log10 residual of ρE as function of CFL.

27

Page 28: Precision and Sensitivity Analysis of the Numerical

0 50 100 150 200 2500

0.2

0.4CL

CFL=0.7

0 50 100 150 200 2500

0.2

0.4

CL

CFL=1.0

0 50 100 150 200 2500

0.2

0.4

CL

CFL=1.3

0 50 100 150 200 2500

0.2

0.4

CL

CFL=1.6

0 50 100 150 200 250# iter

0

0.2

0.4

CL

CFL=1.9

CL coefficient vs. iterations

0 50 100 150 200 250# iter

0

0.2

0.4CL

CFL=2.2

Figure 12: Lift coefficient as function of CFL.

0 50 100 150 200 2500

0.1

0.2

CD

CFL=0.7

0 50 100 150 200 2500

0.1

0.2

CD

CFL=1.0

0 50 100 150 200 2500

0.1

0.2

CD

CFL=1.3

0 50 100 150 200 2500

0.1

0.2

CD

CFL=1.6

0 50 100 150 200 250# iter

0

0.1

0.2

CD

CFL=1.9

CD coefficient vs. iterations

0 50 100 150 200 250# iter

0

0.1

0.2

CD

CFL=2.2

Figure 13: Drag coefficient as function of CFL.

28

Page 29: Precision and Sensitivity Analysis of the Numerical

In addition to loss of rate of convergence that can be seen in the residualplots, also the loss of convergence itself is shown in the Lift and Drag coefficientsplots. For Courant–Friedrichs–Lewy numbers > 2 the solution diverges.

A deeper study was required in order to understand the problem. The follow-ing subsection will show the dependence from the CFL number of the conditionnumber of the Jacobians involved in the Newton iterations.

3.3.4 Analysis of the Jacobians condition number w.r.t. the CFLcondition

Also the following analysis was carried out with a fixed δ = 1e− 10. The CFLnumbers under study are

[0.3, 0.7, 1.0, 1.3, 1.6, 1.9, 2.2] ,

but only the plots for the last three will be shown since the others do notshow any sign of defect in the solution.

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 ANA I

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 ANA J

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 NUM I

Condition number vs. iterations (CFL=1.6)

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 NUM J

Figure 14: Jacobians condition number at CFL=1.6.

29

Page 30: Precision and Sensitivity Analysis of the Numerical

0 50 100 150 200 250# iter

0

2

4

6

8

10K

#1012 ANA I

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 ANA J

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 NUM I

Condition number vs. iterations (CFL=1.9)

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 NUM J

Figure 15: Jacobians condition number at CFL=1.9.

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 ANA I

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 ANA J

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 NUM I

Condition number vs. iterations (CFL=2.2)

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 NUM J

Figure 16: Jacobians condition number at CFL=2.2.

30

Page 31: Precision and Sensitivity Analysis of the Numerical

The plots show how the condition number of the Jacobians, especially theone evaluated at the node J of the interface, change abruptly as the number ofiterations increase, to the point that the system becomes singular if the CFL istoo high, and convergence of the solution is lost.

3.3.5 Backtracking line search method

In order to solve the above problem, a backtracking line search method wasimplemented. Its objective was to reduce the step size α in the Newton iteration,withouth adding too much computation load.

For that reason the line search was implemented on top of the Multigriditeration, and it relies on it in order to reduce the step size. As was previouslystated in section 2.4, no resources were devoted in finding the value of α thatprecisely minimizes the objective function. That is because the computing re-sources needed to find a more precise minimum along one particular directioncould instead be employed to identify a better search direction. The goal is justto identify a value of α that provides a reasonable amount of improvement inthe objective function, rather than to find the actual minimizing value of α.

The following analysis shows that convergence is recovered for some CFLat which there was no convergence without backtracking line search. Let usremark that tere are still CFL numbers (>2.3) that do not allow convergence inthe benchmark test case.

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 ANA I

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 ANA J

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 NUM I

Condition number vs. iterations (CFL=1.9)

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 NUM J

Figure 17: Jacobians condition number at CFL=1.9, with Backtracking LineSearch.

31

Page 32: Precision and Sensitivity Analysis of the Numerical

0 50 100 150 200 250# iter

0

2

4

6

8

10K

#1012 ANA I

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 ANA J

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 NUM I

Condition number vs. iterations (CFL=2.2)

0 50 100 150 200 250# iter

0

2

4

6

8

10

K

#1012 NUM J

Figure 18: Jacobians condition number at CFL=2.2, with Backtracking LineSearch.

The condition number of the Jacobians has improved, it is lower and it isbounded except for a spike at iteration 39 with CFL=2.2.

Convergence of the solution is recovered in those cases as can be seen fromthe following plots:

32

Page 33: Precision and Sensitivity Analysis of the Numerical

Figure 19: log10 residual of ρ as function of CFL, with Backtracking Line Search.

0 50 100 150 200 2500

0.1

0.2

CD

CFL=0.7

0 50 100 150 200 2500

0.1

0.2

CD

CFL=1.0

0 50 100 150 200 2500

0.1

0.2

CD

CFL=1.3

0 50 100 150 200 2500

0.1

0.2

CD

CFL=1.6

0 50 100 150 200 250# iter

0

0.1

0.2

CD

CFL=1.9

CD coefficient vs. iterations

0 50 100 150 200 250# iter

0

0.1

0.2

CD

CFL=2.2

Figure 20: Drag coefficient as function of CFL, with Backtracking Line Search.

33

Page 34: Precision and Sensitivity Analysis of the Numerical

4 C++ code

In this section some portions of the code that was implemented in the numericalcomputation of the Jacobian will be explained with the help of verbatims.

The following classes (and the respective files) were modified:

CNumerics, in ‘numerics structure.hpp’, ‘numerics structure.inl’, ‘nu-merics structure.cpp’

CUpwCUSP Flow, in ‘numerics structure.hpp’, ‘numerics direct mean.cpp’

CUpwROE Flow Num, in ‘numerics structure.hpp’, ‘numerics direct mean.cpp’,‘driver structure.cpp’

CUpwAUSM Flow, in ‘numerics structure.hpp’, ‘numerics direct mean.cpp’

CUpwSLAU Flow, in ‘numerics structure.hpp’, ‘numerics direct mean.cpp’

CUpwSLAU2 Flow, in ‘numerics structure.hpp’, ‘numerics direct mean.cpp’

CUpwHLLC Flow, in ‘numerics structure.hpp’, ‘numerics direct mean.cpp’

CUpwGeneralHLLC Flow, in ‘numerics structure.hpp’, ‘numerics direct mean.cpp’

CCentJST KE Flow, in ‘numerics structure.hpp’, ‘numerics direct mean.cpp’

CCentJST Flow, in ‘numerics structure.hpp’, ‘numerics direct mean.cpp’

CCentLAX Flow, in ‘numerics structure.hpp’, ‘numerics direct mean.cpp’

CConfig, in ‘config structure.hpp’, ‘config structure.inl’, ‘config structure.cpp’

CNumerics::SetPrimitive2Conservative() method, in ‘numerics structure.cpp’

CNumerics::ComputeJacobian() method, in ‘numerics structure.cpp’

CDriver::Numerics Preprocessing() method, in ‘driver structure.cpp’

The following classes were modified in the process of implementing Armijo’salgrithm:

CEulerSolver, in ‘solver structure.hpp’, ‘solver structure.inl’, ‘solver direct mean.cpp’

CEulerSolver::ImplicitEuler Iteration() method, in ‘solver direct mean.cpp’

CMultiGridIntegration::MultiGrid Iteration() method, in ‘integration time.cpp’

CConfig, in ‘config structure.hpp’, ‘config structure.inl’, ‘config structure.cpp’

34

Page 35: Precision and Sensitivity Analysis of the Numerical

4.1 Jacobian implementation

In the following the implementation of the CNumerics::ComputeJacobian() methodwill be shown.

1924 void CNumerics :: ComputeJacobian(su2double ** val_Jacobian_i ,

su2double ** val_Jacobian_j , su2double *val_residual ,

su2double *V_i , su2double *V_j , CConfig *config)

1925 ...

1926 su2double val_residual_pert[nVar];

1927 su2double perturbation = config ->GetPerturbation ();

1928 su2double *user_pert = config ->GetUserMinPerturbation ();

19291930 for (unsigned short iVar = 0; iVar < nVar; iVar ++)

19311932 su2double sign = (0>V_i[iVar ]? -1:1);

1933 su2double epsk = perturbation * sign

1934 * max(fabs(V_i[iVar]), user_pert[iVar]);

1935 V_i_pert[iVar] = V_i[iVar] + epsk;

19361937 // Temperature and Enthalpy update

19381939 ComputeResidualAuxiliar(val_residual_pert , V_i_pert , V_j

, config);

19401941 for (unsigned short jVar = 0; jVar < nVar; jVar ++)

1942 val_Jacobian_i[jVar][iVar] =

1943 (val_residual_pert[jVar] - val_residual[jVar])

1944 / (V_i_pert[iVar] - V_i[iVar]);

19451946 // The process is repeated for node j

1947 ...

1948

1949

That method takes as input parameters the same ones as each CNumericchild class that overloads CNumeric::ComputeResidual().

In this way, CNumerics::ComputeJacobian() can be called from within theoverloaded CNumeric::ComputeResidual() methods.

In the ‘Temperature and Enthalpy update’ section shown in the above listing,the update of the Temperature φ and total enthalpy e variables is performed,as stated in section 2.3.

Let us remark that the variable used by SU2 to store the update variablesP is actually called V i, and is a SU2double (double) array.

Indeed, the Jacobian is being computed at each interface, between the nodei and the node j. First, the variables at node i, V i, are perturbed, then the

35

Page 36: Precision and Sensitivity Analysis of the Numerical

perturbed residual is evaluated using the perturbed variables V i pert and theunperturbed ones V j, and finally the Jacobian at node i is computed using theforward finite differences formula.

The process is then repeated using V i and V j pert to evaluate the per-turbed residual and compute the Jacobian at node j.

Three implementations of CNumerics::ComputeJacobian() were done, thefirst uses forward differences, the second uses backward differences and the lastone uses centered differences.

Let us now see how the overloaded CNumeric::ComputeResidual() methodswere implemented. For instance, let us consider the CCentJST Flow class:

76 void CCentJST_Flow :: ComputeResidual(su2double *val_residual ,

su2double ** val_Jacobian_i , su2double ** val_Jacobian_j ,

CConfig *config)

7778 // Residual computation ...

7980 for (iVar = 0; iVar < nVar; iVar ++)

81 val_residual[iVar] += (Epsilon_2*Diff_U[iVar]

82 - Epsilon_4*Diff_Lapl[iVar])

83 * StretchingFactor * MeanLambda;

8485 if (implicit)

86 // Jacobian computation ...

8788 /*--- Last row of Jacobian_j ---*/

89 val_Jacobian_j[nVar -1][0] -=

90 cte_1*Gamma_Minus_One*sq_vel_j;

91 for (iDim = 0; iDim < nDim; iDim ++)

92 val_Jacobian_j[nVar -1][ iDim +1] +=

93 cte_1*Gamma_Minus_One*Velocity_j

[iDim];

94 val_Jacobian_j[nVar -1][nVar -1] -= cte_1*Gamma;

95

96

The top half consists of the residual evaluation, whereas the bottom halfcomputes the Jacobian matrices if an implicit time integration method is beingused. The evaluation of the residual was delegated to another method in thesame class that overloads the parent’s CNumeric::ComputeResidualAuxiliar()method. The portion in which the Jacobian is computed analytically will bemodified, and a new assert added. Only in the case where the Jacobian must becomputed numerically, the analytical computation will be skipped. Such optioncan be defined by the user in the .cfg file. Let us now see how to call CNumer-ics::ComputeJacobian() method from the overloaded CNumeric::ComputeResidual().

36

Page 37: Precision and Sensitivity Analysis of the Numerical

76 void CCentJST_Flow :: ComputeResidual(su2double *val_residual ,

su2double ** val_Jacobian_i , su2double ** val_Jacobian_j ,

CConfig *config)

7778 ComputeResidualAuxiliar(val_residual , V_i , V_j , config);

7980 if (implicit)

81 /*-- Numerical Jacobian computation --*/

82 if (config ->GetNumJacConvective ())

83 ComputeJacobian(val_Jacobian_i , val_Jacobian_j ,

84 val_residual , V_i , V_j , config);

85

8687 /*-- Analytical Jacobian computation --*/

88 else

8990 // As before ...

9192

93

94

Let us now have a look at the getters declared in the CConfig class andthat have been defined in the ‘config structure.inl’ file.

294 inline bool CConfig :: GetNumJacConvective(void) return

Num_Jac_Convective;

295296 inline bool CConfig :: GetNumJacViscous(void) return

Num_Jac_Viscous;

297298 inline bool CConfig :: GetNumJacSource(void) return

Num_Jac_Source;

299300 inline su2double CConfig :: GetPerturbation(void) return

Perturbation;

301302 inline su2double* CConfig :: GetUserMinPerturbation(void)

return User_Pert;

The respective options have been added to the CConfig class, in the ‘con-fig structure.cpp’ file.

37

Page 38: Precision and Sensitivity Analysis of the Numerical

717 // addOption (".cfg option", CConfig member , default value);

718719 addBoolOption (" NUMERICAL_Jacobian_CONVECTIVE",

Num_Jac_Convective , false);

720721 addBoolOption (" NUMERICAL_Jacobian_VISCOUS",Num_Jac_Viscous ,

false);

722723 addBoolOption (" NUMERICAL_Jacobian_SOURCE",Num_Jac_Source ,

false);

724725 addDoubleOption (" NUMERICAL_Jacobian_PERTURBATION",

Perturbation ,1.0E-7);

726727 default_user_pert [0] = 1.0E-15;

728 default_user_pert [1] = 1.0E-15;

729 default_user_pert [2] = 1.0E-15;

730 default_user_pert [3] = 1.0E-15;

731 default_user_pert [4] = 1.0E-15;

732 addDoubleArrayOption (" USER_PERTURBATION", 5, User_Pert ,

default_user_pert);

4.2 Backtracking line search implementation

In the following the implementation of the Backtracking line search method willbe shown. The main modifications were done in the file ‘solver direct mean.cpp’,which we show a portion of the CEulerSolver::ImplicitEuler Iteration() methodfrom.

6343 /*--- Store information about old Res_RMS for backtracking

procedure ---*/

6344 if (config ->GetExtIter () == 0 && config ->GetMG_iteration ()

== 0)

6345 for (iVar = 0; iVar < nVar; iVar ++)

6346 Residual_RMS_first[iVar] = GetRes_RMS(iVar);

63476348 if (config ->GetExtIter () == 0 && config ->GetMG_iteration ()

== 1)

6349 for (iVar = 0; iVar < nVar; iVar ++)

6350 Residual_RMS_last[iVar] = GetRes_RMS(iVar);

The RMS residuals of the first two iterations of every Multigrid cycle are

38

Page 39: Precision and Sensitivity Analysis of the Numerical

stored in memory for later use. That was done so because at the beginning ofevery iteration the RMS residuals are being set to zero.

6353 /*--- Set maximum residual to zero ---*/

6354 for (iVar = 0; iVar < nVar; iVar ++)

6355 SetRes_RMS(iVar , 0.0);

6356 SetRes_Max(iVar , 0.0, 0);

6357

The update of the solution of the Newton iteration is being done in thefollowing cycle:

6353 if (! adjoint)

6354 for (iPoint = 0; iPoint < nPointDomain; iPoint ++)

6355 for (iVar = 0; iVar < nVar; iVar ++)

6356 if (config ->GetNumJacConvective ())

6357 node[iPoint]->AddSolution(iVar , config ->

GetUser_Relaxation_Factor_Flow ()*

LinSysSol[iPoint*nVar+iVar]);

6358 else

6359 node[iPoint]->AddSolution(iVar , config ->

GetRelaxation_Factor_Flow ()*LinSysSol[

iPoint*nVar+iVar]);

6360

6361

6362

The solution will be updated using the CConfig::Relaxation Factor Flowconfig option if the Jacobian is computed analytically. Striclty speaking, if theJacobian is being computed analytically the code is left unmodified.

On the other hand, if the computation of the Jacobian is numerical, then theCConfig::User Relaxation Factor Flow variable will be used instead. That vari-able is the one that will be updated at every iteration of the Armijo’s algorithmand is set equal to CConfig::Relaxation Factor Flow at the very beginning ofthe simulation.

Since it is not possible to recover the value of the step α at the previous globaliteration, it was decided not to let αbe multiplied by the coefficient τ = 1/2 atevery iteration. Meaning that only when necessary the step would be dividedby the quantity 1/τ. Hence, only when the RMS residual was increasing betweentwo successive iterations of the Multigrid, the step size α would be halved.

39

Page 40: Precision and Sensitivity Analysis of the Numerical

The conditions that define when the RMS residual is increasing are thefollowing:

the actual RMS residual is above the line that interpolates the previoustwo RMS residuals and its angular coefficient is positive (implemented inthis way because an increasing RMS is not striclty correlated to a divergentsolution, but if the RMS keeps on increasing then action must be taken);

the previos condition is verified, but the interpolant line has a negativeangular coefficient. Then we check whether the actual RMS residual isabove or below the RMS residual of two iterations ago.

The above conditions are minimal in terms of computation resources, and doallow recovering convergence of the solution when using CFL numbers up to 2.2and the numerical ROE scheme.

All the code can be downloaded from my personal GitHub repository [11].

40

Page 41: Precision and Sensitivity Analysis of the Numerical

5 Conclusion

5.1 Analysis

While the objective of obtaining a convergent solution when using a numericalcomputation of the Jacobian has been reached, it is not possible to state thathappens in every case. For instance, using CFL > 2.2 devoids the solution ofconvergence. On the other hand, approximation errors that propagated througheach iteration when using forward differences must be taken into account. Itwas possible to fix that problem by using a higher-order method -the centereddifference showed the most promise- but the improvement should not be worththe added function evaluation in terms of computation time. Indeed four eval-uations of the residual are performed each iteration, two for the node i and twofor the node j. Although the centered scheme could become a valuable toolto solve specific test cases, it should not be the standard for a multipurposealgorithm such as SU2 that strives for efficiency.

One of the reasons why the algorithm fails at high CFL could be that thesearch direction is wrong, due to the fact that a numerical approximation of theJacobian is used, and not the exact one which is needed in order to solve theNewton iteration. No amount of backtracking, at least in the simple way it wasimplemented for this paper, could help recover convergence.

Neither finding the optimal step size α nor optimizing the perturbation δwere attempted. They could be the topic of further study.

5.2 Topics for further study

There are a number of issues going on here that likely cannot be fixed simplyby improving the approximation of the Jacobian, and other methods must beresearched. For instance other preconditiong techniques could be used, an im-proved Armijo’s algorithm that optimizes the step size α could be implemented,and the optimization of the perturbation δ could be attempted.

If one insists on using higher-order scheme other than the centered differ-ences, then a first-order Broyden update scheme of the Jacobian could be im-plemented in order to reduce the number of Residual evaluations, and hence thecomputation time.

41

Page 42: Precision and Sensitivity Analysis of the Numerical

A Bibliography

References

[1] Francisco Palacios: Stanford University Unstructured (SU2): An open-sourceintegrated computational environment for multi-physics simulation and design.(p. 5)

[2] Toro Eleuterio F.: “Flux Vector Splitting Methods” In: Riemann Solvers andNumerical Methods for Fluid Dynamics. Ed. Springer, Berlin, Heidelberg, Inc.©1997 ISBN:978-3-662-03490-3 (p. 9)

[3] Cecile Viozat: Implicit Upwind Schemes for Low Mach Number CompressibleFlows. RR-3084, INRIA (1997) inria-00073607 (p. 9)

[4] Robert Loek Van Heyningen: Bachelor Thesis: “Improving the Finite DifferenceApproximation in the Jacobian-Free Newton–Krylov Method”. Lund University,Lund, Sweden (p. 10)

[5] Andrea Lani: MSC Thesis: “Physical modeling and numerical methods”, Ch.4.Politecnico di Milano, Milano, Italy (p. 12)

[6] P.E. Gill, W. Murray, M. H. Wright: “Practical Optimization” Academic Press,London, Inc. ©1981 (pp. 13 and 14)

[7] https://en.wikipedia.org/wiki/Backtracking line search (p. 16)

[8] Armijo, Larry: “Minimization of functions having Lipschitz continu-ous first partial derivatives” Pacific J. Math. 16 (1966), no. 1, 1–3https://projecteuclid.org/euclid.pjm/1102995080 (p. 17)

[9] Ira H. Abbott, Albert E. Von Doenhoff: “Theory of wing sections” Ed. Doverpublications, New York, Inc. ©1959 ISBN:486-60586-8 (p. 18)

[10] SU2 GitHub repository (p. 18)

[11] Jose Villafan’s GitHub repository containing the implementation of theNumerical Jacobian (p. 40)

42