IgorBaratta / simple_fem

Simple Q1 Finite Element Method

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

simple_fem

CI

Simple finite element implementation using Q1 (4 node quadrilateral) elements.

The interface is inspired by the interface of libraries from the FEniCS Project.

Installation

pip install git+https://github.com/IgorBaratta/simple_fem.git

Requirements

The only requirements for running simple_fem are:

  • Scipy - tested with version 1.4.1
  • Numpy - tested with version 1.18.4

Usage

Open In Colab

import numpy
from scipy.sparse.linalg import spsolve

from simple_fem import Mesh, FunctionSpace, Q1Element, plot
from simple_fem.assemble import assemble_matrix, assemble_vector, apply_bc


mesh = Mesh(22, 21)
element = Q1Element()
Q = FunctionSpace(mesh, element)

f = lambda x : 4*(-x[1]**2 + x[1])*numpy.sin(numpy.pi*x[0])

A = assemble_matrix(Q, matrix_type="stiffness")
b = assemble_vector(Q, f)

dofs = Q.locate_boundary_dofs()
apply_bc(A, b, dofs, value=0)

x = spsolve(A, b)

plot(mesh, x)

Solution

About

Simple Q1 Finite Element Method

License:MIT License


Languages

Language:Python 100.0%