In this exercise you will build an implicit solver for a diffusion equation. A one-component stationary diffusion equation with constant coefficients has the form
This equation needs to be solved on a domain of length with on the left and right boundaries a boundary condition of the form
where indicates the outward pointing normal direction, i.e. for the left boundary and for the right boundary.
Questions:
Assume a spatial discretization of cells with points located in cell centers. Write down the spatial discretization formula for the diffusion terms for points . (Note that cells and , are neighboring a boundary).
Write down the spatial discretization formula’s for points and by implementing a Dirichlet boundary condition (, ).
Write down the resulting formula’s in matrix-vector form.
Implement the matrix-vector equation in Python using SciPy. Define a sparse matrix using the SciPy sparse array, e.g., by means of: scipy.sparse.diags_array.
Verify the implementation for Dirichlet BCs on both sides.
Extend the boundary condition implementation to general mixed boundary conditions (any value of and ). Write down the resulting formula’s in matrix-vector form.
Verify the implementation of the mixed boundary conditions by choosing values of , and on both sides and compare the result with the expected analytical solution.
Dispersion with a first order reaction obeys
Questions:
Include the first order reaction term to the matrix-vector equation.
Verify the implementation for varying values of and general mixed boundary conditions by comparison with the expected analytical solution.
The unsteady diffusion (first order) reaction equation is
Questions:
Add an implementation of the accumulation term using Euler-backward time discretization.
Solve the equations in time and verify the accumulation term by comparison with analytical solutions for (simple) initial and boundary conditions.