From 6285f2fc41aa63da1358686e80a2e5b2aff4febd Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Fri, 17 Jul 2020 11:00:40 -0500
Subject: [PATCH] Allow getting mode IDs from the element group

---
 meshmode/discretization/__init__.py     |  6 +++++
 meshmode/discretization/poly_element.py | 35 ++++++++++++++++++++++---
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/meshmode/discretization/__init__.py b/meshmode/discretization/__init__.py
index d19e5b92..31f2deee 100644
--- a/meshmode/discretization/__init__.py
+++ b/meshmode/discretization/__init__.py
@@ -126,6 +126,12 @@ class InterpolatoryElementGroupBase(ElementGroupBase):
     """A subclass of :class:`ElementGroupBase` that is equipped with a
     function space.
 
+    .. method:: mode_ids()
+
+        Return an immutable sequence of opaque (hashable) mode identifiers,
+        one per element of the :meth:`basis`. The meaning of the mode
+        identifiers is defined by the concrete element group.
+
     .. method:: basis()
 
         Returns a :class:`list` of basis functions that take arrays
diff --git a/meshmode/discretization/poly_element.py b/meshmode/discretization/poly_element.py
index e317e311..5845445d 100644
--- a/meshmode/discretization/poly_element.py
+++ b/meshmode/discretization/poly_element.py
@@ -110,11 +110,20 @@ class PolynomialSimplexElementGroupBase(PolynomialElementGroupBase,
     def is_orthogonal_basis(self):
         return self.dim <= 3
 
-    def basis(self):
+    @memoize_method
+    def _mode_ids_and_basis(self):
         if self.dim <= 3:
-            return mp.simplex_onb(self.dim, self.order)
+            return mp.simplex_onb_with_mode_ids(self.dim, self.order)
         else:
-            return mp.simplex_monomial_basis(self.dim, self.order)
+            return mp.simplex_monomial_basis_with_mode_ids(self.dim, self.order)
+
+    def basis(self):
+        mode_ids, basis = self._mode_ids_and_basis()
+        return basis
+
+    def mode_ids(self):
+        mode_ids, basis = self._mode_ids_and_basis()
+        return mode_ids
 
     def grad_basis(self):
         if self.dim <= 3:
@@ -129,6 +138,10 @@ class InterpolatoryQuadratureSimplexElementGroup(PolynomialSimplexElementGroupBa
     hence usable for differentiation and interpolation.
 
     No interpolation nodes are present on the boundary of the simplex.
+
+    The :meth:`~meshmode.discretization.InterpolatoryElementGroupBase.mode_ids`
+    are a tuple (one entry per dimension) of directional polynomial degrees
+    on the reference element.
     """
 
     @memoize_method
@@ -165,6 +178,10 @@ class QuadratureSimplexElementGroup(SimplexElementGroupBase):
     quadarature, but is not necessarily usable for interpolation.
 
     No interpolation nodes are present on the boundary of the simplex.
+
+    The :meth:`~meshmode.discretization.InterpolatoryElementGroupBase.mode_ids`
+    are a tuple (one entry per dimension) of directional polynomial degrees
+    on the reference element.
     """
 
     @memoize_method
@@ -211,6 +228,10 @@ class PolynomialWarpAndBlendElementGroup(_MassMatrixQuadratureElementGroup):
     phenomena. Nodes are present on the boundary of the simplex.
 
     Uses :func:`modepy.warp_and_blend_nodes`.
+
+    The :meth:`~meshmode.discretization.InterpolatoryElementGroupBase.mode_ids`
+    are a tuple (one entry per dimension) of directional polynomial degrees
+    on the reference element.
     """
     @property
     @memoize_method
@@ -238,6 +259,10 @@ class PolynomialRecursiveNodesElementGroup(_MassMatrixQuadratureElementGroup):
 
     Requires :mod:`recursivenodes` to be installed.
 
+    The :meth:`~meshmode.discretization.InterpolatoryElementGroupBase.mode_ids`
+    are a tuple (one entry per dimension) of directional polynomial degrees
+    on the reference element.
+
     .. [Isaac20] Tobin Isaac. Recursive, parameter-free, explicitly defined
         interpolation nodes for simplices.
         `Arxiv preprint <https://arxiv.org/abs/2002.09421>`__.
@@ -268,6 +293,10 @@ class PolynomialEquidistantSimplexElementGroup(_MassMatrixQuadratureElementGroup
     interpolation. Interpolation nodes are present on the boundary of the
     simplex.
 
+    The :meth:`~meshmode.discretization.InterpolatoryElementGroupBase.mode_ids`
+    are a tuple (one entry per dimension) of directional polynomial degrees
+    on the reference element.
+
     .. versionadded:: 2016.1
     """
     @property
-- 
GitLab