Numerical computations with functions defined on the sphere and disk Alex Townsend MIT Grady Wright Heather Wilber NA and PDE Seminar, University of Delaware, 12th November 2015 Introduction A trend in the computing era: adaptive algorithms besselj(0, 3/2) quadgk(f, a, b) fft( x ) For example: (Code will soon be available as part of Chebfun) f = spherefun( @(x,y,z) cos(1 + 2*pi*(x + y) + 5*sin(pi*z)) ) Goal: Adaptive algorithms for computing with functions on the sphere/disk. Alex Townsend @ MIT 1/26 Introduction Proxy computing Proxy computing: Replace number/function by a substitute. >> methods spherefun abs, cdr, coeffs2, cos, diff, feval, grad, length, max, max2, mean, min, min2, norm, plot, plus, pivots, poisson, real, restrict, roots, rotate, sum2, surfacearea, trace, transpose, uplus, etc. Noteworthy proxy software systems: RKToolbox Driscoll, Hale, Trefethen, and many others Alex Townsend @ MIT Guttel and Berljafa 2/26 Introduction Existing methods for the sphere We desire: 1. Regularity preserving 2. “Uniform” resolution 3. Adaptive algorithms Three ideas: 1. DFS method 2. Low rank approx. 3. Uniform grids Ñ FFT Alex Townsend @ MIT 3/26 The double Fourier sphere (DFS) method Part I: The double Fourier sphere method Alex Townsend @ MIT 4/26 The double Fourier sphere (DFS) method The globe (a) 180θ{π (c) 180θ{π (b) 180λ{π Alex Townsend @ MIT 180λ{π 5/26 The double Fourier sphere (DFS) method Extended functions have an interesting symmetry h on sphere f pλ, θq r´π, πs ˆ r0, πs f̃ pλ, θq r´π, πs ˆ r´π, πs 180θ{π g f px, y, z q flipph q flippg q Key papers: [Merilees, 1973], [Orszag, 1974], [Fornberg, 1995], [Cheong, 2000], [Torres & Coutsias, 1999]. 180λ{π Steven Orszag Alex Townsend @ MIT 6/26 The double Fourier sphere (DFS) method Fourier series on spheres [Orszag, 1974] Fourier series on spheres: f̃ pλ, θq « n {2 ÿ m {2 ÿ ajk e ijθ e ik λ j “´n{2 k “´m{2 fi » fi » fi » f´ ´f ´ g h f` f` Preserving symmetry: fl – fl“– fl ` – even-odd decomp. f̃ “ ´ ´ ` ` ´flippf q flippf q flipph q flippg q flippf q flippf q [Yee, 1980] looooooooooomooooooooooon loooooooooooomoooooooooooon even, π-periodic π f ` “ pg `h q{2, odd, π-antiperiodic f ´ “ pg ´h q{2 θ ´π ´π Alex Townsend @ MIT Overresolving the poles λ π 7/26 Low rank approximation Part II: Low rank approximation Alex Townsend @ MIT 8/26 Low rank approximation Skeleton grids [Goreinov, Tyrtyshnikov & Zamarashkin, 1997] A tensor-product grid A skeleton grid “Skeleton grid” = criss-cross of 1D uniform grids. Alleviates overresolving at the poles Computations can be done with 1D algorithms FFT applicable Idea: Use a “skeleton grid”, constructed by a criss-cross of 1D uniform grids. Related work: [Bebendorf 2000], [Carvajal, Chapman & Geddes, 2005], [Goreinov, Tyrtyshnikov & Zamarashkin, 1997], [Halko, Martinsson, & Tropp, 2011], [Hackbusch, 2009], [Mahoney & Drineas, 2009]. Alex Townsend @ MIT 9/26 Low rank approximation Skeleton grids [Goreinov, Tyrtyshnikov & Zamarashkin, 1997] A tensor-product grid A skeleton grid “Skeleton grid” = criss-cross of 1D uniform grids. Alleviates overresolving at the poles Computations can be done with 1D algorithms FFT applicable Idea: Use a “skeleton grid”, constructed by a criss-cross of 1D uniform grids. Related work: [Bebendorf 2000], [Carvajal, Chapman & Geddes, 2005], [Goreinov, Tyrtyshnikov & Zamarashkin, 1997], [Halko, Martinsson, & Tropp, 2011], [Hackbusch, 2009], [Mahoney & Drineas, 2009]. Alex Townsend @ MIT 9/26 Low rank approximation Skeleton grids [Goreinov, Tyrtyshnikov & Zamarashkin, 1997] A tensor-product grid A skeleton grid “Skeleton grid” = criss-cross of 1D uniform grids. Alleviates overresolving at the poles Computations can be done with 1D algorithms FFT applicable Idea: Use a “skeleton grid”, constructed by a criss-cross of 1D uniform grids. Related work: [Bebendorf 2000], [Carvajal, Chapman & Geddes, 2005], [Goreinov, Tyrtyshnikov & Zamarashkin, 1997], [Halko, Martinsson, & Tropp, 2011], [Hackbusch, 2009], [Mahoney & Drineas, 2009]. Alex Townsend @ MIT 9/26 Low rank approximation Skeleton grids [Goreinov, Tyrtyshnikov & Zamarashkin, 1997] A tensor-product grid A skeleton grid “Skeleton grid” = criss-cross of 1D uniform grids. Alleviates overresolving at the poles Computations can be done with 1D algorithms FFT applicable Idea: Use a “skeleton grid”, constructed by a criss-cross of 1D uniform grids. Related work: [Bebendorf 2000], [Carvajal, Chapman & Geddes, 2005], [Goreinov, Tyrtyshnikov & Zamarashkin, 1997], [Halko, Martinsson, & Tropp, 2011], [Hackbusch, 2009], [Mahoney & Drineas, 2009]. Alex Townsend @ MIT 9/26 Low rank approximation Skeleton grids [Goreinov, Tyrtyshnikov & Zamarashkin, 1997] A tensor-product grid A skeleton grid “Skeleton grid” = criss-cross of 1D uniform grids. Alleviates overresolving at the poles Computations can be done with 1D algorithms FFT applicable Idea: Use a “skeleton grid”, constructed by a criss-cross of 1D uniform grids. Related work: [Bebendorf 2000], [Carvajal, Chapman & Geddes, 2005], [Goreinov, Tyrtyshnikov & Zamarashkin, 1997], [Halko, Martinsson, & Tropp, 2011], [Hackbusch, 2009], [Mahoney & Drineas, 2009]. Alex Townsend @ MIT 9/26 Low rank approximation Skeleton grids [Goreinov, Tyrtyshnikov & Zamarashkin, 1997] A tensor-product grid A skeleton grid “Skeleton grid” = criss-cross of 1D uniform grids. Alleviates overresolving at the poles Computations can be done with 1D algorithms FFT applicable Idea: Use a “skeleton grid”, constructed by a criss-cross of 1D uniform grids. Related work: [Bebendorf 2000], [Carvajal, Chapman & Geddes, 2005], [Goreinov, Tyrtyshnikov & Zamarashkin, 1997], [Halko, Martinsson, & Tropp, 2011], [Hackbusch, 2009], [Mahoney & Drineas, 2009]. Alex Townsend @ MIT 9/26 Low rank approximation Gaussian elimination on functions [T. & Trefethen 2013] Standard point of view: A Alex Townsend @ MIT PL U 10/26 Low rank approximation Gaussian elimination on functions [T. & Trefethen 2013] Standard point of view: Different point of view: A ÐÝ A ´ A pj, :qA p:, k q{A pj, k q f ÐÝ f ´ f px, :qf p:, y q{f px, y q Each step of GE is a rank-1 update. Alex Townsend @ MIT A PL U (GE step for matrices) (GE step for functions) 10/26 Low rank approximation Gaussian elimination on functions [T. & Trefethen 2013] Standard point of view: Different point of view: A ÐÝ A ´ A pj, :qA p:, k q{A pj, k q f ÐÝ f ´ f px, :qf p:, y q{f px, y q Each step of GE is a rank-1 update. Alex Townsend @ MIT A PL U (GE step for matrices) (GE step for functions) 10/26 Low rank approximation GE pivot locations cosp10px 2 ` y qq ` sinp10px ` y 2 qq Aip5px ` y 2 qqAip´5px 2 ` y 2 qq 1{p1 ` 100p 21 ´ x 2 ´ y 2 q2 q Here we used complete pivoting, i.e., pick the absolute max. as the pivot. Alex Townsend @ MIT 11/26 Low rank approximation GE with any standard pivoting does not preserve symmetry π f̃ pλ, θq « pλ˚ , θ˚ q f̃ pλ˚ , θqf̃ pλ, θ˚ q f̃ pλ˚ , θ˚ q “ d1 c1 pθqr1 pλq θ ´π ´π λ π Problem: GE with any standard pivoting does not preserve symmetry. Alex Townsend @ MIT 12/26 Low rank approximation GE with any standard pivoting does not preserve symmetry π f̃ pλ, θq « pλ˚ , θ˚ q f̃ pλ˚ , θqf̃ pλ, θ˚ q f̃ pλ˚ , θ˚ q “ d1 c1 pθqr1 pλq θ ´π ´π λ π Problem: GE with any standard pivoting does not preserve symmetry. Alex Townsend @ MIT 12/26 Low rank approximation GE with any standard pivoting does not preserve symmetry π f̃ pλ, θq « pλ˚ , θ˚ q f̃ pλ˚ , θqf̃ pλ, θ˚ q f̃ pλ˚ , θ˚ q “ d1 c1 pθqr1 pλq θ ´π ´π λ π Problem: GE with any standard pivoting does not preserve symmetry. Alex Townsend @ MIT 12/26 Low rank approximation GE with any standard pivoting does not preserve symmetry π f̃ pλ, θq « pλ˚ , θ˚ q f̃ pλ˚ , θqf̃ pλ, θ˚ q f̃ pλ˚ , θ˚ q “ d1 c1 pθqr1 pλq θ ´π ´π λ π Problem: GE with any standard pivoting does not preserve symmetry. Alex Townsend @ MIT 12/26 Low rank approximation Structure preserving GE, motivated by [Bunch & Parlett 1971] π « pλ ´ π, θ q ˚ ˚ ” ı f̃ pλ, θq « f̃ pλ ´ π, θq f̃ pλ , θq M ´1 pλ , θ q ˚ ˚ θ ˚ ˚ f̃ pλ, θ˚ q ff f̃ pλ, ´θ˚ q Rank 2 approx. pλ˚´ π, ´θ˚q pλ˚ , ´θ˚ q ´π ´π λ π Problem: GE with 2 ˆ 2 pivots does preserve symmetry. No pole singularity M ´1 is replaced by an -pseudoinverse. Alex Townsend @ MIT 13/26 Low rank approximation Structure preserving GE, motivated by [Bunch & Parlett 1971] π « pλ ´ π, θ q ˚ ˚ ” ı f̃ pλ, θq « f̃ pλ ´ π, θq f̃ pλ , θq M ´1 pλ , θ q ˚ ˚ θ ˚ ˚ f̃ pλ, θ˚ q ff f̃ pλ, ´θ˚ q Rank 2 approx. pλ˚´ π, ´θ˚q pλ˚ , ´θ˚ q ´π ´π λ π Problem: GE with 2 ˆ 2 pivots does preserve symmetry. No pole singularity M ´1 is replaced by an -pseudoinverse. Alex Townsend @ MIT 13/26 Low rank approximation No pole singularities Rank 2 Rank 4 Rank 6 Rank 2 Rank 4 Rank 6 Standard GE Structure preserving GE Alex Townsend @ MIT 14/26 Low rank approximation Skeleton grid review cospxyz q cospxz ´ sin y q f̃ pλ, θq « d1 c1 pθqr1 pλq ` d2 c2 pθqr2 pλq ` . . . ` dK cK pθqrK pλq Observation: Mathematically, most functions are of infinite rank but can be of low numerical rank. [Chapter 3, T. 2014] Rank 5 Alex Townsend @ MIT Rank 17 15/26 Low rank approximation Approximation theory for our GE procedure Observation: SVD is optimal, but GE is near-optimal. f px, y, z q “ 1{p1 ` γx 2 y 2 z 2 q Best (SVD) GE γ“ L2 error γ“ 10 00 10 Rank of approximant Alex Townsend @ MIT Exact recovery: If f pλ, θq has a finite spherical harmonic expansion, then GE exactly recovers f . Convergence: If f̃ pλ, θq is analytic in both variables separably in a sufficiently large region, then our GE procedure constructs a sequence of low rank approximants that converge geometrically to f̃ . More details in [T. , Wilber, Wright, 2015]. 16/26 Operations and differential equations Part III: Operations and differential equations Alex Townsend @ MIT 17/26 Operations and differential equations Tensor product operations Idea: Two-dimensional operations can exploit 1D Fourier technology f̃ pλ, θq K ÿ dk lo cokmo pθon q « k “1 2π-periodic sum2( f ): ż f px, y, z qdxdydz « S2 K ÿ k “1 żπ dk 0 rkomo pλoqn lo 2π-periodic ck pθq sin θdθ żπ ´π rk pλqdλ diff( f ): » fi ˙ˆ ˙ ÿ ˙ 1 K ˆ K ˆ t ÿ ck pθq B rk pλq B ck pθq Bf – fl pcos λrk pλqq “ 0 ¨∇S2 f « ´ sin λ ` cos θ Bx sin θ B λ B θ k “1 k “1 0 Others include: Very different to [Cheong 2000] and [Yee 1981]. f(x,y,z), curl(f), divergence(F), gradient(f), lu(f), sample(f) Alex Townsend @ MIT 18/26 Operations and differential equations Tensor product operations Idea: Two-dimensional operations can exploit 1D Fourier technology f̃ pλ, θq K ÿ dk lo cokmo pθon q « k “1 2π-periodic sum2( f ): ż f px, y, z qdxdydz « S2 K ÿ k “1 żπ dk 0 rkomo pλoqn lo 2π-periodic ck pθq sin θdθ żπ ´π rk pλqdλ diff( f ): » fi ˙ˆ ˙ ÿ ˙ 1 K ˆ K ˆ t ÿ ck pθq B rk pλq B ck pθq Bf – fl pcos λrk pλqq “ 0 ¨∇S2 f « ´ sin λ ` cos θ Bx sin θ B λ B θ k “1 k “1 0 Others include: Very different to [Cheong 2000] and [Yee 1981]. f(x,y,z), curl(f), divergence(F), gradient(f), lu(f), sample(f) Alex Townsend @ MIT 18/26 Operations and differential equations Tensor product operations Idea: Two-dimensional operations can exploit 1D Fourier technology f̃ pλ, θq K ÿ dk lo cokmo pθon q « k “1 2π-periodic sum2( f ): ż f px, y, z qdxdydz « S2 K ÿ k “1 żπ dk 0 rkomo pλoqn lo 2π-periodic ck pθq sin θdθ żπ ´π rk pλqdλ diff( f ): » fi ˙ˆ ˙ ÿ ˙ 1 K ˆ K ˆ t ÿ ck pθq B rk pλq B ck pθq Bf – fl pcos λrk pλqq “ 0 ¨∇S2 f « ´ sin λ ` cos θ Bx sin θ B λ B θ k “1 k “1 0 Others include: Very different to [Cheong 2000] and [Yee 1981]. f(x,y,z), curl(f), divergence(F), gradient(f), lu(f), sample(f) Alex Townsend @ MIT 18/26 Operations and differential equations Tensor product operations Idea: Two-dimensional operations can exploit 1D Fourier technology f̃ pλ, θq K ÿ dk lo cokmo pθon q « k “1 2π-periodic sum2( f ): ż f px, y, z qdxdydz « S2 K ÿ k “1 żπ dk 0 rkomo pλoqn lo 2π-periodic ck pθq sin θdθ żπ ´π rk pλqdλ diff( f ): » fi ˙ˆ ˙ ÿ ˙ 1 K ˆ K ˆ t ÿ ck pθq B rk pλq B ck pθq Bf – fl pcos λrk pλqq “ 0 ¨∇S2 f « ´ sin λ ` cos θ Bx sin θ B λ B θ k “1 k “1 0 Others include: Very different to [Cheong 2000] and [Yee 1981]. f(x,y,z), curl(f), divergence(F), gradient(f), lu(f), sample(f) Alex Townsend @ MIT 18/26 Operations and differential equations Vector calculus operations Great for vector calculus: div, grad, and curl are surprisingly efficient. Why? Based on 1D algorithms for Fourier series How? All standard vector calculus operations on the sphere can be expressed in terms of Bt f , Bx Bt f , By Bt f . Bz % Rossby-Haurtwitz benchmark problem psi = spherefun(@(la,th) cos(th) + sin(th).ˆ4.*cos(th).*cos(4*la)); u = curl( psi ); % vector-valued spherefun plot( vort( u ) ), hold on, quiver( u ) Alex Townsend @ MIT 19/26 Operations and differential equations Composition operators: e.g. f + g, f.*g, and exp(f) cosp5pxy ` z qq ˆ Rank 15 Ai p5px ´ y ` z qq Rank 37 “ h Rank 43 ! 15 ˆ 37 “ 645 Option: (Call the constructor) h = spherefun( @(la, th) f(la,th).*g(la,th) ); % h = f .* g Composition operations call the constructor. (f+g is THE exception.) Alex Townsend @ MIT 20/26 Operations and differential equations Fourier spectral method for Poisson’s equation Poisson equation on the sphere ż ∇ u “ f, 2 px, y, z q P S , 2 upx, y, z qdxdydz “ 0. S2 Poisson equation in DFS method psin θq2 B ũ B 2 ũ B 2 ũ 2 ` cos θ sin θ ` 2 “ psin θq f̃ , 2 Bθ Bλ B θ Ansatz: ũpλ, θq « n {2 ÿ pλ, θq P r´π, πs ˆ r´π, πs. m {2 ÿ ujk e ijθ e ik λ j “´n{2 k “´m{2 Because B 2 pe ik λ q{B λ2 “ ´k 2 e ik λ , Poisson’s equation decouples. Alex Townsend @ MIT 21/26 Operations and differential equations Fourier spectral method for Poisson’s equation Poisson equation on the sphere ż ∇ u “ f, 2 px, y, z q P S , 2 upx, y, z qdxdydz “ 0. S2 Poisson equation in DFS method psin θq2 B ũ B 2 ũ B 2 ũ 2 ` cos θ sin θ ` 2 “ psin θq f̃ , 2 Bθ Bλ B θ Ansatz: ũpλ, θq « n {2 ÿ pλ, θq P r´π, πs ˆ r´π, πs. m {2 ÿ ujk e ijθ e ik λ j “´n{2 k “´m{2 Because B 2 pe ik λ q{B λ2 “ ´k 2 e ik λ , Poisson’s equation decouples. Alex Townsend @ MIT 21/26 Operations and differential equations Fourier spectral method for Poisson’s equation Poisson equation on the sphere ż ∇ u “ f, 2 px, y, z q P S , 2 upx, y, z qdxdydz “ 0. S2 Poisson equation in DFS method psin θq2 B ũ B 2 ũ B 2 ũ 2 ` cos θ sin θ ` 2 “ psin θq f̃ , 2 Bθ Bλ B θ Ansatz: ũpλ, θq « n {2 ÿ pλ, θq P r´π, πs ˆ r´π, πs. m {2 ÿ ujk e ijθ e ik λ j “´n{2 k “´m{2 Because B 2 pe ik λ q{B λ2 “ ´k 2 e ik λ , Poisson’s equation decouples. Alex Townsend @ MIT 21/26 Operations and differential equations Fourier spectral method for Poisson’s equation (cont.) ż 2 2 ∇ u “ sinp50xyz q, px, y, z q P S , upx, y, z qdxdydz “ 0. S2 10 101 Op n2 q Computational time (sec) upx, y, z q 2 100 10-1 10-2 10-3 102 103 104 105 n2 {2 106 107 108 f = spherefun(@(x,y,z) sin(50*x.*y.*z)); u = Poisson(f,0,150,150); When are spherical harmonic expansions needed? Alex Townsend @ MIT 22/26 Operations and differential equations Fourier spectral method for Poisson’s equation (cont.) ż 2 2 ∇ u “ sinp50xyz q, px, y, z q P S , upx, y, z qdxdydz “ 0. S2 10 101 Op n2 q Computational time (sec) upx, y, z q 2 100 10-1 10-2 10-3 102 103 104 105 n2 {2 106 107 108 f = spherefun(@(x,y,z) sin(50*x.*y.*z)); u = Poisson(f,0,150,150); When are spherical harmonic expansions needed? Alex Townsend @ MIT 22/26 Disk computations Active biological fluids on the disk NOT the sphere High-order variant of Navier–Stokes: Bv ` pv ¨ ∇q v “ ´∇p ` Γ0 ∇2 v ´ Γ2 ∇4 v ` Γ4 ∇6 v, Bt on the unit disk ∇¨v “0 Bacillus subtilis Lab vorticity Numerical vorticity Jonasz Slomka Jörn Dunkel For periodic bcs, a collective “swarming” motion. What is the impact of various geometries on the vortices? Alex Townsend @ MIT [Slomka & Dunkel, 2015] 23/26 Disk computations The same symmetry holds for the disk 1 1 g 0 ´π h π flipph q flippg q ´1 ´π Unit disk r´π, πs ˆ r0, 1s π r´π, πs ˆ r´1, 1s We use Chebyshev technology in r and Fourier in θ. Thanks to OOP, diskfun and spherefun use the same code in many places. f = diskfun(@(x,y) 2.ˆ(-cos(4*x)) + sin(7*pi*x.*sin(y-.1)), ’cart’); Alex Townsend @ MIT 24/26 Disk computations The same symmetry holds for the disk 1 1 g 0 ´π h π flipph q flippg q ´1 ´π Unit disk r´π, πs ˆ r0, 1s π r´π, πs ˆ r´1, 1s We use Chebyshev technology in r and Fourier in θ. Thanks to OOP, diskfun and spherefun use the same code in many places. f = diskfun(@(x,y) 2.ˆ(-cos(4*x)) + sin(7*pi*x.*sin(y-.1)), ’cart’); Alex Townsend @ MIT 24/26 Disk computations The same symmetry holds for the disk 1 1 g 0 ´π h π flipph q flippg q ´1 ´π Unit disk r´π, πs ˆ r0, 1s π r´π, πs ˆ r´1, 1s We use Chebyshev technology in r and Fourier in θ. Thanks to OOP, diskfun and spherefun use the same code in many places. f = diskfun(@(x,y) 2.ˆ(-cos(4*x)) + sin(7*pi*x.*sin(y-.1)), ’cart’); Alex Townsend @ MIT 24/26 Disk computations The same symmetry holds for the disk 1 1 g 0 ´π h π flipph q flippg q ´1 ´π Unit disk r´π, πs ˆ r0, 1s π r´π, πs ˆ r´1, 1s We use Chebyshev technology in r and Fourier in θ. Thanks to OOP, diskfun and spherefun use the same code in many places. f = diskfun(@(x,y) 2.ˆ(-cos(4*x)) + sin(7*pi*x.*sin(y-.1)), ’cart’); Alex Townsend @ MIT 24/26 Demo Demo Alex Townsend @ MIT 25/26 Thank you Sphere and disk computations without worrying about the underlying discretization More information in: T., H. Wilber, and G. Wright, “Computing with functions in spherical and polar geometries I. The sphere”, submitted to SISC. Code soon to be part of Chebfun: http://www.chebfun.org/ Alex Townsend @ MIT 26/26