# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.analysis.differentialequation.pde.finitedifference.parabolic.dim1.convectiondiffusionequation

## Class CrankNicolsonConvectionDiffusionEquation1D

• java.lang.Object
• com.numericalmethod.suanshu.analysis.differentialequation.pde.finitedifference.parabolic.dim1.convectiondiffusionequation.CrankNicolsonConvectionDiffusionEquation1D
• All Implemented Interfaces:
PDESolver

public class CrankNicolsonConvectionDiffusionEquation1D
extends Object
implements PDESolver
This class uses the Crank-Nicolson scheme to obtain a numerical solution of a one-dimensional convection-diffusion PDE. The complexity of this algorithm is $$O(mn^3)$$, where m is the number of grid points in the time-axis, n is the number of grid points in the space-axis. The truncation error is of order $$O(\Delta t^2 + \Delta x^2)$$.

The advantage of the Crank-Nicolson scheme is that it guarantees unconditional stability, but only under the situation that the coefficients of the PDE (such as \sigma and \mu) are fixed (may be relaxed to be linear in state variable). Unconditional stability means that the solution will not be oscillating no matter what you choose for the step size (but doesn't mean that the solution is close to the true result). In general for non-linear \sigma and \mu, the stability cannot be guaranteed. It is very possible to get an oscillating result especially near the boundary grids, but currently our solver can do nothing about this. Even if we find a possible scheme to deal with the boundary points with second-order accuracy, we do not always get stable solutions under non-linear coefficients. Hence, our solver works well only under some conditions (e.g., fixed constants, domain not too big) but not for a general case.

"ref/convection-diffusion-pde/CrankNicolsonForConvectionDiffusionEquation.pdf"
• ### Nested Class Summary

Nested Classes
Modifier and Type Class and Description
static class  CrankNicolsonConvectionDiffusionEquation1D.Coefficients
Gets the coefficients of a discretized 1D convection-diffusion equation for each time step.
• ### Constructor Summary

Constructors
Constructor and Description
CrankNicolsonConvectionDiffusionEquation1D()
Constructs a Crank-Nicolson solver for a 1 dimensional convection-diffusion PDE.
• ### Method Summary

All Methods
Modifier and Type Method and Description
PDESolutionTimeSpaceGrid1D solve(ConvectionDiffusionEquation1D pde, int M, int N)
Solves a 1 dimensional convection-diffusion equation.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### CrankNicolsonConvectionDiffusionEquation1D

public CrankNicolsonConvectionDiffusionEquation1D()
Constructs a Crank-Nicolson solver for a 1 dimensional convection-diffusion PDE.
• ### Method Detail

• #### solve

public PDESolutionTimeSpaceGrid1D solve(ConvectionDiffusionEquation1D pde,
int M,
int N)
Solves a 1 dimensional convection-diffusion equation.
Parameters:
pde - a 1 dimensional convection-diffusion equation
M - the number of grid points along the time-axis (excluding the initial condition)
N - the number of grid points along the space-axis (excluding the two boundaries)
Returns:
the solution $$u(t,x)$$ at the grid points