项目作者: IgorBaratta

项目描述 :
Simple Q1 Finite Element Method
高级语言: Python
项目地址: git://github.com/IgorBaratta/simple_fem.git
创建时间: 2020-06-01T16:21:44Z
项目社区:https://github.com/IgorBaratta/simple_fem

开源协议:MIT License

下载


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

  1. 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

  1. import numpy
  2. from scipy.sparse.linalg import spsolve
  3. from simple_fem import Mesh, FunctionSpace, Q1Element, plot
  4. from simple_fem.assemble import assemble_matrix, assemble_vector, apply_bc
  5. mesh = Mesh(22, 21)
  6. element = Q1Element()
  7. Q = FunctionSpace(mesh, element)
  8. f = lambda x : 4*(-x[1]**2 + x[1])*numpy.sin(numpy.pi*x[0])
  9. A = assemble_matrix(Q, matrix_type="stiffness")
  10. b = assemble_vector(Q, f)
  11. dofs = Q.locate_boundary_dofs()
  12. apply_bc(A, b, dofs, value=0)
  13. x = spsolve(A, b)
  14. plot(mesh, x)

Solution