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)
1.1.1. Partial derivatives#
_U = x**2 + x * y
U_x = D(_U, x).simplify()
Eq(D(U, x), U_x)
U_y = D(_U, y).simplify()
Eq(D(U, y), U_y)
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)
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 #
Show that the diffusion equation with Homogeneous Dirichlet Boundary conditions
has the solution
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
1.1.9.1. Analytical solution#
heat_solution = 2 * sin(pi * x / L) * exp(-k * pi**2 * t / L**2)
Eq(U, heat_solution)
1.1.9.2. Initial condition#
U_0 = heat_solution.subs({t: 0})
Eq(U.subs({t: 0}), U_0)
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)
Eq(U.subs({x: L}), U_right)
1.1.9.4. Checking solution#
U_t = heat_equation.lhs.subs({U: heat_solution}).simplify()
Eq(D(U, t), U_t)
U_xx = heat_equation.rhs.subs({U: heat_solution}).simplify() / k
Eq(D(U, x, 2), U_xx)
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 #
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
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
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
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)
1.2.3. Parabolic PDEs#
t, alpha = symbols("t, alpha")
Eq(D(U, t), alpha * D(U, x, 2))
1.2.4. Hyperbolic PDEs#
c = symbols("c")
Eq(D(U, t, 2), c**2 * D(U, x, 2))
v = symbols("v", cls=Function)(x, y)
U = symbols("U", cls=Function)(t, x)
Eq(D(U, t) + v * D(U, x), 0)