Skip to content

Commit

Permalink
wrap btag -> bdtag promotion into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
majosm committed Sep 7, 2022
1 parent 0518819 commit 5eaf339
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 29 deletions.
7 changes: 3 additions & 4 deletions mirgecom/artificial_viscosity.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@
VolumeDomainTag,
DISCR_TAG_BASE,
DISCR_TAG_MODAL,
as_dofdesc,
)

from mirgecom.utils import normalize_boundaries

import grudge.op as op


Expand Down Expand Up @@ -213,9 +214,7 @@ def av_laplacian_operator(dcoll, boundaries, fluid_state, alpha, gas_model=None,
:class:`mirgecom.fluid.ConservedVars`
The artificial viscosity operator applied to *q*.
"""
boundaries = {
as_dofdesc(bdtag).domain_tag: bdry
for bdtag, bdry in boundaries.items()}
boundaries = normalize_boundaries(boundaries)

cv = fluid_state.cv
actx = cv.array_context
Expand Down
10 changes: 3 additions & 7 deletions mirgecom/diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
DD_VOLUME_ALL,
VolumeDomainTag,
DISCR_TAG_BASE,
as_dofdesc,
)
from grudge.trace_pair import (
TracePair,
interior_trace_pairs,
tracepair_with_discr_tag,
)
import grudge.op as op
from mirgecom.utils import normalize_boundaries


def grad_facial_flux(u_tpair, normal):
Expand Down Expand Up @@ -251,9 +251,7 @@ def grad_operator(

actx = u.array_context

boundaries = {
as_dofdesc(bdtag).domain_tag: bdry
for bdtag, bdry in boundaries.items()}
boundaries = normalize_boundaries(boundaries)

for bdtag, bdry in boundaries.items():
if not isinstance(bdry, DiffusionBoundary):
Expand Down Expand Up @@ -417,9 +415,7 @@ def diffusion_operator(

actx = u.array_context

boundaries = {
as_dofdesc(bdtag).domain_tag: bdry
for bdtag, bdry in boundaries.items()}
boundaries = normalize_boundaries(boundaries)

for bdtag, bdry in boundaries.items():
if not isinstance(bdry, DiffusionBoundary):
Expand Down
6 changes: 2 additions & 4 deletions mirgecom/euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
DD_VOLUME_ALL,
VolumeDomainTag,
DISCR_TAG_BASE,
as_dofdesc,
)

from mirgecom.gas_model import make_operator_fluid_states
Expand All @@ -70,6 +69,7 @@
)

from mirgecom.operators import div_operator
from mirgecom.utils import normalize_boundaries


def euler_operator(dcoll, state, gas_model, boundaries, time=0.0,
Expand Down Expand Up @@ -125,9 +125,7 @@ def euler_operator(dcoll, state, gas_model, boundaries, time=0.0,
Tag for distributed communication
"""
boundaries = {
as_dofdesc(bdtag).domain_tag: bdry
for bdtag, bdry in boundaries.items()}
boundaries = normalize_boundaries(boundaries)

if not isinstance(dd.domain_tag, VolumeDomainTag):
raise TypeError("dd must represent a volume")
Expand Down
6 changes: 2 additions & 4 deletions mirgecom/gas_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@
DD_VOLUME_ALL,
VolumeDomainTag,
DISCR_TAG_BASE,
as_dofdesc,
)
import grudge.op as op
from grudge.trace_pair import (
interior_trace_pairs,
tracepair_with_discr_tag
)
from mirgecom.utils import normalize_boundaries


@dataclass(frozen=True)
Expand Down Expand Up @@ -444,9 +444,7 @@ def make_operator_fluid_states(
boundary domain tags in *boundaries*, all on the quadrature grid (if
specified).
"""
boundaries = {
as_dofdesc(bdtag).domain_tag: bdry
for bdtag, bdry in boundaries.items()}
boundaries = normalize_boundaries(boundaries)

if not isinstance(dd.domain_tag, VolumeDomainTag):
raise TypeError("dd must represent a volume")
Expand Down
3 changes: 3 additions & 0 deletions mirgecom/inviscid.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
)
import grudge.op as op
from mirgecom.fluid import make_conserved
from mirgecom.utils import normalize_boundaries


def inviscid_flux(state):
Expand Down Expand Up @@ -273,6 +274,8 @@ def inviscid_flux_on_element_boundary(
the DOF descriptor of the discretization on which the fluid lives. Must be
a volume on the base discretization.
"""
boundaries = normalize_boundaries(boundaries)

if not isinstance(dd.domain_tag, VolumeDomainTag):
raise TypeError("dd must represent a volume")
if dd.discretization_tag != DISCR_TAG_BASE:
Expand Down
14 changes: 4 additions & 10 deletions mirgecom/navierstokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
DD_VOLUME_ALL,
VolumeDomainTag,
DISCR_TAG_BASE,
as_dofdesc,
)

import grudge.op as op
Expand All @@ -91,6 +90,7 @@
div_operator, grad_operator
)
from mirgecom.gas_model import make_operator_fluid_states
from mirgecom.utils import normalize_boundaries


class _NSGradCVTag:
Expand Down Expand Up @@ -163,9 +163,7 @@ def grad_cv_operator(
CV object with vector components representing the gradient of the fluid
conserved variables.
"""
boundaries = {
as_dofdesc(bdtag).domain_tag: bdry
for bdtag, bdry in boundaries.items()}
boundaries = normalize_boundaries(boundaries)

if not isinstance(dd.domain_tag, VolumeDomainTag):
raise TypeError("dd must represent a volume")
Expand Down Expand Up @@ -266,9 +264,7 @@ def grad_t_operator(
Array of :class:`~meshmode.dof_array.DOFArray` representing the gradient of
the fluid temperature.
"""
boundaries = {
as_dofdesc(bdtag).domain_tag: bdry
for bdtag, bdry in boundaries.items()}
boundaries = normalize_boundaries(boundaries)

if not isinstance(dd.domain_tag, VolumeDomainTag):
raise TypeError("dd must represent a volume")
Expand Down Expand Up @@ -414,9 +410,7 @@ def ns_operator(dcoll, gas_model, state, boundaries, *, time=0.0,
if not state.is_viscous:
raise ValueError("Navier-Stokes operator expects viscous gas model.")

boundaries = {
as_dofdesc(bdtag).domain_tag: bdry
for bdtag, bdry in boundaries.items()}
boundaries = normalize_boundaries(boundaries)

if not isinstance(dd.domain_tag, VolumeDomainTag):
raise TypeError("dd must represent a volume")
Expand Down
13 changes: 13 additions & 0 deletions mirgecom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.. autoclass:: StatisticsAccumulator
.. autofunction:: asdict_shallow
.. autofunction:: force_evaluation
.. autofunction:: normalize_boundaries
"""

__copyright__ = """
Expand Down Expand Up @@ -117,3 +118,15 @@ def force_evaluation(actx, x):
if actx is None:
return x
return actx.freeze_thaw(x)


def normalize_boundaries(boundaries):
"""
Normalize the keys of *boundaries*.
Promotes boundary tags to :class:`grudge.dof_desc.BoundaryDomainTag`.
"""
from grudge.dof_desc import as_dofdesc
return {
as_dofdesc(key).domain_tag: bdry
for key, bdry in boundaries.items()}
4 changes: 4 additions & 0 deletions mirgecom/viscous.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
make_conserved
)

from mirgecom.utils import normalize_boundaries


# low level routine works with numpy arrays and can be tested without
# a full grid + fluid state, etc
Expand Down Expand Up @@ -395,6 +397,8 @@ def viscous_flux_on_element_boundary(
the DOF descriptor of the discretization on which the fluid lives. Must be
a volume on the base discretization.
"""
boundaries = normalize_boundaries(boundaries)

if not isinstance(dd.domain_tag, VolumeDomainTag):
raise TypeError("dd must represent a volume")
if dd.discretization_tag != DISCR_TAG_BASE:
Expand Down

0 comments on commit 5eaf339

Please sign in to comment.