Skip to main content

A Python library for the evaluation of S-splines on the Powell-Sabin 12-split of a triangle.

Project description

SSplines

Simplex Splines on the Powell-Sabin 12-split

Build Status Coverage Status Downloads DOI

SSplines is a Python library for the evaluation of simplex splines over the Powell-Sabin 12-split of a triangle. The library provides efficient evaluation using the matrix recurrence relation for S-spline basis functions for constant, linear, and quadratic simplex splines as developed by Cohen, Lyche and Riesenfeld. The SSplines library was developed as part of the thesis: Simplex Splines on the Powell-Sabin 12-Split.

Features

  • SplineFunction objects: Callable spline functions over a single triangle
  • SplineSpace objects: Facilitate instantiation of multiple functions in the same spline space
  • Evaluation and differentiation: Support for constant, linear, and quadratic simplex splines with convenient shortcuts for gradient, divergence, and Laplacian operators
  • Hermite basis conversion: Conversion between quadratic S-spline basis and quadratic Hermite nodal basis for finite element methods
  • Triangle sampling: Methods for sampling triangles for evaluation and visualization
  • Numerical integration: Basic subdomain integration methods over the Powell-Sabin 12-split for finite element computations
  • Polynomial pieces: Methods for returning polynomial restrictions of splines to each of the twelve sub-triangles
  • Symbolic computation: Integration with SymPy for exact symbolic calculations

Installation

Using pip

pip install SSplines

Using uv (recommended for development)

# Install uv first (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install SSplines
uv pip install SSplines

# For development with testing and visualization
uv pip install "SSplines[dev]"

Local installation

git clone https://github.com/qTipTip/SSplines
cd SSplines
uv pip install -e ".[dev]"

Quick Start

Basic Usage

import numpy as np
from SSplines import SplineSpace, SplineFunction

# Define a triangle
triangle = np.array([
    [0, 0],
    [1, 0], 
    [0, 1]
])

# Create a quadratic spline space
space = SplineSpace(triangle, degree=2)

# Get the dimension of the space
print(f"Spline space dimension: {space.dimension}")  # 12 for quadratic

# Create a spline function with random coefficients
coefficients = np.random.rand(space.dimension)
spline_func = space.function(coefficients)

# Evaluate the spline at points
points = np.array([
    [0.3, 0.3],
    [0.1, 0.2],
    [0.5, 0.1]
])
values = spline_func(points)
print(f"Spline values: {values}")

Working with Basis Functions

# Get all basis functions
basis_functions = space.basis()

# Evaluate the first basis function
first_basis = basis_functions[0]
value_at_point = first_basis([0.3, 0.3])

# Compute derivatives
gradient = first_basis.grad([0.3, 0.3])
laplacian = first_basis.lapl([0.3, 0.3])

Hermite Basis

# For quadratic splines, you can use Hermite basis
hermite_basis = space.hermite_basis()

# Each Hermite basis function corresponds to nodal values or derivatives
h0 = hermite_basis[0]  # Value at first vertex
h1 = hermite_basis[1]  # x-derivative at first vertex
h2 = hermite_basis[2]  # y-derivative at first vertex

Symbolic Computation

from SSplines.symbolic import polynomial_basis_quadratic

# Get symbolic polynomial representations
symbolic_basis = polynomial_basis_quadratic(triangle)

# Each entry contains the polynomial pieces over the 12 sub-triangles
print(f"Number of polynomial pieces: {len(symbolic_basis[0])}")  # 12

Dependencies

  • Core dependencies:

    • numpy ≥ 1.24.0: Numerical computations
    • sympy ≥ 1.10: Symbolic mathematics
  • Development dependencies:

    • pytest ≥ 7.0.1: Testing framework
    • pytest-cov: Test coverage
    • matplotlib ≥ 3.5.1: Plotting and visualization

Development

Setting up a development environment

# Clone the repository
git clone https://github.com/qTipTip/SSplines
cd SSplines

# Install in development mode with all dependencies
uv pip install -e ".[dev]"

Running tests

# Run all tests
uv run pytest

# Run with coverage
uv run pytest --cov SSplines/

# Run specific test file
uv run pytest tests/test_spline_function.py -v

Code structure

SSplines/
├── __init__.py              # Main module exports
├── constants.py             # Mathematical constants and lookup tables
├── helper_functions.py      # Core computational functions
├── simplex_spline.py        # SimplexSpline class
├── spline_function.py       # SplineFunction class  
├── spline_space.py          # SplineSpace class
├── symbolic.py              # Symbolic computation utilities
└── dicts.py                 # Lookup dictionaries for sub-triangles

Mathematical Background

The library implements S-splines on the Powell-Sabin 12-split, which divides a triangle into 12 sub-triangles by:

  1. Adding a point at the centroid
  2. Adding midpoints on each edge
  3. Connecting these points to create 12 sub-triangles

The S-splines are defined using a matrix recurrence relation that allows efficient evaluation without explicit polynomial representation. This approach is particularly useful for:

  • Finite element methods
  • Computer-aided geometric design
  • Approximation theory
  • Scientific computing applications requiring smooth basis functions

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use SSplines in your research, please cite the original theoretical work and the software implementation:

Original S-splines theory:

@article{cohen2013splines,
  title={S-splines},
  author={Cohen, Elaine and Lyche, Tom and Riesenfeld, Richard},
  journal={Mathematics of Computation},
  volume={82},
  number={283},
  pages={1577--1596},
  year={2013},
  doi={10.1090/S0025-5718-2013-02664-6}
}

SSplines software and implementation:

@mastersthesis{stangeby2018ssplines,
  title={Simplex Splines on the Powell-Sabin 12-Split},
  author={Stangeby, Ivar Haugal{\o}kken},
  school={University of Oslo},
  year={2018},
  url={http://hdl.handle.net/10852/64070},
  urn={URN:NBN:no-66606}
}

Software repository:

@software{stangeby2024ssplines,
  title={SSplines: Simplex Splines on the Powell-Sabin 12-split},
  author={Stangeby, Ivar},
  year={2024},
  doi={10.5281/zenodo.15742326},
  url={https://github.com/qTipTip/SSplines}
}

Author

Ivar Stangeby - istangeby@gmail.com

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ssplines-3.0.0.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ssplines-3.0.0-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file ssplines-3.0.0.tar.gz.

File metadata

  • Download URL: ssplines-3.0.0.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ssplines-3.0.0.tar.gz
Algorithm Hash digest
SHA256 9126ae17f50e489fb20e312d7e10fcd3ed29d2cd61db5400b80dd0e4f8e51126
MD5 c01a865244ce9d3113324334efd916a4
BLAKE2b-256 7712d88ccf79e14b7a55c10694f547aa83622327cdfb78e5babeb64c86e1670c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ssplines-3.0.0.tar.gz:

Publisher: release.yml on qTipTip/SSplines

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ssplines-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: ssplines-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ssplines-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7da2627ca3f7815c8bea338672b7e295c849b9dfd2e8d1ee20cf382ba3d69f4e
MD5 37ddd5aaf03194dfb55c394667110c36
BLAKE2b-256 fa2d4cceae9caf84e8ce180764526db2ca5291b3d79a1390f2efb0a9d584460c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ssplines-3.0.0-py3-none-any.whl:

Publisher: release.yml on qTipTip/SSplines

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page