explorations of using ad for solving nonlinear pdes in chebfun2

22
Explorations of using AD for solving (non)linear PDEs in Chebfun2 Asgeir Birkisson University of Oxford Mathematical Institute Numerical Analysis Group 13 th European Workshop on Automatic Differentiation June, 2013 1 / 21

Upload: truongthuan

Post on 10-Dec-2016

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Explorations of using AD for solving nonlinear PDEs in Chebfun2

Explorations of using AD for

solving (non)linear PDEs in Chebfun2

Asgeir Birkisson

University of OxfordMathematical Institute

Numerical Analysis Group

13th European Workshop onAutomatic Differentiation

June, 20131 / 21

Page 2: Explorations of using AD for solving nonlinear PDEs in Chebfun2

Collaboration with Alex Townsend (University of Oxford), Sheehan Olver(University of Sidney) and the Chebfun team (University of Oxford, University ofDelaware).

2 / 21

Page 3: Explorations of using AD for solving nonlinear PDEs in Chebfun2

Table of Contents

Chebfun, AD in Chebfun and ODEs

Chebfun2

Chebfun2

AD in Chebfun 2

Solving PDEs in Chebfun 2

3 / 21

Page 4: Explorations of using AD for solving nonlinear PDEs in Chebfun2

Chebfun

• Chebfun (see www.chebfun.org) — a collection of algorithms and anopen-source software system in object-oriented Matlab.

• Extends familiar powerful methods of numerical computation involving numbersto continuous or piecewise-continuous functions.

• Basic idea: Represent functions using interpolants through (suitably rescaled)Chebyshev nodes

xj = − cos

(jπ

n

), 0 ≤ j ≤ n,

and overload familiar Matlab methods to work with them.

• Such interpolants have excellent approximation properties as described in[Trefethen, 2013]. Closely related to truncated Chebyshev series

∑n−1i=0 aiTi(x).

• Chebfuns are constructed adaptively – more and more points used, untilcoefficients in Chebyshev series fall below machine precision.

4 / 21

Page 5: Explorations of using AD for solving nonlinear PDEs in Chebfun2

<<< Matlab demo >>>

5 / 21

Page 6: Explorations of using AD for solving nonlinear PDEs in Chebfun2

Linear Differential Operators in Chebfun

• In [Driscoll et al., 2008], linear chebops (the linop class) introduced.

• Linear chebops represent linear differential operators, using pseudospectralmethods.

• Lazy evaluation – operators can be instantiated on an arbitrarily fine grid.

• Fits very naturally into the Chebfun framework – solutions returned will bechebfuns.

• Problems solved adaptively until fine enough discretisation of operator has beenachieved.

6 / 21

Page 7: Explorations of using AD for solving nonlinear PDEs in Chebfun2

<<< Matlab demo >>>

7 / 21

Page 8: Explorations of using AD for solving nonlinear PDEs in Chebfun2

AD in Chebfun

• Possible to solve nonlinear ODEs, using Newton iteration in function space.

• Requires the Frechet derivatives of the nonlinear operators – linear operators,the continuous analogue of Jacobian matrices.

• AD came to the rescue – the Frechet derivatives are computed using ADtechniques, represented using linear chebops.

• Able to compute the derivative of any chebfun with respect to any otherchebfun.

• See [Birkisson and Driscoll, 2012] for further details.

8 / 21

Page 9: Explorations of using AD for solving nonlinear PDEs in Chebfun2

<<< Matlab demo >>>

9 / 21

Page 10: Explorations of using AD for solving nonlinear PDEs in Chebfun2

Chebfun in two-dimensions

• Chebfun is an established too for solving problems in 1D, but what abouthigher dimensions?

• Attempts made in the past, but the greatest success has been Chebfun2 (byAlex Townsend).

• Essential idea: represent a general two-dimensional function f (x , y) as a sum ofrank-1 functions

f (x , y) =k∑

i=1

vi(y)ui(x).

• Construction such approximations can be thought of as being the continuousanalogue of Gaussian elimination with complete pivoting.

• This idea allows for exploiting a lot of the current 1D capabilities of Chebfun –the functions ui and vi are represented via 1D chebfuns.

10 / 21

Page 11: Explorations of using AD for solving nonlinear PDEs in Chebfun2

Chebfun in two-dimensions

• Addition to the Chebfun system – Chebfun2. Introdues a new object class –chebfun2.

• Chebfun2 also includes vector-valued 2D functions – chebfun2v. Here, thefunctions represented are

F (x , y) =

[f1(x , y)f2(x , y)

].

• Chebfun2 has become a pretty exhaustive tool for manipulation of 2Dfunctions, including bivariate rootfinding (finding common roots of f and g s.t.f (x , y) = g(x , y) = 0, vector calculus, integration, differentiation, ...

11 / 21

Page 12: Explorations of using AD for solving nonlinear PDEs in Chebfun2

<<< Matlab demo >>>

12 / 21

Page 13: Explorations of using AD for solving nonlinear PDEs in Chebfun2

AD in Chebfun 2

• One capability which would be very desirable for Chebfun2 to have is to solvePDEs.

• Alex Townsend and Sheehan Olver have already started experimenting withsolving linear PDEs with constant coefficients.

• Two questions related to AD arise:◦ Is it possible to enable the nice syntax of chebops and create a chebop2 class?◦ Can AD be used to supply derivatives for solving nonlinear problems?

• The two questions are actually linked – the nice syntax the chebop class offersfor linear problems is enabled through AD.

13 / 21

Page 14: Explorations of using AD for solving nonlinear PDEs in Chebfun2

AD in Chebfun 2

• The spectral method constructed by AT+SO actually works in coefficientspace, rather than value space as pseudospectral methods do.

• It is more useful for that method to know the (variable) coefficients of a PDEexplicitly, rather than a discretisation of the whole operator, as it allows formore efficient solution method.

• I.e., rather than using AD to obtain the matrix discretisation of an operatorsuch as

L : u 7→ a(x , y)uxx + b(x , y)uyy + c(x , y)uxy + d(x , y)ux + . . .

we wish to obtain the coefficients of the linear PDE – a(x , y), b(x , y),c(x , y), . . ..

14 / 21

Page 15: Explorations of using AD for solving nonlinear PDEs in Chebfun2

AD in Chebfun 2

• Solving a nonlinear PDE using the approach “linearise, then discretize”amounts to linearising the PDE operator at each step of the Newton iteration.

• I.e., problems are solved through a series of linear PDEs.

• These linear PDEs have variable coefficients, which depend on the currentguess of the solution.

• Thus, if we’re able to linearise nonlinear PDEs, and determine coefficients oflinear PDEs, we are in a position for solving nonlinear PDEs.

• Obvious task for AD techniques!

• Implement operator overloaded, forward mode AD.

15 / 21

Page 16: Explorations of using AD for solving nonlinear PDEs in Chebfun2

ADchebfun2 and chebfun2der

• Wish to keep AD capabilities separate from core Chebfun2 system – introduceADchebfun2.

• An ADchebfun2 contains a chebfun2 and a chebfun2der – similar to thebasic model of OO forward mode AD.

• A chebfun2der is a “very infinite dimensional” object which contains thecoefficients of linear PDEs, ordered as

a00(x , y) a10(x , y) a20(x , y) . . .a01(x , y) a11(x , y) a21(x , y) . . .a02(x , y) a12(x , y) a22(x , y) . . .

......

.... . .

,where aij(x , y) is the coefficient of the PDE operator for the term ∂ i+ju

∂x i∂y j .

16 / 21

Page 17: Explorations of using AD for solving nonlinear PDEs in Chebfun2

AD in Chebfun 2

• The chebfun2der object can be thought of as a clever Matlab cell-array,which knows how to update itself when computations with ADchebfun2 objectsare carried out.

• At the start of an ADchebfun2 computation, its derivative is seeded to be anchebfun2der, only including the constant function a00(x , y) = 1.

• At subsequent computations, the chebfun2der grows in size, adding morecolumns and rows as derivatives are taking in the x and y variables respectively.

• If an ADchebfun2 gets operated on by a nonlinear operator, the Frechetderivative of that operator is computed, and the derivative updated.

17 / 21

Page 18: Explorations of using AD for solving nonlinear PDEs in Chebfun2

<<< Matlab demo >>>

18 / 21

Page 19: Explorations of using AD for solving nonlinear PDEs in Chebfun2

Solving PDEs in Chebfun2

• Example: Constant coefficient PDE; Helmholtz equation:

uxx + uyy + 10000u = 0, u(±1, y) = u(x ,±1) = 1.

L = chebop2(@(u) diffx(u,2)+diffy(u,2)+10000*u);

L.lbc = 1; L.rbc = 1; L.ubc = 1; L.dbc = 1;

u = L \ 0;

19 / 21

Page 20: Explorations of using AD for solving nonlinear PDEs in Chebfun2

Solving PDEs in Chebfun2

• Example: Variable coefficients PDE:

(1− x2)uxx + (1− y2)uyy + 3u = (1− x2)(1− y2), u(±1, y) = u(x ,±1) = 0.

• Exact solution is u(x , y) = (1− x2)(1− y2).

20 / 21

Page 21: Explorations of using AD for solving nonlinear PDEs in Chebfun2

Further remarks

• Code for solving PDEs with variable coefficients in coefficient space, ratherthen variable space, still has to be made robust in order to be able to obtainsolutions on a fine grid.

• Variable coefficient PDEs often have issues with corner singularities. Thisaffects the residual, rather than the actual error of the linear problems, but thelarge residual has the potential to affect the Newton iteration.

• Still a lot of work to be done, but AD will be crucial for this approach to work!

21 / 21

Page 22: Explorations of using AD for solving nonlinear PDEs in Chebfun2

Birkisson, A. and Driscoll, T. A. (2012).Automatic frechet differentiation for the numerical solution of boundary-value problems.ACM Trans. Math. Softw., 38(4):26:1–26:29.

Driscoll, T. A., Bornemann, F., and Trefethen, L. N. (2008).The chebop system for automatic solution of differential equations.BIT Numerical Mathematics, 48:701–723.

Trefethen, L. N. (2013).Approximation Theory and Approximation Practice.SIAM, Philadelphia.

21 / 21