Assignment 6: Inhomogeneous PDE using LAPACKE
In this assignment, we want to numerically solve the Laplace equation for the electric field in an inhomogeneous 1d medium, using LAPACKE.
For our problem, the domain for the electric field \(V\) is the unit interval \(x\in[0,1]\), with boundary conditions \(V(x=0)=0\) and \(V(x=1)=1\). The Laplace equation to solve is
$$\frac{d}{dx}\left[\epsilon(x)\frac{dV}{dx}\right] = 0$$
where the inhomogeneous dielectric constant is (in arbitrary units) given by
$$\epsilon(x)=1+10\cos^2(2\pi x)$$
Use a discretization scheme where the \(x\) axis will be discretized into \(N+1\) points, such that \(x_i=i\Delta x\), with \(\Delta x=1/N\).
The boundary conditions become \(V_0=0\) and \(V_N=1\).
The discretization of this Laplace equation needs to take into account the \(x\) dependence of \(\epsilon\). To \(O(\Delta x^2)\) , this works out as follows:
$$\frac{d}{dx}\left[\epsilon(x)\frac{dV}{dx}\right]_{x=x_i}$$
$$\approx \frac{\epsilon(x+\Delta x/2)V_{i+1}+\epsilon(x-\Delta x/2)V_{i-1}-\{\epsilon(x+\Delta x/2)+\epsilon(x-\Delta x/2)\}V_i}{\Delta x^2}$$
This holds for \(i>0\) and \(i<N\).
If we denote by \(v\) the \(N-1\)-dimensional vector \((V_1,V_2,..,V_{N-1})\), we can write the discretized equation as
$$\mathbf{A}\cdot v = b$$
where \(\mathbf A\) is an \(N-1\) x \(N-1\) "tri-diagonal" matrix, and \(b\) is an \(N-1\) dimensional vector \((0,...,0,-\epsilon(x+\Delta x/2)V_N/\Delta x^2)\) (that is, unless you factor out the common factor of \(1/\Delta x^2\)).
Your task for this assignment is as follows
- Install openblas on your Teach cluster account.
- Construct the matrix \(\mathbf{A}\) and vector \(b\), and write a program to solve the equation for \(v\)in double precision using a solver routine from LAPACKE that can take advantage of the tri-diagonal form of the matrix.
- Store both the values of \(\epsilon\) and the solution for V on the grid in a netcdf file.
- N can be an input value. The output should be the one produced for N=10000.
As usual, use git and make. Modularity is not a requirement in this assignment, but your code should use functions. Submit your repo as a zip file.