Skip to content

Commit

Permalink
move basix.quadrature.make_quadrature back to basix.make_quadrature
Browse files Browse the repository at this point in the history
  • Loading branch information
mscroggs committed Aug 8, 2023
1 parent f4fb350 commit 3237ad1
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 34 deletions.
6 changes: 3 additions & 3 deletions demo/python/demo_custom_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
# We compute these integrals using a degree 4 quadrature rule (this is the largest degree
# that the integrand will be, so these integrals will be exact).

pts, wts = basix.quadrature.make_quadrature(CellType.quadrilateral, 4)
pts, wts = basix.make_quadrature(CellType.quadrilateral, 4)
poly = basix.tabulate_polynomials(PolynomialType.legendre, CellType.quadrilateral, 2, pts)
x = pts[:, 0]
y = pts[:, 1]
Expand Down Expand Up @@ -190,7 +190,7 @@
wcoeffs[0, 0] = 1
wcoeffs[1, 3] = 1

pts, wts = basix.quadrature.make_quadrature(CellType.triangle, 2)
pts, wts = basix.make_quadrature(CellType.triangle, 2)
poly = basix.tabulate_polynomials(PolynomialType.legendre, CellType.triangle, 1, pts)
x = pts[:, 0]
y = pts[:, 1]
Expand All @@ -205,7 +205,7 @@
# the element are integrals. We begin by defining a degree 1 quadrature rule on an interval.
# This quadrature rule will be used to integrate on the edges of the triangle.

pts, wts = basix.quadrature.make_quadrature(CellType.interval, 1)
pts, wts = basix.make_quadrature(CellType.interval, 1)

# The points associated with each edge are calculated by mapping the quadrature points to each edge.

Expand Down
2 changes: 1 addition & 1 deletion demo/python/demo_custom_element_conforming_cr.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def create_ccr_triangle(degree):
wcoeffs[dof_n, dof_n] = 1
dof_n += 1

pts, wts = basix.quadrature.make_quadrature(CellType.triangle, 2 * (degree + 1))
pts, wts = basix.make_quadrature(CellType.triangle, 2 * (degree + 1))
poly = basix.tabulate_polynomials(PolynomialType.legendre, CellType.triangle, degree + 1, pts)
for i in range(1, degree):
x = pts[:, 0]
Expand Down
2 changes: 1 addition & 1 deletion demo/python/demo_facet_integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# rule on a triangle. We use an order 3 rule so that we can integrate the
# basis functions in our space exactly.

points, weights = basix.quadrature.make_quadrature(CellType.triangle, 3)
points, weights = basix.make_quadrature(CellType.triangle, 3)

# Next, we must map the quadrature points to our facet. We use the function
# `geometry` to get the coordinates of the vertices of the tetrahedron, and
Expand Down
4 changes: 2 additions & 2 deletions demo/python/demo_quadrature.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
# `make_quadrature` returns two values: the points and the weights of the
# quadrature rule.

points, weights = basix.quadrature.make_quadrature(CellType.triangle, 4)
points, weights = basix.make_quadrature(CellType.triangle, 4)

# If we want to control the type of quadrature used, we can pass in three
# inputs to `make_quadrautre`. For example, the following code would force basix
# to use a Gauss-Jacobi quadrature rule:

points, weights = basix.quadrature.make_quadrature(
points, weights = basix.make_quadrature(
CellType.triangle, 4, rule=basix.QuadratureType.gauss_jacobi)

# We now use this quadrature rule to integrate the functions :math:`f(x,y)=x^3y`
Expand Down
1 change: 1 addition & 0 deletions python/basix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@

from ._basixcpp import superset as polyset_superset
from ._basixcpp import restriction as polyset_restriction
from .quadrature import make_quadrature
4 changes: 2 additions & 2 deletions test/test_custom_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ def test_raviart_thomas_triangle_degree1():
wcoeffs[0, 0] = 1
wcoeffs[1, 3] = 1

pts, wts = basix.quadrature.make_quadrature(basix.CellType.triangle, 2)
pts, wts = basix.make_quadrature(basix.CellType.triangle, 2)
poly = basix.tabulate_polynomials(basix.PolynomialType.legendre, basix.CellType.triangle, 1, pts)
for i in range(3):
wcoeffs[2, i] = sum(pts[:, 0] * poly[i, :] * wts)
wcoeffs[2, 3 + i] = sum(pts[:, 1] * poly[i, :] * wts)

pts, wts = basix.quadrature.make_quadrature(basix.CellType.interval, 2)
pts, wts = basix.make_quadrature(basix.CellType.interval, 2)

x = [[], [], [], []]
for _ in range(3):
Expand Down
4 changes: 2 additions & 2 deletions test/test_lagrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def test_legendre_lagrange_variant(celltype, degree):
basix.ElementFamily.P, celltype, degree, basix.LagrangeVariant.legendre, discontinuous=True)

# Test that the basis functions are orthogonal
pts, wts = basix.quadrature.make_quadrature(celltype, degree * 2)
pts, wts = basix.make_quadrature(celltype, degree * 2)
values = e.tabulate(0, pts)[0, :, :, 0].T
for i, row_i in enumerate(values):
for j, row_j in enumerate(values):
Expand Down Expand Up @@ -655,7 +655,7 @@ def test_legendre_dpc_variant(celltype, degree):
basix.ElementFamily.DPC, celltype, degree, dpc_variant=basix.DPCVariant.legendre, discontinuous=True)

# Test that the basis functions are orthogonal
pts, wts = basix.quadrature.make_quadrature(celltype, degree * 2)
pts, wts = basix.make_quadrature(celltype, degree * 2)
values = e.tabulate(0, pts)[0, :, :, 0].T
for i, row_i in enumerate(values):
for j, row_j in enumerate(values):
Expand Down
14 changes: 7 additions & 7 deletions test/test_orthonormal_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@pytest.mark.parametrize("order", [1, 2, 3])
def test_quad(order):
Lpts, Lwts = basix.quadrature.make_quadrature(basix.CellType.interval, 2*order + 1)
Lpts, Lwts = basix.make_quadrature(basix.CellType.interval, 2*order + 1)
Qwts = []
Qpts = []
for p, u in zip(Lpts, Lwts):
Expand All @@ -30,7 +30,7 @@ def test_quad(order):

@pytest.mark.parametrize("order", [1, 2, 3, 4])
def test_pyramid(order):
Lpts, Lwts = basix.quadrature.make_quadrature(basix.CellType.interval, 4*order + 2)
Lpts, Lwts = basix.make_quadrature(basix.CellType.interval, 4*order + 2)
Qwts = []
Qpts = []
for p, u in zip(Lpts, Lwts):
Expand All @@ -53,7 +53,7 @@ def test_pyramid(order):

@pytest.mark.parametrize("order", [1, 2, 3])
def test_hex(order):
Lpts, Lwts = basix.quadrature.make_quadrature(basix.CellType.interval, 2*order + 1)
Lpts, Lwts = basix.make_quadrature(basix.CellType.interval, 2*order + 1)
Qwts = []
Qpts = []
for p, u in zip(Lpts, Lwts):
Expand All @@ -75,8 +75,8 @@ def test_hex(order):

@pytest.mark.parametrize("order", [1, 2, 3])
def test_prism(order):
Tpts, Twts = basix.quadrature.make_quadrature(basix.CellType.triangle, 2*order + 1)
Lpts, Lwts = basix.quadrature.make_quadrature(basix.CellType.interval, 2*order + 1)
Tpts, Twts = basix.make_quadrature(basix.CellType.triangle, 2*order + 1)
Lpts, Lwts = basix.make_quadrature(basix.CellType.interval, 2*order + 1)
Qwts = []
Qpts = []
for p, u in zip(Tpts, Twts):
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_prism(order):
])
@pytest.mark.parametrize("order", [0, 1, 2, 3, 4])
def test_standard(cell_type, order):
Qpts, Qwts = basix.quadrature.make_quadrature(cell_type, 2*order + 1)
Qpts, Qwts = basix.make_quadrature(cell_type, 2*order + 1)
basis = basix._basixcpp.tabulate_polynomial_set(
cell_type, basix.PolysetType.standard, order, 0, Qpts)[0]

Expand All @@ -123,7 +123,7 @@ def test_standard(cell_type, order):
])
@pytest.mark.parametrize("order", [0, 1, 2, 3, 4])
def test_macroedge(cell_type, order):
Qpts, Qwts = basix.quadrature.make_quadrature(cell_type, 2*order + 1, polyset_type=basix.PolysetType.macroedge)
Qpts, Qwts = basix.make_quadrature(cell_type, 2*order + 1, polyset_type=basix.PolysetType.macroedge)
basis = basix._basixcpp.tabulate_polynomial_set(
cell_type, basix.PolysetType.macroedge, order, 0, Qpts)[0]

Expand Down
4 changes: 2 additions & 2 deletions test/test_polynomials.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
basix.CellType.tetrahedron, basix.CellType.hexahedron,
])
def test_legendre(cell_type, degree):
points, weights = basix.quadrature.make_quadrature(cell_type, 2 * degree)
points, weights = basix.make_quadrature(cell_type, 2 * degree)

polys = basix.tabulate_polynomials(basix.PolynomialType.legendre, cell_type, degree, points)

Expand Down Expand Up @@ -63,7 +63,7 @@ def evaluate(function, pt):
x**2, x**2 * z, x**2 * z**2], 2],
])
def test_order(cell_type, functions, degree):
points, weights = basix.quadrature.make_quadrature(cell_type, 2 * degree)
points, weights = basix.make_quadrature(cell_type, 2 * degree)
polys = basix.tabulate_polynomials(basix.PolynomialType.legendre, cell_type, degree, points)

assert len(functions) == polys.shape[0]
Expand Down
20 changes: 10 additions & 10 deletions test/test_quadrature.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
(basix.CellType.tetrahedron, 1.0/6.0)])
@pytest.mark.parametrize("order", range(9))
def test_cell_quadrature(celltype, order):
Qpts, Qwts = basix.quadrature.make_quadrature(celltype[0], order)
Qpts, Qwts = basix.make_quadrature(celltype[0], order)
assert np.isclose(sum(Qwts), celltype[1])


@pytest.mark.parametrize("m", range(7))
@pytest.mark.parametrize("scheme", [basix.QuadratureType.Default, basix.QuadratureType.gll])
def test_qorder_line(m, scheme):
Qpts, Qwts = basix.quadrature.make_quadrature(basix.CellType.interval, m, rule=scheme)
Qpts, Qwts = basix.make_quadrature(basix.CellType.interval, m, rule=scheme)
x = sympy.Symbol('x')
f = x**m
q = sympy.integrate(f, (x, 0, (1)))
Expand All @@ -36,7 +36,7 @@ def test_qorder_line(m, scheme):
@pytest.mark.parametrize("m", range(6))
@pytest.mark.parametrize("scheme", [basix.QuadratureType.Default, basix.QuadratureType.gauss_jacobi])
def test_qorder_tri(m, scheme):
Qpts, Qwts = basix.quadrature.make_quadrature(basix.CellType.triangle, m, rule=scheme)
Qpts, Qwts = basix.make_quadrature(basix.CellType.triangle, m, rule=scheme)
x = sympy.Symbol('x')
y = sympy.Symbol('y')
f = x**m + y**m
Expand All @@ -50,7 +50,7 @@ def test_qorder_tri(m, scheme):
@pytest.mark.parametrize("m", range(1, 20))
@pytest.mark.parametrize("scheme", [basix.QuadratureType.xiao_gimbutas])
def test_xiao_gimbutas_tri(m, scheme):
Qpts, Qwts = basix.quadrature.make_quadrature(basix.CellType.triangle, m, rule=scheme)
Qpts, Qwts = basix.make_quadrature(basix.CellType.triangle, m, rule=scheme)
x = sympy.Symbol('x')
y = sympy.Symbol('y')
f = x**m + 2 * y**m
Expand All @@ -64,7 +64,7 @@ def test_xiao_gimbutas_tri(m, scheme):
@pytest.mark.parametrize("m", range(1, 16))
@pytest.mark.parametrize("scheme", [basix.QuadratureType.xiao_gimbutas])
def test_xiao_gimbutas_tet(m, scheme):
Qpts, Qwts = basix.quadrature.make_quadrature(basix.CellType.tetrahedron, m, rule=scheme)
Qpts, Qwts = basix.make_quadrature(basix.CellType.tetrahedron, m, rule=scheme)
x = sympy.Symbol('x')
y = sympy.Symbol('y')
z = sympy.Symbol('z')
Expand All @@ -79,7 +79,7 @@ def test_xiao_gimbutas_tet(m, scheme):
@pytest.mark.parametrize("m", range(9))
@pytest.mark.parametrize("scheme", [basix.QuadratureType.Default, basix.QuadratureType.gauss_jacobi])
def test_qorder_tet(m, scheme):
Qpts, Qwts = basix.quadrature.make_quadrature(basix.CellType.tetrahedron, m, rule=scheme)
Qpts, Qwts = basix.make_quadrature(basix.CellType.tetrahedron, m, rule=scheme)
x = sympy.Symbol('x')
y = sympy.Symbol('y')
z = sympy.Symbol('z')
Expand All @@ -92,7 +92,7 @@ def test_qorder_tet(m, scheme):


def test_quadrature_function():
Qpts, Qwts = basix.quadrature.make_quadrature(basix.CellType.interval, 3)
Qpts, Qwts = basix.make_quadrature(basix.CellType.interval, 3)
# Scale to interval [0.0, 2.0]
Qpts *= 2.0
Qwts *= 2.0
Expand All @@ -109,7 +109,7 @@ def test_gll():
m = 5

# 1D interval
pts, wts = basix.quadrature.make_quadrature(
pts, wts = basix.make_quadrature(
basix.CellType.interval, m+1, rule=basix.QuadratureType.gll)
pts, wts = 2*pts.flatten()-1, 2*wts.flatten()
ref_pts = np.array([-1., 1., -np.sqrt(3/7), 0.0, np.sqrt(3/7)])
Expand All @@ -120,7 +120,7 @@ def test_gll():
assert np.isclose(sum(wts), 2)

# 2D quad
pts, wts = basix.quadrature.make_quadrature(
pts, wts = basix.make_quadrature(
basix.CellType.quadrilateral, m+1, rule=basix.QuadratureType.gll)
pts, wts = 2*pts-1, 4*wts
ref_pts2 = np.array([[x, y] for x in ref_pts for y in ref_pts])
Expand All @@ -131,7 +131,7 @@ def test_gll():
assert np.isclose(sum(wts), 4)

# 3D hex
pts, wts = basix.quadrature.make_quadrature(
pts, wts = basix.make_quadrature(
basix.CellType.hexahedron, m+1, rule=basix.QuadratureType.gll)
pts, wts = 2*pts-1, 8*wts
ref_pts3 = np.array([[x, y, z] for x in ref_pts for y in ref_pts for z in ref_pts])
Expand Down
8 changes: 4 additions & 4 deletions test/test_tensor_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_tensor_product_factorisation_quadrilateral(degree):

# Quadrature degree
Q = 2 * P + 2
points, w = basix.quadrature.make_quadrature(cell_type, Q)
points, w = basix.make_quadrature(cell_type, Q)

# FIXME: This test assumes all factors formed by a single element
perm = factors[1]
Expand All @@ -88,7 +88,7 @@ def test_tensor_product_factorisation_quadrilateral(degree):
assert points.shape[0] == (P+2) * (P+2)

cell1d = element0.cell_type
points, _ = basix.quadrature.make_quadrature(cell1d, Q)
points, _ = basix.make_quadrature(cell1d, Q)
data = element0.tabulate(1, points)
phi0 = data[0, :, :, 0]
dphi0 = data[1, :, :, 0]
Expand Down Expand Up @@ -129,7 +129,7 @@ def test_tensor_product_factorisation_hexahedron(degree):

# Quadrature degree
Q = 2 * P + 2
points, _ = basix.quadrature.make_quadrature(
points, _ = basix.make_quadrature(
basix.CellType.hexahedron, Q)

# FIXME: This test assumes all factors formed by a single element
Expand All @@ -149,7 +149,7 @@ def test_tensor_product_factorisation_hexahedron(degree):
assert points.shape[0] == (P+2) * (P+2) * (P+2)

cell1d = element0.cell_type
points, w = basix.quadrature.make_quadrature(cell1d, Q)
points, w = basix.make_quadrature(cell1d, Q)
data = element0.tabulate(1, points)
phi0 = data[0, :, :, 0]
dphi0 = data[1, :, :, 0]
Expand Down

0 comments on commit 3237ad1

Please sign in to comment.