Skip to content

Commit 858f014

Browse files
authored
Add orthonormal polynomials (#190)
* Add function to create orthonormal functions * changelog
1 parent b83fdac commit 858f014

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

CHANGELOG_SINCE_LAST_VERSION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
- Remove svgwrite dependency
2+
- Added normalised orthogonal functions

symfem/polynomials.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,3 +779,18 @@ def orthogonal_basis(
779779
return orthogonal_basis_pyramid(*args)
780780

781781
raise ValueError(f"Unsupported cell type: {cell}")
782+
783+
784+
def orthonormal_basis(
785+
cell, order: int, derivs: int, variables: AxisVariablesNotSingle = None
786+
) -> typing.List[typing.List[ScalarFunction]]:
787+
"""Create a basis of orthonormal polynomials."""
788+
from .create import create_reference
789+
790+
poly = orthogonal_basis(cell, order, derivs, variables)
791+
ref = create_reference(cell)
792+
norms = [sympy.sqrt((f ** 2).integral(ref, x)) for f in poly[0]]
793+
for i, n in enumerate(norms):
794+
for j in range(len(poly)):
795+
poly[j][i] /= n
796+
return poly

test/test_polynomials.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
from symfem import create_element, create_reference
99
from symfem.functions import VectorFunction
10-
from symfem.polynomials import Hcurl_polynomials, Hdiv_polynomials, orthogonal_basis
10+
from symfem.polynomials import (Hcurl_polynomials, Hdiv_polynomials, orthogonal_basis,
11+
orthonormal_basis)
1112
from symfem.symbols import t, x
1213

1314

@@ -120,3 +121,18 @@ def test_orthogonal_polynomial_derivatives(reference, order):
120121
for i, j, k in second_d:
121122
for p, q in zip(polynomials[0], polynomials[i]):
122123
assert p.diff(x[j]).diff(x[k]) == q
124+
125+
126+
@pytest.mark.parametrize("reference", [
127+
"interval", "triangle", "quadrilateral",
128+
"tetrahedron", "hexahedron", "prism",
129+
"pyramid"])
130+
@pytest.mark.parametrize("order", range(3))
131+
def test_orthonormal_polynomials(reference, order, speed):
132+
if speed == "fast" and order > 2:
133+
pytest.skip()
134+
135+
polynomials = orthonormal_basis(reference, order, 0)[0]
136+
ref = create_reference(reference)
137+
for p in polynomials:
138+
assert (p ** 2).integral(ref, x) == 1

0 commit comments

Comments
 (0)