Giter Club home page Giter Club logo

thbsplines's Introduction

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, and is heavily influenced by the 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.

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()

# 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

pip install .

from the root directory. Verify the installation by calling

pytest

from the root directory.

thbsplines's People

Contributors

qtiptip avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

thbsplines's Issues

ImportError

Hi,
I followed the steps for installation in the document. However, I could not import THBSplines.
When I ran pytest, there were errors. One of them is
==================================== ERRORS ====================================
______________ ERROR collecting THBSplines/tests/test_assembly.py ______________
ImportError while importing test module '/Users/huangwei/Desktop/THBSplines/THBSplines/tests/test_assembly.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
THBSplines/tests/test_assembly.py:3: in
from THBSplines import hierarchical_stiffness_matrix, local_stiffness_matrix
../../opt/anaconda3/lib/python3.8/site-packages/THBSplines/init.py:1: in
from THBSplines.src.hierarchical_space import *
../../opt/anaconda3/lib/python3.8/site-packages/THBSplines/src/hierarchical_space.py:8: in
from THBSplines.src.tensor_product_space import TensorProductSpace, TensorProductSpace2D
../../opt/anaconda3/lib/python3.8/site-packages/THBSplines/src/tensor_product_space.py:6: in
from THBSplines.src_c.BSpline import TensorProductBSpline
E ModuleNotFoundError: No module named 'THBSplines.src_c'

Could you please help me? Thanks in advance!
Best wishes,
Wei

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.