Git Product home page Git Product logo

scikit-fem's Introduction

scikit-fem

PyPI version Build Status License DOI status

scikit-fem is a lightweight Python 3.6+ library for performing finite element assembly. Its main purpose is the transformation of bilinear forms into sparse matrices and linear forms into vectors. The library supports triangular, quadrilateral, tetrahedral and hexahedral meshes as well as one-dimensional problems.

The library fills an important gap in the spectrum of finite element codes. The library is lightweight meaning that it has minimal dependencies. It contains no compiled code meaning that it's easy to install and use on all platforms that support NumPy. Despite being fully interpreted, the code has a reasonably good performance.

Examples

Forms are defined using an intuitive syntax:

from skfem import *
from skfem.helpers import dot, grad

@BilinearForm
def laplace(u, v, w):
    return dot(grad(u), grad(v))

Meshes can be initialized manually, loaded from external files using meshio, or created with the help of special constructors:

import numpy as np

mesh = MeshLine(np.array([0.0, 0.5, 1.0]))
mesh = MeshTri.load("docs/examples/square.msh")
mesh = MeshTet.init_tensor(*((np.linspace(0, 1, 60),) * 3))

We support many common finite elements. Below the stiffness matrix is assembled using second-order tetrahedra:

basis = InteriorBasis(mesh, ElementTetP2())
A = laplace.assemble(basis)  # type: scipy.sparse.csr_matrix

The matrix A has 1.5 million rows/columns and took only a few seconds to assemble!

More examples can be found in the source code distribution.

Documentation

The project is documented using Sphinx. A recent version of the documentation can be found from Github pages.

Installation

The most recent release can be installed simply by pip install scikit-fem. For more cutting edge features, you can clone this repository.

Acknowledgements

This project was started while working under a grant from the Finnish Cultural Foundation. The approach used in the finite element assembly has been inspired by the work of A. Hannukainen and M. Juntunen.

Contributing

We are happy to welcome any contributions to the library. Reasonable projects for first timers include:

By contributing code to scikit-fem, you are agreeing to release it under BSD-3-Clause, see LICENSE.md.

In literature

The library has been used in the preparation of the following scientific works:

  • Gustafsson, T., Stenberg, R., & Videman, J. (2020). On Nitsche's method for elastic contact problems. SIAM Journal on Scientific Computing, 42(2), B425–B446. arXiv preprint arXiv:1902.09312.
  • Gustafsson, T., Stenberg, R., & Videman, J. (2019). Nitsche's Master-Slave Method for Elastic Contact Problems. arXiv:1912.08279.
  • McBain, G. D., Mallinson, S. G., Brown, B. R., Gustafsson, T. (2019). Three ways to compute multiport inertance. The ANZIAM Journal, 60, C140–C155. Open access.
  • Gustafsson, T., Stenberg, R., & Videman, J. (2019). Error analysis of Nitsche's mortar method. Numerische Mathematik, 142(4), 973–994. Open access.
  • Gustafsson, T., Stenberg, R., & Videman, J. (2019). Nitsche's method for unilateral contact problems. Port. Math. 75, 189–204. arXiv preprint arXiv:1805.04283.
  • Gustafsson, T., Stenberg, R. & Videman, J. (2018). A posteriori estimates for conforming Kirchhoff plate elements. SIAM Journal on Scientific Computing, 40(3), A1386–A1407. arXiv preprint arXiv:1707.08396.
  • Gustafsson, T., Rajagopal, K. R., Stenberg, R., & Videman, J. (2018). An adaptive finite element method for the inequality-constrained Reynolds equation. Computer Methods in Applied Mechanics and Engineering, 336, 156–170. arXiv preprint arXiv:1711.04274.
  • Gustafsson, T., Stenberg, R., & Videman, J. (2018). A stabilised finite element method for the plate obstacle problem. BIT Numerical Mathematics, 59(1), 97–124. arXiv preprint arXiv:1711.04166.
  • Gustafsson, T., Stenberg, R., & Videman, J. (2017). Nitsche’s Method for the Obstacle Problem of Clamped Kirchhoff Plates. In European Conference on Numerical Mathematics and Advanced Applications, 407–415. Springer.
  • Gustafsson, T., Stenberg, R., & Videman, J. (2017). A posteriori analysis of classical plate elements. Rakenteiden Mekaniikka, 50(3), 141–145. Open access.

In case you want to cite the library, you can use the DOI provided by Zenodo.

Changelog

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

Added

  • Dofs.__or__ and Dofs.__add__, for merging degree-of-freedom sets (i.e. Dofs objects) using | and + operators
  • Dofs.drop and Dofs.keep, for further filtering the degree-of-freedom sets

[1.2.0] - 2020-07-07

Added

  • Mesh.__add__, for merging meshes using + operator: duplicated nodes are joined
  • ElementHexS2, a 20-node quadratic hexahedral serendipity element
  • ElementLineMini, MINI-element for one-dimensional mesh

Fixed

  • Mesh3D.boundary_edges was broken in case of hexahedral meshes
  • skfem.utils.project did not work for ElementGlobal

Changed

  • MeshQuad._splitquads aliased as MeshQuad.to_meshtri: should not be private

[1.1.0] - 2020-05-18

Added

  • ElementTetMini, MINI-element for tetrahedral mesh

Fixed

  • Mesh3D.boundary_edges incorrectly returned all edges where both nodes are on the boundary

[1.0.0] - 2020-04-22

Added

  • New-style form constructors BilinearForm, LinearForm, and Functional
  • skfem.io.json for serialization of meshes to/from json-files
  • ElementLinePp, p-th order one-dimensional elements
  • ElementQuadP, p-th order quadrilateral elements
  • ElementQuadDG for transforming quadrilateral H1 elements to DG elements
  • ElementQuadBFS, Bogner-Fox-Schmit element for biharmonic problems
  • ElementTriMini, MINI-element for Stokes problems
  • ElementComposite for using multiple elements in one bilinear form
  • ElementQuadS2, quadratic Serendipity element
  • ElementLineHermite, cubic Hermite element for Euler-Bernoulli beams
  • Mesh.define_boundary for defining named boundaries
  • Basis.find_dofs for finding degree-of-freedom indices
  • Mesh.from_basis for defining high-order meshes
  • Basis.split for splitting multicomponent solutions
  • MortarMapping with basic support for mortar methods in 2D
  • Basis constructors now accept quadrature keyword argument for specifying a custom quadrature rule

Deprecated

  • Old-style form constructors bilinear_form, linear_form, and functional.

Changed

  • Basis.interpolate returns DiscreteField objects instead of ndarray tuples
  • Basis.interpolate works now properly for vectorial and high-order elements by interpolating all components and higher order derivatives
  • Form.assemble accepts now any keyword arguments (with type DiscreteField) that are passed over to the forms
  • Renamed skfem.importers to skfem.io
  • Renamed skfem.models.helpers to skfem.helpers
  • skfem.utils.solve will now expand also the solutions of eigenvalue problems

[0.4.1] - 2020-01-19

Added

  • Additional keyword arguments to skfem.utils.solve get passed on to linear solvers

Fixed

  • Made skfem.visuals.matplotlib Python 3.6 compatible

[0.4.0] - 2020-01-03

Changed

  • Renamed GlobalBasis to Basis
  • Moved all Mesh.plot and Mesh.draw methods to skfem.visuals module
  • Made matplotlib an optional dependency

scikit-fem's People

Contributors

kinnala avatar gdmcbain avatar ahojukka5 avatar ahhuhtal avatar gitter-badger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.