Skip to content

Commit

Permalink
Fix some deprecated usage in Firedrake connections
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Jun 28, 2023
1 parent 92ad291 commit 64d59bb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
28 changes: 15 additions & 13 deletions examples/from_firedrake.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# This example provides a brief template for bringing information in
# from firedrake and makes some plots to help you better understand
# what a FromBoundaryFiredrakeConnection does
def main():
def main(visualize=True):
# If can't import firedrake, do nothing
#
# filename MUST include "firedrake" (i.e. match *firedrake*.py) in order
Expand All @@ -52,7 +52,7 @@ def main():
# Make connections
cl_ctx = cl.create_some_context()
queue = cl.CommandQueue(cl_ctx)
actx = PyOpenCLArrayContext(queue)
actx = PyOpenCLArrayContext(queue, force_device_scalars=True)

fd_connection = build_connection_from_firedrake(actx, fd_fspace)
fd_bdy_connection = \
Expand Down Expand Up @@ -84,24 +84,26 @@ def main():
vis = make_visualizer(actx, discr, discr.groups[0].order+3)
field = fd_connection.from_firedrake(fd_fntn, actx=actx)

fig = plt.figure()
ax1 = fig.add_subplot(1, 2, 1, projection="3d")
ax1.set_title("cos(x+y) in\nFiredrakeConnection")
vis.show_scalar_in_matplotlib_3d(field, do_show=False)
if visualize:
fig = plt.figure()
ax1 = fig.add_subplot(1, 2, 1, projection="3d")
ax1.set_title("cos(x+y) in\nFiredrakeConnection")
vis.show_scalar_in_matplotlib_3d(field, do_show=False)

# Now repeat using FiredrakeConnection restricted to "on_boundary"
bdy_discr = fd_bdy_connection.discr
bdy_vis = make_visualizer(actx, bdy_discr, bdy_discr.groups[0].order+3)
bdy_field = fd_bdy_connection.from_firedrake(fd_fntn, actx=actx)

ax2 = fig.add_subplot(1, 2, 2, projection="3d")
plt.sca(ax2)
ax2.set_title("cos(x+y) in\nFiredrakeConnection 'on_boundary'")
bdy_vis.show_scalar_in_matplotlib_3d(bdy_field, do_show=False)
if visualize:
ax2 = fig.add_subplot(1, 2, 2, projection="3d")
plt.sca(ax2)
ax2.set_title("cos(x+y) in\nFiredrakeConnection 'on_boundary'")
bdy_vis.show_scalar_in_matplotlib_3d(bdy_field, do_show=False)

import matplotlib.cm as cm
fig.colorbar(cm.ScalarMappable(), ax=ax2)
plt.show()
import matplotlib.cm as cm
fig.colorbar(cm.ScalarMappable(), ax=ax2)
plt.show()


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/to_firedrake.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def main():

cl_ctx = cl.create_some_context()
queue = cl.CommandQueue(cl_ctx)
actx = PyOpenCLArrayContext(queue)
actx = PyOpenCLArrayContext(queue, force_device_scalars=True)

nel_1d = 16
from meshmode.mesh.generation import generate_regular_rect_mesh
Expand Down
8 changes: 4 additions & 4 deletions meshmode/interop/firedrake/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,8 @@ def from_meshmode(self, mm_field, out=None):
:return: a :class:`firedrake.function.Function` holding the transported
data (*out*, if *out* was not *None*)
"""
# All firedrake functions are the same dtype
dtype = self.firedrake_fspace().mesh().coordinates.dat.data.dtype
self._validate_field(mm_field, "mm_field", dtype=dtype)
# Don't check dtype: if it's numpy-assignable, that's good enough for us.
self._validate_field(mm_field, "mm_field")

# get the shape of mm_field
from meshmode.dof_array import DOFArray
Expand All @@ -523,7 +522,8 @@ def from_meshmode(self, mm_field, out=None):
# make sure out is a firedrake function in an appropriate
# function space
if out is not None:
self._validate_function(out, "out", fspace_shape, dtype)
# Don't check dtype: if it's numpy-assignable, that's good enough for us.
self._validate_function(out, "out", fspace_shape)
else:
from firedrake.function import Function
# Translate shape so that don't always get a TensorFunctionSpace,
Expand Down
8 changes: 4 additions & 4 deletions meshmode/interop/firedrake/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import logging
import numpy as np

from modepy import resampling_matrix, simplex_best_available_basis
from modepy import resampling_matrix, basis_for_space, PN, Simplex

from meshmode.mesh import (
BTAG_ALL,
Expand Down Expand Up @@ -875,7 +875,7 @@ def export_mesh_to_firedrake(mesh, group_nr=None, comm=None):

import firedrake.mesh as fd_mesh
with _PyOp2CommDuplicator(comm) as comm:
plex = fd_mesh._from_cell_list(group.dim, cells, coords, comm)
plex = fd_mesh.plex_from_cell_list(group.dim, cells, coords, comm)

# Nb : One might be tempted to pass reorder=False and thereby save some
# hassle in exchange for forcing firedrake to have slightly
Expand Down Expand Up @@ -949,8 +949,8 @@ def export_mesh_to_firedrake(mesh, group_nr=None, comm=None):
fd_unit_nodes = get_finat_element_unit_nodes(coords_fspace.finat_element)
fd_unit_nodes = fd_ref_cell_to_mm(fd_unit_nodes)

basis = simplex_best_available_basis(group.dim, group.order)
resampling_mat = resampling_matrix(basis,
basis = basis_for_space(PN(group.dim, group.order), Simplex(group.dim))
resampling_mat = resampling_matrix(basis.functions,
new_nodes=fd_unit_nodes,
old_nodes=group.unit_nodes)
# Store the meshmode data resampled to firedrake unit nodes
Expand Down
4 changes: 2 additions & 2 deletions meshmode/interop/firedrake/reference_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def get_affine_reference_simplex_mapping(ambient_dim, firedrake_to_meshmode=True
f"'{type(firedrake_to_meshmode)}'")

from FIAT.reference_element import ufc_simplex
from modepy.tools import unit_vertices
from modepy import unit_vertices_for_shape, Simplex
# Get the unit vertices from each system,
# each stored with shape *(dim, nunit_vertices)*
firedrake_unit_vertices = np.array(ufc_simplex(ambient_dim).vertices).T
modepy_unit_vertices = unit_vertices(ambient_dim).T
modepy_unit_vertices = unit_vertices_for_shape(Simplex(ambient_dim))

if firedrake_to_meshmode:
from_verts = firedrake_unit_vertices
Expand Down

0 comments on commit 64d59bb

Please sign in to comment.