Developing FEM in 1D

Copyright (C) 2020 Andreas Kloeckner

MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Boundary Value Problem

$$ \begin{align*} - u'' &= f(x)\\ u(0) = u(1) &= 0 \end{align*} $$

Grid Setup

V is a list of vertices. E is a list of elements (segments).

COOrdinate Matrix Semantics

Note: What happened to the duplicated entry?

Reference Matrix

Basis functions (on [0,1]): $$ \begin{align*} \phi_1(x) &= 1-x,\\ \phi_2(x) &= x, \end{align*} $$

For both degrees of freedom in the element, figure: $$ \hat A_{i,j} = \int \phi_i'(x) \phi_j'(x) dx $$

Assembly Helper

Assembly of the Linear System

Assemble $A$:

For both degrees of freedom involved in each element, assemble the RHS vector: $$ b_i=\int_E f(x) \phi_i(x) dx $$

Examine the matrix.

Notice anything?

Boundary Conditions

Add boundary conditions.

Examine the matrix after applying BCs:

Computing the Solution

Plot the RHS $f$.

Solve and plot the solution.