\begin{align}
\alpha & = \frac{1}{\sqrt{1+2M/r}} & \beta^i & = \frac{2Mx^i}{r+2M} & \gamma_{ij} & = \delta_{ij} + \frac{2Mx_{i}x_{j}}{r^3} & H & = M/r
\end{align}

\begin{align}
K & = 2\alpha^3(1+H)x_{i}\partial_{i}H + 2\alpha H \partial_{i}(x^{i}/r) & \Gamma^k_{ij} & = 0.5 * ( \gamma^{kl}(\partial_{i}\gamma_{lj})+\partial_{j}\gamma_{li}-\partial_{l}\gamma_{ij} )
\end{align}

\begin{align}
\partial_{t}\varphi & = \alpha\Pi + \beta^i\partial_{i}\varphi \\
\partial_{t}\Pi & = \alpha\partial_{i}\partial^{i}\varphi + \alpha (K\Pi - \gamma^{ij}\Gamma^k_{ij}\partial_{k}\varphi+\frac{dV}{d\varphi}) + \partial_{i}\varphi \partial^{i}\alpha +\beta^i\partial_{i}\Pi
\end{align}

## That is 

\begin{align}
\partial_{t}\varphi & = \alpha\Pi + \beta^x\partial_{x}\varphi + \beta^y\partial_{y}\varphi + \beta^z\partial_{z}\varphi\\
& = \alpha\Pi + \frac{2Mx}{r+2M}\partial_{x}\varphi + \frac{2My}{r+2M}\partial_{y}\varphi + \frac{2Mz}{r+2M}\partial_{z}\varphi
\end{align}

x component of $\partial_{t}\Pi$ :
\begin{align}
\partial_{t}\Pi & = \alpha\partial_{i}\partial^{i}\varphi 
+ \alpha (K\Pi - \gamma^{ij}\Gamma^k_{ij}\partial_{k}\varphi+\frac{dV}{d\varphi}) 
+ \partial_{i}\varphi \partial^{i}\alpha +\beta^i\partial_{i}\Pi \\
& = {\alpha\partial_{x}\partial^{x}\varphi 
+ \alpha [(2\alpha^3(1+H)x\partial_{x}H + 2\alpha H \partial_{x}(x/r))\Pi - \gamma^{xj}\Gamma^k_{xj}\partial_{k}\varphi+\frac{dV}{d\varphi}] 
+ \partial_{x}\varphi \partial^{x}\alpha +\beta^x\partial_{x}\Pi} 
\end{align}

where $\gamma^{xj}\Gamma^k_{xj}$ is :
\begin{align}
\gamma^{xj}\Gamma^k_{xj} & = \gamma^{xx} \Gamma^k_{xx} + \gamma^{xy} \Gamma^k_{xy} + \gamma^{xz} \Gamma^k_{xz}\\
& = \gamma^{xx} \Gamma^x_{xx} + \gamma^{xx} \Gamma^y_{xx} + \gamma^{xx} \Gamma^z_{xx} + \gamma^{xy} \Gamma^x_{xy} + \gamma^{xy} \Gamma^y_{xy} + \gamma^{xy} \Gamma^z_{xy} + \gamma^{xz} \Gamma^x_{xz} + \gamma^{xz} \Gamma^y_{xz} + \gamma^{xz} \Gamma^z_{xz}
\end{align}

Since $$\Gamma^k_{ij}  = 0.5 * ( \gamma^{kl}(\partial_{i}\gamma_{lj})+\partial_{j}\gamma_{li}-\partial_{l}\gamma_{ij} )$$
Then that is:
\begin{align}
\Gamma^x_{xx} = 0.5 * ( \gamma^{xl}(\partial_{x}\gamma_{lx})+\partial_{x}\gamma_{lx}-\partial_{l}\gamma_{xx} )
\end{align}

## Scalar Wave

The Scalar Wave Equations are:
\begin{align}
\partial_t u &= v \\
\partial_t v &= c^2 \nabla^2 u.
\end{align}

The second order derivative term is:
\begin{equation}
\left[\partial_x^2 u(t,x)\right]_j = \frac{1}{(\Delta x)^2}
\left(
-\frac{1}{12} \left(u_{j+2} + u_{j-2}\right) 
+ \frac{4}{3}  \left(u_{j+1} + u_{j-1}\right)
- \frac{5}{2} u_j \right)
+ \mathcal{O}\left((\Delta x)^4\right).
\end{equation}


## In our case

$$(\partial_x u)_0 \approx \frac{1}{(\Delta x)} \times \left(\frac{1}{12}( u_{-2} - u_{2}) + \frac{2}{3}( -u_{-1} + u_{1})\right)$$
\begin{equation}
\left[\partial_x\partial_y u(t,x,y)\right]_j = \frac{1}{(\Delta x)(\Delta y)}
\left(
-\frac{1}{12} \left(u_{j+2} + u_{j-2}\right) 
+ \frac{4}{3}  \left(u_{j+1} + u_{j-1}\right)
- \frac{5}{2} u_j \right)
+ \mathcal{O}\left((\Delta x\Delta y)^2\right).
\end{equation} (wrong!!)

The inverse of $\gamma$
\begin{align}
\gamma_{ij} & = \delta_{ij} + \frac{2Mx_{i}x_{j}}{r^3}
\end{align}

$$ \gamma = \begin{pmatrix}
1 + \frac{2Mxx}{r^3} &  \frac{2Mxy}{r^3} &  \frac{2Mxz}{r^3} \\
\frac{2Myx}{r^3} & 1 + \frac{2Myy}{r^3} & \frac{2Myz}{r^3} \\
\frac{2Mzx}{r^3} & \frac{2Mzy}{r^3} & 1 + \frac{2Mzz}{r^3}
\end{pmatrix} $$

So the inverse is:
$$ \gamma^{-1} = \frac{r}{r + 2M} \begin{pmatrix}
1 + \frac{2Myy}{r^3} + \frac{2Mzz}{r^3} &  -\frac{2Myx}{r^3} &  -\frac{2Mzx}{r^3} \\
-\frac{2Mxy}{r^3} & 1 + \frac{2Mxx}{r^3} + \frac{2Mzz}{r^3} & \frac{2Mzy}{r^3} \\
-\frac{2Mxz}{r^3} & -\frac{2Myz}{r^3} & 1 + \frac{2Mxx}{r^3} + \frac{2Myy}{r^3}
\end{pmatrix} $$

$$ \gamma^{-1}\gamma = \frac{r}{r + 2M} \begin{pmatrix}
1 + \frac{2M}{r} & 0 & 0\\
0 & 1 + \frac{2M}{r} & 0\\
0 & 0 & 1 + \frac{2M}{r}
\end{pmatrix} = 1$$ 

$$K  = 2\alpha^3(1+H)x_{i}\partial_{i}H + 2\alpha H \partial_{i}(x^{i}/r) $$

\begin{align}
\partial_{x} H & = -\frac{Mx}{(x^2+y^2+z^2)^{3/2}} = -\frac{Mx}{r^3} & \partial_{y} H & = -\frac{My}{(x^2+y^2+z^2)^{3/2}} = -\frac{My}{r^3} & \partial_{z} H & = -\frac{Mz}{(x^2+y^2+z^2)^{3/2}} = -\frac{Mz}{r^3}
\end{align}

\begin{align}
\partial_{x}(\frac{x}{r}) & = \dfrac{z^2+y^2}{\left(x^2+z^2+y^2\right)^\frac{3}{2}} = \frac{z^2+y^2}{r^3} & \partial_{y}(\frac{y}{r}) & = \dfrac{z^2+x^2}{\left(x^2+z^2+y^2\right)^\frac{3}{2}} = \frac{z^2+x^2}{r^3} & \partial_{z}(\frac{z}{r}) & = \dfrac{x^2+y^2}{\left(x^2+z^2+y^2\right)^\frac{3}{2}} = \frac{x^2+y^2}{r^3}
\end{align}

$$ K = -2\alpha^3(1+H)H + \frac{4\alpha H}{r}$$

## First component
$$\alpha\partial_{i}\partial^{i}\varphi = \alpha\gamma^{-1}\partial_{i}\partial_{j}\varphi $$

## Second component
$$\alpha (K\Pi - \gamma^{ij}\Gamma^k_{ij}\partial_{k}\varphi)$$

Where
$$ \partial_{x}\gamma = \begin{pmatrix}
\dfrac{4mx}{r^3}-\dfrac{6mx^3}{r^5} & \dfrac{2my}{r^3}-\dfrac{6myx^2}{r^5} & \dfrac{2mz}{r^3}-\dfrac{6mzx^2}{r^5}\\
\dfrac{2my}{r^3}-\dfrac{6myx^2}{r^5} & -\dfrac{6my^2x}{r^5} & -\dfrac{6myzx}{r^5} \\
\dfrac{2mz}{r^3}-\dfrac{6mzx^2}{r^5} & -\dfrac{6myzx}{r^5} & -\dfrac{6mz^2x}{r^5}
\end{pmatrix} $$

Simplify
$$ \partial_{x}\gamma = \frac{2M}{r^5}\begin{pmatrix}
2xr^2-3x^3 & yr^2-3yx^2 & zr^2-3zx^2\\
yr^2-3yx^2 & -3y^2x & -3yzx \\
zr^2-3zx^2 & -3yzx & -3z^2x
\end{pmatrix} $$

And 
$$ \partial_{y}\gamma = \frac{2M}{r^5}\begin{pmatrix}
-3x^2y & xr^2-3xy^2 & -3xyz\\
xr^2-3xy^2 & 2yr^2 - 3y^3 & zr^2 - 3zy^2 \\
-3xyz & zr^2 - 3zy^2 & -3z^2y
\end{pmatrix} $$

$$ \partial_{z}\gamma = \frac{2M}{r^5}\begin{pmatrix}
-3x^2z & -3xyz & xr^2-3xz^2\\
-3xyz & -3y^2z & yr^2-3yz^2 \\
xr^2-3xz^2 & yr^2-3yz^2 & 2zr^2-3z^3
\end{pmatrix} $$

## Third component
$$ \partial_{i}\varphi \partial^{i}\alpha = \gamma^{-1} \partial_{i}\varphi \partial_{j}\alpha $$

$$\partial_{x}\alpha = \dfrac{mx}{\left(x^2+z^2+y^2\right)^\frac{3}{4}\left(\sqrt{x^2+z^2+y^2}+2m\right)^\frac{3}{2}} = \frac{mx}{r^\frac{3}{2} (r+2m)^\frac{3}{2}} $$


```python
%matplotlib inline
import matplotlib.pyplot as plt
import mpmath as mp
import csv

def file_reader(filename):
    with open(filename) as file:
        reader = csv.reader(file, delimiter=" ")
        data  = list(zip(*reader))
        data0 = []
        data1 = []
        data2 = []
        data3 = []
        for i in range(len(data[0])):           
            data0.append(float(data[0][i]))
            data1.append(float(data[1][i]))
            data2.append(float(data[2][i]))
            data3.append(float(data[3][i]))
        return data0,data1,data2,data3
```


```python
from mpl_toolkits import mplot3d
from matplotlib.pyplot import savefig
from matplotlib import cm
import numpy as np

itermax = 10
i = 0
while i <= itermax:
    filename = 'ScalarHair_resolution_100x100x100__iter_'+str(i)
    x_iter_0,y_iter_0,num_0,exact_0 = file_reader(filename+".txt")
    fig = plt.figure()
    ax = plt.axes(projection='3d')
    ax.set_xlabel('x_coord')
    ax.set_ylabel('y_coord')
    ax.set_zlabel('Numerical Soln.(log)')
    ax.set_title('ScalarHair_resolution_100x100x100')
    ax.scatter3D(x_iter_0,y_iter_0,np.log10(num_0), c=num_0, cmap='viridis',s=1)
#    ax.plot_trisurf(x_iter_0,y_iter_0,np.log10(num_0),cmap=cm.jet, linewidth=0)
    savefig(filename+".png",dpi=450)
    plt.close(fig)
    i+=1
```

    D:\Anaconda3\lib\site-packages\ipykernel_launcher.py:17: RuntimeWarning: invalid value encountered in log10



```python
import matplotlib.image as mgimg
from matplotlib import animation

fig = plt.figure(frameon=False)
ax = fig.add_axes([0, 0, 1, 1])
ax.axis('off')

myimages = []

i = 0
while i <= itermax:
    filename = 'ScalarHair_resolution_100x100x100__iter_'+str(i)
    img = mgimg.imread(filename+".png")
    imgplot = plt.imshow(img)
    myimages.append([imgplot])
    i += 1

ani = animation.ArtistAnimation(fig, myimages, interval=100,  repeat_delay=1000)
plt.close()
ani.save("ScalarHair_resolution_100x100x100_Gauss.mp4", fps=5,dpi=450)
```


```python
from IPython.display import HTML
#the filename needed to be changed manually

HTML("""
    
""")
```











```python
from IPython.display import HTML
#the filename needed to be changed manually

HTML("""
    
""")
```










$\partial_t B^i = \beta^j \bar{D}_j B^i
                       + \frac{3}{4} ( \partial_t \bar{\Lambda}^{i} - \beta^j \bar{D}_j \bar{\Lambda}^{i} ) 
                       - \eta B^{i}
                         = \beta^j B^i_{,j} + \beta^j \bar{\Gamma}^i_{mj} B^m
                       + \frac{3}{4}[ \partial_t \bar{\Lambda}^{i} 
                                    - \beta^j (\bar{\Lambda}^i_{,j} + \bar{\Gamma}^i_{mj} \bar{\Lambda}^m)] 
                       - \eta B^{i}$


```python

```

001e1c8e9ae4c8b8894991af49432d5911aa4065
ipynb
Jupyter Notebook
Scalar Field Equations.ipynb
Yancheng-Li-PHYS/nrpytutorial
73b706c7f7e80ba22dd563735c0a7452c82c5245
BSD-2-Clause
2019-12-23T05:31:25.000Z
2019-12-23T05:31:25.000Z
Scalar Field Equations.ipynb
Yancheng-Li-PHYS/nrpytutorial
73b706c7f7e80ba22dd563735c0a7452c82c5245
BSD-2-Clause
Scalar Field Equations.ipynb
Yancheng-Li-PHYS/nrpytutorial
73b706c7f7e80ba22dd563735c0a7452c82c5245
BSD-2-Clause
Qwen/Qwen-72B
1. YES
2. YES