Just to give some background: I am currently working on a fluid simulation and am trying to clear any divergence from my discretized velocity field (i.e. it's split up into grids).
To eliminate such divergences I'm using the Helmholtz-Hodge theorem, meaning I do this: $$ w = u_c + \nabla p $$ where
- $u_c$ represents the divergence-free, curl-only velocity field,
- $w$ represents the total velocity field and
- $\nabla p $ represents the curl-free, divergence-only velocity field. In this case, the scalar function $p$ is that of pressure.
Dot-multiplying both sides by $\nabla$ and refactoring the terms, cancelling out $\nabla\cdot u_c$ then yields: $$ \nabla^2 p = \nabla\cdot w. $$ Now making use of the discrete Poisson equation (i.e. converting $\nabla^2 p$ into its finite discretized form) we can say, given $dx$ = $dy$: $$ \nabla^2 p = \frac{p(x-1,y)+p(x+1,y)+p(x,y-1)+p(x,y+1)-4p(x,y)}{dx^2}. $$ From here I'm solving for $p(x,y)$, like so: $$ p(x,y) = \frac{p(x-1,y)+p(x+1,y)+p(x,y-1)+p(x,y+1)-dx^2\cdot\nabla^2 p}{4}. $$ Now the question was what $dx^2 \cdot \nabla^2 p$ would equal, so I looked up some online resources and found this equation:
$\nabla\cdot v(x,y) = [p(x-1,y)+p(x+1,y)+p(x,y-1)+p(x,y+1)]-4p(x,y)$
where
- $v(x,y)$ is the velocity associated with one grid cell and
- $p(x,y)$ is the pressure at $(x,y)$. (Source: https://www.youtube.com/watch?v=qsYE1wMEMPA&t=691s at 13:50)
This is implying that $dx^2 \cdot \nabla^2 p$ would be equal to $\nabla\cdot v(x,y)$, i.e. the divergence of cell $(x,y)$'s velocity vector.
However, I fail to see the correlation. Or maybe there is no correlation and I went wrong in some other step. I am still very new to vector field calculus so perhaps this is an obvious question but I've looked and I found no answers online with the keywords I used in my research. I'm very sorry if this is a bad question but this is my last resort for answers.
I figured it out :)
What helped everything click was refactoring this: $$ p(x−1,y)+p(x+1,y)+p(x,y−1)+p(x,y+1)−4p(x,y) $$ into this: $$ p(x-1,y) - p(x,y) + p(x+1,y) - p(x,y) + p(x,y+1) - p(x,y) + p(x,y-1) - p(x,y) $$ All this equation is, intuitively speaking, outflow - inflow. You calculate the difference between $p(x+1,y)$ and $p(x,y)$, thus yielding the outflow in x-direction and you do the same for $p(x-1,y)$ and $p(x,y)$ thus yielding the inflow in the x-direction. You do the same for the y-direction. You then subtract them from one another, i.e.: $$\DeclareMathOperator{\Div}{div} \begin{align} & \textit{outflow}_x - \textit{inflow}_x\\ & \iff p(x+1,y) - p(x,y) - (p(x,y) - p(x-1,y))\\ & \iff p(x+1,y) - p(x,y) + p(x-1,y) - p(x,y) = \Div_x(\nabla p) \end{align} $$ (in final difference form).
This is exactly what divergence is. Now all you do to obtain you final formula is adding $\Div_x(\nabla p)$ and $$ \Div_y(\nabla p) = p(x,y+1) - p(x,y) + p(x,y-1)-p(x,y) $$ and you get $\Div(\nabla p)$ (again obviously NOT in the continuous form but in its finite difference form. Thus the equality I was confused about holds ONLY when looking at things from a discretized point of view.