# How to check if my stiffness matrix is correct

I built the stiffness matrix for the Poisson equation on a 2-dimensional domain with the shape of "almost" an octagon, using pyramid basis functions. I used almost to intend the fact that I have an "irregular" shape.

The mesh has been given to me by a point matrix $$P$$ and a connectivity matrix $$T$$. In $$P$$ I have the points of the domain, while in the matrix $$T$$ I have in each entry the vertices of the triangles. On page 47 of Larson & Bengzon book (section "Data Storage Structures") is explained better what I mean with a simple example.

Anyway, I implemented the assembly procedure as described on page 85 and I
obtain the right result for simple squared domains. I also tried to use the code for the $$[0,1]$$-interval with grid size $$h$$ and things are good.

Of course here the point matrix is made by a linspace from $$0$$ to $$1$$, while $$T$$ is a matrix like $$T =\begin{bmatrix} 1& 2&3 \\ 2&3&4\end{bmatrix}$$ and I end up with the usual Laplacian matrix (modulo a factor of $$h$$). So it's right.

Now the main question:

How can I check that the matrix I obtain for the "irregular" domain is correct?

I already checked it's symmetric, and since there were Homogeneous Dirichlet boundary conditions I followed the approach of Wolfgang Bangerth explained here at slide 14 (approach 2a). After this, I computed the condition number $$K$$ of the matrix and it is $$K \approx 6$$.

• Have you checked the Jacobian for irregular elements? – nicoguaro Nov 26 '19 at 4:19
• Yes, I precomputed the gradient since each gradient is a constant vector on each triangle. I also wrote the same routine in the book. One stupid questio: that algorithm for the assembly should work in every geometry, right? – slamWolfen Nov 26 '19 at 8:21
• Is my question bad-posed? – slamWolfen Nov 26 '19 at 16:30
• Yes, the assembly is the same for irregular elements. No, I don't think it is bad posted. My question has the purpose of helping, but is not complete enough to be an answer. – nicoguaro Nov 26 '19 at 16:36
• Okay, thank you. By the way, I used the MatLab command assema to see if the matrix is the same, but the MatLab stiffness matrix is even singular! (My matrix, as wrote above, has condition number equal to $6$. As far as I know, this is usual for matrix coming from finite element discretizations – slamWolfen Nov 26 '19 at 16:40