Created
November 20, 2024 14:49
-
-
Save jhale/def1036e238cc2568cdcccd96bf632d5 to your computer and use it in GitHub Desktop.
Numerical Methods for Variational Problems - Canonical Ordering Nodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def lagrange_points(cell, degree): | |
| """Construct the locations of the equispaced Lagrange nodes on cell. | |
| :param cell: the :class:`~.reference_elements.ReferenceCell` | |
| :param degree: the degree of polynomials for which to construct nodes. | |
| :returns: a rank 2 :class:`~numpy.array` whose rows are the | |
| coordinates of the nodes. | |
| The implementation of this function is left as an :ref:`exercise | |
| <ex-lagrange-points>`. | |
| """ | |
| if cell is ReferenceInterval: | |
| points = [[i / degree] for i in range(degree + 1)] | |
| points_mapped = [] | |
| for dim in range(0, cell.dim + 1): | |
| for entity in range(0, cell.entity_counts[dim]): | |
| for point in points: | |
| if cell.point_in_entity(point, (dim, entity)) and point not in points_mapped: | |
| points_mapped.append(point) | |
| return np.array(points_mapped, dtype=np.float64) | |
| elif cell is ReferenceTriangle: | |
| points = [[i / degree, j / degree] | |
| for j in range(degree + 1) | |
| for i in range(degree + 1 - j)] | |
| points_mapped = [] | |
| for dim in range(0, cell.dim + 1): | |
| for entity in range(0, cell.entity_counts[dim]): | |
| for point in points: | |
| if cell.point_in_entity(point, (dim, entity)) and point not in points_mapped: | |
| points_mapped.append(point) | |
| return np.array(points_mapped, dtype=np.float64) | |
| else: | |
| return NotImplementedError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment