mscroggs / symfem

A symbolic finite element definition library
MIT License
53 stars 9 forks source link
finite-elements symbolic-algebra

Symfem

Badges
Documentation Documentation status
Testing & coverage Style checks Run tests Coverage Status DefElement: used as verification baseline
Packages PyPI conda
Paper DOI

Symfem is a symbolic finite element definition library, that can be used to symbolically evaluate the basis functions of a finite element space. Symfem can:

You can find details of recent changes to Symfem in the changelog.

Installing Symfem

Installing from source using pip

Symfem can be installed by downloading the GitHub repo and running:

pip3 install .

You may also use -e to install in editable mode:

pip3 install -e .

Installing from PyPI using pip

The latest release of Symfem can be installed by running:

pip3 install symfem

Installing using conda

The latest release of Symfem can be installed by running:

conda install -c conda-forge symfem

Testing Symfem

To run the Symfem unit tests, clone the repository and run:

python3 -m pytest test/

You may instead like to run the following, as this will skip the slowest tests.

python3 -m pytest test/ --speed fast

Using Symfem

Finite elements can be created in Symfem using the symfem.create_element() function. For example, some elements are created in the following snippet:

import symfem

lagrange = symfem.create_element("triangle", "Lagrange", 1)
rt = symfem.create_element("tetrahedron", "Raviart-Thomas", 2)
nedelec = symfem.create_element("triangle", "N2curl", 1)
qcurl = symfem.create_element("quadrilateral", "Qcurl", 2)

The basis functions of an element can be obtained by calling get_basis_functions():


lagrange = symfem.create_element("triangle", "Lagrange", 1)
print(lagrange.get_basis_functions())
[-x - y + 1, x, y]

Each basis function will be a Sympy symbolic expression.

Derivative of these basis functions can be computed using the functions in symfem.functions.

The function map_to_cell can be used to map the basis functions of a finite element to a non-default cell:


lagrange = symfem.create_element("triangle", "Lagrange", 1)
print(lagrange.get_basis_functions())
print(lagrange.map_to_cell([(0,0), (2, 0), (2, 1)]))
[-x - y + 1, x, y]
[1 - x/2, x/2 - y, y]

Further documentation

More detailed documentation of the latest release version of Symfem can be found on Read the Docs. A series of example uses of Symfem can be found in the demo folder or viewed on Read the Docs.

Details of the definition of each element can be found on DefElement alongside Symfem snippets for creating the element.

Getting help

You can ask questions about using Symfem by using GitHub Discussions. Bugs can be reported using the GitHub issue tracker.

Contributing to Symfem

Reporting bugs

If you find a bug in Symfem, please report it on the issue tracker.

Suggesting enhancements

If you want to suggest a new feature or an improvement of a current feature, you can submit this on the issue tracker.

Adding a new element

If you want to add a new element to Symfem, take a look at the Adding an element guide.

Submitting a pull request

If you want to directly submit code to Symfem, you can do this by forking the Symfem repo, then submitting a pull request. If you want to contribute, but are unsure where to start, have a look at the issues labelled "good first issue".

On opening a pull request, unit tests and flake8 style checks will run. You can click on these in the pull request to see where (if anywhere) there are errors in your code.

Code of conduct

We expect all our contributors to follow the Contributor Covenant. Any unacceptable behaviour can be reported to Matthew (symfem@mscroggs.co.uk).

Available cells and elements

Interval

The reference interval has vertices (0,) and (1,). Its sub-entities are numbered as follows.

The numbering of a reference interval

List of supported elements

Triangle

The reference triangle has vertices (0, 0), (1, 0), and (0, 1). Its sub-entities are numbered as follows.

The numbering of a reference triangle

List of supported elements

Quadrilateral

The reference quadrilateral has vertices (0, 0), (1, 0), (0, 1), and (1, 1). Its sub-entities are numbered as follows.

The numbering of a reference quadrilateral

List of supported elements

Tetrahedron

The reference tetrahedron has vertices (0, 0, 0), (1, 0, 0), (0, 1, 0), and (0, 0, 1). Its sub-entities are numbered as follows.

The numbering of a reference tetrahedron

List of supported elements

Hexahedron

The reference hexahedron has vertices (0, 0, 0), (1, 0, 0), (0, 1, 0), (1, 1, 0), (0, 0, 1), (1, 0, 1), (0, 1, 1), and (1, 1, 1). Its sub-entities are numbered as follows.

The numbering of a reference hexahedron

List of supported elements

Prism

The reference prism has vertices (0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 0, 1), and (0, 1, 1). Its sub-entities are numbered as follows.

The numbering of a reference prism

List of supported elements

Pyramid

The reference pyramid has vertices (0, 0, 0), (1, 0, 0), (0, 1, 0), (1, 1, 0), and (0, 0, 1). Its sub-entities are numbered as follows.

The numbering of a reference pyramid

List of supported elements

Dual polygon

The reference dual polygon (hexagon example shown) has vertices (1, 0), (3/4, sqrt(3)/4), (1/2, sqrt(3)/2), (0, sqrt(3)/2), (-1/2, sqrt(3)/2), (-3/4, sqrt(3)/4), (-1, 0), (-3/4, -sqrt(3)/4), (-1/2, -sqrt(3)/2), (0, -sqrt(3)/2), (1/2, -sqrt(3)/2), and (3/4, -sqrt(3)/4). Its sub-entities are numbered as follows.

The numbering of a reference dual polygon

List of supported elements