Discontinuous Galerkin operatorsÂ¶
Core DG routinesÂ¶
Elementwise differentiationÂ¶
- grudge.op.local_grad(dcoll: grudge.discretization.DiscretizationCollection, vec, *, nested=False) â†’ numpy.ndarray[source]Â¶
Return the element-local gradient of a function \(f\) represented by vec:
\[\nabla|_E f = \left( \partial_x|_E f, \partial_y|_E f, \partial_z|_E f \right)\]
- grudge.op.local_d_dx(dcoll: grudge.discretization.DiscretizationCollection, xyz_axis, vec)[source]Â¶
Return the element-local derivative along axis xyz_axis of a function \(f\) represented by vec:
\[\frac{\partial f}{\partial \lbrace x,y,z\rbrace}\Big|_E\]
- grudge.op.local_div(dcoll: grudge.discretization.DiscretizationCollection, vecs)[source]Â¶
Return the element-local divergence of the vector function \(\mathbf{f}\) represented by vecs:
\[\nabla|_E \cdot \mathbf{f} = \sum_{i=1}^d \partial_{x_i}|_E \mathbf{f}_i\]
Weak derivative operatorsÂ¶
- grudge.op.weak_local_grad(dcoll: grudge.discretization.DiscretizationCollection, *args, nested=False)[source]Â¶
Return the element-local weak gradient of the volume function represented by vec.
May be called with
(vecs)
or(dd, vecs)
.Specifically, the function returns an object array where the \(i\)-th component is the weak derivative with respect to the \(i\)-th coordinate of a scalar function \(f\). See
weak_local_d_dx()
for further information. For non-scalar \(f\), the function will return a nested object array containing the component-wise weak derivatives.- Parameters
- Returns
an object array (possibly nested) of
DOFArray
s.
- grudge.op.weak_local_d_dx(dcoll: grudge.discretization.DiscretizationCollection, *args)[source]Â¶
Return the element-local weak derivative along axis xyz_axis of the volume function represented by vec.
May be called with
(xyz_axis, vecs)
or(dd, xyz_axis, vecs)
.Specifically, this function computes the volume contribution of the weak derivative in the \(i\)-th component (specified by xyz_axis) of a function \(f\), in each element \(E\), with respect to polynomial test functions \(\phi\):
\[\int_E \partial_i\phi\,f\,\mathrm{d}x \sim \mathbf{D}_{E,i}^T \mathbf{M}_{E}^T\mathbf{f}|_E,\]where \(\mathbf{D}_{E,i}\) is the polynomial differentiation matrix on an \(E\) for the \(i\)-th spatial coordinate, \(\mathbf{M}_E\) is the elemental mass matrix (see
mass()
for more information), and \(\mathbf{f}|_E\) is a vector of coefficients for \(f\) on \(E\).
- grudge.op.weak_local_div(dcoll: grudge.discretization.DiscretizationCollection, *args)[source]Â¶
Return the element-local weak divergence of the vector volume function represented by vecs.
May be called with
(vecs)
or(dd, vecs)
.Specifically, this function computes the volume contribution of the weak divergence of a vector function \(\mathbf{f}\), in each element \(E\), with respect to polynomial test functions \(\phi\):
\[\int_E \nabla \phi \cdot \mathbf{f}\,\mathrm{d}x \sim \sum_{i=1}^d \mathbf{D}_{E,i}^T \mathbf{M}_{E}^T\mathbf{f}_i|_E,\]where \(\mathbf{D}_{E,i}\) is the polynomial differentiation matrix on an \(E\) for the \(i\)-th spatial coordinate, and \(\mathbf{M}_E\) is the elemental mass matrix (see
mass()
for more information).
Mass, inverse mass, and face mass operatorsÂ¶
- grudge.op.mass(dcoll: grudge.discretization.DiscretizationCollection, *args)[source]Â¶
Return the action of the DG mass matrix on a vector (or vectors) of
DOFArray
s, vec. In the case of vec being an object array ofDOFArray
s, the mass operator is applied in the Kronecker sense (component-wise).May be called with
(vec)
or(dd, vec)
.Specifically, this function applies the mass matrix elementwise on a vector of coefficients \(\mathbf{f}\) via: \(\mathbf{M}_{E}\mathbf{f}|_E\), where
\[\left(\mathbf{M}_{E}\right)_{ij} = \int_E \phi_i \cdot \phi_j\,\mathrm{d}x,\]where \(\phi_i\) are local polynomial basis functions on \(E\).
- grudge.op.inverse_mass(dcoll: grudge.discretization.DiscretizationCollection, vec)[source]Â¶
Return the action of the DG mass matrix inverse on a vector (or vectors) of
DOFArray
s, vec. In the case of vec being an object array ofDOFArray
s, the inverse mass operator is applied in the Kronecker sense (component-wise).For affine elements \(E\), the element-wise mass inverse is computed directly as the inverse of the (physical) mass matrix:
\[\left(\mathbf{M}_{J^e}\right)_{ij} = \int_{\widehat{E}} \widehat{\phi}_i\cdot\widehat{\phi}_j J^e \mathrm{d}\widehat{x},\]where \(\widehat{\phi}_i\) are basis functions over the reference element \(\widehat{E}\), and \(J^e\) is the (constant) Jacobian scaling factor (see
grudge.geometry.area_element()
).For non-affine \(E\), \(J^e\) is not constant. In this case, a weight-adjusted approximation is used instead following [Chan_2016]:
\[\mathbf{M}_{J^e}^{-1} \approx \widehat{\mathbf{M}}^{-1}\mathbf{M}_{1/J^e}\widehat{\mathbf{M}}^{-1},\]where \(\widehat{\mathbf{M}}\) is the reference mass matrix on \(\widehat{E}\).
- grudge.op.face_mass(dcoll: grudge.discretization.DiscretizationCollection, *args)[source]Â¶
Return the action of the DG face mass matrix on a vector (or vectors) of
DOFArray
s, vec. In the case of vec being an object array ofDOFArray
s, the mass operator is applied in the Kronecker sense (component-wise).May be called with
(vec)
or(dd, vec)
.Specifically, this function applies the face mass matrix elementwise on a vector of coefficients \(\mathbf{f}\) as the sum of contributions for each face \(f \subset \partial E\):
\[\sum_{f=1}^{N_{\text{faces}}} \mathbf{M}_{f, E}\mathbf{f}|_f,\]where
\[\left(\mathbf{M}_{f, E}\right)_{ij} = \int_{f \subset \partial E} \phi_i(s)\psi_j(s)\,\mathrm{d}s,\]where \(\phi_i\) are (volume) polynomial basis functions on \(E\) evaluated on the face \(f\), and \(\psi_j\) are basis functions for a polynomial space defined on \(f\).
Trace PairsÂ¶
Container classÂ¶
- class grudge.trace_pair.TracePair(dd, *, interior, exterior)[source]Â¶
A container class for data (both interior and exterior restrictions) on the boundaries of mesh elements.
- ddÂ¶
an instance of
grudge.dof_desc.DOFDesc
describing the discretization on whichint
andext
live.
- intÂ¶
A class:~meshmode.dof_array.DOFArray or
ArrayContainer
of them representing the interior value to be used for the flux.
- extÂ¶
A class:~meshmode.dof_array.DOFArray or
ArrayContainer
of them representing the exterior value to be used for the flux.
- avgÂ¶
A class:~meshmode.dof_array.DOFArray or
ArrayContainer
of them representing the average of the interior and exterior values.
- __getattr__(name)[source]Â¶
Return a new
TracePair
resulting from executing attribute lookup with name onint
andext
.
- __getitem__(index)[source]Â¶
Return a new
TracePair
resulting from executing subscripting with index onint
andext
.
- __len__()[source]Â¶
Return the total number of arrays associated with the
int
andext
restrictions of theTracePair
. Note that both must be the same.
Note
TracePair
is currently used both by the symbolic (deprecated) and the current interfaces, with symbolic information or concrete data.
Boundary trace functionsÂ¶
- grudge.trace_pair.bdry_trace_pair(dcoll: grudge.discretization.DiscretizationCollection, dd, interior, exterior) â†’ grudge.trace_pair.TracePair[source]Â¶
Returns a trace pair defined on the exterior boundary. Input arguments are assumed to already be defined on the boundary denoted by dd.
- Parameters
dd â€“ a
DOFDesc
, or a value convertible to one, which describes the boundary discretization.interior â€“ a
DOFArray
that contains data already on the boundary representing the interior value to be used for the flux.exterior â€“ a
DOFArray
that contains data that already lives on the boundary representing the exterior value to be used for the flux.
- Returns
a
TracePair
on the boundary.
- grudge.trace_pair.bv_trace_pair(dcoll: grudge.discretization.DiscretizationCollection, dd, interior, exterior) â†’ grudge.trace_pair.TracePair[source]Â¶
Returns a trace pair defined on the exterior boundary. The interior argument is assumed to be defined on the volume discretization, and will therefore be restricted to the boundary dd prior to creating a
TracePair
.- Parameters
dd â€“ a
DOFDesc
, or a value convertible to one, which describes the boundary discretization.interior â€“ a
DOFArray
that contains data defined in the volume, which will be restricted to the boundary denoted by dd. The result will be used as the interior value for the flux.exterior â€“ a
DOFArray
that contains data that already lives on the boundary representing the exterior value to be used for the flux.
- Returns
a
TracePair
on the boundary.
Interior and cross-rank trace functionsÂ¶
- grudge.trace_pair.interior_trace_pairs(dcoll: grudge.discretization.DiscretizationCollection, vec) â†’ list[source]Â¶
Return a
list
ofTracePair
objects defined on the interior faces of dcoll and any faces connected to a parallel boundary.
- grudge.trace_pair.cross_rank_trace_pairs(dcoll: grudge.discretization.DiscretizationCollection, ary, tag=None) â†’ list[source]Â¶
Get a
list
of ary trace pairs for each partition boundary.For each partition boundary, the field data values in ary are communicated to/from the neighboring partition. Presumably, this communication is MPI (but strictly speaking, may not be, and this routine is agnostic to the underlying communication).
For each face on each partition boundary, a
TracePair
is created with the locally, and remotely owned partition boundary face data as the internal, and external components, respectively. Each of the TracePair components are structured like ary.
Transfering data between discretizationsÂ¶
ProjectionsÂ¶
- grudge.op.project(dcoll: grudge.discretization.DiscretizationCollection, src, tgt, vec)[source]Â¶
Project from one discretization to another, e.g. from the volume to the boundary, or from the base to the an overintegrated quadrature discretization.
- Parameters
src â€“ a
DOFDesc
, or a value convertible to one.tgt â€“ a
DOFDesc
, or a value convertible to one.vec â€“ a
DOFArray
or aArrayContainer
.
ReductionsÂ¶
Nodal ReductionsÂ¶
Note
In a distributed-memory setting, these reductions automatically
reduce over all ranks involved, and return the same value on
all ranks, in the manner of an MPI allreduce
.
- grudge.op.norm(dcoll: grudge.discretization.DiscretizationCollection, vec, p, dd=None) â†’ float[source]Â¶
Return the vector p-norm of a function represented by its vector of degrees of freedom vec.
- Parameters
vec â€“ a
DOFArray
or an object array of aDOFArray
s, where the last axis of the array must have length matching the volume dimension.p â€“ an integer denoting the order of the integral norm. Currently, only values of 2 or numpy.inf are supported.
dd â€“ a
DOFDesc
, or a value convertible to one. Defaults to the base volume discretization if not provided.
- Returns
a nonegative scalar denoting the norm.
- grudge.op.nodal_sum(dcoll: grudge.discretization.DiscretizationCollection, dd, vec) â†’ float[source]Â¶
Return the nodal sum of a vector of degrees of freedom vec.
- grudge.op.nodal_min(dcoll: grudge.discretization.DiscretizationCollection, dd, vec) â†’ float[source]Â¶
Return the nodal minimum of a vector of degrees of freedom vec.
- grudge.op.nodal_max(dcoll: grudge.discretization.DiscretizationCollection, dd, vec) â†’ float[source]Â¶
Return the nodal maximum of a vector of degrees of freedom vec.
- grudge.op.integral(dcoll: grudge.discretization.DiscretizationCollection, dd, vec) â†’ float[source]Â¶
Numerically integrates a function represented by a
DOFArray
of degrees of freedom.
Rank-local reductionsÂ¶
- grudge.op.nodal_sum_loc(dcoll: grudge.discretization.DiscretizationCollection, dd, vec) â†’ float[source]Â¶
Return the rank-local nodal sum of a vector of degrees of freedom vec.
- grudge.op.nodal_min_loc(dcoll: grudge.discretization.DiscretizationCollection, dd, vec) â†’ float[source]Â¶
Return the rank-local nodal minimum of a vector of degrees of freedom vec.
- grudge.op.nodal_max_loc(dcoll: grudge.discretization.DiscretizationCollection, dd, vec) â†’ float[source]Â¶
Return the rank-local nodal maximum of a vector of degrees of freedom vec.
Elementwise reductionsÂ¶
- grudge.op.elementwise_sum(dcoll: grudge.discretization.DiscretizationCollection, *args) â†’ meshmode.dof_array.DOFArray[source]Â¶
Returns a vector of DOFs with all entries on each element set to the sum of DOFs on that element.
May be called with
(dcoll, vec)
or(dcoll, dd, vec)
.
- grudge.op.elementwise_max(dcoll: grudge.discretization.DiscretizationCollection, *args) â†’ meshmode.dof_array.DOFArray[source]Â¶
Returns a vector of DOFs with all entries on each element set to the maximum over all DOFs on that element.
May be called with
(dcoll, vec)
or(dcoll, dd, vec)
.- Parameters
dcoll â€“ a
grudge.discretization.DiscretizationCollection
.dd â€“ a
DOFDesc
, or a value convertible to one. Defaults to the base volume discretization if not provided.vec â€“ a
DOFArray
- Returns
a
DOFArray
whose entries denote the element-wise max of vec.
- grudge.op.elementwise_min(dcoll: grudge.discretization.DiscretizationCollection, *args) â†’ meshmode.dof_array.DOFArray[source]Â¶
Returns a vector of DOFs with all entries on each element set to the minimum over all DOFs on that element.
May be called with
(dcoll, vec)
or(dcoll, dd, vec)
.- Parameters
dcoll â€“ a
grudge.discretization.DiscretizationCollection
.dd â€“ a
DOFDesc
, or a value convertible to one. Defaults to the base volume discretization if not provided.vec â€“ a
DOFArray
- Returns
a
DOFArray
whose entries denote the element-wise min of vec.
- grudge.op.elementwise_integral(dcoll: grudge.discretization.DiscretizationCollection, dd, vec) â†’ meshmode.dof_array.DOFArray[source]Â¶
Numerically integrates a function represented by a
DOFArray
of degrees of freedom in each element of a discretization, given by dd.