\documentclass[12pt]{article}

\renewcommand\thesubsection{\alph{subsection}}

\usepackage{float}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{fancyhdr}
\usepackage{enumerate}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{cancel}
\usepackage[justification=centering]{caption}
\usepackage{parskip}
\usepackage{array}
\usepackage{tabu}
\usepackage{subcaption}
\usepackage[style=ieee]{biblatex}
\usepackage{setspace}
\usepackage[section]{placeins}
\pagestyle{fancy}
\fancyhf{}
\rhead{CEE 262B Week 1}
\lhead{Section Notes}
\rfoot{\thepage}


\begin{document}

\section{Section Agenda}
\begin{enumerate}
\item Introductions and general agenda 
\item Partial differential equations (PDEs) review
\item Advection-Diffusion equation: math and physical interpretation
\item Lecture notes summary
\end{enumerate}

\section{PDEs Review}
This class will have lots of PDEs, so it's good to be comfortable with common notation and terms used to describe them. In general, a PDE is a differential equation that is a function of more than one variable. If it's only a function of one variable, it's called an ordinary differential equation (ODE). Here's a list of the main things to know about PDEs:

\begin{enumerate}
\item Order: The order of a PDE refers to the order of the highest derivative in each dimension (i.e. time or space). For example, the 1D diffusion equation $\frac{\partial C}{\partial t} = \frac{\partial^2 C}{\partial x^2}$ is first-order in time, and second-order in space. 
\item Linearity: A PDE is linear if the dependent variable (e.g. $C$ in the advection-diffusion equation) appears in terms with degree of at most 1. For example, the diffusion equation above is linear, but if we replaced $C$ with $C^2$, it would be nonlinear. Though there are some exceptions, nonlinear PDEs generally don't have analytical solutions, and we need to rely on numerical methods to solve them.
\item Initial and Boundary Conditions (ICs and BCs): Related to the first point, a PDE that is order $n$ in space will require $n$ boundary conditions, meaning we have to specify the behavior of the solution at $n$ spatial points in our domain, usually at the boundaries of the problem. Often in this class, we'll sort of fudge this by saying that the solution decays to 0 at $+\infty$ and $-\infty$, assuming an infinite domain. Similarly, a PDE that is order $m$ in time requires $m$ initial conditions, meaning we have to specify the behavior of the solution at $m$ points in time, usually at $t = 0$. 
\item Types of ICs and BCs: There are three primary types of ICs and BCs. The first is called a Dirichlet condition, which specifies the value of the function at a point in time or space. For example, we could say for the diffusion equation above that $C=0$ at $x=0$ and $x=1$. We can also specify Neumann conditions, which are in terms of the \textit{derivative} of the solution. For example, $\frac{\partial C}{\partial x} = 0$ at $x=1$. This is often called a ``no-flux'' boundary condition. Finally, there is the Robin condition, which is a combination of the previous two types (we won't see this very often, if at all).
\item PDE solutions: In this class we won't actually be solving PDEs. For that, you need to take CME 204. However, we will be using the solutions extensively and discussing qualitatively how we got there, so it's good to be familiar with some of the solution methods. For example, the 1D advection equation can be solved via the method of characteristics. Depending on the boundary and initial conditions, the diffusion equation can be solved via separation of variables, a similarity solution (recall Stokes' 2nd problem), or even with a Fourier transform! I encourage you to do some reading and familiarize yourself with the basic ideas behind these methods if you are interested. 
\end{enumerate}

\section{Advection-Diffusion equation}
We can write the advection-diffusion equation as:

\begin{equation*}
\frac{\partial{C}}{\partial{t}}+U\cdot\nabla C=\nabla \cdot \left(D\nabla C\right)
\end{equation*}

And now a few exercises: first, write this equation using Einstein summation notation. 

Next, show graphically how the advection term (2nd term LHS) advects stuff with the flow, and how the diffusion term (RHS) diffuses stuff from high to low concentrations. 

And finally, relate each term in the A-D equation to a term in Navier-Stokes, and explain how they are similar or different. 


\section{Intro Lecture}

This lecture is meant to give you some basic exposure to the advection-diffusion equation, and to Fickian diffusion in general. Don't worry if it seems a little confusing at the moment, things will become clearer once we start applying the concepts to physical examples. However, there are a couple things that you should pay close attention to:
\subsection{The Advection-Diffusion Equation}
\begin{gather}\label{eq:ADgen}
\frac{\partial{C}}{\partial{t}}+U\cdot\nabla C=\nabla \cdot \left(D\nabla C\right)
\end{gather}
\begin{gather*}
[C]=[\frac{kg}{m^3}]\qquad [U]=[\frac{m}{s}] \qquad  [D]=[\frac{m^2}{s}]
\end{gather*}

This equation relates in concentration over time (1st term LHS) to two things:
\begin{enumerate}
\item Advection. This is the 2nd term on the LHS, and describes how the velocity advects the concentration (meaning it transports it with the flow). If you dropped some pollutant in a river, this is the current carrying it downstream. 
\item Diffusion. This is the term on the RHS, and it describes how the concentration spreads out (independently from the advection). We'll look at this more below (and even more in depth in later lectures), but think of this like adding a drop of food dye into a cup of water. Even if you don't stir it, it will start to spread out eventually. 
\end{enumerate}

\subsection{Statistical Definition of Diffusion}
\begin{gather*}
\sigma^2 = 2Dt\\
[\sigma]=[m] \qquad [D]=[\frac{m^2}{s}]\qquad [t]=[s]
\end{gather*}
For an interpretation of this equation, imagine that you have a big group of particles. The \textit{variance} of the positions of these particles will increase linearly in time with a slope of $2D$. 

\section{Mathematics of Diffusion Equation}
In this lecture we are going to look at some idealized solutions to the diffusion equation given specific sets of initial and boundary conditions. 
\subsection{Diffusion of a point source}
The basic PDE that we're going to be solving is:
\begin{equation}\label{eq:diffusion}
\frac{\partial C}{\partial t}= D \frac{\partial^2 C}{\partial x^2}
\end{equation}

This is equivalent to equation \ref{eq:ADgen}, but with $U=0$, $D$ constant, and no lateral ($y$-direction) or vertical ($z$-direction) variability. 

This PDE is second-order in space (because of the $\partial^2/\partial x^2$ term), and first-order in time (because of the $\partial/\partial t$ term). Thus, we need two boundary conditions, and one initial condition. If we assume the concentration decays as  $x \rightarrow -\infty$ and $x \rightarrow \infty$, and an initial condition:
\begin{equation*}
C(x,t=0) = M \delta (x)
\end{equation*}
This has a solution given by:
\begin{gather}\label{eq:diffsol}
C(x,t) = \left(\frac{M}{\sqrt{4\pi D t}}\right)\textrm{exp}\left(\frac{-x^2}{4Dt}\right)
\end{gather}
\begin{gather*}
[C]=[\frac{kg}{m}] \qquad [D]=[\frac{m^2}{s}] \qquad [M]=[kg]\qquad [x]=[m]
\end{gather*}
This equation describes  \textit{1-Dimensional} diffusion. You can now calculate the concentration at a given time $t$ and a given distance $x$, based on the initial mass $M$ of a point source. 
It is useful here to examine the two terms being multiplied together. The first term is essentially the ``peak" concentration, or the amplitude of the Gaussian which decays in time like $\sim t^{-1/2}$. The second term (the exponential) accounts for the decay from the peak concentration as you move further out in space from the center. 

As we will learn in lecture, at large values of time, it doesn't actually matter whether or not this starts as a point source! Once the variance gets large enough, the mass could start out as a finite blob (not an infinitely small point), and the answer would be the same.

A note about this infinitely small point...here we defined our initial concentration as:
\begin{equation*}
C(x,0) = M\delta(x)
\end{equation*}
Here, $\delta(x)$ is the Dirac Delta function. This is defined as a function that is 0 everywhere, but with an infinitely tall, thin spike at the origin, such that if you integrate the function from $-\infty$ to $\infty$, the area under the ``curve" will be 1. This is sort of a mathematical trick to represent a unit mass confined to an infinitely small space. In this case, the units of $\delta(x)$ will be [$\frac{1}{m}$]. 

\subsection{Moments}
Moments are statistical quantities that describe different properties (such as spread, and shape) of a set of points. In our case, where the zeroth moment $M_0$ represents the total mass, we can describe the following based on $M_0$ and higher order moments. 
\begin{equation*}
\mu = \frac{M_1}{M_0}\\
\end{equation*}
This is the location of the centroid of the distribution. We also have:
\begin{equation*}
\sigma^2 = \frac{M_2}{M_0}- \mu^2
\end{equation*}
This is the variance about the centroid of the distribution. Now recalling that $\sigma^2 = 2Dt$ we can write equation \ref{eq:diffsol} as:
\begin{equation}\label{eq:Cstat}
C(x,t) = \frac{M}{\sigma (t)\sqrt{2\pi}}\textrm{exp}\left(\frac{-x^2}{2\sigma (t)^2}\right)
\end{equation}

As a reference, here are the general equations for moments from the lecture: 

\begin{figure}[H]
    \includegraphics[width=0.8\textwidth]{moments.png}
\end{figure}

\subsection{1-D diffusion with constant boundary concentration}
We are given the following set of initial and boundary conditions:
\begin{enumerate}
\item $C(x=0,t>0) = C_0$ (BC)
\item $C(x\rightarrow \infty,t) = 0$ (BC)
\item $C(x,t=0)=0$ (IC)
\end{enumerate}
As soon as the clock starts ticking, we raise the concentration at $x=0$ up to a constant $C_0$ and hold it there. Then our solution becomes:
\begin{equation}\label{eq:co}
C(x,t) = C_0\left[1-\textrm{erf}\left(\frac{x}{\sqrt{4 D t}}\right)\right]
\end{equation}


\subsection{Initial spatial concentration distribution}
We are given the following set of initial and boundary conditions:
\begin{enumerate}
\item $C(x,t=0) = M\delta(x-\xi)$ (IC)
\item $C(x \rightarrow \infty,t)=C(x \rightarrow -\infty,t)=0$ (BCs)
\end{enumerate}
Qualitatively, this is the case where a mass M (still estimated as a point source) is released at a position $x=\xi$.
Our solution looks a lot like equation \ref{eq:diffsol}, but with the spatial variable shifted by $\xi$. 
\begin{equation}\label{eq:shifteddiffsol}
C(x,t) = \left(\frac{M}{\sqrt{4\pi D t}}\right)\textrm{exp}\left(\frac{-(x-\xi)^2}{4Dt}\right)
\end{equation}

Now changing the initial condition to:
 \begin{displaymath}
   C(x,t=0) = \left\{
     \begin{array}{lr}
       0 &  x <0\\
       C_0 & x>0
     \end{array}
   \right.
\end{displaymath} 

Then our solution is:
\begin{equation}\label{eq:diffsoladdup}
C(x,t)=\int_0^\infty \frac{C_0}{\sqrt{4\pi Dt}}\textrm{exp}\left(\frac{-(x-\xi)^2}{4Dt}\right)d\xi
\end{equation}

This is like equation \ref{eq:shifteddiffsol}, but with all of the initial point sources added up via integration from 0 to $\infty$. 
 
After some math, this reduces to:
\begin{equation}\label{eq:pipediff1}
C(x,t)=\frac{C_0}{2}\left[1 + \textrm{erf}\left(\frac{x}{\sqrt{4Dt}}\right)
\right]
\end{equation}

\subsection{Solutions in higher dimensions}
As it turns out, if we have a 2D problem, we can just multiply the two 1D solutions together to obtain a 2D solution. In mathematical terms...
\begin{equation*}
C(x,y,t) = C_1(x,t)C_2(y,t)
\end{equation*}
So for the problem of an initial point source:
\begin{equation*}
\frac{\partial C}{\partial t} = D_x \frac{\partial^2 C}{\partial x^2} + D_y \frac{\partial^2 C}{\partial y^2}
\end{equation*}

with initial condition:

\begin{equation*}
C(x,y,t=0) = M \delta(x) \delta(y)
\end{equation*}

the solutions becomes:
\begin{equation}\label{eq:higherdim}
C(x,y,t)=\frac{M}{4\pi t \sqrt{D_xD_y}}\textrm{exp}\left(-\frac{x^2}{4D_xt}-\frac{y^2}{4D_yt}\right)
\end{equation}
This will work for 3D as well. In general, it works for the diffusion equation as long as the PDE remains linear and homogeneous with linear, homogeneous boundary conditions and a nice problem geometry. 

\subsection{Boundaries}
The solution to the point source problem assumes that there are no boundaries in the problem. If we have a wall somewhere in our domain, then $\frac{\partial C}{\partial x}=0$ at that location (this is called a no-flux BC). The notes will go into further details, but if you've ever taken a hydrology class that delved into groundwater problems, you may be familiar with the idea of ``image wells". We're going to use the same principle here, with a real pollutant source, and an image pollutant source that mirrors the real one on the opposite side of the boundary. We can superimpose the real and image solution, resulting in:
\begin{equation}\label{eq:boundaries}
C(x,t) = \frac{M}{\sqrt{4\pi D t}}\left[\textrm{exp}\left(\frac{-x^2}{4Dt}\right) + \textrm{exp}\left(\frac{-(x-2L)^2}{4Dt}\right)\right]
\end{equation}
Here, we're assuming the pollutant is released at $x=0$, and the boundary is at $x=L$. Thus, the image source is at $x=2L$, which the solution reflects. In a case with more than one boundary, things get much more complicated, so I'll only cover that if you need it to solve a specific problem.


\section{Advection and Diffusion Together}
In the previous set of notes, we were just looking at diffusion. Now we're going to include advection as well. We'll start with some theoretical scaling analysis, and then go into various problems that we can solve with this equation.
\subsection{Scaling, Timescales, and Peclet Number}
This may seem simple, but it's actually one of the most important concepts that we're going to cover in this class. When we're looking at the advection-diffusion equation, there are two main timescales of interest:
\begin{enumerate}
\item Advective Timescale: $T_{adv}=L/U$
\item Diffusive Timescale: $T_{diff}=L^2/D$
\end{enumerate}
The ratio of these two timescales is called the Peclet number:
\begin{equation*}
\textrm{Pe}=T_{diff}/T_{adv}=UL/D
\end{equation*}
If the Peclet number is large, that means that advection dominates. If the Peclet number is small, that means that diffusion dominates. Remember, this will only be meaningful if you choose the proper length scales, velocity, and diffusion coefficient! 

\subsection{Solutions to A-D: Coordinate Transformations}
Let's look at the solution for 1D advection-diffusion of a blob in a pipe. We have the PDE:
\begin{equation*}
\frac{\partial C}{\partial t} + U \frac{\partial C}{\partial x} = D \frac{\partial^2 C}{\partial x^2}
\end{equation*}
Where $U \: [m/s]$ is the flow velocity.

We have an initial condition such that that there is a uniform concentration for $x < 0$:
 \begin{displaymath}
   C(x,t=0) = \left\{
     \begin{array}{lr}
       0 &  x >0\\
       C_0 & x<0
     \end{array}
   \right.
\end{displaymath} 
After doing a coordinate transformation by plugging in $x' = x - Ut$ (see the notes), the PDE that we're solving is:
\begin{equation*}
\frac{\partial C}{\partial t}= D \frac{\partial^2 C}{\partial x'^2}
\end{equation*}

The solution ends up looking a lot like it did for the pure diffusion problem with a similar initial condition, because the equation we are solving is identical. We just have to account for the coordinate transformation:
\begin{equation}\label{eq:ADtrans}
C(x,t)=\frac{C_0}{2}\left[1 - \textrm{erf}\left(\frac{x-Ut}{\sqrt{4Dt}}\right)
\right]
\end{equation}

What if we have a pulse of stuff between two positions $x=-h$ and $x=+h$? This will look pretty similar again, we just add two solutions together: 
\begin{equation}\label{eq:addtogether}
C(x,t)=\frac{C_0}{2}\left[\textrm{erf}\left(\frac{x+h-Ut}{\sqrt{4Dt}}\right)- \textrm{erf}\left(\frac{x-h-Ut}{\sqrt{4Dt}}\right)\right]
\end{equation}

Now let's look at a case where we have advection and \textit{lateral} diffusion, i.e. solving the following PDE:
\begin{equation*}
U\frac{\partial C}{\partial x}=D\frac{\partial^2 C}{\partial y^2}
\end{equation*}
with boundary conditions:
 \begin{displaymath}
   C(x=0,y) = \left\{
     \begin{array}{lr}
       0 &  y \geq 0\\
       C_0 & y<0
     \end{array}
   \right.
\end{displaymath} 

and $C(x,y\rightarrow \infty) = 0$, $C(x,y \rightarrow -\infty) = C_0$

Letting $t=x/U$, this too looks very much like a diffusion problem, with solution: 
\begin{equation}
C(x,t) = \frac{C_0}{2}\left[1 - \textrm{erf}\left(\frac{y}{\sqrt{4Dx/U}}\right)\right]
\end{equation}

If we introduce some unsteadiness:
 \begin{displaymath}
     \begin{array}{lr}
       C(x=0,t)=C_0 &  0<t<\infty \\
       C(x,t=0)=0 & 0<x<\infty
     \end{array}
\end{displaymath} 

Then the solution to the PDE:
\begin{equation*}
\frac{\partial C}{\partial t} + U \frac{\partial C}{\partial x} = D \frac{\partial^2 C}{\partial x^2}
\end{equation*}

is given by:

\begin{equation}
C(x,t)=\frac{C_0}{2}\left[\textrm{erfc}\left(\frac{x-Ut}{\sqrt{4Dt}}\right) + \textrm{erfc}\left(\frac{x+Ut}{\sqrt{4Dt}}\right)\textrm{exp}\left(\frac{Ux}{D}\right)\right]
\end{equation}

Those are the primary solutions that you'll need to know. The rest of the notes go into some special cases which I won't write out here, but will discuss if you need them to solve any problems. 


\subsection{Gaussian Plume}
Now let's look at the case where a steady (i.e. $\frac{\partial}{\partial t} = 0$) plume is being discharged from a source at some rate $\dot{M}\: [kg/s]$. The plume is being advected in the x-direction, so let's ignore diffusion in that direction (i.e. assume advection dominates). However, since it is not being advected in the other directions we should account for diffusion in y and z. Thus the PDE that we're solving is:
\begin{equation*}
U\frac{\partial C}{\partial x}= D\left(\frac{\partial^2 C}{\partial y^2} + \frac{\partial^2 C}{\partial z^2}\right)
\end{equation*}

The solution here (note change of units from previous examples) will be:
\begin{gather}
C(x,y,z)=\frac{\dot{M}}{4\pi D x}\textrm{exp}\left(-U\left\lbrace\frac{y^2 + z^2}{4 D x}\right\rbrace\right)
\end{gather}
\begin{gather*}
[C] = [\frac{kg}{m^3}]
\end{gather*}

If we have a 2D Guassian plume, e.g. the case where a pollutant is instantly mixed over the vertical, the concentration is described by:
\begin{equation}
C(x,y) = \frac{\dot{M}}{U\sqrt{4 \pi D x/U}}\exp\left(-\frac{y^2U}{4 D x}\right)
\end{equation}

There's an interesting example in the notes that goes over the case where you have multiple sources. Go over that on your own if you'd like. If you need to solve a problem similar to that, I'll provide further details. 

\end{document}