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

Remove deprecations #353

Merged
merged 16 commits into from
Jul 16, 2024
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
43 changes: 14 additions & 29 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
from importlib import metadata
from urllib.request import urlopen


Expand All @@ -9,39 +11,22 @@
extensions = globals()["extensions"] + [
"matplotlib.sphinxext.plot_directive"]

copyright = "2015-21, grudge contributors"
author = "grudge contributors"


def get_version():
conf = {}
src = "../grudge/version.py"
exec(
compile(open(src).read(), src, "exec"),
conf)
return conf["VERSION_TEXT"]


version = get_version()

# The full version, including alpha/beta/rc tags.
release = version
copyright = "2015-2024, Grudge contributors"
author = "Grudge contributors"
release = metadata.version("grudge")
version = ".".join(release.split(".")[:2])

intersphinx_mapping = {
"python": ("https://docs.python.org/3/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"pyopencl": ("https://documen.tician.de/pyopencl/", None),
"modepy": ("https://documen.tician.de/modepy/", None),
"pymbolic": ("https://documen.tician.de/pymbolic/", None),
"arraycontext": ("https://documen.tician.de/arraycontext/", None),
"meshmode": ("https://documen.tician.de/meshmode/", None),
"loopy": ("https://documen.tician.de/loopy/", None),
"meshmode": ("https://documen.tician.de/meshmode/", None),
"modepy": ("https://documen.tician.de/modepy/", None),
"mpi4py": ("https://mpi4py.readthedocs.io/en/stable", None),
}
"numpy": ("https://numpy.org/doc/stable/", None),
"pymbolic": ("https://documen.tician.de/pymbolic/", None),
"pyopencl": ("https://documen.tician.de/pyopencl/", None),
"python": ("https://docs.python.org/3/", None),
}

# index-page demo uses pyopencl via plot_directive
import os


# switch to "port:cpu" once we're firmly migrated to pocl 4.0
os.environ["PYOPENCL_TEST"] = "port:0"
os.environ["PYOPENCL_TEST"] = "port:cpu"
18 changes: 9 additions & 9 deletions examples/advection/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

import pyopencl as cl
import pyopencl.tools as cl_tools
from arraycontext import flatten
from meshmode.discretization.connection import FACE_RESTR_INTERIOR
from meshmode.dof_array import flatten
from pytools.obj_array import make_obj_array

import grudge.dof_desc as dof_desc
Expand Down Expand Up @@ -61,8 +61,8 @@ def __init__(self, actx, dcoll, order, visualize=True):
import matplotlib.pyplot as pt
self.fig = pt.figure(figsize=(8, 8), dpi=300)

x = actx.thaw(dcoll.discr_from_dd(dof_desc.DD_VOLUME).nodes())
self.x = actx.to_numpy(flatten(actx.np.arctan2(x[1], x[0])))
x = actx.thaw(dcoll.discr_from_dd(dof_desc.DD_VOLUME_ALL).nodes())
self.x = actx.to_numpy(flatten(actx.np.arctan2(x[1], x[0]), self.actx))
elif self.ambient_dim == 3:
from grudge.shortcuts import make_visualizer
self.vis = make_visualizer(dcoll)
Expand All @@ -74,7 +74,7 @@ def __call__(self, evt, basename, overwrite=True):
return

if self.ambient_dim == 2:
u = self.actx.to_numpy(flatten(evt.state_component))
u = self.actx.to_numpy(flatten(evt.state_component, self.actx))

filename = f"{basename}.png"
if not overwrite and os.path.exists(filename):
Expand Down Expand Up @@ -158,14 +158,14 @@ def main(ctx_factory, dim=2, order=4, use_quad=False, visualize=False):
discr_tag_to_group_factory[qtag] = \
QuadratureSimplexGroupFactory(order=4*order)

from grudge import DiscretizationCollection
from grudge.discretization import make_discretization_collection

dcoll = DiscretizationCollection(
dcoll = make_discretization_collection(
actx, mesh,
discr_tag_to_group_factory=discr_tag_to_group_factory
)

volume_discr = dcoll.discr_from_dd(dof_desc.DD_VOLUME)
volume_discr = dcoll.discr_from_dd(dof_desc.DD_VOLUME_ALL)
logger.info("ndofs: %d", volume_discr.ndofs)
logger.info("nelements: %d", volume_discr.mesh.nelements)

Expand Down Expand Up @@ -196,7 +196,7 @@ def rhs(t, u):
# check velocity is tangential
from grudge.geometry import normal

surf_normal = normal(actx, dcoll, dd=dof_desc.DD_VOLUME)
surf_normal = normal(actx, dcoll, dd=dof_desc.DD_VOLUME_ALL)

error = op.norm(dcoll, c.dot(surf_normal), 2)
logger.info("u_dot_n: %.5e", error)
Expand Down Expand Up @@ -236,7 +236,7 @@ def rhs(t, u):
overwrite=True
)

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

Expand Down
14 changes: 7 additions & 7 deletions examples/advection/var-velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import pyopencl as cl
import pyopencl.tools as cl_tools
from meshmode.dof_array import flatten
from arraycontext import flatten
from meshmode.mesh import BTAG_ALL
from pytools.obj_array import flat_obj_array

Expand Down Expand Up @@ -58,8 +58,8 @@ def __init__(self, actx, dcoll, order, visualize=True, ylim=None):
self.fig = pt.figure(figsize=(8, 8), dpi=300)
self.ylim = ylim

volume_discr = dcoll.discr_from_dd(dof_desc.DD_VOLUME)
self.x = actx.to_numpy(flatten(actx.thaw(volume_discr.nodes()[0])))
volume_discr = dcoll.discr_from_dd(dof_desc.DD_VOLUME_ALL)
self.x = actx.to_numpy(flatten(volume_discr.nodes()[0], self.actx))
else:
from grudge.shortcuts import make_visualizer
self.vis = make_visualizer(dcoll)
Expand All @@ -69,7 +69,7 @@ def __call__(self, evt, basename, overwrite=True):
return

if self.dim == 1:
u = self.actx.to_numpy(flatten(evt.state_component))
u = self.actx.to_numpy(flatten(evt.state_component, self.actx))

filename = f"{basename}.png"
if not overwrite and os.path.exists(filename):
Expand Down Expand Up @@ -139,9 +139,9 @@ def main(ctx_factory, dim=2, order=4, use_quad=False, visualize=False,
else:
discr_tag_to_group_factory = {}

from grudge import DiscretizationCollection
from grudge.discretization import make_discretization_collection

dcoll = DiscretizationCollection(
dcoll = make_discretization_collection(
actx, mesh, order=order,
discr_tag_to_group_factory=discr_tag_to_group_factory
)
Expand All @@ -160,7 +160,7 @@ def f_halfcircle(x):
* (0.5+0.5*actx.np.tanh(500*(dist[0]))))

def zero_inflow_bc(dtag, t=0):
dd = dof_desc.DOFDesc(dtag, qtag)
dd = dof_desc.as_dofdesc(dtag, qtag)
return dcoll.discr_from_dd(dd).zeros(actx)

from grudge.models.advection import VariableCoefficientAdvectionOperator
Expand Down
12 changes: 6 additions & 6 deletions examples/advection/weak.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import pyopencl as cl
import pyopencl.tools as cl_tools
from meshmode.dof_array import flatten
from arraycontext import flatten
from meshmode.mesh import BTAG_ALL

import grudge.dof_desc as dof_desc
Expand All @@ -58,8 +58,8 @@ def __init__(self, actx, dcoll, order, visualize=True, ylim=None):
self.fig = pt.figure(figsize=(8, 8), dpi=300)
self.ylim = ylim

volume_discr = dcoll.discr_from_dd(dof_desc.DD_VOLUME)
self.x = actx.to_numpy(flatten(actx.thaw(volume_discr.nodes()[0])))
volume_discr = dcoll.discr_from_dd(dof_desc.DD_VOLUME_ALL)
self.x = actx.to_numpy(flatten(volume_discr.nodes()[0], self.actx))
else:
from grudge.shortcuts import make_visualizer
self.vis = make_visualizer(dcoll)
Expand All @@ -69,7 +69,7 @@ def __call__(self, evt, basename, overwrite=True):
return

if self.dim == 1:
u = self.actx.to_numpy(flatten(evt.state_component))
u = self.actx.to_numpy(flatten(evt.state_component, self.actx))

filename = f"{basename}.png"
if not overwrite and os.path.exists(filename):
Expand Down Expand Up @@ -131,9 +131,9 @@ def main(ctx_factory, dim=2, order=4, visualize=False):
[np.linspace(-d/2, d/2, npoints) for _ in range(dim)],
order=order)

from grudge import DiscretizationCollection
from grudge.discretization import make_discretization_collection

dcoll = DiscretizationCollection(actx, mesh, order=order)
dcoll = make_discretization_collection(actx, mesh, order=order)

# }}}

Expand Down
16 changes: 9 additions & 7 deletions examples/euler/acoustic_pulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import pyopencl as cl
import pyopencl.tools as cl_tools
from arraycontext import ArrayContext
from meshmode.mesh import BTAG_ALL
from pytools.obj_array import make_obj_array

Expand All @@ -42,6 +43,7 @@


def gaussian_profile(
actx: ArrayContext,
x_vec, t=0, rho0=1.0, rhoamp=1.0, p0=1.0, gamma=1.4,
center=None, velocity=None):

Expand All @@ -57,12 +59,11 @@ def gaussian_profile(
rel_center = make_obj_array(
[x_vec[i] - lump_loc[i] for i in range(dim)]
)
actx = x_vec[0].array_context
r = actx.np.sqrt(np.dot(rel_center, rel_center))
expterm = rhoamp * actx.np.exp(1 - r ** 2)

mass = expterm + rho0
mom = velocity * mass
mom = velocity.astype(object) * mass
energy = (p0 / (gamma - 1.0)) + np.dot(mom, mom) / (2.0 * mass)

return ConservedEulerField(mass=mass, energy=energy, momentum=mom)
Expand All @@ -81,11 +82,12 @@ def make_pulse(amplitude, r0, w, r):
return amplitude * actx.np.exp(-.5 * r2)


def acoustic_pulse_condition(x_vec, t=0):
def acoustic_pulse_condition(actx: ArrayContext, x_vec, t=0):
dim = len(x_vec)
vel = np.zeros(shape=(dim,))
orig = np.zeros(shape=(dim,))
uniform_gaussian = gaussian_profile(
actx,
x_vec, t=t, center=orig, velocity=vel, rhoamp=0.0)

amplitude = 1.0
Expand Down Expand Up @@ -126,7 +128,7 @@ def run_acoustic_pulse(actx,
default_simplex_group_factory,
)

from grudge import DiscretizationCollection
from grudge.discretization import make_discretization_collection
from grudge.dof_desc import DISCR_TAG_BASE, DISCR_TAG_QUAD

exp_name = f"fld-acoustic-pulse-N{order}-K{resolution}"
Expand All @@ -136,7 +138,7 @@ def run_acoustic_pulse(actx,
else:
quad_tag = None

dcoll = DiscretizationCollection(
dcoll = make_discretization_collection(
actx, mesh,
discr_tag_to_group_factory={
DISCR_TAG_BASE: default_simplex_group_factory(
Expand All @@ -158,7 +160,7 @@ def run_acoustic_pulse(actx,
)

def rhs(t, q):
return euler_operator.operator(t, q)
return euler_operator.operator(actx, t, q)

compiled_rhs = actx.compile(rhs)

Expand All @@ -168,7 +170,7 @@ def rhs(t, q):
cn = 0.5*(order + 1)**2
dt = cfl * actx.to_numpy(h_min_from_volume(dcoll)) / cn

fields = acoustic_pulse_condition(actx.thaw(dcoll.nodes()))
fields = acoustic_pulse_condition(actx, actx.thaw(dcoll.nodes()))

logger.info("Timestep size: %g", dt)

Expand Down
6 changes: 3 additions & 3 deletions examples/euler/vortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def run_vortex(actx, order=3, resolution=8, final_time=5,
default_simplex_group_factory,
)

from grudge import DiscretizationCollection
from grudge.discretization import make_discretization_collection
from grudge.dof_desc import DISCR_TAG_BASE, DISCR_TAG_QUAD

exp_name = f"fld-vortex-N{order}-K{resolution}-{flux_type}"
Expand All @@ -85,7 +85,7 @@ def run_vortex(actx, order=3, resolution=8, final_time=5,
else:
quad_tag = None

dcoll = DiscretizationCollection(
dcoll = make_discretization_collection(
actx, mesh,
discr_tag_to_group_factory={
DISCR_TAG_BASE: default_simplex_group_factory(
Expand All @@ -106,7 +106,7 @@ def run_vortex(actx, order=3, resolution=8, final_time=5,
)

def rhs(t, q):
return euler_operator.operator(t, q)
return euler_operator.operator(actx, t, q)

compiled_rhs = actx.compile(rhs)

Expand Down
11 changes: 6 additions & 5 deletions examples/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@

from grudge.array_context import PyOpenCLArrayContext

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


def main(write_output=True):
Expand All @@ -47,13 +48,13 @@ def main(write_output=True):

from meshmode.mesh import BTAG_ALL
from meshmode.mesh.generation import generate_warped_rect_mesh
mesh = generate_warped_rect_mesh(dim=2, order=4, nelements_side=6)

dcoll = DiscretizationCollection(actx, mesh, order=4)
mesh = generate_warped_rect_mesh(dim=2, order=4, nelements_side=6)
dcoll = make_discretization_collection(actx, mesh, order=4)

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

if write_output:
vis = shortcuts.make_visualizer(dcoll)
Expand Down
6 changes: 3 additions & 3 deletions examples/maxwell/cavities.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import pyopencl as cl
import pyopencl.tools as cl_tools

import grudge.op as op
from grudge import DiscretizationCollection
from grudge import op
from grudge.array_context import PyOpenCLArrayContext
from grudge.discretization import make_discretization_collection
from grudge.models.em import get_rectangular_cavity_mode
from grudge.shortcuts import set_up_rk4

Expand All @@ -56,7 +56,7 @@ def main(ctx_factory, dim=3, order=4, visualize=False):
b=(1.0,)*dim,
nelements_per_axis=(4,)*dim)

dcoll = DiscretizationCollection(actx, mesh, order=order)
dcoll = make_discretization_collection(actx, mesh, order=order)

if 0:
epsilon0 = 8.8541878176e-12 # C**2 / (N m**2)
Expand Down
Loading
Loading