Skip to content

Commit eb8407b

Browse files
mscroggsjorgensd
andauthored
get vertex quadrature from basix (#736)
* get vertex quadrature from basix * Update ffcx/ir/representation.py correction * Update ffcx/ir/representation.py Co-authored-by: Jørgen Schartum Dokken <dokken@simula.no> * ) * ruff --------- Co-authored-by: Jørgen Schartum Dokken <dokken@simula.no>
1 parent 7164d8c commit eb8407b

File tree

1 file changed

+6
-51
lines changed

1 file changed

+6
-51
lines changed

ffcx/ir/representation.py

+6-51
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import typing
2323
import warnings
2424

25+
import basix
2526
import numpy as np
2627
import numpy.typing as npt
2728
import ufl
@@ -256,8 +257,6 @@ def _compute_integral_ir(
256257
points = md["quadrature_points"]
257258
weights = md["quadrature_weights"]
258259
elif scheme == "vertex":
259-
# FIXME: Could this come from basix?
260-
261260
# The vertex scheme, i.e., averaging the function value in the
262261
# vertices and multiplying with the simplex volume, is only of
263262
# order 1 and inferior to other generic schemes in terms of
@@ -276,55 +275,11 @@ def _compute_integral_ir(
276275
"Explicitly selected vertex quadrature (degree 1), "
277276
f"but requested degree is {degree}."
278277
)
279-
if cellname == "tetrahedron":
280-
points, weights = (
281-
np.array(
282-
[[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
283-
),
284-
np.array([1.0 / 24.0, 1.0 / 24.0, 1.0 / 24.0, 1.0 / 24.0]),
285-
)
286-
elif cellname == "triangle":
287-
points, weights = (
288-
np.array([[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]]),
289-
np.array([1.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0]),
290-
)
291-
elif cellname == "interval":
292-
# Trapezoidal rule
293-
points, weights = (np.array([[0.0], [1.0]]), np.array([1.0 / 2.0, 1.0 / 2.0]))
294-
elif cellname == "quadrilateral":
295-
points, weights = (
296-
np.array([[0.0, 0], [1.0, 0.0], [0.0, 1.0], [1.0, 1]]),
297-
np.array([1.0 / 4.0, 1.0 / 4.0, 1.0 / 4.0, 1.0 / 4.0]),
298-
)
299-
elif cellname == "hexahedron":
300-
points, weights = (
301-
np.array(
302-
[
303-
[0.0, 0.0, 0.0],
304-
[1.0, 0.0, 0.0],
305-
[0.0, 1.0, 0.0],
306-
[1.0, 1.0, 0.0],
307-
[0.0, 0.0, 1.0],
308-
[1.0, 0.0, 1.0],
309-
[0.0, 1.0, 1.0],
310-
[1.0, 1.0, 1.0],
311-
]
312-
),
313-
np.array(
314-
[
315-
1.0 / 8.0,
316-
1.0 / 8.0,
317-
1.0 / 8.0,
318-
1.0 / 8.0,
319-
1.0 / 8.0,
320-
1.0 / 8.0,
321-
1.0 / 8.0,
322-
1.0 / 8.0,
323-
]
324-
),
325-
)
326-
else:
327-
raise RuntimeError(f"Vertex scheme is not supported for cell: {cellname}")
278+
points = basix.cell.geometry(getattr(basix.CellType, cellname))
279+
cell_volume = basix.cell.volume(getattr(basix.CellType, cellname))
280+
weights = np.full(
281+
points.shape[0], cell_volume / points.shape[0], dtype=points.dtype
282+
)
328283
else:
329284
degree = md["quadrature_degree"]
330285
points, weights, tensor_factors = create_quadrature_points_and_weights(

0 commit comments

Comments
 (0)