Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate DiscretizationCollection.normal #315

Merged
merged 2 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/advection/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import grudge.dof_desc as dof_desc
import grudge.op as op
import grudge.geometry as geo

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -237,7 +238,7 @@ def rhs(t, u):

df = dof_desc.DOFDesc(FACE_RESTR_INTERIOR)
face_discr = dcoll.discr_from_dd(df)
face_normal = actx.thaw(dcoll.normal(dd=df))
face_normal = geo.normal(actx, dcoll, dd=df)

from meshmode.discretization.visualization import make_visualizer
vis = make_visualizer(actx, face_discr)
Expand Down
3 changes: 2 additions & 1 deletion examples/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from grudge.array_context import PyOpenCLArrayContext

from grudge import DiscretizationCollection, shortcuts
import grudge.geometry as geo


def main(write_output=True):
Expand All @@ -52,7 +53,7 @@ def main(write_output=True):

nodes = actx.thaw(dcoll.nodes())
bdry_nodes = actx.thaw(dcoll.nodes(dd=BTAG_ALL))
bdry_normals = actx.thaw(dcoll.normal(dd=BTAG_ALL))
bdry_normals = geo.normal(actx, dcoll, dd=BTAG_ALL)

if write_output:
vis = shortcuts.make_visualizer(dcoll)
Expand Down
3 changes: 2 additions & 1 deletion examples/hello-grudge.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pyopencl as cl
from grudge.discretization import DiscretizationCollection
import grudge.op as op
import grudge.geometry as geo
from meshmode.mesh.generation import generate_box_mesh
from meshmode.array_context import PyOpenCLArrayContext
from grudge.dof_desc import BoundaryDomainTag, FACE_RESTR_INTERIOR
Expand Down Expand Up @@ -42,7 +43,7 @@ def left_boundary_condition(x, t):
def flux(dcoll, u_tpair):
dd = u_tpair.dd
velocity = np.array([2 * np.pi])
normal = actx.thaw(dcoll.normal(dd))
normal = geo.normal(actx, dcoll, dd)

v_dot_n = np.dot(velocity, normal)
u_upwind = actx.np.where(v_dot_n > 0,
Expand Down
3 changes: 2 additions & 1 deletion examples/wave/wave-op-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from grudge.shortcuts import make_visualizer, compiled_lsrk45_step

import grudge.op as op
import grudge.geometry as geo

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -77,7 +78,7 @@ def wave_flux(actx, dcoll, c, w_tpair):
v = w_tpair.v
dd = w_tpair.dd

normal = actx.thaw(dcoll.normal(dd))
normal = geo.normal(actx, dcoll, dd)

flux_weak = WaveState(
u=v.avg @ normal,
Expand Down
3 changes: 2 additions & 1 deletion examples/wave/wave-op-var-velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from grudge.shortcuts import make_visualizer, rk4_step

import grudge.op as op
import grudge.geometry as geo

import logging
logger = logging.getLogger(__name__)
Expand All @@ -54,7 +55,7 @@ def wave_flux(actx, dcoll, c, w_tpair):
u = w_tpair[0]
v = w_tpair[1:]

normal = actx.thaw(dcoll.normal(dd))
normal = geo.normal(actx, dcoll, dd)

flux_weak = flat_obj_array(
np.dot(v.avg, normal),
Expand Down
9 changes: 8 additions & 1 deletion grudge/discretization.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,15 @@ def normal(self, dd):
:arg dd: a :class:`~grudge.dof_desc.DOFDesc` as the surface discretization.
:returns: an object array of frozen :class:`~meshmode.dof_array.DOFArray`\ s.
"""
from grudge.geometry import normal
warn("DiscretizationCollection.normal is deprecated and "
"will stop working in 2024. "
"Use grudge.geometry.normal instead. "
"DiscretizationCollection.normal may provide non-P^0 normals "
"even when this would otherwise be possible, see "
"https://github.com/inducer/grudge/issues/314 for details.",
DeprecationWarning, stacklevel=2)

from grudge.geometry import normal
return self._setup_actx.freeze(normal(self._setup_actx, self, dd))

# }}}
Expand Down
7 changes: 4 additions & 3 deletions grudge/models/advection.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import numpy as np
import grudge.op as op
import types
import grudge.geometry as geo

from grudge.models import HyperbolicOperator

Expand All @@ -41,7 +42,7 @@ def advection_weak_flux(dcoll, flux_type, u_tpair, velocity):
"""
actx = u_tpair.int.array_context
dd = u_tpair.dd
normal = actx.thaw(dcoll.normal(dd))
normal = geo.normal(actx, dcoll, dd)
v_dot_n = np.dot(velocity, normal)

flux_type = flux_type.lower()
Expand Down Expand Up @@ -90,7 +91,7 @@ class StrongAdvectionOperator(AdvectionOperatorBase):
def flux(self, u_tpair):
actx = u_tpair.int.array_context
dd = u_tpair.dd
normal = actx.thaw(self.dcoll.normal(dd))
normal = geo.normal(actx, self.dcoll, dd)
v_dot_normal = np.dot(self.v, normal)

return u_tpair.int * v_dot_normal - self.weak_flux(u_tpair)
Expand Down Expand Up @@ -283,7 +284,7 @@ def v_dot_n_tpair(actx, dcoll, velocity, trace_dd):
from grudge.trace_pair import TracePair
from meshmode.discretization.connection import FACE_RESTR_INTERIOR

normal = actx.thaw(dcoll.normal(trace_dd.with_discr_tag(None)))
normal = geo.normal(actx, dcoll, trace_dd.with_discr_tag(None))
v_dot_n = velocity.dot(normal)
i = op.project(dcoll, trace_dd.with_discr_tag(None), trace_dd, v_dot_n)

Expand Down
5 changes: 3 additions & 2 deletions grudge/models/em.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from pytools.obj_array import flat_obj_array, make_obj_array

import grudge.op as op
import grudge.geometry as geo
import numpy as np


Expand Down Expand Up @@ -239,7 +240,7 @@ def flux(self, wtpair):
"""

actx = get_container_context_recursively(wtpair)
normal = actx.thaw(self.dcoll.normal(wtpair.dd))
normal = geo.normal(actx, self.dcoll, wtpair.dd)

if self.fixed_material:
e, h = self.split_eh(wtpair)
Expand Down Expand Up @@ -340,7 +341,7 @@ def absorbing_bc(self, w):
"""

actx = get_container_context_recursively(w)
absorb_normal = actx.thaw(self.dcoll.normal(dd=self.absorb_tag))
absorb_normal = geo.normal(actx, self.dcoll, dd=self.absorb_tag)

e, h = self.split_eh(w)

Expand Down
5 changes: 3 additions & 2 deletions grudge/models/euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
from pytools.obj_array import make_obj_array

import grudge.op as op
import grudge.geometry as geo


# {{{ Array containers for the Euler model
Expand Down Expand Up @@ -203,7 +204,7 @@ def boundary_tpair(
state: ConservedEulerField, t=0):
actx = state.array_context
dd_base = as_dofdesc("vol").with_discr_tag(DISCR_TAG_BASE)
nhat = actx.thaw(dcoll.normal(dd_bc))
nhat = geo.normal(actx, dcoll, dd_bc)
interior = op.project(dcoll, dd_base, dd_bc, state)

return TracePair(
Expand Down Expand Up @@ -270,7 +271,7 @@ def euler_numerical_flux(
exterior=euler_volume_flux(dcoll, q_rr, gamma=gamma)
)
num_flux = flux_tpair.avg
normal = actx.thaw(dcoll.normal(dd_intfaces))
normal = geo.normal(actx, dcoll, dd_intfaces)

if lf_stabilization:
from arraycontext import outer
Expand Down
9 changes: 5 additions & 4 deletions grudge/models/wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from pytools.obj_array import flat_obj_array

import grudge.op as op
import grudge.geometry as geo


# {{{ constant-velocity
Expand Down Expand Up @@ -91,7 +92,7 @@ def flux(self, wtpair):
u = wtpair[0]
v = wtpair[1:]
actx = u.int.array_context
normal = actx.thaw(self.dcoll.normal(wtpair.dd))
normal = geo.normal(actx, self.dcoll, wtpair.dd)

central_flux_weak = -self.c*flat_obj_array(
np.dot(v.avg, normal),
Expand Down Expand Up @@ -134,7 +135,7 @@ def operator(self, t, w):
neu_bc = flat_obj_array(neu_u, -neu_v)

# radiation BCs -------------------------------------------------------
rad_normal = actx.thaw(dcoll.normal(dd=self.radiation_tag))
rad_normal = geo.normal(actx, dcoll, dd=self.radiation_tag)

rad_u = op.project(dcoll, "vol", self.radiation_tag, u)
rad_v = op.project(dcoll, "vol", self.radiation_tag, v)
Expand Down Expand Up @@ -244,7 +245,7 @@ def flux(self, wtpair):
u = wtpair[1]
v = wtpair[2:]
actx = u.int.array_context
normal = actx.thaw(self.dcoll.normal(wtpair.dd))
normal = geo.normal(actx, self.dcoll, wtpair.dd)

flux_central_weak = -0.5 * flat_obj_array(
np.dot(v.int*c.int + v.ext*c.ext, normal),
Expand Down Expand Up @@ -296,7 +297,7 @@ def operator(self, t, w):
neu_bc = flat_obj_array(neu_c, neu_u, -neu_v)

# radiation BCs -------------------------------------------------------
rad_normal = actx.thaw(dcoll.normal(dd=self.radiation_tag))
rad_normal = geo.normal(actx, dcoll, dd=self.radiation_tag)

rad_c = op.project(dcoll, "vol", self.radiation_tag, c)
rad_u = op.project(dcoll, "vol", self.radiation_tag, u)
Expand Down
9 changes: 5 additions & 4 deletions test/test_grudge.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import grudge.dof_desc as dof_desc
import grudge.op as op
import grudge.geometry as geo


import pytest
Expand Down Expand Up @@ -340,7 +341,7 @@ def test_face_normal_surface(actx_factory, mesh_name):
)
surf_normal = surf_normal / actx.np.sqrt(sum(surf_normal**2))

face_normal_i = actx.thaw(dcoll.normal(df))
face_normal_i = geo.normal(actx, dcoll, df)
face_normal_e = dcoll.opposite_face_connection(
dof_desc.BoundaryDomainTag(
dof_desc.FACE_RESTR_INTERIOR, dof_desc.VTAG_ALL)
Expand Down Expand Up @@ -463,7 +464,7 @@ def f(x):
int_1 = op.integral(dcoll, "vol", op.local_div(dcoll, f_volm))

prj_f = op.project(dcoll, "vol", BTAG_ALL, f_volm)
normal = actx.thaw(dcoll.normal(BTAG_ALL))
normal = geo.normal(actx, dcoll, BTAG_ALL)
int_2 = op.integral(dcoll, BTAG_ALL, prj_f.dot(normal))

assert abs(int_1 - int_2) < 1e-13
Expand Down Expand Up @@ -572,7 +573,7 @@ def f(x):

kappa = summed_curvature(actx, dcoll, dd=dq)
normal = normal(actx, dcoll, dd=dq)
face_normal = actx.thaw(dcoll.normal(df))
face_normal = geo.normal(actx, dcoll, df)
face_f = op.project(dcoll, dd, df, f_num)

# operators
Expand Down Expand Up @@ -1064,7 +1065,7 @@ def test_empty_boundary(actx_factory):
a=(-0.5,)*dim, b=(0.5,)*dim,
nelements_per_axis=(8,)*dim, order=4)
dcoll = DiscretizationCollection(actx, mesh, order=4)
normal = dcoll.normal(BTAG_NONE)
normal = geo.normal(actx, dcoll, BTAG_NONE)
from meshmode.dof_array import DOFArray
for component in normal:
assert isinstance(component, DOFArray)
Expand Down
6 changes: 3 additions & 3 deletions test/test_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from pytools.obj_array import make_obj_array

from grudge import op, DiscretizationCollection
from grudge import op, geometry as geo, DiscretizationCollection
from grudge.dof_desc import DOFDesc

import pytest
Expand Down Expand Up @@ -97,7 +97,7 @@ def grad_f(x):
def get_flux(u_tpair):
dd = u_tpair.dd
dd_allfaces = dd.with_dtag("all_faces")
normal = actx.thaw(dcoll.normal(dd))
normal = geo.normal(actx, dcoll, dd)
u_avg = u_tpair.avg
if vectorize:
if nested:
Expand Down Expand Up @@ -223,7 +223,7 @@ def div_f(x):
def get_flux(u_tpair):
dd = u_tpair.dd
dd_allfaces = dd.with_dtag("all_faces")
normal = actx.thaw(dcoll.normal(dd))
normal = geo.normal(actx, dcoll, dd)
flux = u_tpair.avg @ normal
return op.project(dcoll, dd, dd_allfaces, flux)

Expand Down
Loading