Skip to content

Commit

Permalink
default to GX except for tetrahedron degree=3
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrubeck committed Dec 1, 2023
1 parent 717b974 commit c7fdfb0
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions FIAT/quadrature_schemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,8 @@ def xg_scheme(ref_el, degree):
http://dx.doi.org/10.1016/j.camwa.2009.10.027
"""
dim = ref_el.get_spatial_dimension()
if dim == 2:
if dim == 2 or dim == 3:
from FIAT.xg_quad_data import triangle_table as table
elif dim == 3:
from FIAT.xg_quad_data import tetrahedron_table as table
else:
raise ValueError(f"Xiao-Gambutas rule not availale for {dim} dimensions.")
try:
Expand All @@ -350,18 +348,17 @@ def xg_scheme(ref_el, degree):

# Get affine map from the (-1,1)^d triangle to the G-X equilateral triangle
if dim == 2:
A = numpy.array([[1, -1/numpy.sqrt(3)],
[0, 2/numpy.sqrt(3)]])
b = numpy.array([-1/3, -1/3])
A = numpy.array([[1, 1/2],
[0, numpy.sqrt(3)/2]])
b = A.sum(axis=1)/3
else:
A = numpy.array([[1, -1/numpy.sqrt(3), -1/numpy.sqrt(6)],
[0, 2/numpy.sqrt(3), -1/numpy.sqrt(6)],
[0, 0, numpy.sqrt(6)/2]])
b = numpy.array([-1/2, -1/2, -1/2])
A = numpy.array([[1, 1/2, 1/2],
[0, numpy.sqrt(3)/2, numpy.sqrt(3)/6],
[0, 0, numpy.sqrt(6)/3]])
b = A.sum(axis=1)/2

A = numpy.linalg.inv(A)
Ref1 = default_simplex(dim)
v = numpy.dot(numpy.array(Ref1.vertices) - b[None, :], A.T)
v = numpy.dot(Ref1.vertices, A.T) + b[None, :]
Ref1.vertices = tuple(map(tuple, v))

pts_ref = order_table["points"]
Expand All @@ -373,6 +370,11 @@ def xg_scheme(ref_el, degree):
def _triangle_scheme(ref_el, degree):
"""Return a quadrature scheme on a triangle of specified order. Falls
back on canonical rule for higher orders."""
try:
# Get Xiao-Gambutas scheme
return xg_scheme(ref_el, degree)
except ValueError:
pass

if degree == 0 or degree == 1:
# Scheme from Zienkiewicz and Taylor, 1 point, degree of precision 1
Expand Down Expand Up @@ -441,12 +443,8 @@ def _triangle_scheme(ref_el, degree):
w[6:12] = 0.082851075618374
w = w/2.0
else:
try:
# Get Xiao-Gambutas scheme
return xg_scheme(ref_el, degree)
except ValueError:
# Get canonical scheme
return _fiat_scheme(ref_el, degree)
# Get canonical scheme
return _fiat_scheme(ref_el, degree)

# Return scheme
x, w = map_quadrature(x, w, UFCTriangle(), ref_el)
Expand All @@ -456,6 +454,12 @@ def _triangle_scheme(ref_el, degree):
def _tetrahedron_scheme(ref_el, degree):
"""Return a quadrature scheme on a tetrahedron of specified
degree. Falls back on canonical rule for higher orders"""
if degree != 3:
try:
# Get Xiao-Gambutas scheme
return xg_scheme(ref_el, degree)
except ValueError:
pass

if degree == 0 or degree == 1:
# Scheme from Zienkiewicz and Taylor, 1 point, degree of precision 1
Expand Down Expand Up @@ -565,12 +569,8 @@ def _tetrahedron_scheme(ref_el, degree):
w[12:24] = 0.0482142857142857
w = w/6.0
else:
try:
# Get Xiao-Gambutas scheme
return xg_scheme(ref_el, degree)
except ValueError:
# Get canonical scheme
return _fiat_scheme(ref_el, degree)
# Get canonical scheme
return _fiat_scheme(ref_el, degree)

# Return scheme
x, w = map_quadrature(x, w, UFCTetrahedron(), ref_el)
Expand Down

0 comments on commit c7fdfb0

Please sign in to comment.