From 75ff300d7595a3e265648aa4a962c45bdcca6b79 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 18:02:45 -0500 Subject: [PATCH 01/14] Git ignore json files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 94648fab..14be95d1 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ run-debug-* .cache .pytest_cache + +*.json -- GitLab From e8f42f84fe22c49f8ba9b58da5f8fd18defac94d Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 18:03:01 -0500 Subject: [PATCH 02/14] Fix a missing word in discr.order deprecation message --- grudge/discretization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grudge/discretization.py b/grudge/discretization.py index 7c0573c2..67c87273 100644 --- a/grudge/discretization.py +++ b/grudge/discretization.py @@ -390,7 +390,7 @@ class DGDiscretizationWithBoundaries(DiscretizationBase): def order(self): from warnings import warn warn("DGDiscretizationWithBoundaries.order is deprecated, " - "consider the orders of element groups instead. " + "consider using the orders of element groups instead. " "'order' will go away in 2021.", DeprecationWarning, stacklevel=2) -- GitLab From 5d6b6e90d1e036f9881ca080f745975241d8402f Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 18:03:35 -0500 Subject: [PATCH 03/14] Add eager reductions to doc index --- grudge/eager.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/grudge/eager.py b/grudge/eager.py index 87368161..a79d9c7a 100644 --- a/grudge/eager.py +++ b/grudge/eager.py @@ -54,6 +54,11 @@ class EagerDGDiscretization(DGDiscretizationWithBoundaries): .. automethod:: normal .. automethod:: inverse_mass .. automethod:: face_mass + + .. automethod:: norm + .. automethod:: nodal_sum + .. automethod:: nodal_min + .. automethod:: nodal_max """ def interp(self, src, tgt, vec): -- GitLab From 3934cfd6dc69fcc022a23652344ac2683f506ff5 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 18:04:03 -0500 Subject: [PATCH 04/14] Eager nodes: allow passing dd --- grudge/eager.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/grudge/eager.py b/grudge/eager.py index a79d9c7a..407c182e 100644 --- a/grudge/eager.py +++ b/grudge/eager.py @@ -77,8 +77,17 @@ class EagerDGDiscretization(DGDiscretizationWithBoundaries): return self.connection_from_dds(src, tgt)(vec) - def nodes(self): - return self._volume_discr.nodes() + def nodes(self, dd=None): + r"""Return the nodes of a discretization. + + :arg dd: a :class:`~grudge.sym.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: + return self._volume_discr.nodes() + else: + return self.discr_from_dd(dd).nodes() @memoize_method def _bound_grad(self): -- GitLab From 5b8020c7c18996437d9839c8f15ba1e0710ddb6f Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 18:06:05 -0500 Subject: [PATCH 05/14] Add documentation on eager derivatives --- grudge/eager.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/grudge/eager.py b/grudge/eager.py index 407c182e..5fcd3a61 100644 --- a/grudge/eager.py +++ b/grudge/eager.py @@ -69,6 +69,14 @@ class EagerDGDiscretization(DGDiscretizationWithBoundaries): return self.project(src, tgt, vec) def project(self, src, tgt, vec): + """Project from one discretization to another, e.g. from the + volume to the boundary, or from the base to the an overintegrated + quadrature discretization. + + :arg src: a :class:`~grudge.sym.DOFDesc`, or a value convertible to one + :arg tgt: a :class:`~grudge.sym.DOFDesc`, or a value convertible to one + :arg vec: a :class:`~meshmode.dof_array.DOFArray` + """ if (isinstance(vec, np.ndarray) and vec.dtype.char == "O" and not isinstance(vec, DOFArray)): @@ -94,11 +102,25 @@ class EagerDGDiscretization(DGDiscretizationWithBoundaries): return bind(self, sym.nabla(self.dim) * sym.Variable("u"), local_only=True) def grad(self, vec): + r"""Return the gradient of the volume function represented by *vec*. + + :arg vec: a :class:`~meshmode.dof_array.DOFArray` + :returns: an object array of :class:`~meshmode.dof_array.DOFArray`\ s + """ return self._bound_grad()(u=vec) def div(self, vecs): return sum( self.grad(vec_i)[i] for i, vec_i in enumerate(vecs)) + r"""Return the divergence of the vector volume function + represented by *vecs*. + + :arg vec: an object array of + a :class:`~meshmode.dof_array.DOFArray`\ s, + where the last axis of the array must have length + matching the volume dimension. + :returns: a :class:`~meshmode.dof_array.DOFArray` + """ @memoize_method def _bound_weak_grad(self, dd): @@ -107,6 +129,16 @@ class EagerDGDiscretization(DGDiscretizationWithBoundaries): local_only=True) def weak_grad(self, *args): + r"""Return the "weak gradient" of the volume function represented by + *vec*. + + May be called with ``(vecs)`` or ``(dd, vecs)``. + + :arg dd: a :class:`~grudge.sym.DOFDesc`, or a value convertible to one. + Defaults to the base volume discretization if not provided. + :arg vec: a :class:`~meshmode.dof_array.DOFArray` + :returns: an object array of :class:`~meshmode.dof_array.DOFArray`\ s + """ if len(args) == 1: vec, = args dd = sym.DOFDesc("vol", sym.QTAG_NONE) @@ -118,6 +150,19 @@ class EagerDGDiscretization(DGDiscretizationWithBoundaries): return self._bound_weak_grad(dd)(u=vec) def weak_div(self, *args): + r"""Return the "weak divergence" of the vector volume function + represented by *vecs*. + + May be called with ``(vecs)`` or ``(dd, vecs)``. + + :arg dd: a :class:`~grudge.sym.DOFDesc`, or a value convertible to one. + Defaults to the base volume discretization if not provided. + :arg vec: a object array of + a :class:`~meshmode.dof_array.DOFArray`\ s, + where the last axis of the array must have length + matching the volume dimension. + :returns: a :class:`~meshmode.dof_array.DOFArray` + """ if len(args) == 1: vecs, = args dd = sym.DOFDesc("vol", sym.QTAG_NONE) -- GitLab From 3d858e9dbcf499475c1d9eae97abbfebd3916aa7 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 18:06:36 -0500 Subject: [PATCH 06/14] Add some sectioning comments in grudge.eager --- grudge/eager.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/grudge/eager.py b/grudge/eager.py index 5fcd3a61..8f0c624d 100644 --- a/grudge/eager.py +++ b/grudge/eager.py @@ -97,6 +97,8 @@ class EagerDGDiscretization(DGDiscretizationWithBoundaries): else: return self.discr_from_dd(dd).nodes() + # {{{ derivatives + @memoize_method def _bound_grad(self): return bind(self, sym.nabla(self.dim) * sym.Variable("u"), local_only=True) @@ -174,6 +176,8 @@ class EagerDGDiscretization(DGDiscretizationWithBoundaries): return sum( self.weak_grad(dd, vec_i)[i] for i, vec_i in enumerate(vecs)) + # }}} + @memoize_method def normal(self, dd): surface_discr = self.discr_from_dd(dd) @@ -280,6 +284,8 @@ def interior_trace_pair(discrwb, vec): return TracePair("int_faces", i, e) +# {{{ distributed-memory functionality + class _RankBoundaryCommunication: base_tag = 1273 @@ -354,5 +360,7 @@ def cross_rank_trace_pairs(discrwb, vec, tag=None): else: return _cross_rank_trace_pairs_scalar_field(discrwb, vec, tag=tag) +# }}} + # vim: foldmethod=marker -- GitLab From 236e5571aec158902625a536402d3f6bde5d7415 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 18:07:10 -0500 Subject: [PATCH 07/14] Add per-axis eager derivatives, make divergence use them, allow divergence of nD arrays --- grudge/eager.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/grudge/eager.py b/grudge/eager.py index 8f0c624d..1a845fc9 100644 --- a/grudge/eager.py +++ b/grudge/eager.py @@ -47,10 +47,15 @@ class EagerDGDiscretization(DGDiscretizationWithBoundaries): """ .. automethod:: project .. automethod:: nodes + .. automethod:: grad + .. automethod:: d_dx .. automethod:: div + .. automethod:: weak_grad + .. automethod:: weak_d_dx .. automethod:: weak_div + .. automethod:: normal .. automethod:: inverse_mass .. automethod:: face_mass @@ -111,9 +116,41 @@ class EagerDGDiscretization(DGDiscretizationWithBoundaries): """ return self._bound_grad()(u=vec) + @memoize_method + def _bound_d_dx(self, xyz_axis): + return bind(self, sym.nabla(self.dim)[xyz_axis] * sym.Variable("u"), + local_only=True) + + def d_dx(self, xyz_axis, vec): + r"""Return the derivative along axis *xyz_axis* of the volume function + represented by *vec*. + + :arg xyz_axis: an integer indicating the axis along which the derivative + is taken + :arg vec: a :class:`~meshmode.dof_array.DOFArray` + :returns: a :class:`~meshmode.dof_array.DOFArray`\ s + """ + return self._bound_d_dx(xyz_axis)(u=vec) + + def _div_helper(self, diff_func, vecs): + if not isinstance(vecs, np.ndarray): + raise TypeError("argument must be an object array") + assert vecs.dtype == np.object + + if vecs.shape[-1] != self.ambient_dim: + raise ValueError("last dimension of *vecs* argument must match " + "ambient dimension") + + if len(vecs.shape) == 1: + return sum(diff_func(i, vec_i) for i, vec_i in enumerate(vecs)) + else: + result = np.zeros(vecs.shape[:-1], dtype=object) + for idx in np.ndindex(vecs.shape[:-1]): + result[idx] = sum( + diff_func(i, vec_i) for i, vec_i in enumerate(vecs[idx])) + return result + def div(self, vecs): - return sum( - self.grad(vec_i)[i] for i, vec_i in enumerate(vecs)) r"""Return the divergence of the vector volume function represented by *vecs*. @@ -124,6 +161,10 @@ class EagerDGDiscretization(DGDiscretizationWithBoundaries): :returns: a :class:`~meshmode.dof_array.DOFArray` """ + return self._div_helper( + lambda i, subvec: self.d_dx(i, subvec), + vecs) + @memoize_method def _bound_weak_grad(self, dd): return bind(self, @@ -151,6 +192,34 @@ class EagerDGDiscretization(DGDiscretizationWithBoundaries): return self._bound_weak_grad(dd)(u=vec) + @memoize_method + def _bound_weak_d_dx(self, dd, xyz_axis): + return bind(self, + sym.stiffness_t(self.dim, dd_in=dd)[xyz_axis] + * sym.Variable("u", dd), + local_only=True) + + def weak_d_dx(self, *args): + r"""Return the derivative along axis *xyz_axis* of the volume function + represented by *vec*. + + May be called with ``(xyz_axis, vecs)`` or ``(dd, xyz_axis, vecs)``. + + :arg xyz_axis: an integer indicating the axis along which the derivative + is taken + :arg vec: a :class:`~meshmode.dof_array.DOFArray` + :returns: a :class:`~meshmode.dof_array.DOFArray`\ s + """ + if len(args) == 2: + xyz_axis, vec = args + dd = sym.DOFDesc("vol", sym.QTAG_NONE) + elif len(args) == 3: + dd, xyz_axis, vec = args + else: + raise TypeError("invalid number of arguments") + + return self._bound_weak_d_dx(dd, xyz_axis)(u=vec) + def weak_div(self, *args): r"""Return the "weak divergence" of the vector volume function represented by *vecs*. @@ -173,8 +242,9 @@ class EagerDGDiscretization(DGDiscretizationWithBoundaries): else: raise TypeError("invalid number of arguments") - return sum( - self.weak_grad(dd, vec_i)[i] for i, vec_i in enumerate(vecs)) + return self._div_helper( + lambda i, subvec: self.weak_d_dx(dd, i, subvec), + vecs) # }}} -- GitLab From a674d26d7400e3cad48a10e0bdfcdb4045627cdc Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 18:19:55 -0500 Subject: [PATCH 08/14] Add github doc job --- .github/workflows/ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f0f630b..8f93ba12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,19 @@ jobs: build_py_project_in_conda_env run_examples + docs: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: "Main Script" + run: | + CONDA_ENVIRONMENT=.test-conda-env-py3.yml + curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/ci-support.sh + . ci-support.sh + build_py_project_in_conda_env + build_docs + # vim: sw=4 -- GitLab From c266096becdd786715fe5c6ded07e17f00c5cdfb Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 18:20:05 -0500 Subject: [PATCH 09/14] Run Gitlab doc job on all branches --- .gitlab-ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 66fc4e49..ebe42624 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -128,8 +128,6 @@ Documentation: - ". ./build-docs.sh" tags: - python3 - only: - - master Flake8: script: -- GitLab From 68b67983f94d153cc01d555e3de72e2141c9a5cf Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 21:31:59 -0500 Subject: [PATCH 10/14] Install MPI for doc Github CI job --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f93ba12..25e262d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,8 @@ jobs: - uses: actions/checkout@v2 - name: "Main Script" run: | + sudo apt-get update + sudo apt-get install openmpi-bin libopenmpi-dev CONDA_ENVIRONMENT=.test-conda-env-py3.yml curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/ci-support.sh . ci-support.sh -- GitLab From f846899d98255433d4dd7e7ff6b782c0d948bb28 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 21:32:26 -0500 Subject: [PATCH 11/14] Set doc autoclass_content to 'class' --- doc/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index d75d2aa2..dc8f0e24 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -170,7 +170,7 @@ html_sidebars = { # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +#html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied @@ -327,4 +327,4 @@ intersphinx_mapping = { 'https://documen.tician.de/meshmode/': None, 'http://documen.tician.de/loopy/': None, } -autoclass_content = "both" +autoclass_content = "class" -- GitLab From 4fcd12b7c0dbbce089f46e67e06ac1d6f16936ab Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 21:33:22 -0500 Subject: [PATCH 12/14] Discretization docs --- doc/discretization.rst | 12 ++++++++++++ doc/eager.rst | 5 ----- doc/index.rst | 4 ++-- grudge/discretization.py | 10 +++++----- grudge/eager.py | 3 +++ 5 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 doc/discretization.rst delete mode 100644 doc/eager.rst diff --git a/doc/discretization.rst b/doc/discretization.rst new file mode 100644 index 00000000..41411134 --- /dev/null +++ b/doc/discretization.rst @@ -0,0 +1,12 @@ +Discretization +============== + +.. module:: grudge + +.. automodule:: grudge.discretization + +Discretization with Eager Evaluation +==================================== + +.. automodule:: grudge.eager + diff --git a/doc/eager.rst b/doc/eager.rst deleted file mode 100644 index 5d2bdd5b..00000000 --- a/doc/eager.rst +++ /dev/null @@ -1,5 +0,0 @@ -Eagerly-evaluated Operation -=========================== - -.. automodule:: grudge.eager - diff --git a/doc/index.rst b/doc/index.rst index 6d7782bc..7b6ce79d 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -6,9 +6,9 @@ Contents: .. toctree:: :maxdepth: 2 - misc + discretization symbolic - eager + misc Indices and Tables diff --git a/grudge/discretization.py b/grudge/discretization.py index 67c87273..58ae9f82 100644 --- a/grudge/discretization.py +++ b/grudge/discretization.py @@ -30,12 +30,12 @@ import numpy as np # noqa: F401 from meshmode.array_context import ArrayContext -# FIXME Naming not ideal -class DiscretizationBase(object): - pass +__doc__ = """ +.. autoclass:: DGDiscretizationWithBoundaries +""" -class DGDiscretizationWithBoundaries(DiscretizationBase): +class DGDiscretizationWithBoundaries(object): """ .. automethod :: discr_from_dd .. automethod :: connection_from_dds @@ -53,7 +53,7 @@ class DGDiscretizationWithBoundaries(DiscretizationBase): """ :param quad_tag_to_group_factory: A mapping from quadrature tags (typically strings--but may be any hashable/comparable object) to a - :class:`meshmode.discretization.ElementGroupFactory` indicating with + :class:`~meshmode.discretization.poly_element.ElementGroupFactory` indicating with which quadrature discretization the operations are to be carried out, or *None* to indicate that operations with this quadrature tag should be carried out with the standard volume discretization. diff --git a/grudge/eager.py b/grudge/eager.py index 1a845fc9..4cff62c5 100644 --- a/grudge/eager.py +++ b/grudge/eager.py @@ -45,6 +45,9 @@ __doc__ = """ class EagerDGDiscretization(DGDiscretizationWithBoundaries): """ + Inherits from :class:`~grudge.discretization.DGDiscretizationWithBoundaries`. + + .. automethod:: __init__ .. automethod:: project .. automethod:: nodes -- GitLab From 005aa131299c74231c9797343982be1c2a5d1e08 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 21:33:43 -0500 Subject: [PATCH 13/14] Doc fixes --- grudge/symbolic/operators.py | 9 ++++++--- grudge/symbolic/primitives.py | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/grudge/symbolic/operators.py b/grudge/symbolic/operators.py index 4ecd920c..df886d45 100644 --- a/grudge/symbolic/operators.py +++ b/grudge/symbolic/operators.py @@ -94,12 +94,12 @@ class Operator(pymbolic.primitives.Expression): """ .. attribute:: dd_in - an instance of :class:`~grudge.symbolic.primitives.DOFDesc` describing the + an instance of :class:`~grudge.sym.DOFDesc` describing the input discretization. .. attribute:: dd_out - an instance of :class:`~grudge.symbolic.primitives.DOFDesc` describing the + an instance of :class:`~grudge.sym.DOFDesc` describing the output discretization. """ @@ -477,7 +477,10 @@ class VandermondeOperator(ElementwiseLinearOperator): class MassOperatorBase(Operator): """ - :attr:`dd_in` and :attr:`dd_out` may be surface or volume discretizations. + Inherits from :class:`Operator`. + + :attr:`~Operator.dd_in` and :attr:`~Operator.dd_out` may be surface or volume + discretizations. """ def __init__(self, dd_in=None, dd_out=None): diff --git a/grudge/symbolic/primitives.py b/grudge/symbolic/primitives.py index 78261d65..0a490345 100644 --- a/grudge/symbolic/primitives.py +++ b/grudge/symbolic/primitives.py @@ -55,6 +55,8 @@ class ExpressionBase(prim.Expression): __doc__ = """ +.. currentmodule:: grudge.sym + DOF description ^^^^^^^^^^^^^^^ -- GitLab From 84b43817da8220e3e18c6f9dcbf0b39cbe0a1f81 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Aug 2020 21:35:20 -0500 Subject: [PATCH 14/14] Placate flake8 --- grudge/discretization.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/grudge/discretization.py b/grudge/discretization.py index 58ae9f82..a5452a24 100644 --- a/grudge/discretization.py +++ b/grudge/discretization.py @@ -53,10 +53,11 @@ class DGDiscretizationWithBoundaries(object): """ :param quad_tag_to_group_factory: A mapping from quadrature tags (typically strings--but may be any hashable/comparable object) to a - :class:`~meshmode.discretization.poly_element.ElementGroupFactory` indicating with - which quadrature discretization the operations are to be carried out, - or *None* to indicate that operations with this quadrature tag should - be carried out with the standard volume discretization. + :class:`~meshmode.discretization.poly_element.ElementGroupFactory` + indicating with which quadrature discretization the operations are + to be carried out, or *None* to indicate that operations with this + quadrature tag should be carried out with the standard volume + discretization. """ self._setup_actx = array_context -- GitLab