Skip to content

Commit

Permalink
Fix some deprecation warnings in hello-grudge
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Sep 7, 2023
1 parent 190ab9c commit ccb1a85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
21 changes: 10 additions & 11 deletions examples/hello-grudge.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
# BEGINEXAMPLE
import numpy as np
import pyopencl as cl
from grudge.discretization import DiscretizationCollection
from grudge.discretization import make_discretization_collection
import grudge.op as op
import grudge.geometry as geo
from grudge.dof_desc import as_dofdesc
from meshmode.mesh.generation import generate_box_mesh
from meshmode.array_context import PyOpenCLArrayContext
from grudge.dof_desc import BoundaryDomainTag, FACE_RESTR_INTERIOR
Expand All @@ -27,7 +28,7 @@
mesh = generate_box_mesh((coords,),
boundary_tag_to_face={"left": ["-x"],
"right": ["+x"]})
dcoll = DiscretizationCollection(actx, mesh, order=1)
dcoll = make_discretization_collection(actx, mesh, order=1)


def initial_condition(x):
Expand All @@ -52,8 +53,8 @@ def flux(dcoll, u_tpair):


vol_discr = dcoll.discr_from_dd("vol")
left_bndry = BoundaryDomainTag("left")
right_bndry = BoundaryDomainTag("right")
left_bndry = as_dofdesc(BoundaryDomainTag("left"))
right_bndry = as_dofdesc(BoundaryDomainTag("right"))

x_vol = actx.thaw(dcoll.nodes())
x_bndry = actx.thaw(dcoll.discr_from_dd(left_bndry).nodes())
Expand All @@ -78,8 +79,7 @@ def flux(dcoll, u_tpair):
exterior=op.project(dcoll, "vol",
right_bndry, uh))
# extract the trace pairs on the interior faces
interior_tpair = op.interior_trace_pair(dcoll,
uh)
interior_tpair = op.local_interior_trace_pair(dcoll, uh)
Su = op.weak_local_grad(dcoll, uh)

lift = op.face_mass(dcoll,
Expand Down Expand Up @@ -114,11 +114,10 @@ def u_exact(x, t):
uh - u_exact(x_vol, t_final),
p=2) <= 0.1
import matplotlib.pyplot as plt
from arraycontext import to_numpy
plt.plot(to_numpy(actx.np.ravel(x_vol[0][0]), actx),
to_numpy(actx.np.ravel(uh[0]), actx), label="Numerical")
plt.plot(to_numpy(actx.np.ravel(x_vol[0][0]), actx),
to_numpy(actx.np.ravel(u_exact(x_vol, t_final)[0]), actx), label="Exact")
plt.plot(actx.to_numpy(actx.np.ravel(x_vol[0][0])),
actx.to_numpy(actx.np.ravel(uh[0])), label="Numerical")
plt.plot(actx.to_numpy(actx.np.ravel(x_vol[0][0])),
actx.to_numpy(actx.np.ravel(u_exact(x_vol, t_final)[0])), label="Exact")
plt.xlabel("$x$")
plt.ylabel("$u$")
plt.legend()
Expand Down
8 changes: 3 additions & 5 deletions grudge/geometry/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,18 +568,16 @@ def _signed_face_ones(
actx, dtype=dcoll.real_dtype
) + 1

from arraycontext import to_numpy, from_numpy

_signed_face_ones_numpy = to_numpy(signed_ones, actx)
_signed_face_ones_numpy = actx.to_numpy(signed_ones)

for igrp, grp in enumerate(all_faces_conn.groups):
for batch in grp.batches:
i = to_numpy(actx.thaw(batch.to_element_indices), actx)
i = actx.to_numpy(actx.thaw(batch.to_element_indices))
grp_field = _signed_face_ones_numpy[igrp].reshape(-1)
grp_field[i] = \
(2.0 * (batch.to_element_face % 2) - 1.0) * grp_field[i]

return from_numpy(_signed_face_ones_numpy, actx)
return actx.from_numpy(_signed_face_ones_numpy)


def parametrization_derivative(
Expand Down

0 comments on commit ccb1a85

Please sign in to comment.