3

I'm having trouble understanding how to code 2-D Poisson's Equation with Dirichlet boundary conditions. What I have thus far is

  1. Constructed square mesh with triangular elements
  2. Assembled stiffness matrix. The function for this also gives the area of each element (all same, since square).
  3. Use Gaussian Quadrature to construct the right hand side.

edit: I may have been a little vague in my question. Hopefully this is a better rephrasing: Separate from FE, my code for gaussian quadrature works just fine. However, I don't understand how gaussian quadrature can even be relevant/involved with obtaining a solution to 2D Poisson; hence, I don't know how to continue coding.

TheRealFakeNews
  • 593
  • 1
  • 4
  • 16
  • It would be helpful to have more information on what you have tried and what exactly you can't make work. – Wolfgang Bangerth Feb 19 '13 at 05:04
  • @WolfgangBangerth Well, my question isn't so much coding. I'm not sure how Gaussian quadrature is involved, i.e. how or even why it plays a role. – TheRealFakeNews Feb 19 '13 at 05:08
  • This is a different question but may be helpful (also on Dirichlet conditions): http://scicomp.stackexchange.com/questions/5072/how-to-properly-apply-non-homogeneous-dirichlet-boundary-conditions-with-fem/5073#5073 – Nathan Collier Feb 19 '13 at 10:29
  • 1
    Well, what I'm saying is that I simply don't understand your question. You say you have Gaussian quadrature working but that you don't know how to "implement that into 2D Poisson". Would it be correct to say that you know how Gaussian quadrature works but you simply don't know how quadrature is relevant to the solution of PDEs with the finite element method? – Wolfgang Bangerth Feb 20 '13 at 00:12
  • @WolfgangBangerth Ah. I apologize. I wasn't sure how to phrase the question accurately to begin with. So, separate from FE, my code for Gaussian quadrature works. However, in regards to 2D Poisson, as you put, I'm not sure how it is relevant to the solution of 2D Poisson. I hope that clarifies my issues. – TheRealFakeNews Feb 20 '13 at 02:18
  • If the integral is difficult to compute analytically, you can use the Gaussian quadrature. FEM is a numerical method either, so it produces errors. If the error of the quadrature is not bigger then the error produced by FEM, then you can neglect the error of quadrature. Your code will also become more flexible because you can use it for more functions. – vanCompute Feb 20 '13 at 12:38
  • @vanCompute So why does finite difference not consider an integral then? If they're the same on a square grid, then shouldn't FD also integrate? – TheRealFakeNews Feb 20 '13 at 21:26
  • Finite differences approximate the solution at a point. Finite elements approximate the coefficients of the basis functions you are using. This is why you need different procedures. – vanCompute Feb 21 '13 at 08:49

1 Answers1

3

In the finite element method, you need to compute matrix entries (here in the case of the Laplace equation) $$ A_{ij} = \sum_K \int_K \nabla\varphi_i \cdot \nabla \varphi_j $$ and right hand side entries $$ F_{i} = \sum_K \int_K \varphi_i(x) f(x) $$ where $K$ are the cells of the mesh. The former can sometimes be computed analytically, but depending on the form of $f(x)$ in the latter, you may not be able to do that. If you can't analytically compute an integral, you use quadrature.

I don't know if it's a shameless plug, but I've actually recorded a video lecture on this topic -- see lecture 4 here: http://www.math.tamu.edu/~bangerth/videos.html

Wolfgang Bangerth
  • 55,373
  • 59
  • 119