Semi-discretization (Method of Lines)
Most problems have complex domains.
Boundary conditions crucial.
Little “structure” to problem.
What use is “structure” in the grid?
Use unstructured grids.
But how, whilst keeping accuracy?
Take a “general” PDE
\[ \partial_t \phi = −\partial_x f(\phi) + \partial_x ( \kappa \partial_x \phi) = \mathcal{F}(\phi). \]
Use eg finite differences to approximate \(\mathcal{F} \to F\):
\[ \partial_t \phi_j = F(\phi_j) \simeq \frac{f_{i+1/2} - f_{i-1/2}}{\Delta x} + \dots \]
These are coupled ODEs. Solve using (eg) Runge-Kutta methods.
\[ \begin{aligned} \partial_t \phi_j &= -u \left. \left( \partial_x \phi \right) \right|_{x_j} \\ & \to -u \left( \phi_j - \phi_{j-1} \right) / \Delta x \, . \end{aligned} \]
def dphidt_bs(phi, dx, u=1):
dphidt = np.zeros_like(phi)
dphidt[:-1] = -u * (phi[:-1] - phi[1:]) / dx
dphidt[-1] = dphidt[1] # Periodic, 1 ghost point
return dphidt
def euler_step(phi_n, dphidt, dx, dt, u=1):
return phi_n + dt * dphidt(phi_n, dx, u)
...
t=0
while t < t_end:
t += dt
phi_n = euler_step(phi_n, dphidt_bs, dx, dt)RK2:
\[ \begin{aligned} \symbf{\phi}^{[1]} &= \symbf{\phi}^{n} + \Delta t \, F ( \symbf{\phi}^n ) \, , \\ \symbf{\phi}^{n+1} &= \tfrac{1}{2} \left\{ \symbf{\phi}^{n} + \symbf{\phi}^{[1]} + \Delta t \, F ( \symbf{\phi}^{[1]} ) \right\} \, . \end{aligned} \]