File: quadrature.py

package info (click to toggle)
fenics-basix 0.10.0.post0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,156 kB
  • sloc: cpp: 23,435; python: 10,829; makefile: 43; sh: 26
file content (77 lines) | stat: -rw-r--r-- 2,101 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Copyright (C) 2023-2024 Matthew Scroggs and Garth N. Wells
#
# This file is part of Basix (https://www.fenicsproject.org)
#
# SPDX-License-Identifier:    MIT
"""Functions to manipulate quadrature types."""

import numpy as _np
import numpy.typing as _npt

from basix._basixcpp import QuadratureType
from basix._basixcpp import make_quadrature as _mq
from basix._basixcpp import gauss_jacobi_rule as _gjr
from basix.cell import CellType
from basix.polynomials import PolysetType

__all__ = ["string_to_type", "make_quadrature"]


def string_to_type(rule: str) -> QuadratureType:
    """Convert a string to a Basix QuadratureType enum.

    Args:
        rule: Qquadrature rule as a string.

    Returns:
        The quadrature type.
    """
    if rule == "default":
        return QuadratureType.default
    elif rule in ["Gauss-Lobatto-Legendre", "GLL"]:
        return QuadratureType.gll
    elif rule in ["Gauss-Legendre", "GL", "Gauss-Jacobi"]:
        return QuadratureType.gauss_jacobi
    elif rule == "Xiao-Gimbutas":
        return QuadratureType.xiao_gimbutas

    return QuadratureType[rule]


def make_quadrature(
    cell: CellType,
    degree: int,
    rule: QuadratureType = QuadratureType.default,
    polyset_type: PolysetType = PolysetType.standard,
) -> tuple[_npt.ArrayLike, _npt.ArrayLike]:
    """Create a quadrature rule.

    Args:
        cell: Cell type.
        degree: Maximum polynomial degree that will be integrated
            exactly.
        rule: Quadrature rule.
        polyset_type: Type of polynomial that will be integrated
            exactly.

    Returns:
        Quadrature points and weights.
    """
    return _mq(rule, cell, polyset_type, degree)


def gauss_jacobi_rule(
    alpha: _np.floating,
    npoints: int,
) -> tuple[_npt.ArrayLike, _npt.ArrayLike]:
    """Create a Gauss-Jacobi quadrature rule for integrating f(x)*(1-x)**alpha
    on the interval [0, 1].

    Args:
        alpha: The exponent alpha
        npoints: Number of points

    Returns:
        Quadrature points and weights.
    """
    return _gjr(_np.float64(alpha), npoints)