Brief Outline
description
Transcript of Brief Outline
![Page 1: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/1.jpg)
Aerodynamic Design Using VLMGradient Generation Using
ADIFOR (Automatic Differentiation in Fortran)
Santosh N. AbhyankarProf. K. Sudhakar
![Page 2: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/2.jpg)
Brief Outline
• Why ADIFOR ?
• What is ADIFOR ?
• Where ADIFOR has been used ?
• Case studies in CASDE
![Page 3: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/3.jpg)
Why ADIFOR ?
![Page 4: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/4.jpg)
Gradient-based Optimization
• Gradients calculated to give search direction
• Accuracy of gradients affect:– Efficiency of the optimizer– Accuracy of the optimum solution
![Page 5: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/5.jpg)
Different Ways to Calculate Gradients
• Numerical methods– Finite difference– Complex variable method– Adjoint method
• Analytical methods– Manual differentiation– Automated differentiation
dx
xfdxxfxf
)()()(
![Page 6: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/6.jpg)
Finite Difference Vs Complex Variable
• CFL3D of NASA. Inviscil, Laminar, Turb., (Un)steady, Multi-blk, Accel, etcComplex 115 mts 75.2 MB
FD 36 mts 37.7 MB
41 mts 37.7 MB
Note : For several cases FDM required trying out several step sizes to get correct derivative. Factoring this in, it was seen that time taken on an average was more than 2 times for a single analysis.
![Page 7: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/7.jpg)
Optimizer)(xf )(xh )(xg
General Flowchart of an Optimization Cycle
xAnalysis Functions
Say: f(x),h(x),g(x) = any
Complicated functions
![Page 8: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/8.jpg)
Optimizer)( ii hxf )( ii hxh
)( ii hxg
Gradient Calculation using Forward Difference Method
x
)( ii hx Analysis Functions
Say: f(x),g(x),h(x) =
anyComplicated
function
![Page 9: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/9.jpg)
Drawbacks of Numerical Gradients
• Approximate
• Round-off errors
• Computational requirements:
requires (n+1) evaluations of function f
• Difficulties with noisy functions
nx
f
x
f
x
f
,,21
![Page 10: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/10.jpg)
Optimizer
Analysis Functions
Say: f(x) = Sin(x)
x
)(xf )(xh )(xg
Externally supplied Analytical Gradients:
= Cos(x)f h g
x
Facility to provide user-supplied Gradients
)(xf
![Page 11: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/11.jpg)
Optimizer
F(x)/g(x)/h(x): Complex
Analysis Code
x
)(xf )(xh )(xg
Externally supplied Analytical Gradients:
= ?f h g
x
Facility to provide user-supplied Gradients
)(xf
![Page 12: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/12.jpg)
User Supplied Gradients
Complex AnalysisCode in Fortran
Manually extractsequence of mathematical
operations
Code the complex derivative evaluator
in Fortran
Manually differentiatemathematical
functions - chain rule
FORTRANsource code
that can evaluategradients
![Page 13: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/13.jpg)
User Supplied Gradients
Manually extractsequence of mathematical
operations
Use symbolic math packages to automate derivative evaluation
Code the complex derivative evaluator
in Fortran
Complex AnalysisCode in FORTARN
FORTRANsource code
that can evaluategradients
![Page 14: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/14.jpg)
User Supplied Gradients
Parse and extract the sequence
of mathematical operations
Use symbolic math packages to automate derivative evaluation
Code the complex derivative evaluator
in Fortran
Complex AnalysisCode in FORTARN
FORTRANsource code
that can evaluategradients
![Page 15: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/15.jpg)
Gradients by ADIFOR
Complex AnalysisCode in FORTARN
FORTRANsource code
that can evaluategradients
Automated Differentiation
Package
![Page 16: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/16.jpg)
What is ADIFOR ?
![Page 17: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/17.jpg)
AAutomatic utomatic DIDIfferentiation in fferentiation in FORFORtrantran{ADIFOR}{ADIFOR}
byMathematics and Computer Science
Division,Argonne National Laboratories,
NASA.
![Page 18: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/18.jpg)
Initial Inputs to ADIFOR
• The top level routine which contains the functions
• The dependant and the independent variables
• The maximum number of independent variables
![Page 19: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/19.jpg)
Functionality of ADIFOR• Consider
• The derivative of
is given by
22
21211 ),( xxxxf
21212 ),( xxxxf
2
1
2
2
1
2
3
2
2
2
1
1
3
1
2
1
1
3
2
1
6
2
2
2
x
x
x
x
x
x
fx
fx
f
x
fx
fx
f
f
f
f
f
)(xf
221213 32),( xxxxf
![Page 20: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/20.jpg)
Functionality of ADIFOR …contd.
• For any set of functions say:
• ADIFOR generates a Jacobian:
)(xf
n
mm
n
x
f
x
f
x
f
x
f
J
1
1
1
1
![Page 21: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/21.jpg)
SUBROUTINE test(x,f) double precision x(2),f(3) f(1) = x(1)**2 + x(2)**2 f(2) = x(1)*x(2) f(3) = 2.*x(1) + 3.*x(2)**2 return end
ADIFOR
![Page 22: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/22.jpg)
subroutine g_test(g_p_, x, g_x, ldg_x, f, g_f, ldg_f) double precision x(2), f(3) integer g_pmax_ parameter (g_pmax_ = 2) integer g_i_, g_p_, ldg_f, ldg_x double precision d6_b, d4_v, d2_p, d1_p, d5_b, d4_b, d2_v, g_f(l *dg_f, 3), g_x(ldg_x, 2) integer g_ehfid intrinsic dble data g_ehfid /0/C call ehsfid(g_ehfid, 'test','g_subrout5.f')C if (g_p_ .gt. g_pmax_) then print *, 'Parameter g_p_ is greater than g_pmax_' stop endif
![Page 23: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/23.jpg)
d2_v = x(1) * x(1) d2_p = 2.0d0 * x(1) d4_v = x(2) * x(2) d1_p = 2.0d0 * x(2) do g_i_ = 1, g_p_ g_f(g_i_, 1) = d1_p * g_x(g_i_, 2) + d2_p * g_x(g_i_, 1) enddo f(1) = d2_v + d4_vC-------- do g_i_ = 1, g_p_ g_f(g_i_, 2) = x(1) * g_x(g_i_, 2) + x(2) * g_x(g_i_, 1) enddo f(2) = x(1) * x(2)C--------
g_test contd.
![Page 24: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/24.jpg)
d4_v = x(2) * x(2) d1_p = 2.0d0 * x(2) d4_b = dble(3.) d5_b = d4_b * d1_p d6_b = dble(2.) do g_i_ = 1, g_p_ g_f(g_i_, 3) = d5_b * g_x(g_i_, 2) + d6_b * g_x(g_i_, 1) enddo f(3) = dble(2.) * x(1) + dble(3.) * d4_vC-------- return end
g_test contd.
![Page 25: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/25.jpg)
ADIFOR
Where ??
![Page 26: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/26.jpg)
Applications of ADIFOR and ADICApplications of ADIFOR and ADIC
ADIFOR and ADIC have been applied to application codes from various domains of science and engineering. • Atmospheric Chemistry • On-Chip Interconnect Modeling • Mesoscale Weather Modeling • CFD Analysis of the High-Speed Civil Transport • Rotorcraft Flight • 3-D Groundwater Contaminant Transport • 3-D Grid Generation for the High-Speed Civil Transport • A Numerically Complicated Statistical Function -- the Log-Likelihood for log-F distribution (LLDRLF).
![Page 27: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/27.jpg)
Mesoscale Weather Modeling :Temperature sensitivity as computed by Divided Difference using a second-order forward-difference formula
![Page 28: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/28.jpg)
Mesoscale Weather Modeling:
Temperature sensitivity as computed by ADIFOR
![Page 29: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/29.jpg)
Case Study at
CASDE
![Page 30: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/30.jpg)
Optimization Problem • Minimize : induced drag (Cdi)• Subject to: CL = 0.2• Design variables: jig-twist() and angle of attack
at root (
has a linear variation from zero at root to at tip.
is constant over the entire wing semi-span.
cr
ct
![Page 31: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/31.jpg)
The VLM Code600 lines (approx)
SUBROUTINE vlm(amach, cr, ct, bby2, sweep,twist,alp0,isym, ni_gr, nj_gr, cl, cd, cm)
CALL mesh(cr, ct, bby2, sweep, …,ni_gr, nj_gr)CALL matinv(aic, np_max, index, np)CALL setalp(r_p, beta, twist, bby2, alp0, alp, np)CALL mataxb(aic, alp, gama, np_max, np_max, np, np, 1)CALL mataxb(aiw, gama, w , np_max, np_max, np, np, 1)CALL loads(…,gama, w, str_lift, alift, cl, cd, cm)
![Page 32: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/32.jpg)
The ADIFOR-generated derivative of VLM
subroutine g_vlm(g_p_, …, twist, g_twist,ldg_twist, alp0, g_alp0, ldg_alp0, isym, ni_gr, nj_gr, cl, g_cl,ldg_cl, cd, g_cd, ldg_cd, cm)
call mesh(cr, ct, bby2, sweep, …, ni_gr, nj_gr)call matinv(aic, np_max, index, np)call g_setalp(g_p_, r_p, beta, twist, g_twist, ldg_twist, bby2,
alp0, g_alp0, ldg_alp0, alp, g_alp, g_pmax_, np)call g_mataxb(g_p_, aic, alp, g_alp, g_pmax_, gama, g_gama, g_pmax_,
np_max, np_max, np, np, 1)call g_mataxb(g_p_, aiw, gama, g_gama, g_pmax_, w, g_w, g_pmax_, np_max, np_max, np, np, 1)call g_loads(g_p_, …, ni_gr, nj_gr, np, …, gama, g_gama, g_pmax_, w,
g_w, g_pmax_, str_lift, alift, g_alift, g_pmax_, cl, g_cl, ldg_cl, cd, g_cd, ldg_cd, cm)
![Page 33: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/33.jpg)
Optimization ResultsJig-twist CL CDi
Starting
Values
2.0 5.4 0.4522 0.01104
Values at
Optimum
(FD)
-2.27439 3.782271 0.2 0.00191156
Values at
Optimum
(ADIFOR)
-2.29910 3.793176 0.2 0.00191155
![Page 34: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/34.jpg)
Optimization ResultsJig-twist CL CDi
Starting
Values
2.0
-6.0
5.4
1.9
0.4522
-0.0538
0.01104
0.00121
Values at
Optimum
(FD)
-2.27439
-2.27439
3.782271
3.782271
0.2
0.2
0.00191156
0.00191156
Values at
Optimum
(ADIFOR)
-2.29910
-2.29910
3.793176
3.793176
0.2
0.2
0.00191155
0.00191155
![Page 35: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/35.jpg)
Comparison of Time Takenfor Optimization
With
Finite Difference
With
ADIFOR
No. of function
Evaluations
25 15
Total time in
Seconds
35.41 21.45
![Page 36: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/36.jpg)
Codes with CASDE
• Inviscid 3D Code for arbitrary configurations. Tried on ONERA M6. Optimised for memory and CPU time. – total subroutines : 93– total source lines : 5077
• Viscous laminar, 2D, Cartesian for simple configurations. Not optimized. More easily readable. Research code.– total subroutines : 35– total source lines : 2316
![Page 37: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/37.jpg)
Limitations
• Strict ANSI Fortran 77 code.
![Page 38: Brief Outline](https://reader035.fdocuments.us/reader035/viewer/2022062301/56815a65550346895dc7ad14/html5/thumbnails/38.jpg)
Thank YouThank You