final project 587

Suppose we have a diffusion equation Tt=k(T)2T\pder{T}{t} = k(T) \nabla^2 T which we're solving with MOL. We use spectral decomposition T=Tijkpi(x)pj(y)pk(z) T = \sum T_{ijk} p_i(x)p_j(y)p_k(z) Suppose we want to solve newton's method (Tti+1Tti)Δt(k(T)2T)=0 (T_{t_{i+1}} - T_{t_{i}}) - \Delta t(k(T) \nabla^2 T) = 0 Let us work within a singular element. At a particular GLL node indexed by ijk ijk , if we were to use an explicit method then Tti+1,ijk=Tti,ijk+Δt(k(Tijk)[ijkTijk(pi(xi)p(yj)p(zk)+pi(xi)pj(yj)pk(zk)+pi(xi)pj(yj)pk(zk))]) \begin{align*} T_{t_{i+1}, ijk} &= T_{t_{i}, ijk} + \Delta t \left( k\left(T_{ijk}\right)\left[\sum_{ijk} T_{ijk}(p_i''(x_i)p(y_j)p(z_k) + p_i(x_i)p_j''(y_j)p_k(z_k) + p_i(x_i)p_j(y_j)p_k''(z_k))\right] \right)\\ \end{align*} Working in implicit we get

0=(Tti+1Tti)Δt(k(Tti+1)2Tti+1)=[(Tti+1,ijkTti,ijk)]Δt(k(Tti+1,ijk)2ijkTti+1,ijkpi(x)pj(y)pk(z))=[(Tti+1,ijkTti,ijk)]Δt(k(Tti+1,ijk)(qTti+1,qjkpq(xi)+Tti+1,iqkpq(yj)+Tti+1,ijqpq(zk))) \begin{align*} 0 &= (T_{t_{i+1}} - T_{t_{i}}) - \Delta t(k(T_{t_{i+1}}) \nabla^2 T_{t_{i+1}}) \\ &= \left[(T_{t_{i+1}, ijk} - T_{t_{i}, ijk})\right] - \Delta t\left(k(T_{t_{i+1}, ijk}) \nabla^2 \sum_{ijk} T_{t_{i+1}, ijk} p_i(x)p_j(y)p_k(z) \right)\\ &= \left[(T_{t_{i+1}, ijk} - T_{t_{i}, ijk})\right] - \Delta t\left(k(T_{t_{i+1}, ijk}) \left(\sum_{q} T_{t_{i+1}, qjk} p_q''(x_i) + T_{t_{i+1}, iqk} p_q''(y_j) + T_{t_{i+1}, ijq} p_q''(z_k) \right)\right) \end{align*}

This is a system of algebraic equations Gijk(Tlmn)=0 G_{ijk}(T_{lmn}) = 0 and in order to solve this we must find the matrix (after identifying ijk ijk and lmnlmn with indices) G\mathbf{G} with Gijk,lmn=TlmnGijk \mathbf{G}_{ijk,lmn} = \partial_{T_{lmn}} G_{ijk} and for the above equations this gives Gijk,lmn=Tlmn[(Tti+1,ijkTti,ijk)]Δt(k(Tti+1,ijk)(qTti+1,qjkpq(xi)+Tti+1,iqkpq(yj)+Tti+1,ijqpq(zk)))=δ(ijk,lmn)Δt(δ(ijk,lmn)k(Tti+1,ijk)(qTti+1,qjkpq(xi)+Tti+1,iqkpq(yj)+Tti+1,ijqpq(zk))+k(Tti+1,ijk)(δ(jk,mn)pl(xi)+δ(ik,ln)pm(yj)+δ(ij,lm)pn(zk))) \begin{align*} \mathbf{G}_{ijk,lmn} &= \partial_{T_{lmn}}\left[(T_{t_{i+1}, ijk} - T_{t_{i}, ijk})\right] - \Delta t\left(k(T_{t_{i+1}, ijk}) \left(\sum_{q} T_{t_{i+1}, qjk} p_q''(x_i) + T_{t_{i+1}, iqk} p_q''(y_j) + T_{t_{i+1}, ijq} p_q''(z_k) \right)\right) \\ &= \delta(ijk, lmn) - \Delta t\bigg(\delta(ijk, lmn) k'(T_{t_{i+1}, ijk}) \left(\sum_{q} T_{t_{i+1}, qjk} p_q''(x_i) + T_{t_{i+1}, iqk} p_q''(y_j) + T_{t_{i+1}, ijq} p_q''(z_k) \right)\\ &+ k(T_{t_{i+1}, ijk}) \left(\delta(jk, mn) p_l''(x_i) + \delta(ik, ln) p_m''(y_j) + \delta(ij, lm) p_n''(z_k) \right) \bigg) \end{align*} with δ(xyz,αβγ)\delta(xyz, \alpha \beta \gamma) is a kronecker delta operating on tuples (x,y,z)(x, y, z) and (α,β,γ)(\alpha, \beta, \gamma)

and so `$$\mathbf{G} (T_{i+1} - T_i) = G

Let's do navier stokes:

tu+uuν(T)2u=1ρp+gu=0tρ+uρ=0tT+uT=k2T \begin{align*} \partial_t \mathbf{u} + \mathbf{u} \cdot \nabla \mathbf{u} - \nu(T) \nabla^2 \mathbf{u} &= -\frac{1}{\rho} \nabla p + \mathbf{g}\\ \nabla \cdot \mathbf{u} &= 0\\ \partial_t \rho + \mathbf{u} \cdot \nabla \rho &= 0 \\ \partial_t T + \mathbf{u} \cdot \nabla T &= k \nabla^2 T \end{align*}

We use the split from the glass paper: 0=ρt+Δt[u^ut]+Δt(ρt+Δt(u^u^)+ν(Tt+Δt)2u^+pguessg)0=Tt+ΔtTt+Δt(u^Tt+Δt+κ2Tt+Δt)0=ρt+Δtρt+Δt(u^ρt+Δt)pguess=pt+βΔt1ρtu^ \begin{align*} 0 &= \rho_{t+\Delta t} \left[ \hat{\mathbf{u}} - \mathbf{u}_{t}\right] + \Delta t \left( \rho_{t+\Delta t} (\hat{\mathbf{u}} \cdot \nabla \hat{\mathbf{u}}) + \nu (T_{t + \Delta t}) \nabla^2 \hat{\mathbf{u}} + \nabla p_{\textrm{guess}} - \mathbf{g} \right)\\ 0 &= T_{t + \Delta t} - T_{t} + \Delta t \left( \hat{\mathbf{u}} \cdot \nabla T_{t + \Delta t} + \kappa \nabla^2 T_{t+\Delta t} \right)\\ 0 &= \rho_{t+\Delta t} - \rho_{t} + \Delta t \left( \hat{\mathbf{u}} \cdot \nabla \rho_{t+\Delta t} \right)\\ p_{\textrm{guess}} &= p_{t} + \beta \Delta t \frac{1}{\rho_{t}} \nabla \cdot \hat{\mathbf{u}} \end{align*} Repeat until converged.

0=u^Δt2[pt+Δtpguess]+τ2pt+Δt 0 = \nabla \cdot \hat{\mathbf{u}} - \Delta t \nabla^2\left[ p_{t + \Delta t} - p_{\textrm{guess}} \right] + \tau \nabla^2 p_{t + \Delta t} Then a final non-divergent form 0=ρt+Δt[ut+Δtu^]+Δt(ρt+Δt(ut+Δtut+Δt)+(pt+Δtpguess))) 0 = \rho_{t+\Delta t} \left[\mathbf{u}_{t+\Delta t} - \hat{\mathbf{u}} \right] + \Delta t\left(\rho_{t+\Delta t} (\mathbf{u}_{t+\Delta t} \cdot \nabla \mathbf{u}_{t+\Delta t}) + \nabla \left( p_{t+\Delta t} - p_{\textrm{guess}}) \right) \right)

Note that τ(2uh+4ν(T)h2)1\tau \equiv \left(\frac{2\|\mathbf{u}\|}{h} + \frac{4\nu(T)}{h^2} \right)^{-1}

lagrangian SE decomposition

For a test of the curvilinear differential operators, we start with a position function a(x)a(x) which maps the unit cube [1,1]3[-1, 1]^3 to itself with some sort of curvature. Let's try the function xx2+x1xxx \begin{align*} \mathbf{x} \mapsto \frac{\|\mathbf{x}\|_{2 + \frac{\|\mathbf{x}\|_\infty}{1 - \|\mathbf{x} \|_\infty}}}{\|\mathbf{x}\|_\infty} \mathbf{x} \end{align*}

Note: I think I've finally determined how to do covariant/contravariant vectors? Note that the euclidean structure into which our manifold is embedded gives us that for physical vectors u,v \mathbf{u}, \mathbf{v} then u,v=upvp.\langle \mathbf{u}, \mathbf{v} \rangle = \mathbf{u}_{p} \mathbf{v}^p. Note that this site gives that g=JJ.\mathbf{g} = \mathbf{J}^\top \mathbf{J}. This seems to indicate that covariant uα=u(J1) \mathbf{u}_\alpha = \mathbf{u}^\top (\mathbf{J}^{-1})^\top and uα=J1u \mathbf{u}^\alpha = \mathbf{J}^{-1}\mathbf{u} which gives uα,vα=u(J1)gJ1v=u(J1)JJJ1v=uv \begin{align*} \langle \mathbf{u}_\alpha, \mathbf{v}^\alpha \rangle &= \mathbf{u}^\top (\mathbf{J}^{-1})^\top \mathbf{g} \mathbf{J}^{-1}\mathbf{v} \\ &= \mathbf{u}^\top (\mathbf{J}^{-1})^\top \mathbf{J}^\top \mathbf{J} \mathbf{J}^{-1}\mathbf{v} \\ &= \mathbf{u}^\top \mathbf{v} \\ \end{align*}

GMRES

We'll use the wikipedia writeup as a starting point, Suppose we have a system A~x=b~ \tilde{\mathbf{A}}\mathbf{x} = \tilde{\mathbf{b}} and in order to conform to the wikipidia conventions we use the modified equation (b1A~)x=b1b~    Ax=b \left(\|\mathbf{b}\|^{-1}\tilde{\mathbf{A}}\right)\mathbf{x} = \|\mathbf{b}\|^{-1} \tilde{\mathbf{b}} \implies \mathbf{A} \mathbf{x} = \mathbf{b}

We want to find a basis for the Krylov subspace Kn=span(r0,Ar0,A2r0,,An1r0)K_n = \textrm{span}\left(\mathbf{r}_0, \mathbf{A}\mathbf{r}_0, \mathbf{A}^2\mathbf{r}_0, \ldots, \mathbf{A}^{n-1}\mathbf{r}_0 \right) where r0=bAx0.\mathbf{r}_0 = \mathbf{b}-\mathbf{A}\mathbf{x}_0.

We use the convention that q0=r021r0 \mathbf{q}_0 = \|\mathbf{r}_0\|_2^{-1} \mathbf{r}_0 to do the Arnoldi iteration. That is

  • for k=1,n1k=1,n-1
  • qk=Aqk1\mathbf{q}_k = \mathbf{A} \mathbf{q}_{k-1}
  • for j=1,k1j = 1,k-1
    • hj,k1=qj,qkh_{j,k-1} = \langle \mathbf{q}_j, \mathbf{q}_k \rangle
    • qk=qkhj,k1qj \mathbf{q}_k = \mathbf{q}_k - h_{j, k-1}\mathbf{q}_j
  • hk,k1=qk h_{k, k-1} = \|\mathbf{q}_k\|
  • qk=qkhk,k1 \mathbf{q}_k = \frac{\mathbf{q}_k}{h_{k,k-1}}

If we let Qn\mathbf{Q}_n have as columns the qn\mathbf{q}_n computed above, the wikipedia page gives the form AQn=Qn+1Hn\mathbf{A}\mathbf{Q}_n = \mathbf{Q}_{n+1} \mathbf{H}_n where the Hi,j \mathbf{H}_{i,j} coefficients are drawn from the hj,k1 h_{j, k-1} given above. This is a good checkpoint in the code to make sure I'm on the right track.

Let β=r0\beta = \|\mathbf{r}_0\| , then we need to find the vector that minimizes bAxn \|\mathbf{b} - \mathbf{A} \mathbf{x}_n \| which can be found to be equivalent to minimizing Hnynβe1,n+1 \|\mathbf{H}_n \mathbf{y}_n - \beta \mathbf{e}_{1, n+1}\|

QR decomposition

We wish to find ΩnH~n=R~n \boldsymbol \Omega_n \tilde{\mathbf{H}}_n = \tilde{\mathbf{R}}_n where R~n=[Rn0]\tilde{\mathbf{R}}_n = \begin {bmatrix} \mathbf{R}_n \\ 0 \end{bmatrix} to account for the fact that H~n \tilde{\mathbf{H}}_n is an (n+1)×n(n+1)\times n matrix.

In the subroutine where we update Ωn\boldsymbol{\Omega}_n, we are given Ωn\boldsymbol{\Omega}_n, H~n\tilde{\mathbf{H}}_{n} , hn+1,n+2\mathbf{h}_{n+1, n+2} (which comes from the arnoldi iteration), hn+2.h_{n+2}. Define H~n+1=[H~nhn+10hn+1,n+2]\tilde{\mathbf{H}}_{n+1} = \begin{bmatrix} \tilde{\mathbf{H}}_n & \mathbf{h}_{n+1} \\ 0 & h_{n+1, n+2}\end{bmatrix}

Note that [Ωn001]H~n+1=[Rnrn+10ρ0σ]\begin{bmatrix}\boldsymbol{\Omega}_n & \boldsymbol{0} \\ \boldsymbol{0} & 1\end{bmatrix}\tilde{\mathbf{H}}_{n+1} = \begin{bmatrix} \mathbf{R}_n & \mathbf{r}_{n+1} \\ 0 & \rho \\ 0 & \sigma \end{bmatrix} where rn+1 \mathbf{r}_{n+1}, ρ\rho and σ\sigma can be computed by matrix-vector products, I think.

Assuming we have cn=ρρ2+σ2c_n = \frac{\rho}{\sqrt{\rho^2 + \sigma^2}} sn=σρ2+σ2s_n = \frac{\sigma}{\sqrt{\rho^2 + \sigma^2}} . define the Givens rotation Gn=[In000cnsn0sncn] \mathbf{G}_n = \begin{bmatrix} \mathbf{I}_n & 0 & 0 \\ 0 & c_n & s_n \\ 0 & -s_n & c_n \end{bmatrix} Ωn+1=Gn[Ωn001]\boldsymbol{\Omega}_{n+1} = \mathbf{G}_n \begin{bmatrix}\boldsymbol{\Omega}_n & \boldsymbol{0} \\ \boldsymbol{0} & 1 \end{bmatrix}

and under this definition we find Ωn+1H~n+1=[Rnrn+10ρ2+σ200]\boldsymbol{\Omega}_{n+1}\tilde{\mathbf{H}}_{n+1} = \begin{bmatrix} \mathbf{R}_n & \mathbf{r}_{n+1} \\ 0 & \sqrt{\rho^2 + \sigma^2} \\ 0 & 0 \end{bmatrix} (this doesn't need to be computed, but can be verified as a check.)

Therefore writing βΩne1=[gnξ] \beta \boldsymbol{\Omega}_n\mathbf{e}_1 = \begin{bmatrix} \mathbf{g}_n \\ \xi \end{bmatrix}

then we find that Rnyn=gn \mathbf{R}_n \mathbf{y}_n = \mathbf{g}_n

Need: Q\mathbf{Q}, H\mathbf{H}, Ω,\boldsymbol{\Omega}, and R\mathbf{R}

At a given step:

  • Do arnoldi iteration to calculate hn+1\mathbf{h}_{n+1}, hn+1,n+2h_{n+1,n+2} and qn+1.\mathbf{q}_{n+1}.
  • Update H~ \tilde{\mathbf{H}} to form H~n+1\tilde{\mathbf{H}}_{n+1}
  • Update R \mathbf{R} to form Rn+1\mathbf{R}_{n+1} via calculating rn+1, \mathbf{r}_{n+1}, ρ\rho, and σ\sigma.
  • Calculate Givens rotation Gn\mathbf{G}_n and use to compute Ωn+1 \boldsymbol{\Omega}_{n+1} (possibly can be done without storing Ωn \boldsymbol{\Omega}_n).
  • Use βΩn+1e1\beta \boldsymbol{\Omega}_{n+1} e_1 to calculate gn\mathbf{g}_n and then compute Rn+1yn+1=gn+1\mathbf{R}_{n+1}\mathbf{y}_{n+1} = \mathbf{g}_{n+1}

How to derive the matrix for an operator?

Suppose we have a subroutine f(x_i) which takes a vector x_i and populates a vector y_i satisfying Ax=y. Ax = y. Then if we just rewrite any intermediate operators that comprise AA and apply the first operator to II instead of xx, then we will be able to populate our matrix.

Parent post: