Skip to main content

Triangle Cubature Rules

This repo serves as a collection of well-tested triangle cubature rules, i.e. numerical integration schemes for integrals of the form

$$ \int_K f(x, y) ~\mathrm{d}x ~\mathrm{d}y, $$

where $K \subset \mathbb{R}^2$ is a triangle. All cubature rules are based on [1].

Usage

Using the cubature schemes is fairly simple.

from triangle_cubature.cubature_rule import CubatureRuleEnum
from triangle_cubature.integrate import integrate_on_mesh
from triangle_cubature.integrate import integrate_on_triangle
import numpy as np

# specifying the mesh
coordinates = np.array([
  [0., 0.],
  [1., 0.],
  [1., 1.],
  [0., 1.]
])

elements = np.array([
  [0, 1, 2],
  [0, 2, 3]
], dtype=int)


# defining the function to be integrated
# NOTE the function must be able to handle coordinates as array
# of shape (N, 2)
def constant(coordinates: np.ndarray):
    """returns 1"""
    return np.ones(coordinates.shape[0])


# integrating over the whole mesh
integral_on_mesh = integrate_on_mesh(
    f=constant,
    coordinates=coordinates,
    elements=elements,
    cubature_rule=CubatureRuleEnum.MIDPOINT)

# integrating over a single triangle, e.g.
# in this case, the "first" element of the mesh
integral_on_triangle = integrate_on_triangle(
    f=constant,
    triangle=coordinates[elements[0], :],
    cubature_rule=CubatureRuleEnum.MIDPOINT)

print(f'Integral value on mesh: {integral_on_mesh}')
print(f'Integral value on triangle: {integral_on_triangle}')

Available Rules

The available cubature rules can be found in triangle_cubature/cubature_rule.py.

  • CubatureRuleEnum.MIDPOINT
    • degree of exactness: 1
    • Ref: [1]
  • CubatureRuleEnum.LAUFFER_LINEAR
    • degree of exactness: 1
    • Ref: [1]
  • CubatureRuleEnum.SMPLX1
    • degree of exactness: 2
    • Ref: [1]
  • CubatureRuleEnum.DAYTAYLOR
    • degree of exactness: 6
    • Ref: [2]

(Unit) Tests

To run auto tests, you do

python -m unittest discover tests/auto/

The unit tests use sympy to verify the degree of exactness of the implemented cubature rules, i.e. creates random polynomials $p_d$ of the expected degree of exactness $d$ and compares the exact result of $\int_K p_d(x, y) ~\mathrm{d}x ~\mathrm{d}y$ to the value obtained with the cubature rule at hand.

References

  • [1] Stenger, Frank. 'Approximate Calculation of Multiple Integrals (A. H. Stroud)'. SIAM Review 15, no. 1 (January 1973): 234-35. https://doi.org/10.1137/1015023. p. 306-315
  • [2] D.M. Day and M.A. Taylor 'A new 11 point degree 6 formula for the triangle', PAMM Proc. Appl. Math. Mech. 7 1022501-1022502 (2007).

Metadata

Release files for triangle-cubature 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for triangle-cubature 1.2.0
File Size Uploaded
triangle_cubature-1.2.0.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for triangle-cubature 1.2.0
File Interpreter ABI Platform
triangle_cubature-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / triangle_cubature-1.2.0.tar.gz

Download URL triangle_cubature-1.2.0.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
99c546dd5178874446d9d4133f90a8bc67c366854e1a84d7df9855dc202d457b
BLAKE2b-256 checksum
How to use checksums
a2f3d286c390d52ed8340ecdff79c4854cbb4600bde0d98f34f8a6e9cd3a1027
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.18

Release files / triangle_cubature-1.2.0-py3-none-any.whl

Download URL triangle_cubature-1.2.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a5eaad1f93da916f53d84731070da8f43ee19ca7c290882139b23aac7295a76
BLAKE2b-256 checksum
How to use checksums
0731397bcb9702cd68b81d67f3b712ecd586bedbabcaf614660ee62262be8208
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.18

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page