From c4f46abac8d62dd63aeb2d3700cc91d79a1fc440 Mon Sep 17 00:00:00 2001
From: Thomas Gibson <gibsonthomas1120@hotmail.com>
Date: Mon, 24 May 2021 11:54:58 -0500
Subject: [PATCH] Add normals/nodes to dcoll

---
 grudge/discretization.py | 38 ++++++++++++++++++++++++++++++++++++--
 grudge/eager.py          |  6 ------
 grudge/op.py             | 11 +++--------
 3 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/grudge/discretization.py b/grudge/discretization.py
index 47b425e6..fe9a52b9 100644
--- a/grudge/discretization.py
+++ b/grudge/discretization.py
@@ -32,8 +32,12 @@ THE SOFTWARE.
 from pytools import memoize_method
 
 from grudge.dof_desc import (
-    DISCR_TAG_BASE, DISCR_TAG_MODAL,
-    DTAG_BOUNDARY, DOFDesc, as_dofdesc
+    DD_VOLUME,
+    DISCR_TAG_BASE,
+    DISCR_TAG_MODAL,
+    DTAG_BOUNDARY,
+    DOFDesc,
+    as_dofdesc
 )
 
 import numpy as np  # noqa: F401
@@ -69,6 +73,9 @@ class DiscretizationCollection:
 
     .. automethod:: empty
     .. automethod:: zeros
+
+    .. automethod:: nodes
+    .. automethod:: normal
     """
 
     def __init__(self, array_context: ArrayContext, mesh: Mesh,
@@ -601,6 +608,33 @@ class DiscretizationCollection:
         from pytools import single_valued
         return single_valued(egrp.order for egrp in self._volume_discr.groups)
 
+    # {{{ Discretization-specific geometric properties
+
+    def nodes(self, dd=None):
+        r"""Return the nodes of a discretization specified by *dd*.
+
+        :arg dd: a :class:`~grudge.dof_desc.DOFDesc`, or a value convertible to one.
+            Defaults to the base volume discretization.
+        :returns: an object array of :class:`~meshmode.dof_array.DOFArray`\ s
+        """
+        if dd is None:
+            dd = DD_VOLUME
+        return self.discr_from_dd(dd).nodes()
+
+    @memoize_method
+    def normal(self, dd):
+        r"""Get the unit normal to the specified surface discretization, *dd*.
+
+        :arg dd: a :class:`~grudge.dof_desc.DOFDesc` as the surface discretization.
+        :returns: an object array of :class:`~meshmode.dof_array.DOFArray`\ s.
+        """
+        from arraycontext import freeze
+        from grudge.geometry import normal
+
+        return freeze(normal(self._setup_actx, self, dd))
+
+    # }}}
+
 
 class DGDiscretizationWithBoundaries(DiscretizationCollection):
     def __init__(self, *args, **kwargs):
diff --git a/grudge/eager.py b/grudge/eager.py
index 22dd4298..1886cfd0 100644
--- a/grudge/eager.py
+++ b/grudge/eager.py
@@ -47,12 +47,6 @@ class EagerDGDiscretization(DiscretizationCollection):
     def project(self, src, tgt, vec):
         return op.project(self, src, tgt, vec)
 
-    def nodes(self, dd=None):
-        return op.nodes(self, dd)
-
-    def normal(self, dd):
-        return op.normal(self, dd)
-
     def grad(self, vec):
         return op.local_grad(self, vec)
 
diff --git a/grudge/op.py b/grudge/op.py
index 3929503f..104ae3b1 100644
--- a/grudge/op.py
+++ b/grudge/op.py
@@ -89,8 +89,7 @@ from functools import reduce
 from arraycontext import (
     ArrayContext,
     FirstAxisIsElementsTag,
-    make_loopy_program,
-    freeze
+    make_loopy_program
 )
 
 from grudge.discretization import DiscretizationCollection
@@ -183,20 +182,16 @@ def nodes(dcoll: DiscretizationCollection, dd=None) -> np.ndarray:
         dd = dof_desc.DD_VOLUME
     dd = dof_desc.as_dofdesc(dd)
 
-    return dcoll.discr_from_dd(dd).nodes()
+    return dcoll.nodes(dd)
 
 
-@memoize_on_first_arg
 def normal(dcoll: DiscretizationCollection, dd) -> np.ndarray:
     r"""Get the unit normal to the specified surface discretization, *dd*.
 
     :arg dd: a :class:`~grudge.dof_desc.DOFDesc` as the surface discretization.
     :returns: an object array of :class:`~meshmode.dof_array.DOFArray`\ s.
     """
-    from grudge.geometry import normal
-
-    actx = dcoll.discr_from_dd(dd)._setup_actx
-    return freeze(normal(actx, dcoll, dd))
+    return dcoll.normal(dd)
 
 
 @memoize_on_first_arg
-- 
GitLab