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)
xU(x,y)

1.1.1. Partial derivatives#

_U = x**2 + x * y
U_x = D(_U, x).simplify()
Eq(D(U, x), U_x)
xU(x,y)=2x+y
U_y = D(_U, y).simplify()
Eq(D(U, y), U_y)
yU(x,y)=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)
a(x,y)xU(x,y)+b(x,y)yU(x,y)+c(x,y)2x2U(x,y)+d(x,y)2y2U(x,y)+e(x,y)2xyU(x,y)=f(x,y)

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

{Ut=kUxx for 0<x<L,t>0.U(0,x)=2sin(πxL) for 0<x<L.U(t,0)=U(t,L)=0 for t>0.

has the solution

U(t,x)=2sin(πxL)exp(kπ2tL2).
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
tU(t,x)=k2x2U(t,x)

1.1.9.1. Analytical solution#

heat_solution = 2 * sin(pi * x / L) * exp(-k * pi**2 * t / L**2)
Eq(U, heat_solution)
U(t,x)=2eπ2ktL2sin(πxL)

1.1.9.2. Initial condition#

U_0 = heat_solution.subs({t: 0})
Eq(U.subs({t: 0}), U_0)
U(0,x)=2sin(πxL)

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)
U(t,0)=0
Eq(U.subs({x: L}), U_right)
U(t,L)=0

1.1.9.4. Checking solution#

U_t = heat_equation.lhs.subs({U: heat_solution}).simplify()
Eq(D(U, t), U_t)
tU(t,x)=2π2keπ2ktL2sin(πxL)L2
U_xx = heat_equation.rhs.subs({U: heat_solution}).simplify() / k
Eq(D(U, x, 2), U_xx)
2x2U(t,x)=2π2eπ2ktL2sin(πxL)L2
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
2x2U(x,y)+2y2U(x,y)=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
tU(t,x)=k2x2U(t,x)
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
2t2U(t,x)=c22x2U(t,x)
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)
2x2U(x,y)+2y2U(x,y)=f(x,y)

1.2.3. Parabolic PDEs#

t, alpha = symbols("t, alpha")
Eq(D(U, t), alpha * D(U, x, 2))
tU(x,y)=α2x2U(x,y)

1.2.4. Hyperbolic PDEs#

c = symbols("c")
Eq(D(U, t, 2), c**2 * D(U, x, 2))
2t2U(x,y)=c22x2U(x,y)
v = symbols("v", cls=Function)(x, y)
U = symbols("U", cls=Function)(t, x)
Eq(D(U, t) + v * D(U, x), 0)
v(x,y)xU(t,x)+tU(t,x)=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#