1. Partial Differential Equations#

This chapter will introduce the concept of partial differential equations, the different types and the general methodology used to solve partial differential equations using numerical methods.

1.1. Definitions#

from helper import cleaner
from sympy import Derivative as D
from sympy import Eq, Function, exp, pi, sin, symbols
x, y = symbols("x, y")
U = symbols("U", cls=Function)(x, y)
D(U, x)
\[\displaystyle \frac{\partial}{\partial x} U{\left(x,y \right)}\]

1.1.1. Partial derivatives#

_U = x**2 + x * y
U_x = D(_U, x).simplify()
Eq(D(U, x), U_x)
\[\displaystyle \frac{\partial}{\partial x} U{\left(x,y \right)} = 2 x + y\]
U_y = D(_U, y).simplify()
Eq(D(U, y), U_y)
\[\displaystyle \frac{\partial}{\partial y} U{\left(x,y \right)} = x\]

1.1.2. Partial differential equations#

a = symbols("a", cls=Function)(x, y)
b = symbols("b", cls=Function)(x, y)
c = symbols("c", cls=Function)(x, y)
d = symbols("d", cls=Function)(x, y)
e = symbols("e", cls=Function)(x, y)
f = symbols("f", cls=Function)(x, y)
Eq(a * D(U, x) + b * D(U, y) + c * D(U, x, 2) + d * D(U, y, 2) + e * D(D(U, y), x), f)
\[\displaystyle a{\left(x,y \right)} \frac{\partial}{\partial x} U{\left(x,y \right)} + b{\left(x,y \right)} \frac{\partial}{\partial y} U{\left(x,y \right)} + c{\left(x,y \right)} \frac{\partial^{2}}{\partial x^{2}} U{\left(x,y \right)} + d{\left(x,y \right)} \frac{\partial^{2}}{\partial y^{2}} U{\left(x,y \right)} + e{\left(x,y \right)} \frac{\partial^{2}}{\partial x\partial y} U{\left(x,y \right)} = f{\left(x,y \right)}\]

1.1.3. Order of a PDE#

1.1.4. Linear PDEs#

1.1.5. Domain#

1.1.6. Initial conditions#

1.1.7. Boundary conditions#

1.1.8. Solution of a PDE#

cleaner(["x", "y", "U", "U_x", "U_y", "a", "b", "c", "d", "e", "f"])
Symbolic variables already cleared

1.1.9. Example \(1\)#

Show that the diffusion equation with Homogeneous Dirichlet Boundary conditions

\[\begin{split} \begin{cases} U_{t}=k U_{xx} & \text { for }0<x<L, t>0. \\ U \left(0, x\right)= 2\sin\left(\dfrac{\pi x}{L}\right) & \text { for }0<x<L. \\ U \left(t, 0\right)= U\left(t, L\right)=0 & \text { for }t>0. \\ \end{cases} \end{split}\]

has the solution

\[ U\left(t,x\right)= 2\sin\left(\dfrac{\pi x}{L}\right) \exp\left(-\dfrac{k\pi^2 t}{L^2}\right). \]
t, x, k, L = symbols("t, x, k, L")
U = symbols("U", cls=Function)(t, x)
heat_equation = Eq(D(U, t), k * D(U, x, 2))
heat_equation
\[\displaystyle \frac{\partial}{\partial t} U{\left(t,x \right)} = k \frac{\partial^{2}}{\partial x^{2}} U{\left(t,x \right)}\]

1.1.9.1. Analytical solution#

heat_solution = 2 * sin(pi * x / L) * exp(-k * pi**2 * t / L**2)
Eq(U, heat_solution)
\[\displaystyle U{\left(t,x \right)} = 2 e^{- \frac{\pi^{2} k t}{L^{2}}} \sin{\left(\frac{\pi x}{L} \right)}\]

1.1.9.2. Initial condition#

U_0 = heat_solution.subs({t: 0})
Eq(U.subs({t: 0}), U_0)
\[\displaystyle U{\left(0,x \right)} = 2 \sin{\left(\frac{\pi x}{L} \right)}\]

1.1.9.3. Dirichlet Boundary condition#

U_left, U_right = heat_solution.subs({x: 0}), heat_solution.subs({x: L})
Eq(U.subs({x: 0}), U_left)
\[\displaystyle U{\left(t,0 \right)} = 0\]
Eq(U.subs({x: L}), U_right)
\[\displaystyle U{\left(t,L \right)} = 0\]

1.1.9.4. Checking solution#

U_t = heat_equation.lhs.subs({U: heat_solution}).simplify()
Eq(D(U, t), U_t)
\[\displaystyle \frac{\partial}{\partial t} U{\left(t,x \right)} = - \frac{2 \pi^{2} k e^{- \frac{\pi^{2} k t}{L^{2}}} \sin{\left(\frac{\pi x}{L} \right)}}{L^{2}}\]
U_xx = heat_equation.rhs.subs({U: heat_solution}).simplify() / k
Eq(D(U, x, 2), U_xx)
\[\displaystyle \frac{\partial^{2}}{\partial x^{2}} U{\left(t,x \right)} = - \frac{2 \pi^{2} e^{- \frac{\pi^{2} k t}{L^{2}}} \sin{\left(\frac{\pi x}{L} \right)}}{L^{2}}\]
U_t.equals(k * U_xx)
True
cleaner(["t", "x", "k", "L", "U", "U_t", "U_xx"])
Symbolic variables already cleared

1.2. Classifying PDEs#

def classification(a: float, b: float, c: float):
    discriminant = b**2 - 4 * a * c
    if discriminant < 0:
        print("Elliptic PDE")
    elif discriminant == 0:
        print("Parabolic PDE")
    else:
        print("Hyperbolic PDE")

1.2.1. Example \(2\)#

For each of the PDEs given below, classify them as either an elliptic, parabolic or hyperbolic PDE.

x, y = symbols("x, y")
U = symbols("U", cls=Function)(x, y)
laplace_equation = Eq(D(U, x, 2) + D(U, y, 2), 0)
laplace_equation
\[\displaystyle \frac{\partial^{2}}{\partial x^{2}} U{\left(x,y \right)} + \frac{\partial^{2}}{\partial y^{2}} U{\left(x,y \right)} = 0\]
classification(a=1, b=0, c=1)
Elliptic PDE
t, k = symbols("t, k")
U = symbols("U", cls=Function)(t, x)
heat_equation = Eq(D(U, t), k * D(U, x, 2))
heat_equation
\[\displaystyle \frac{\partial}{\partial t} U{\left(t,x \right)} = k \frac{\partial^{2}}{\partial x^{2}} U{\left(t,x \right)}\]
classification(a=-k, b=0, c=0)
Parabolic PDE
c = symbols("c", positive=True)
U = symbols("U", cls=Function)(t, x)
wave_equation = Eq(D(U, t, 2), c**2 * D(U, x, 2))
wave_equation
\[\displaystyle \frac{\partial^{2}}{\partial t^{2}} U{\left(t,x \right)} = c^{2} \frac{\partial^{2}}{\partial x^{2}} U{\left(t,x \right)}\]
classification(a=-(c**2), b=0, c=1)
Hyperbolic PDE
cleaner(["t", "x", "y", "k", "c", "U"])
Symbolic variables already cleared

1.2.2. Elliptic PDEs#

x, y = symbols("x, y")
f = symbols("f", cls=Function)(x, y)
U = symbols("U", cls=Function)(x, y)
Eq(D(U, x, 2) + D(U, y, 2), f)
\[\displaystyle \frac{\partial^{2}}{\partial x^{2}} U{\left(x,y \right)} + \frac{\partial^{2}}{\partial y^{2}} U{\left(x,y \right)} = f{\left(x,y \right)}\]

1.2.3. Parabolic PDEs#

t, alpha = symbols("t, alpha")
Eq(D(U, t), alpha * D(U, x, 2))
\[\displaystyle \frac{\partial}{\partial t} U{\left(x,y \right)} = \alpha \frac{\partial^{2}}{\partial x^{2}} U{\left(x,y \right)}\]

1.2.4. Hyperbolic PDEs#

c = symbols("c")
Eq(D(U, t, 2), c**2 * D(U, x, 2))
\[\displaystyle \frac{\partial^{2}}{\partial t^{2}} U{\left(x,y \right)} = c^{2} \frac{\partial^{2}}{\partial x^{2}} U{\left(x,y \right)}\]
v = symbols("v", cls=Function)(x, y)
U = symbols("U", cls=Function)(t, x)
Eq(D(U, t) + v * D(U, x), 0)
\[\displaystyle v{\left(x,y \right)} \frac{\partial}{\partial x} U{\left(t,x \right)} + \frac{\partial}{\partial t} U{\left(t,x \right)} = 0\]

1.3. Domain of dependence#

1.4. Using PDEs to model real world phenomena#

1.4.1. Eulerian and Lagrangian methods#

1.4.2. Exact solution versus numerical approximation#