Skip to content

Simple FEM solver for poission equation on quad unit squares

Notifications You must be signed in to change notification settings

jorgensd/SimpleFEM

Repository files navigation

SimpleFEM

This repository contains a Finite Element Solver for the Poisson equation - Δ u = f on Ω = [0,1]×[0,1], a unit square consisting of Nx elements in the x direction, Ny elements in the y-direction. The elements are four-noded quadrilateral elements.

Structure:

To run the example: python3 problem.py.

Following is a list describing the contents of each file:

  • assembly.py: Contains assembly routines for the Stiffness matrix, the right hand side and integration of a single finite element function.
  • dolfin_reference.py: A dolfin implementation of the problem, used for verification of the solution in test_solutions.py.
  • functionspace.py: Contains the implementation of a minimal version of the function space for first order Lagrange elements on quadrilaterals, corresponding to having dofs at each vertex.
  • mesh.py: Contains the implementation of the UnitSquareMesh
  • plotting.py: Contains several plotting routines for visualising the solution.
  • problem.py: Contains the example where f=4(-y2+y) sin(π x).
  • test_solution.py: Compares ∫ u dx obtained with this finite element solver with a FEniCS implementation. This is done for meshes of different sizes and different source terms. Runtime: ~ 3 minutes.

Dependencies

This finite element solver uses the numpy, sympy, scipy and matplotlib library. To run the comparasion of results with dolfin, you can use the FEniCS docker image, running

docker run --rm -ti -v $(pwd):/home/fenics/shared/ -w /home/fenics/shared/ quay.io/fenicsproject/stable:latest

Results

Running problem.py produces the following figures:

  • Solution of the Poisson equation on a 25×10 grid with f=4(-y2+y) sin(π x) Solution of the Poisson equation visualized

  • Visualization of the solution from a 25×10 with the exact values on a 40×40 grid. Custom mesh visualization

  • Contour-plot of the solution from a 25×10 grid. Custom mesh visualization

About

Simple FEM solver for poission equation on quad unit squares

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages