WRT in 2D: Poisson Example Consider 2 u f on [, L x [, L y with u. WRT: For all v X N, find u X N a(v, u) such that v u dv v f dv. Follows from strong form plus integration by parts: ( ) 2 u v + 2 u dx dy }{{ 2 }}{{ 2 } I x I y v f dv. First integral: I x : Ly [ Lx Ly [ Lx v 2 u dx dy 2 v u dx v(x, y) u xl x,y x,y } {{ } dy Ly Lx v u dx dy. Second integral, by symmetry: I y Ly Lx v u dx dy.
Evaluating Integrals Using Basis Functions For all v, u X N, v(x, y) u(x, y) N N v ij φ i (x) ψ j (y) i j N N u pq φ p (x) ψ q (y). p q Here, we take φ and ψ to be the bases on [, L x [, L y, φ i (x) : l i (r(x)), r(x) : + 2 L x x, ψ j (y) : l j (s(y)), s(y) : + 2 L y y, and the l i s and l j s are the (same) Lagrange interpolating polynomials based on the Gauss-Lobatto-Legendre (GLL) points r j [, : ˆ. Derivative with respect to x: Derivative with respect to y: N v i N u N φ i(x) ψ j (y) v ij j p q N v i N u N φ p(x) ψ q (y) u pq. N φ i (x) ψ j(y) v ij j p q N φ p (x) ψ q(y) u pq.
First integral, I x Ly Lx pq pq pq ( ) ( v ij φ i(x) ψ j (y)v ij pq ij Ly v ij ij ( Ly v ij ij v ij By,jq Ā x,ip u pq ij v T ( By Āx) ū. Second integral, by symmetry, I y v T ( Ā y B x ) ū. [ Lx ψ j (y) ψ q (y) ) ( Lx ψ j (y) ψ q (y) dy u pq φ p(x) ψ q (y)u pq ) φ i(x) φ p(x) dx dy u pq ) φ i(x) φ p(x) dx u pq, dx dy
Following as we did in D, we end up with the linear system Au Bf A B y A x + A y B x. Let, as in D, Ā x : 2 L x ˆDT ˆB ˆD, [Āx ip : Lx φ i(x) φ p(x) dx N φ i(x k ) k [ N 2 k L x 2 L x N k 2 L x N k ( ) Lx 2 ρ k φ p(x k ) dl i dr [ 2 L x ˆDT ˆB ˆD rk (Lx ˆD ki ρ k ˆDkp ˆD ki ˆBkk ˆDkp. ip 2 ρ k ) [ 2 L x (GLL quadrature) dl p dr rk This gives us the bar matrix, Ā x, which includes the endpoints.
To get the interior points only, we (re-)introduce the restriction matrix, R, and prolongation matrix, P : R T. Recall P T I T lr (N+) (N ). Q: What is the role of P in a matrix-vector product? Q: What is the role of R in a matrix-vector product?
Matlab Example wrttest.m N5; % Polynomial Order [Ah,Bh,Ch,Dh,z,w semhat(n); R speye(n+); RR(2:(end-),:); % Dirichlet Restriction Matrix A R*Ah*R ; f+*z; u A \ (R*(Bh*f)); u[;u;; ue.5*(-z.*z); err max(abs(u-ue)) After executing this code we can look at R: R full(r) R Ah 5.667e+ -5.7553e+ 7.529e- -2.3287e-.97e- -3.3333e-2-5.7553e+ 9.267e+ -3.989e+ 8.385e- -3.233e-.97e- 7.529e- -3.989e+ 6.4e+ -3.4e+ 8.385e- -2.3287e- -2.3287e- 8.385e- -3.4e+ 6.4e+ -3.989e+ 7.529e-.97e- -3.233e- 8.385e- -3.989e+ 9.267e+ -5.7553e+ -3.3333e-2.97e- -2.3287e- 7.529e- -5.7553e+ 5.667e+ >> A A 9.267e+ -3.989e+ 8.385e- -3.233e- -3.989e+ 6.4e+ -3.4e+ 8.385e- 8.385e- -3.4e+ 6.4e+ -3.989e+ -3.233e- 8.385e- -3.989e+ 9.267e+ >> Bh Bh 6.6667e-2 3.7847e- 5.5486e- 5.5486e- 3.7847e- 6.6667e-2 >> R*Bh*R ans 3.7847e- 5.5486e- 5.5486e- 3.7847e- We see that R does just what we need. It picks out the active rows (i.e., equations) in the ODE/PDE.
R T u extends u by zero, so that we can apply quadrature and/or differentiate u(x) on x, x,..., x N, as needed. >> u[ 2 3 4 u 2 3 4 >> R *u ans 2 3 4
Note: If we have Neumann conditions in the y-direction (say), then y-indices range from to N. For example, LHS of the ij-th equation will be I N q N p [B y A x + A y B x u A u. (B y,jq A x,ip + A y,jq B x,ip ) u pq { i,..., N j,..., N The mass matrices, B x, B y, and stiffness matrices, A x, A y, will have the correct size (and hence, correct index range in the first expression), if we set B x R x BR T x A x R x ĀR T x B y R y BR T y A y R y ĀR T y, with R T x T I T lr (N+) (N ), R T y I lr (N+) (N+). We typically refer to Ā and B as the Neumann operators. They are the full (N + ) (N + ) matrices corresponding to the Neumann problem. In terms of the generic ( hat ) matrices, they are (for x, say) Ā 2 L x Â, B L x 2 ˆB. Example: Solve 2 u on [, 2 [, u(x, y) at x, 2. u at y,.
Variable Coefficients in 2D: Recall D example: d dx q(x)du dx { u() f(x) + BCs u () WRT: v d dx q(x)du dx dx dv dx q(x)du dx dx v f(x) dx v f(x) dx (Dv) T QBDu v T Bf v T D T QBDu v T Bf Au Bf A : D T QBD. With (highly accurate) GLL quadrature, it is sufficient to evaluate q(x) at the GLL nodal points, x k, k,..., N The matrices Q and B are thus both diagonal: Q kk q(x k ), B kk ρ k, k,..., N.
2D example: [q(x, y) u f(x, y) + BCs v [q u dx dy v f(x, y) dx dy v [ q u + q u dx dy v f(x, y) dx dy First term on left, itegrated by parts [ Ly Lx I x Let Γ i denote the ith faces of, i: left face i2: right face i3: lower face i4: upper face v q u u dx v q Let ˆn i be the associated outward-pointing unit-normals on these faces: i: ˆn (ˆn x,, ˆn y, ) (, ) i2: ˆn 2 (ˆn x,2, ˆn y,2 ) (, ) i3: ˆn 3 (ˆn x,3, ˆn y,3 ) (, ) i4: ˆn 4 (ˆn x,4, ˆn y,4 ) (, ) We can rewrite I x as: I x Ly Lx v q u 2 dx dy i x x Γ i v q u ˆn x,i dy. dy Similarly, I y is I y Ly Lx v q u 4 dx dy i3 Γ i v q u ˆn y,i dy. Combining I x and I y, I I x + I y Ly Lx v q u + v q u 4 dx dy v (q u) dv v q u ˆn ds. i Γ i v q ( u ˆn x,i + v q u ) ˆn y,i ds.
If v q u ˆn, then u satisfies v (q u) dv v f dv for all v X N. Note: For any u X N we have the gradient ) u u u ( Dx D y u I 2 L x ˆD ˆD I 2 L y u. Example: x L x 2 (z + ), y L y (z + ) 2 [X, Y ndgrid(x, y) U sin πx U x D x U, U y D y U D x Î 2 ˆD, Dy 2 ˆD Î L x L y Plot U x, U y.
Returning to our weighted residual form, insertion of the bases and using quadrature yields I Ly Lx v q u + v q u dx dy (D x v) T Q B D x u + (D y v) T Q B D y u v T D T x Q B D x u + v T D T y Q B D y u. Note that if the range of indices on v and u includes all nodes, including the boundaries, then we would have the form of our Neumann operator, Ā D T x Q B D x + D T y Q B D y. To construct the A-matrix that governs the interior degrees of freedom, apply the restriction operator R to Ā: A R Ā RT. In the case of a rectangular domain, R restricts index sets in both the x and y directions and it can be written in tensor-product form: R R y R x. As always, the R x matrix is on the right, because it is acting on the fastest changing index in the u T [u u... u NN T lexicographical ordering of the unknowns.
Gradient-Based Form It is sometimes convenient to write Ā in a higher-level form. We can also write Ā [ Dx D y T [ QB QB [ Dx D y D T Q D. Here, we use the bold font to indicate that the matrices are working on or producing vector fields, i.e., inputs and/or outputs that have two components in 2D, three components in 3D, etc. Obviously, the D matrix is the discrete gradient operator introduced above.
Deformed Geometries If is deformed, ˆ x(r, s) ij x ij l i (r) l j (s) N N x ij l i (r) l j (s). j i Derivative is computed using the chain rule [w pq u u rps q + u (r x ) pq (u r ) pq + (s x ) pq (u s ) pq w [r x (Î ˆD)u + [s x ( ˆD Î)u. The full gradient (vector field) is given by, w u [ [rx [s x [r y [s y }{{} R x [ Dr D s u R x D r u. Here, we use bold font to indicate a vector field or a matrix that operates on and/or produces a vector field.
Metrics What is? rpsq pq ij pq ij dl i x ij dr l j (s q ) D r x (Î ˆD)x p x ij l i (r p ) dl j ds q D s x ( ˆD Î)x. Chain Rule: Set u x: u u + u. + + + +. At each point, (r p, s q ): [ [ [. Thus we find the inverse metrics, i j, by inverting the 2 2 matrix of computable derivatives i j, at each gridpoint (r p, s q ).
Integration in Similarly, we must transform f da ˆ f J dr ds. Here, J is the Jacobian: It is a scalar field corresponding to the amount of area in that is associated with a unit area in ˆ. An example is shown in the figure below. The blue area is given by the cross product, da dr ds J dr ds [ dr ds dr ds. ˆ That is, J pq is the determinant of the 2 2 metric tensor at each quadrature point. Mass Matrix: We note that the mass matrix in the deformed geometry is diagonal, evaluated at the GLL points: B diag(ρ p ρ q J pq J ( ˆB ˆB), if we view J as a diagonal matrix, following standard practice with GLL quadrature.
Bilinear Form in Deformed Coordinates As usual, we evaluate the bilinear form, a(v, u) v u da [Dv T (B) [Du [R x D r v T (B) [R x D r u v T ( Dr D s ) T [ [rx [s x [r y [s y T ( J ( ˆB ˆB) J ( ˆB ˆB) ) [ [rx [s x [r y [s y ( Dr D s ) u. v T D T r GDu. In d space dimensions, ( d ) i j G ij : J B, i,..., d, j,..., d, d 2 or 3. k k k Example, d 2: [ Grr G rs [ G G 2 G G sr G ss G 2 G 22. Note: G ij G ji. Each G.. is a diagonal matrix with (N + ) 2 (or, (N + ) d ) entries.