06. Discretisation
In one spatial dimension , consider the boundary value problem (BVP) with solution :
where and are functions. This equation is supplemented with Dirichlet or Neumann boundary conditions.
We will solve this problem by discretising the equation using finite differences to turn the differential equation into an algebraic one with matrices.
This will involve inverting a matrix which we will achieve with the linear algebra package LAPACK.
Solving such equations are described in this exemplar, but we will list the important steps here:
- Preprocessing:
- Using
reader.f90
we read in the specified input data from the filesettings.input
. - Using
domain.f90
we build the uniform computational grids for the problem. - With
equations/definitions.f90
we then specify the equations we are solving, with boundary conditions.
- Using
- Discretisation:
- In
equations.f90
, specifically in the subroutinebuild_the_matrix
, the equation is spatially discretised into discrete algebraic equations using finite differences. - Both the left and right hand side of the equation above need to be assembled, including all boundary conditions.
- The equation is then transformed in a banded form. This is due to the fact that most of the matrix entries will be zero when finite differences are used. Again refer to this exemplar for more details.
- In
- Solution: we then solve the problem in the module
solve_bvp.f90
by calling on the LAPACK linear solver defined inlinear_algebra.f90
with the subroutinesolver_banded_double_precision
. - The solution is then outputted to a data file called
BVP.dat
.