# Discontinuous Galerkin - Inhomogeneous Dirichlet B.C. for 1D Poisson Equation

I am trying to get some code working for the 1D Poisson equation using the textbook: Nodal Discontinuous Galerkin Methods Algorithms, Analysis, and Applications.

I use the following formulation (for a homogeneous case):

In order to account for inhomogeneous cases, the textbook proposes the following:

where $\mathcal A$ is given from the homogeneous case. When I attempt to implement the added term on the right-hand side of the equation above, I obtain the following response, which seems to almost respond correctly; however, the first and last terms deviate greatly from their specified b.c:

I implement the extra rhs term with the following code:

e = zeros((basisdegree+1),numelements);
enp = e; enp(end) = 1; e1 = e; e1(1) = 1;
extraterm = Dr*(enp*b - e1*a);


Where e is just a vector the size of the solution u, with 1 located in the first and last element. Dr is the same as in the homogeneous equations which are $\mathcal{M}^{-1} \mathcal{S}$.

You did everything right but forgot that the way you impose boundary values leads to a solution that has zero boundary values (when applied strongly) and for which you have to set the first and last degree of freedom to their correct value after solving the linear system. The solution will then be correct/as expected.

• Hi Wolfgang, thanks for the answer. When I hardset the values after solving the equation the graph looks good. The only issue I run into now is that when I use higher order basis functions the points around the start and end of the graph I attached in the initial question (all the points with different values on the same node) begin oscillating largely. Is this an issue with how I have enforced my boundary conditions? – Mitchell Apr 20 '18 at 6:11
• I also realised that I was using Dr (inv(M)*S) instead of S*inv(M) which now also throws the graph out of alignment with the BC's however still maintains the correct(ish) form. – Mitchell Apr 20 '18 at 7:11
• I have a hard time understanding the formulation you use, but basically you subtract something from the solution that has the correct boundary values and shove it over to the right hand side. Then you solve for the "rest", but the complete solution is this "rest" plus whatever you subtracted. You'll have to think about what that is exactly. – Wolfgang Bangerth Apr 20 '18 at 20:44