Consider a a flow with a velocity field $\mathbf{u}$. The rate of change of $\phi$ can be evaluated casting the **transport equation**:
$$
\frac{\partial(\rho\phi)}{\partial t}
+\nabla \cdot (\rho\phi\mathbf{u})
= \nabla \cdot (D \nabla \phi) +F_{\phi}
$$
In the Finite Difference Method, the region of interest would be divided in points and the derivatives would be approximated with numerical derivatives.
In the case of Finite Volume, the region of interest is divided in volumes and the **equation is integrated over those control volumes**:
**This is the key difference between FDM and FVM**.
Now, Gauss's divergence theorem is used to rewrite the advection and diffusion terms. Gauss's theorem replaces the integral over the volume for integrals over the surface(s) as:
The physical interpretation of $\mathbf{n}\cdot\mathbf{r}$ is a projection of the vector $\mathbf{r}$ over the normal component of the surface. In other words, it replaces the changes over the volume of $\mathbf{\nabla}\cdot\mathbf{r}$ for a flux over the surface! Applying it over the integral form of the transport equation:
The first term represents the rate of change of the property $\phi$ over in the volume. The component inside the second integral represents the flux of $\phi$ (due to advection) along the normal vector of the surface, as it point outwards it represents the net rate of decrease. The component inside the third integral is the diffusive flux, as diffusion is directed towards negative gradients, the integral represents the net rate of increase due to diffusion. The fourth integral is the net rate of creation/removal of $\phi$ depending on fount/sink behavior inside the volume, e.g. a volume can coincide with a pollutant (enterococcus) source location or the pollutant can decrease due to sun exposure.
Finally, the fluxes can be approximated with a finite difference, e.g. central differences, and the integral can be approximated with any of the numerical integration techniques that were treated last quarter, e.g. midpoint rule, if evaluated at the mid point of the surface.
```{figure} ./figs/fvm1.svg
---
width: 60%
name: fvm1
---
Generalized schematic of a 3D "volume", $V$, illustrated by a 2D ellipse, with bounding surface $\S$ and a single vector of the field $\mathbf{u}$. Flux out of the volume is through an infinitesimal part of the surface, $d\mathbf{\S}$, which has a surface normal vector $\mathbf{\hat{n}}$.
```
```{figure} ./figs/fvm2.svg
---
width:40%
name:fvm2
---
Illustration of a finite volume. The quantity of interest ($\mathbf{u}$ in this case) and conservation laws are identical to the generic case illustrated in {numref}`fvm1`, and computed at the center of the finite volume.
```
For an domain of interest, many finite volumes can be defined. For a Cartesian coordinate system, $\mathbf{x}$, such that the center point of each volume $\mathbf{x}_{i,j,k}$ is the point where $\mathbf{u}_{i,j,k}$ is computed. This is illustrated for a 2D example illustrated in {numref}`fvm3`, for volume $i$, $j$. In this case the $x$ and $y$ axes are sub-divided into increments $\Delta x$ and $\Delta y$. Although only cubic volumes are considered here (square in 2D), in practice the finite volumes can employ a variety of different shapes to make the geometric discretization into finite volumes and numerical computations more efficient.
```{figure} ./figs/fvm3.svg
---
width:60%
name:fvm3
---
Discretization of a generic domain of interest into finite volumes $V$ in the 2D Cartesian coordinate system. Volume $i$, $j$ is shown alongside neighboring volumes that will be used in flux calculations. The quantity of interest ($\mathbf{u}$ in this case) are computed at the center of each finite volume.
```
As seen in other chapters of this textbook, to solve PDE's numerically, values of the function of interest at several discrete points in $\mathbf{x}$ are required to formulate and computing numerical differentiation and integration schemes (in space _and_ time). However, as illustrated in {numref}`fvm2` and {numref}`fvm3`, the finite volume discretization uses only a single central point to represent the quantity of interest. Therefore, the finite volume method requires use of neighboring volumes in the numerical schemes. As the conservation laws require $\mathbf{u}$ to be balanced at the boundaries of every finite volume, this forms an ideal point at which to make computations. The boundary of a standard finite volume is thus divided into four faces, North, South, East, West (abbreviated N, S, E, W), as illustrated in {numref}`fvm4`, and $\mathbf{u}$ is computed at each face, typically as an average using the neighboring volumes.
```{figure} ./figs/fvm4.svg
---
width:60%
name:fvm4
---
Left: specification of North, South, East and West faces (N, S, E, W) for a standard finite volume. Right: center points of neighboring finite volumes that can be used to compute $\mathbf{u}$ at each face, as well as $\mathbf{u}$.
```
Subsequent chapters will illustrate the specific discretization for certain cases of the transport equation.
## Comparison with Finite Differences in a 2D regular mesh
Both methods can be used to solve the same conservation laws over a discretized domain of interest $V$; in fact, the points at which the quantity of interest is calculated are exactly the same. However, whereas the FVM uses each point to represent the _center_ of a finite volume, FDM uses the points as corners of square units in a grid. Unlike FDM, FVM uses surface fluxes, computed at the boundary of each finite volume; these points are located between the evaluation points of the FDM grid. In addition, FVM integrates over the volumes prior to applying numerical integration schemes, whereas FDM uses numerical differentiation to discretize the PDE's. This gives a very important advantage to the FVM: quantities are conserved! This is not ensured while using FDM.
```{figure} ./figs/fvm-fdm.svg
---
width:60%
name:fvm_fdm
---
A finite difference unit compared to a finite volume using the same grid of points $(x_i,y_j)$ for computation of the quantity of interest $\mathbf{u}_{i,j}$ in both methods. Boundary surface fluxes of FVM volumes are computed at points located between evaluation points of the FDM.
```
%% Cell type:markdown id: tags:
:::{card} Exercises
This is to practice with the concept conservation laws and Gauss' divergence theorem. The divergence theorem can be used to connect a PDE(which applies at every point in space) to a global integral form of the conservation laws over a region of space.
Let take for example Gauss's law for Electric Fields, this law describes the relationship between electric flux through a surface and the charge within that surface:
$$
\epsilon_0 \nabla \cdot E = \rho
$$
From this deferential equations integrate over the control volumes and derive the global conservation law
```{admonition} Solution
:class: tip, dropdown
$$
\epsilon_0 \nabla \cdot \mathbf{E} = \rho
$$
By integrating both sides over a volume $V$:
$$
\int_{V} \epsilon_0 \nabla \cdot \mathbf{E} dV = \int_{V} \rho dV
$$
$$
\epsilon_0 \int_{V} \nabla \cdot \mathbf{E} dV = \int_{V} \rho dV
$$
apply the Gauss' divergence theorem
$$
\int_{V}\mathbf{\nabla}\cdot\mathbf{r}\,dV
=\int_{S}\mathbf{n} \cdot \mathbf{r},dS
$$
After applying the Divergence Theorem, we arrive at: