Skip to content

Commit 52f099f

Browse files
committed
change reference cell
having a different reference cell will strengthen the documentation
1 parent 25fff6b commit 52f099f

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ values = e.tabulate(points)
3232

3333
## Conventions
3434
### Reference cell
35-
The reference cell used by simplefem is the triangle with vertices at (0, 0), (1, 0),
35+
The reference cell used by simplefem is the triangle with vertices at (-1, 0), (1, 0),
3636
and (0, 1).
3737

3838
### Point ordering
@@ -41,13 +41,13 @@ are ordered lexicographically: for example, the points that define a degree 3 el
4141
are arranged like this:
4242

4343
```
44-
9
45-
|\
46-
7 8
47-
| \
48-
4 5 6
49-
| \
50-
0-1-2-3
44+
9
45+
/ \
46+
7 8
47+
/ \
48+
4 5 6
49+
/ \
50+
0---1---2---3
5151
```
5252

5353

simplefem/lagrange.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ def __init__(self, degree):
1212
"""Initialise."""
1313
self.degree = degree
1414
self.evaluation_points = np.array(
15-
[[j / degree, i / degree] for i in range(degree + 1) for j in range(degree + 1 - i)]
15+
[
16+
[(2 * j + i) / degree - 1, i / degree]
17+
for i in range(degree + 1)
18+
for j in range(degree + 1 - i)
19+
]
1620
)
1721

1822
self.coeffs = np.linalg.inv(tabulate(self.evaluation_points, degree))

simplefem/polynomials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def tabulate(points: npt.NDArray[np.float64], degree: int) -> npt.NDArray[np.flo
4444
table = np.zeros(((degree + 1) * (degree + 2) // 2, points.shape[0]))
4545
table[_index(0, 0)] = 1
4646

47-
x = points[:, 0]
47+
x = (points[:, 0] - points[:, 1] + 1) / 2
4848
y = points[:, 1]
4949

5050
for p in range(1, degree + 1):

test/test_lagrange.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def test_lagrange1_element():
1313
x = points[:, 0]
1414
y = points[:, 1]
1515

16-
assert np.allclose(values[0], 1 - x - y)
17-
assert np.allclose(values[1], x)
16+
assert np.allclose(values[0], (1 - x - y) / 2)
17+
assert np.allclose(values[1], (1 + x - y) / 2)
1818
assert np.allclose(values[2], y)
1919

2020

@@ -27,9 +27,16 @@ def test_lagrange2_element():
2727
x = points[:, 0]
2828
y = points[:, 1]
2929

30-
assert np.allclose(values[0], (1 - x - y) * (1 - 2 * x - 2 * y))
31-
assert np.allclose(values[1], 4 * x * (1 - x - y))
32-
assert np.allclose(values[2], x * (2 * x - 1))
33-
assert np.allclose(values[3], 4 * y * (1 - x - y))
34-
assert np.allclose(values[4], 4 * x * y)
30+
assert np.allclose(values[0], (y + x - 1) * (y + x) / 2)
31+
assert np.allclose(values[1], (1 + x - y) * (1 - x - y))
32+
assert np.allclose(values[2], (y - x - 1) * (y - x) / 2)
33+
assert np.allclose(values[3], 2 * y * (1 - x - y))
34+
assert np.allclose(values[4], 2 * y * (1 + x - y))
3535
assert np.allclose(values[5], y * (2 * y - 1))
36+
37+
38+
def test_vertices():
39+
e = lagrange_element(1)
40+
assert np.allclose(e.evaluation_points[0], [-1, 0])
41+
assert np.allclose(e.evaluation_points[1], [1, 0])
42+
assert np.allclose(e.evaluation_points[2], [0, 1])

test/test_orthogonal.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def test_orthogonal(degree):
1111
quadraturerules.Domain.Triangle,
1212
max(1, 2 * degree),
1313
)
14-
pts = pts[:, 1:]
14+
pts = np.array([[p[1] - p[0], p[2]] for p in pts])
1515
values = tabulate(pts, degree)
1616

1717
for i, v_i in enumerate(values):
@@ -26,7 +26,7 @@ def test_orthonormal(degree):
2626
quadraturerules.Domain.Triangle,
2727
max(1, 2 * degree),
2828
)
29-
pts = pts[:, 1:]
29+
pts = np.array([[p[1] - p[0], p[2]] for p in pts])
3030
values = tabulate(pts, degree)
3131

3232
for v in values:
@@ -35,7 +35,7 @@ def test_orthonormal(degree):
3535

3636
@pytest.mark.parametrize("degree", range(6))
3737
def test_not_nan_at_vertices(degree):
38-
pts = np.array([[0, 0], [1, 0], [0, 1]])
38+
pts = np.array([[-1, 0], [1, 0], [0, 1]])
3939

4040
values = tabulate(pts, degree)
4141

0 commit comments

Comments
 (0)