The Method of Lines (MOL) is a powerful numerical technique used to solve partial differential equations (PDEs), particularly those that are time-dependent (evolutionary).
Instead of discretizing all dimensions(space and time) simultaneously, the core idea is to discretize the spatial variables while leaving the time variable continuous. This transforms a single PDE into a system of coupled Ordinary Differential Equations(ODEs).
How It Works: The 3-Step Process
Imagine you are solving the heat equation:
- Spatial Discretization: You divide the spatial domain into a grid of points(e.g., x_1, x_2, \cdot, x_n). You replace the spatial derivatives (\frac{\partial^2 u}{\partial x^2}) with finite difference approximations, such as:
- Conversion to ODEs: By applying this at every grid point, the PDE becomes a set of ODEs, one for each point :
- Temporal Integration: Now that you have a system of ODEs, you can use standard, high-performance ODE solvers like Runge-Kutta or Euler’s method to step forward in time.
## Why Use It? (Advantages)
- Leverages Existing Tech: You can use sophisticated, pre-built ODE solvers(like
Ode45/Ode45ain SepalSolver orode45in MATLAB) that automatically handle error control and adaptive time-stepping. - Flexibility: You can use different spatial discretization methods, such as finite differences, finite elements, or spectral methods, depending on the geometry of your problem
- Simplification: It breaks a complex multi-dimensional problem into a more manageable "line-by-line" temporal evolution.
## Limitations
- Stiffness: The resulting system of ODEs is often "stiff," meaning you may need implicit solvers to avoid tiny, inefficient time steps.
- Not for All PDEs: It is designed for "evolutionary" problems (parabolic and hyperbolic). It cannot be used directly for purely "steady-state" elliptic equations(like Laplace’s equation) without adding a "pseudo-time" variable.
| Feature | Standard Finite Difference(FDM) | Method of Lines(MOL) |
|---|---|---|
| Time Treatment | Discretized at the start | Kept continuous initially |
| Solving Logic | Solves the whole grid at once | Solves ODEs along "lines" of time |
| Software | Requires custom time-stepping | Uses off-the-shelf ODE solvers |
In sepalsolver, the nnumerical solution of pde (Pdepe) is built on Ode45a: our differential algebraic equation solver that relies on L-stable diagonally implicit Runge Kutta. This allows it to handle the boundary conditions implicitly and also correct the egde values in situation where the initial condition is not consitent with the boundary condition
Example 1: Solving the Heat Equation
Consider the one-dimensional heat equation:
with initial condition u(x,0) = \sin(\pi x) and boundary conditions u(0,t) = u(1,t) = 0.
Example 1C#

Example 2: Solving Reactive Diffusion Equation
The Fisher-KPP reaction-diffusion model transformed into a cylindrical coordinate system (m = 1). In cylindrical coordinates, the model represents radial population dispersion or chemical wavefront propagation outward from a central core (e.g., cell growth in a Petri dish or cylindrical tissue scaffold).
initial condition
boundary condition
Example 2C#


It is important to note that pdepe can be invoked with a shothand form as shown in the example below
Example 3C#
Example 3: System of Partial Differential Equations
Here is a classic engineering problem: Coupled Transient Heat and Mass Transfer in a Cylindrical Reactor / Packed Bed (with m = 1). This models fluid flowing axially through a cylindrical pipe where a chemical reaction occurs, generating heat and consuming reactant along both the radial direction r and over time t.
Governing System of Equations For radial coordinate r \in [r_0, R] (or x \in [0, R]) and time t > 0, we track two coupled variables:
- Temperature T(r,t)
- Reactant Concentration C(r,t)
Standard Pdepe Vector Mapping
In terms of the pdepe flux-source balance equation with cylindrical symmetry (m = 1):
We map state vector \mathbf{u} = \begin{bmatrix} T \\ C \end{bmatrix} (where u_1 = T, u_2 = C and spatial coordinate x = r):
-Capacities \mathbf{c}:
Fluxes \mathbf{f}:
Sources \mathbf{s}:
Example 4C#

Example 4: Higher Order in time: Wave Equation 1D
This is haneld using the system of PDE just like we use system of ode to handle higher oder odes. We first convert the higher oder derivative in time to system of first order time pdes.
Lets look as example of a string fixed at the right end and exited at the left end according to 0.5 Sin(10*t).
initial condition
boundary condition
To solve this, we set v = \cfrac{\partial u}{\partial t} This means we also have to differentiate the boundary conditions. And then we have
initial condition
boundary condition
Example 5C#
Example 5: Higher Dimension: Wave Equation Example
For higher dimensions, the same method can be applied. This will be demonstrated using wave equation assume c > 0
initial condition
where r = \sqrt{(x - x_c)^2 + (y - y_c)^2}
boundary condition
Step 1: Convert to system of first order PDEs in time
and hence
Step 2: discretize the spatial part of the equation as:
Step 3: Assemble the system of coupled ODEs
We were given boundary conditions for u but we introduce v, so we have to create the boubdary condition for that by differentiating the given boundary condition.
we can do so for \partial u/\partial t too