https://github.com/qtiptip/thbsplines
Truncated Hierarchical B-Splines in Python
https://github.com/qtiptip/thbsplines
finite-element-method python3 splines
Last synced: 4 months ago
JSON representation
Truncated Hierarchical B-Splines in Python
- Host: GitHub
- URL: https://github.com/qtiptip/thbsplines
- Owner: qTipTip
- Created: 2018-11-08T10:48:15.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-14T09:52:35.000Z (over 5 years ago)
- Last Synced: 2025-05-07T14:11:19.256Z (6 months ago)
- Topics: finite-element-method, python3, splines
- Language: Python
- Homepage:
- Size: 3.64 MB
- Stars: 13
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# THBSplines
## Truncated Hierarchical B-Splines in Python
This repository contains a dimension-independent Python-implementation of truncated hierarchical B-splines, and methods for the assembly of stiffness
and mass matrices. The code is currently in a fairly undocumented state, and may contain bugs - so use at your own discretion.
The implementation is based on the article [Algorithms for the implementation of adaptive isogeometric methods using hierarchical B-splines](https://doi.org/10.1016/j.apnum.2017.08.006),
and is heavily influenced by the [GeoPDEs](http://rafavzqz.github.io/geopdes/) Matlab/Octave package for isogeometric analysis developed by the authors.
## Example - computing the mass and stiffness matrix
The computation of finite element matrices is fairly simple. Initialize the hierarchical space. Refine the space by choosing specific elements, or a rectangular region of refinement, and finally, assemble the matrices.
```python
import THBSplines as thb
import matplotlib.pyplot as plt
# Initialize a biquadraic space of Truncated Hierarchical B-Splines
knots = [
[0, 0, 1/3, 2/3, 1, 1],
[0, 0, 1/3, 2/3, 1, 1]
]
degrees = [2, 2]
dimension = 2
T = thb.HierarchicalSpace(knots, degrees, dimension)
# Select cells to refine at each level, either by explicitly marking the elements, or by choosing a rectangular region.
cells_to_refine = {}
cells_to_refine[0] = [0, 1, 2, 3, 4, 5, 6]
T = thb.refine(T, cells_to_refine)
rect = np.array([[0, 1 / 3], [0, 2 / 3]])
cells_to_refine[1] = T.refine_in_rectangle(rect, level = 1)
T = thb.refine(T, cells_to_refine)
T.mesh.plot_cells()
```

```python
# If no integration order is specified, exact gauss quadrature suitable for the given basis is used.
mass_matrix = thb.hierarchical_mass_matrix(T)
stiffness_matrix = thb.hierarchical_stiffness_matrix(T)
plt.spy(mass_matrix, markersize=1)
plt.show()
```

## Installation
Simply clone or download the repository and execute
```shell
pip install .
```
from the root directory. Verify the installation by calling
```shell
pytest
```
from the root directory.