diff --git a/doc/conf.py b/doc/conf.py index ee936c52..64cd3677 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,5 +1,6 @@ from urllib.request import urlopen + _conf_url = \ "https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py" with urlopen(_conf_url) as _inf: @@ -54,4 +55,5 @@ # why this name is as global-sounding as it is. import sys + sys._BUILDING_SPHINX_DOCS = True diff --git a/examples/from_firedrake.py b/examples/from_firedrake.py index f681cb20..55419b48 100644 --- a/examples/from_firedrake.py +++ b/examples/from_firedrake.py @@ -38,10 +38,10 @@ def main(visualize=True): except ImportError: return 0 - from meshmode.interop.firedrake import build_connection_from_firedrake from firedrake import ( - UnitSquareMesh, FunctionSpace, SpatialCoordinate, Function, cos - ) + Function, FunctionSpace, SpatialCoordinate, UnitSquareMesh, cos) + + from meshmode.interop.firedrake import build_connection_from_firedrake # Create a firedrake mesh and interpolate cos(x+y) onto it fd_mesh = UnitSquareMesh(10, 10) @@ -62,6 +62,7 @@ def main(visualize=True): # Plot the meshmode meshes that the connections connect to import matplotlib.pyplot as plt + from meshmode.mesh.visualization import draw_2d_mesh fig, (ax1, ax2) = plt.subplots(1, 2) ax1.set_title("FiredrakeConnection") diff --git a/examples/mesh-to-tikz.py b/examples/mesh-to-tikz.py index e27587fb..e0c38bc8 100644 --- a/examples/mesh-to-tikz.py +++ b/examples/mesh-to-tikz.py @@ -1,6 +1,7 @@ -from meshmode.mesh.io import generate_gmsh, FileSource +from meshmode.mesh.io import FileSource, generate_gmsh from meshmode.mesh.visualization import mesh_to_tikz + h = 0.3 order = 1 diff --git a/examples/moving-geometry.py b/examples/moving-geometry.py index 7337d1d6..35ae149f 100644 --- a/examples/moving-geometry.py +++ b/examples/moving-geometry.py @@ -20,18 +20,19 @@ THE SOFTWARE. """ +import logging from typing import Optional, Type import numpy as np + import pyopencl as cl +from pytools import keyed_memoize_in +from pytools.obj_array import make_obj_array from meshmode.array_context import PyOpenCLArrayContext from meshmode.transform_metadata import FirstAxisIsElementsTag -from pytools import keyed_memoize_in -from pytools.obj_array import make_obj_array -import logging logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) @@ -121,6 +122,7 @@ def run(actx, *, # {{{ element groups import modepy as mp + import meshmode.discretization.poly_element as poly # NOTE: picking the same unit nodes for the mesh and the discr saves diff --git a/examples/multiple-meshes.py b/examples/multiple-meshes.py index a3866891..aea174aa 100644 --- a/examples/multiple-meshes.py +++ b/examples/multiple-meshes.py @@ -1,13 +1,13 @@ -import numpy as np # noqa import sys +import numpy as np # noqa + order = 4 def main(): - from meshmode.mesh.generation import ( # noqa - make_curve_mesh, starfish) + from meshmode.mesh.generation import make_curve_mesh, starfish # noqa mesh1 = make_curve_mesh(starfish, np.linspace(0, 1, 20), 4) from meshmode.mesh.processing import affine_map, merge_disjoint_meshes diff --git a/examples/parallel-vtkhdf.py b/examples/parallel-vtkhdf.py index c5ead8db..0d93ac7f 100644 --- a/examples/parallel-vtkhdf.py +++ b/examples/parallel-vtkhdf.py @@ -1,8 +1,10 @@ import logging + import numpy as np from meshmode.mesh import Mesh + logger = logging.getLogger(__file__) @@ -33,8 +35,8 @@ def main(*, ambient_dim: int) -> None: from mpi4py import MPI comm = MPI.COMM_WORLD - from meshmode.mesh.processing import partition_mesh from meshmode.distributed import membership_list_to_map + from meshmode.mesh.processing import partition_mesh order = 5 nelements = 64 if ambient_dim == 3 else 256 diff --git a/examples/plot-connectivity.py b/examples/plot-connectivity.py index fea5d9c1..c4a4fc31 100644 --- a/examples/plot-connectivity.py +++ b/examples/plot-connectivity.py @@ -1,8 +1,10 @@ import numpy as np # noqa + import pyopencl as cl from meshmode.array_context import PyOpenCLArrayContext + order = 4 @@ -12,15 +14,15 @@ def main(): actx = PyOpenCLArrayContext(queue) from meshmode.mesh.generation import ( # noqa: F401 - generate_sphere, generate_icosahedron, - generate_torus) + generate_icosahedron, generate_sphere, generate_torus) + #mesh = generate_sphere(1, order=order) mesh = generate_icosahedron(1, order=order) #mesh = generate_torus(3, 1, order=order) from meshmode.discretization import Discretization - from meshmode.discretization.poly_element import \ - PolynomialWarpAndBlend3DRestrictingGroupFactory + from meshmode.discretization.poly_element import ( + PolynomialWarpAndBlend3DRestrictingGroupFactory) discr = Discretization( actx, mesh, PolynomialWarpAndBlend3DRestrictingGroupFactory(order)) @@ -32,8 +34,7 @@ def main(): ("f", actx.thaw(discr.nodes()[0])), ]) - from meshmode.discretization.visualization import \ - write_nodal_adjacency_vtk_file + from meshmode.discretization.visualization import write_nodal_adjacency_vtk_file write_nodal_adjacency_vtk_file("adjacency.vtu", mesh) diff --git a/examples/simple-dg.py b/examples/simple-dg.py index 47d47351..a0eda7a4 100644 --- a/examples/simple-dg.py +++ b/examples/simple-dg.py @@ -20,29 +20,26 @@ THE SOFTWARE. """ +import logging from dataclasses import dataclass + import numpy as np import numpy.linalg as la # noqa import pyopencl as cl import pyopencl.array as cla # noqa - -from pytools import memoize_method, log_process +from arraycontext import ( + ArrayContainer, dataclass_array_container, map_array_container, + with_container_arithmetic) +from pytools import log_process, memoize_method from pytools.obj_array import flat_obj_array, make_obj_array -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from meshmode.array_context import PyOpenCLArrayContext, PytatoPyOpenCLArrayContext from meshmode.dof_array import DOFArray, flat_norm -from meshmode.array_context import (PyOpenCLArrayContext, - PytatoPyOpenCLArrayContext) -from arraycontext import ( - ArrayContainer, - map_array_container, - with_container_arithmetic, - dataclass_array_container, - ) +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa from meshmode.transform_metadata import FirstAxisIsElementsTag -import logging + logger = logging.getLogger(__name__) @@ -73,8 +70,8 @@ def __init__(self, actx, mesh, order): self.order = order from meshmode.discretization import Discretization - from meshmode.discretization.poly_element import \ - PolynomialWarpAndBlend2DRestrictingGroupFactory + from meshmode.discretization.poly_element import ( + PolynomialWarpAndBlend2DRestrictingGroupFactory) self.group_factory = PolynomialWarpAndBlend2DRestrictingGroupFactory( order=order) self.volume_discr = Discretization(actx, mesh, self.group_factory) @@ -103,7 +100,7 @@ def boundary_connection(self, boundary_tag): @memoize_method def interior_faces_connection(self): from meshmode.discretization.connection import ( - make_face_restriction, FACE_RESTR_INTERIOR) + FACE_RESTR_INTERIOR, make_face_restriction) return make_face_restriction( self.volume_discr._setup_actx, self.volume_discr, @@ -113,8 +110,7 @@ def interior_faces_connection(self): @memoize_method def opposite_face_connection(self): - from meshmode.discretization.connection import \ - make_opposite_face_connection + from meshmode.discretization.connection import make_opposite_face_connection return make_opposite_face_connection( self._setup_actx, self.interior_faces_connection()) @@ -122,7 +118,7 @@ def opposite_face_connection(self): @memoize_method def all_faces_connection(self): from meshmode.discretization.connection import ( - make_face_restriction, FACE_RESTR_ALL) + FACE_RESTR_ALL, make_face_restriction) return make_face_restriction( self.volume_discr._setup_actx, self.volume_discr, @@ -132,8 +128,8 @@ def all_faces_connection(self): @memoize_method def get_to_all_face_embedding(self, where): - from meshmode.discretization.connection import \ - make_face_to_all_faces_embedding + from meshmode.discretization.connection import ( + make_face_to_all_faces_embedding) faces_conn = self.get_connection("vol", where) return make_face_to_all_faces_embedding( @@ -277,7 +273,7 @@ def get_local_face_mass_matrix(self, afgrp, volgrp, dtype): shape = mp.Simplex(volgrp.dim) for face in mp.faces_for_shape(shape): - from modepy import basis_for_space, quadrature_for_space, PN, Simplex + from modepy import PN, Simplex, basis_for_space, quadrature_for_space face_space = PN(volgrp.dim - 1, volgrp.order) face_shape = Simplex(volgrp.dim-1) face_quad = quadrature_for_space(face_space, face_shape) diff --git a/examples/to_firedrake.py b/examples/to_firedrake.py index 754cb366..d8ca8dc3 100644 --- a/examples/to_firedrake.py +++ b/examples/to_firedrake.py @@ -22,6 +22,7 @@ import numpy as np + import pyopencl as cl from meshmode.array_context import PyOpenCLArrayContext @@ -63,8 +64,8 @@ def main(): order = 3 from meshmode.discretization import Discretization - from meshmode.discretization.poly_element import \ - InterpolatoryQuadratureSimplexGroupFactory + from meshmode.discretization.poly_element import ( + InterpolatoryQuadratureSimplexGroupFactory) group_factory = InterpolatoryQuadratureSimplexGroupFactory(order=order) discr = Discretization(actx, mesh, group_factory) @@ -91,8 +92,8 @@ def main(): # set up dirichlet laplace problem in fd and solve from firedrake import ( - FunctionSpace, TrialFunction, TestFunction, Function, inner, grad, dx, - Constant, project, DirichletBC, solve) + Constant, DirichletBC, Function, FunctionSpace, TestFunction, TrialFunction, + dx, grad, inner, project, solve) # because it's easier to write down the variational problem, # we're going to project from our "DG" space diff --git a/examples/tp-lagrange-stl.py b/examples/tp-lagrange-stl.py index e7c43114..bd973bb4 100644 --- a/examples/tp-lagrange-stl.py +++ b/examples/tp-lagrange-stl.py @@ -3,15 +3,16 @@ import numpy as np import numpy.linalg as la + +import modepy import pyopencl as cl -from meshmode.array_context import PyOpenCLArrayContext -import meshmode.mesh.generation as mgen -import meshmode.discretization.poly_element as poly + import meshmode.discretization.connection as conn +import meshmode.discretization.poly_element as poly +import meshmode.mesh.generation as mgen +from meshmode.array_context import PyOpenCLArrayContext from meshmode.discretization import Discretization -from meshmode.mesh import Mesh, BTAG_ALL - -import modepy +from meshmode.mesh import BTAG_ALL, Mesh def main(): diff --git a/meshmode/__init__.py b/meshmode/__init__.py index 8f5cc282..d707a281 100644 --- a/meshmode/__init__.py +++ b/meshmode/__init__.py @@ -29,6 +29,7 @@ """ from builtins import FileExistsError # noqa: F401 + from meshmode.mesh.tools import AffineMap # noqa: F401 @@ -53,6 +54,7 @@ def _acf(): argument when running them from the command line. """ import pyopencl as cl + from meshmode.array_context import PyOpenCLArrayContext context = cl._csc() diff --git a/meshmode/array_context.py b/meshmode/array_context.py index 259ceabc..731fd060 100644 --- a/meshmode/array_context.py +++ b/meshmode/array_context.py @@ -27,12 +27,13 @@ import sys from warnings import warn -from arraycontext import PyOpenCLArrayContext as PyOpenCLArrayContextBase -from arraycontext import PytatoPyOpenCLArrayContext as PytatoPyOpenCLArrayContextBase + +from arraycontext import ( + PyOpenCLArrayContext as PyOpenCLArrayContextBase, + PytatoPyOpenCLArrayContext as PytatoPyOpenCLArrayContextBase) from arraycontext.pytest import ( - _PytestPyOpenCLArrayContextFactoryWithClass, - _PytestPytatoPyOpenCLArrayContextFactory, - register_pytest_array_context_factory) + _PytestPyOpenCLArrayContextFactoryWithClass, + _PytestPytatoPyOpenCLArrayContextFactory, register_pytest_array_context_factory) def thaw(actx, ary): @@ -48,11 +49,11 @@ def thaw(actx, ary): def _transform_loopy_inner(t_unit): import loopy as lp - from meshmode.transform_metadata import FirstAxisIsElementsTag from arraycontext.transform_metadata import ElementwiseMapKernelTag - from pymbolic.primitives import Subscript, Variable + from meshmode.transform_metadata import FirstAxisIsElementsTag + default_ep = t_unit.default_entrypoint # FIXME: Firedrake branch lacks kernel tags @@ -155,8 +156,8 @@ def _transform_loopy_inner(t_unit): # {{{ element/dof iname tag - from meshmode.transform_metadata import \ - ConcurrentElementInameTag, ConcurrentDOFInameTag + from meshmode.transform_metadata import ( + ConcurrentDOFInameTag, ConcurrentElementInameTag) el_inames = [iname.name for iname in default_ep.inames.values() if ConcurrentElementInameTag() in iname.tags] diff --git a/meshmode/discretization/__init__.py b/meshmode/discretization/__init__.py index 3f5ae457..a14d02d8 100644 --- a/meshmode/discretization/__init__.py +++ b/meshmode/discretization/__init__.py @@ -24,25 +24,22 @@ """ from abc import ABC, abstractmethod +from typing import Hashable, Iterable, Optional, Protocol, runtime_checkable from warnings import warn -from typing import Hashable, Iterable, Protocol, Optional, runtime_checkable import numpy as np import loopy as lp from arraycontext import ArrayContext, make_loopy_program, tag_axes -from pytools import memoize_in, memoize_method, keyed_memoize_in +from pytools import keyed_memoize_in, memoize_in, memoize_method from pytools.obj_array import make_obj_array -from meshmode.transform_metadata import ( - ConcurrentElementInameTag, ConcurrentDOFInameTag, - FirstAxisIsElementsTag, DiscretizationElementAxisTag, - DiscretizationDOFAxisTag) # underscored because it shouldn't be imported from here. from meshmode.dof_array import DOFArray as _DOFArray -from meshmode.mesh import ( - Mesh as _Mesh, - MeshElementGroup as _MeshElementGroup) +from meshmode.mesh import Mesh as _Mesh, MeshElementGroup as _MeshElementGroup +from meshmode.transform_metadata import ( + ConcurrentDOFInameTag, ConcurrentElementInameTag, DiscretizationDOFAxisTag, + DiscretizationElementAxisTag, FirstAxisIsElementsTag) __doc__ = """ diff --git a/meshmode/discretization/connection/__init__.py b/meshmode/discretization/connection/__init__.py index 2d667ef6..00fa51ea 100644 --- a/meshmode/discretization/connection/__init__.py +++ b/meshmode/discretization/connection/__init__.py @@ -23,34 +23,29 @@ THE SOFTWARE. """ -from meshmode.discretization.connection.direct import ( - InterpolationBatch, - DiscretizationConnectionElementGroup, - DiscretizationConnection, - IdentityDiscretizationConnection, - DirectDiscretizationConnection) -from meshmode.discretization.connection.chained import \ - ChainedDiscretizationConnection -from meshmode.discretization.connection.projection import \ - L2ProjectionInverseDiscretizationConnection +import logging from arraycontext import ArrayContext -from meshmode.discretization.connection.same_mesh import \ - make_same_mesh_connection + +from meshmode.discretization.connection.chained import ( + ChainedDiscretizationConnection, flatten_chained_connection) +from meshmode.discretization.connection.direct import ( + DirectDiscretizationConnection, DiscretizationConnection, + DiscretizationConnectionElementGroup, IdentityDiscretizationConnection, + InterpolationBatch) from meshmode.discretization.connection.face import ( - FACE_RESTR_INTERIOR, FACE_RESTR_ALL, - make_face_restriction, - make_face_to_all_faces_embedding) -from meshmode.discretization.connection.opposite_face import \ - make_opposite_face_connection, make_partition_connection -from meshmode.discretization.connection.refinement import \ - make_refinement_connection -from meshmode.discretization.connection.chained import \ - flatten_chained_connection -from meshmode.discretization.connection.modal import \ - NodalToModalDiscretizationConnection, ModalToNodalDiscretizationConnection + FACE_RESTR_ALL, FACE_RESTR_INTERIOR, make_face_restriction, + make_face_to_all_faces_embedding) +from meshmode.discretization.connection.modal import ( + ModalToNodalDiscretizationConnection, NodalToModalDiscretizationConnection) +from meshmode.discretization.connection.opposite_face import ( + make_opposite_face_connection, make_partition_connection) +from meshmode.discretization.connection.projection import ( + L2ProjectionInverseDiscretizationConnection) +from meshmode.discretization.connection.refinement import make_refinement_connection +from meshmode.discretization.connection.same_mesh import make_same_mesh_connection + -import logging logger = logging.getLogger(__name__) diff --git a/meshmode/discretization/connection/chained.py b/meshmode/discretization/connection/chained.py index a131d632..79dea7cb 100644 --- a/meshmode/discretization/connection/chained.py +++ b/meshmode/discretization/connection/chained.py @@ -21,11 +21,12 @@ """ from dataclasses import dataclass + import numpy as np import modepy as mp -from meshmode.discretization.connection.direct import \ - DiscretizationConnection + +from meshmode.discretization.connection.direct import DiscretizationConnection # {{{ chained discretization connection @@ -145,8 +146,7 @@ def find_batch(nodes, gtb): def _build_batches(actx, from_bins, to_bins, batch): - from meshmode.discretization.connection.direct import \ - InterpolationBatch + from meshmode.discretization.connection.direct import InterpolationBatch def to_device(x): return actx.freeze(actx.from_numpy(np.asarray(x))) @@ -196,10 +196,8 @@ def flatten_chained_connection(actx, connection): :class:`~meshmode.discretization.connection.DirectDiscretizationConnection`. """ from meshmode.discretization.connection import ( - IdentityDiscretizationConnection, - DirectDiscretizationConnection, - DiscretizationConnectionElementGroup, - make_same_mesh_connection) + DirectDiscretizationConnection, DiscretizationConnectionElementGroup, + IdentityDiscretizationConnection, make_same_mesh_connection) if not hasattr(connection, "connections"): return connection @@ -284,8 +282,8 @@ def make_full_resample_matrix(actx, connection): :return: a :class:`pyopencl.array.Array` of shape `(connection.from_discr.ndofs, connection.to_discr.ndofs)`. """ - from meshmode.discretization.connection.direct import \ - DirectDiscretizationConnection, make_direct_full_resample_matrix + from meshmode.discretization.connection.direct import ( + DirectDiscretizationConnection, make_direct_full_resample_matrix) if isinstance(connection, DirectDiscretizationConnection): return make_direct_full_resample_matrix(actx, connection) diff --git a/meshmode/discretization/connection/direct.py b/meshmode/discretization/connection/direct.py index 0a01dbba..2dfffc4e 100644 --- a/meshmode/discretization/connection/direct.py +++ b/meshmode/discretization/connection/direct.py @@ -20,29 +20,25 @@ THE SOFTWARE. """ -import numpy as np -import numpy.linalg as la from abc import ABC, abstractmethod +from dataclasses import dataclass +from typing import Generic, List, Optional, Sequence, Tuple -from typing import Generic, Sequence, Optional, List, Tuple -from pytools import memoize_method +import numpy as np +import numpy.linalg as la import loopy as lp -from meshmode.transform_metadata import ( - ConcurrentElementInameTag, ConcurrentDOFInameTag, - DiscretizationElementAxisTag, DiscretizationDOFAxisTag) -from pytools import memoize_in, keyed_memoize_method from arraycontext import ( - ArrayContext, ArrayT, ArrayOrContainerT, NotAnArrayContainerError, - serialize_container, deserialize_container, make_loopy_program, - tag_axes - ) + ArrayContext, ArrayOrContainerT, ArrayT, NotAnArrayContainerError, + deserialize_container, make_loopy_program, serialize_container, tag_axes) from arraycontext.metadata import NameHint +from pytools import keyed_memoize_method, memoize_in, memoize_method from meshmode.discretization import Discretization, ElementGroupBase from meshmode.dof_array import DOFArray - -from dataclasses import dataclass +from meshmode.transform_metadata import ( + ConcurrentDOFInameTag, ConcurrentElementInameTag, DiscretizationDOFAxisTag, + DiscretizationElementAxisTag) def _reshape_and_preserve_tags( diff --git a/meshmode/discretization/connection/face.py b/meshmode/discretization/connection/face.py index ae03cb58..62d67cd1 100644 --- a/meshmode/discretization/connection/face.py +++ b/meshmode/discretization/connection/face.py @@ -20,14 +20,17 @@ THE SOFTWARE. """ +import logging from dataclasses import dataclass -from meshmode.transform_metadata import DiscretizationElementAxisTag -from arraycontext.metadata import NameHint import numpy as np + import modepy as mp +from arraycontext.metadata import NameHint + +from meshmode.transform_metadata import DiscretizationElementAxisTag + -import logging logger = logging.getLogger(__name__) @@ -64,9 +67,8 @@ class _ConnectionBatchData: def _build_boundary_connection(actx, vol_discr, bdry_discr, connection_data, per_face_groups): from meshmode.discretization.connection.direct import ( - InterpolationBatch, - DiscretizationConnectionElementGroup, - DirectDiscretizationConnection) + DirectDiscretizationConnection, DiscretizationConnectionElementGroup, + InterpolationBatch) ibdry_grp = 0 batches = [] @@ -406,9 +408,8 @@ def make_face_to_all_faces_embedding(actx, faces_connection, all_faces_discr, "same number of groups") from meshmode.discretization.connection import ( - DirectDiscretizationConnection, - DiscretizationConnectionElementGroup, - InterpolationBatch) + DirectDiscretizationConnection, DiscretizationConnectionElementGroup, + InterpolationBatch) i_faces_grp = 0 diff --git a/meshmode/discretization/connection/modal.py b/meshmode/discretization/connection/modal.py index 4a45ceab..3897f883 100644 --- a/meshmode/discretization/connection/modal.py +++ b/meshmode/discretization/connection/modal.py @@ -25,17 +25,17 @@ import numpy as np import numpy.linalg as la -import modepy as mp +import modepy as mp from arraycontext import ( - NotAnArrayContainerError, serialize_container, deserialize_container, tag_axes) -from meshmode.transform_metadata import (FirstAxisIsElementsTag, - DiscretizationDOFAxisTag) + NotAnArrayContainerError, deserialize_container, serialize_container, tag_axes) +from pytools import keyed_memoize_in + from meshmode.discretization import InterpolatoryElementGroupBase -from meshmode.discretization.poly_element import QuadratureSimplexElementGroup from meshmode.discretization.connection.direct import DiscretizationConnection - -from pytools import keyed_memoize_in +from meshmode.discretization.poly_element import QuadratureSimplexElementGroup +from meshmode.transform_metadata import ( + DiscretizationDOFAxisTag, FirstAxisIsElementsTag) class NodalToModalDiscretizationConnection(DiscretizationConnection): diff --git a/meshmode/discretization/connection/opposite_face.py b/meshmode/discretization/connection/opposite_face.py index 19051ac8..5d248a70 100644 --- a/meshmode/discretization/connection/opposite_face.py +++ b/meshmode/discretization/connection/opposite_face.py @@ -21,11 +21,14 @@ """ +import logging + import numpy as np import numpy.linalg as la + from meshmode.discretization.connection.direct import InterpolationBatch -import logging + logger = logging.getLogger(__name__) @@ -479,8 +482,9 @@ def make_opposite_face_connection(actx, volume_to_bdry_conn): print("TVE", adj.elements[adj_tgt_flags]) print("TBE", tgt_bdry_element_indices) print("FVE", src_vol_element_indices) - from meshmode.mesh.visualization import draw_2d_mesh import matplotlib.pyplot as pt + + from meshmode.mesh.visualization import draw_2d_mesh draw_2d_mesh(vol_discr.mesh, draw_element_numbers=True, set_bounding_box=True, draw_vertex_numbers=False, @@ -507,7 +511,7 @@ def make_opposite_face_connection(actx, volume_to_bdry_conn): groups[i_tgt_grp].extend(batches) from meshmode.discretization.connection import ( - DirectDiscretizationConnection, DiscretizationConnectionElementGroup) + DirectDiscretizationConnection, DiscretizationConnectionElementGroup) return DirectDiscretizationConnection( from_discr=bdry_discr, to_discr=bdry_discr, @@ -541,9 +545,9 @@ def make_partition_connection(actx, *, local_bdry_conn, .. warning:: Interface is not final. """ - from meshmode.mesh.processing import find_group_indices from meshmode.discretization.connection import ( - DirectDiscretizationConnection, DiscretizationConnectionElementGroup) + DirectDiscretizationConnection, DiscretizationConnectionElementGroup) + from meshmode.mesh.processing import find_group_indices local_vol_mesh = local_bdry_conn.from_discr.mesh local_vol_groups = local_vol_mesh.groups diff --git a/meshmode/discretization/connection/projection.py b/meshmode/discretization/connection/projection.py index 179dbf8e..5c13d8da 100644 --- a/meshmode/discretization/connection/projection.py +++ b/meshmode/discretization/connection/projection.py @@ -22,19 +22,17 @@ import numpy as np -from pytools import keyed_memoize_method, keyed_memoize_in, memoize_in - import loopy as lp - from arraycontext import ( - NotAnArrayContainerError, - make_loopy_program, serialize_container, deserialize_container) -from meshmode.transform_metadata import FirstAxisIsElementsTag + NotAnArrayContainerError, deserialize_container, make_loopy_program, + serialize_container) +from pytools import keyed_memoize_in, keyed_memoize_method, memoize_in + +from meshmode.discretization.connection.chained import ( + ChainedDiscretizationConnection) from meshmode.discretization.connection.direct import ( - DiscretizationConnection, - DirectDiscretizationConnection) -from meshmode.discretization.connection.chained import \ - ChainedDiscretizationConnection + DirectDiscretizationConnection, DiscretizationConnection) +from meshmode.transform_metadata import FirstAxisIsElementsTag class L2ProjectionInverseDiscretizationConnection(DiscretizationConnection): @@ -89,10 +87,11 @@ def _batch_weights(self, actx): :return: a dictionary with keys ``(group_id, batch_id)``. """ - from pymbolic.geometric_algebra import MultiVector from functools import reduce from operator import xor + from pymbolic.geometric_algebra import MultiVector + def det(v): nnodes = v[0].shape[0] det_v = np.empty(nnodes) @@ -186,7 +185,7 @@ def kproj(): name="conn_projection_knl" ) from meshmode.transform_metadata import ( - ConcurrentElementInameTag, ConcurrentDOFInameTag) + ConcurrentDOFInameTag, ConcurrentElementInameTag) return lp.tag_inames(t_unit, { "iel_init": ConcurrentElementInameTag(), "idof_init": ConcurrentDOFInameTag(), diff --git a/meshmode/discretization/connection/refinement.py b/meshmode/discretization/connection/refinement.py index 204d2728..f6252e32 100644 --- a/meshmode/discretization/connection/refinement.py +++ b/meshmode/discretization/connection/refinement.py @@ -20,10 +20,13 @@ THE SOFTWARE. """ +import logging + import numpy as np from pytools import log_process -import logging + + logger = logging.getLogger(__name__) @@ -126,8 +129,7 @@ def make_refinement_connection(actx, refiner, coarse_discr, group_factory): for discretizing the fine mesh. """ from meshmode.discretization.connection import ( - DiscretizationConnectionElementGroup, - DirectDiscretizationConnection) + DirectDiscretizationConnection, DiscretizationConnectionElementGroup) coarse_mesh = refiner.get_previous_mesh() fine_mesh = refiner.get_current_mesh() diff --git a/meshmode/discretization/connection/same_mesh.py b/meshmode/discretization/connection/same_mesh.py index 4c64728b..9cf2b24b 100644 --- a/meshmode/discretization/connection/same_mesh.py +++ b/meshmode/discretization/connection/same_mesh.py @@ -21,6 +21,7 @@ """ import numpy as np + from meshmode.transform_metadata import DiscretizationElementAxisTag @@ -28,10 +29,8 @@ def make_same_mesh_connection(actx, to_discr, from_discr): from meshmode.discretization.connection.direct import ( - InterpolationBatch, - DiscretizationConnectionElementGroup, - IdentityDiscretizationConnection, - DirectDiscretizationConnection) + DirectDiscretizationConnection, DiscretizationConnectionElementGroup, + IdentityDiscretizationConnection, InterpolationBatch) if from_discr.mesh is not to_discr.mesh: raise ValueError("from_discr and to_discr must be based on " diff --git a/meshmode/discretization/poly_element.py b/meshmode/discretization/poly_element.py index 7dd99417..10006e17 100644 --- a/meshmode/discretization/poly_element.py +++ b/meshmode/discretization/poly_element.py @@ -28,20 +28,19 @@ from warnings import warn import numpy as np -from pytools import memoize_method, memoize_on_first_arg -from meshmode.mesh import ( - MeshElementGroup as _MeshElementGroup, - SimplexElementGroup as _MeshSimplexElementGroup, - TensorProductElementGroup as _MeshTensorProductElementGroup) -from meshmode.discretization import ( - NoninterpolatoryElementGroupError, - ElementGroupBase, - ElementGroupFactory, - NodalElementGroupBase, ModalElementGroupBase, - InterpolatoryElementGroupBase) import modepy as mp from modepy import Basis +from pytools import memoize_method, memoize_on_first_arg + +from meshmode.discretization import ( + ElementGroupBase, ElementGroupFactory, InterpolatoryElementGroupBase, + ModalElementGroupBase, NodalElementGroupBase, NoninterpolatoryElementGroupError) +from meshmode.mesh import ( + MeshElementGroup as _MeshElementGroup, + SimplexElementGroup as _MeshSimplexElementGroup, + TensorProductElementGroup as _MeshTensorProductElementGroup) + __doc__ = """ Group types diff --git a/meshmode/discretization/visualization.py b/meshmode/discretization/visualization.py index 0597abd0..ddbd7d65 100644 --- a/meshmode/discretization/visualization.py +++ b/meshmode/discretization/visualization.py @@ -23,21 +23,22 @@ THE SOFTWARE. """ +import logging from dataclasses import dataclass from functools import singledispatch from typing import Any, Dict, List, Optional, Tuple import numpy as np +from arraycontext import flatten +from modepy.shapes import Hypercube, Shape, Simplex from pytools import memoize_method from pytools.obj_array import make_obj_array -from arraycontext import flatten + from meshmode.dof_array import DOFArray from meshmode.transform_metadata import DiscretizationFlattenedDOFAxisTag -from modepy.shapes import Shape, Simplex, Hypercube -import logging logger = logging.getLogger(__name__) __doc__ = """ @@ -62,8 +63,7 @@ def separate_by_real_and_imag(names_and_fields, real_only): if isinstance(field, np.ndarray) and field.dtype.char == "O": assert len(field.shape) == 1 from pytools.obj_array import ( - obj_array_real_copy, obj_array_imag_copy, - obj_array_vectorize) + obj_array_imag_copy, obj_array_real_copy, obj_array_vectorize) if field[0].dtype.kind == "c": if real_only: @@ -312,6 +312,7 @@ def tensor_cell_types(self): def connectivity_for_element_group(self, grp): import modepy as mp + from meshmode.mesh import _ModepyElementGroup if isinstance(grp.mesh_el_group, _ModepyElementGroup): @@ -428,8 +429,8 @@ def connectivity_for_element_group(self, grp): vtk_version = tuple(int(v) for v in self.version.split(".")) if isinstance(grp.mesh_el_group, SimplexElementGroup): from pyvisfile.vtk.vtk_ordering import ( - vtk_lagrange_simplex_node_tuples, - vtk_lagrange_simplex_node_tuples_to_permutation) + vtk_lagrange_simplex_node_tuples, + vtk_lagrange_simplex_node_tuples_to_permutation) node_tuples = vtk_lagrange_simplex_node_tuples( grp.dim, grp.order, vtk_version=vtk_version) @@ -441,8 +442,8 @@ def connectivity_for_element_group(self, grp): elif isinstance(grp.mesh_el_group, TensorProductElementGroup): from pyvisfile.vtk.vtk_ordering import ( - vtk_lagrange_quad_node_tuples, - vtk_lagrange_quad_node_tuples_to_permutation) + vtk_lagrange_quad_node_tuples, + vtk_lagrange_quad_node_tuples_to_permutation) node_tuples = vtk_lagrange_quad_node_tuples( grp.dim, grp.order, vtk_version=vtk_version) @@ -742,10 +743,8 @@ def write_vtk_file(self, file_name, names_and_fields, use_high_order = False from pyvisfile.vtk import ( - UnstructuredGrid, DataArray, - AppendedDataXMLGenerator, - ParallelXMLGenerator, - VF_LIST_OF_COMPONENTS) + VF_LIST_OF_COMPONENTS, AppendedDataXMLGenerator, DataArray, + ParallelXMLGenerator, UnstructuredGrid) nodes = self._vis_nodes_numpy() @@ -977,6 +976,7 @@ def create_dataset(grp, name, data, *, shape, offset): global_conn_count = conn_count else: from mpi4py import MPI + # FIXME: should be able to do all these in one go global_cell_offset = comm.scan(cell_count) - cell_count global_node_offset = comm.scan(node_count) - node_count @@ -1123,8 +1123,7 @@ def write_xdmf_file(self, file_name, names_and_fields, # Paraview. from pyvisfile.xdmf import ( - XdmfUnstructuredGrid, DataArray, - GeometryType, Information) + DataArray, GeometryType, Information, XdmfUnstructuredGrid) if self.vis_discr.ambient_dim == 2: geometry_type = GeometryType.XY @@ -1203,7 +1202,6 @@ def write_xdmf_file(self, file_name, names_and_fields, def show_scalar_in_matplotlib_3d(self, field, **kwargs): import matplotlib.pyplot as plt - # This import also registers the 3D projection. import mpl_toolkits.mplot3d.art3d as art3d @@ -1290,11 +1288,11 @@ def make_visualizer(actx, discr, vis_order=None, vis_discr = discr else: if force_equidistant: - from meshmode.discretization.poly_element import \ - InterpolatoryEquidistantGroupFactory as VisGroupFactory + from meshmode.discretization.poly_element import ( + InterpolatoryEquidistantGroupFactory as VisGroupFactory) else: - from meshmode.discretization.poly_element import \ - InterpolatoryEdgeClusteredGroupFactory as VisGroupFactory + from meshmode.discretization.poly_element import ( + InterpolatoryEdgeClusteredGroupFactory as VisGroupFactory) vis_discr = discr.copy(actx=actx, group_factory=VisGroupFactory(vis_order)) @@ -1353,10 +1351,8 @@ def write_nodal_adjacency_vtk_file(file_name, mesh, compressor=None, overwrite=False): from pyvisfile.vtk import ( - UnstructuredGrid, DataArray, - AppendedDataXMLGenerator, - VTK_LINE, - VF_LIST_OF_COMPONENTS) + VF_LIST_OF_COMPONENTS, VTK_LINE, AppendedDataXMLGenerator, DataArray, + UnstructuredGrid) centroids = np.empty( (mesh.ambient_dim, mesh.nelements), diff --git a/meshmode/distributed.py b/meshmode/distributed.py index 9ebf9b81..ee0403ab 100644 --- a/meshmode/distributed.py +++ b/meshmode/distributed.py @@ -36,23 +36,18 @@ """ from dataclasses import dataclass +from typing import TYPE_CHECKING, List, Mapping, Sequence, Set, Union, cast +from warnings import warn + import numpy as np -from typing import List, Set, Union, Mapping, cast, Sequence, TYPE_CHECKING from arraycontext import ArrayContext -from meshmode.discretization.connection import ( - DirectDiscretizationConnection) +from meshmode.discretization import ElementGroupFactory +from meshmode.discretization.connection import DirectDiscretizationConnection from meshmode.mesh import ( - Mesh, - InteriorAdjacencyGroup, - InterPartAdjacencyGroup, - PartID, -) + InteriorAdjacencyGroup, InterPartAdjacencyGroup, Mesh, PartID) -from meshmode.discretization import ElementGroupFactory - -from warnings import warn # This file needs to be importable without mpi4py. So don't be tempted to add # that import here--push it into individual functions instead. @@ -61,8 +56,9 @@ if TYPE_CHECKING: import mpi4py.MPI - import logging + + logger = logging.getLogger(__name__) TAG_BASE = 83411 diff --git a/meshmode/dof_array.py b/meshmode/dof_array.py index da247110..f72a4d04 100644 --- a/meshmode/dof_array.py +++ b/meshmode/dof_array.py @@ -1,5 +1,6 @@ from __future__ import annotations + __copyright__ = "Copyright (C) 2020 Andreas Kloeckner" __license__ = """ @@ -22,28 +23,28 @@ THE SOFTWARE. """ -import threading import operator as op -from warnings import warn -from numbers import Number +import threading from contextlib import contextmanager from functools import partial, update_wrapper +from numbers import Number from typing import Any, Callable, Iterable, Optional, Tuple +from warnings import warn import numpy as np -import loopy as lp -from pytools import MovedFunctionDeprecationWrapper -from pytools import single_valued, memoize_in +import loopy as lp +from arraycontext import ( + Array, ArrayContext, ArrayOrContainerT, NotAnArrayContainerError, + deserialize_container, make_loopy_program, mapped_over_array_containers, + multimapped_over_array_containers, rec_map_array_container, + rec_multimap_array_container, serialize_container, with_array_context, + with_container_arithmetic) +from pytools import MovedFunctionDeprecationWrapper, memoize_in, single_valued from meshmode.transform_metadata import ( - ConcurrentElementInameTag, ConcurrentDOFInameTag) -from arraycontext import ( - Array, ArrayContext, ArrayOrContainerT, NotAnArrayContainerError, - make_loopy_program, with_container_arithmetic, - serialize_container, deserialize_container, with_array_context, - rec_map_array_container, rec_multimap_array_container, - mapped_over_array_containers, multimapped_over_array_containers) + ConcurrentDOFInameTag, ConcurrentElementInameTag) + __doc__ = """ .. autoclass:: DOFArray @@ -735,8 +736,8 @@ def _unflatten_from_numpy(subary): # {{{ flat_norm def _reduce_norm(actx, arys, ord): - from numbers import Number from functools import reduce + from numbers import Number # NOTE: actx can be None if there are no DOFArrays in the container, in # which case all the entries should be Numbers and using numpy is ok diff --git a/meshmode/interop/firedrake/__init__.py b/meshmode/interop/firedrake/__init__.py index 727e2c67..eaf96581 100644 --- a/meshmode/interop/firedrake/__init__.py +++ b/meshmode/interop/firedrake/__init__.py @@ -22,10 +22,11 @@ from meshmode.interop.firedrake.connection import ( - build_connection_from_firedrake, build_connection_to_firedrake, - FiredrakeConnection) + FiredrakeConnection, build_connection_from_firedrake, + build_connection_to_firedrake) from meshmode.interop.firedrake.mesh import ( - import_firedrake_mesh, export_mesh_to_firedrake) + export_mesh_to_firedrake, import_firedrake_mesh) + __all__ = ["build_connection_from_firedrake", "build_connection_to_firedrake", "FiredrakeConnection", "import_firedrake_mesh", diff --git a/meshmode/interop/firedrake/connection.py b/meshmode/interop/firedrake/connection.py index 5b6f7fbf..f9ebfee9 100644 --- a/meshmode/interop/firedrake/connection.py +++ b/meshmode/interop/firedrake/connection.py @@ -30,22 +30,17 @@ import numpy.linalg as la from modepy import resampling_matrix +from pytools import memoize_method +from meshmode.discretization import Discretization, InterpolatoryElementGroupBase +from meshmode.discretization.poly_element import ( + ElementGroupFactory, default_simplex_group_factory) from meshmode.interop.firedrake.mesh import ( - import_firedrake_mesh, export_mesh_to_firedrake) + export_mesh_to_firedrake, import_firedrake_mesh) from meshmode.interop.firedrake.reference_cell import ( get_affine_reference_simplex_mapping, get_finat_element_unit_nodes) - from meshmode.mesh.processing import get_simplex_element_flip_matrix -from meshmode.discretization.poly_element import ( - default_simplex_group_factory, - ElementGroupFactory) -from meshmode.discretization import ( - Discretization, InterpolatoryElementGroupBase) - -from pytools import memoize_method - def _reorder_nodes(orient, nodes, flip_matrix, unflip=False): """ @@ -526,6 +521,7 @@ def from_meshmode(self, mm_field, out=None): self._validate_function(out, "out", fspace_shape) else: from firedrake.function import Function + # Translate shape so that don't always get a TensorFunctionSpace, # but instead get FunctionSpace or VectorFunctionSpace when # reasonable diff --git a/meshmode/interop/firedrake/mesh.py b/meshmode/interop/firedrake/mesh.py index 20ee7c73..35565c5c 100644 --- a/meshmode/interop/firedrake/mesh.py +++ b/meshmode/interop/firedrake/mesh.py @@ -1,4 +1,4 @@ -arg = "Copyright (C) 2020 Benjamin Sepanski" +__copyright__ = "Copyright (C) 2020 Benjamin Sepanski" __license__ = """ Permission is hereby granted, free of charge, to any person obtaining a copy @@ -20,25 +20,20 @@ THE SOFTWARE. """ -from warnings import warn import logging +from warnings import warn + import numpy as np -from modepy import resampling_matrix, basis_for_space, PN, Simplex +from modepy import PN, Simplex, basis_for_space, resampling_matrix +from pytools import ProcessLogger -from meshmode.mesh import ( - BTAG_ALL, - BTAG_INDUCED_BOUNDARY, - Mesh, - SimplexElementGroup, - NodalAdjacency, - InteriorAdjacencyGroup, - BoundaryAdjacencyGroup - ) from meshmode.interop.firedrake.reference_cell import ( get_affine_reference_simplex_mapping, get_finat_element_unit_nodes) +from meshmode.mesh import ( + BTAG_ALL, BTAG_INDUCED_BOUNDARY, BoundaryAdjacencyGroup, InteriorAdjacencyGroup, + Mesh, NodalAdjacency, SimplexElementGroup) -from pytools import ProcessLogger __doc__ = """ .. autofunction:: import_firedrake_mesh @@ -437,8 +432,8 @@ def _get_firedrake_orientations(fdrake_mesh, unflipped_group, vertices, if gdim == tdim: # If the co-dimension is 0, :mod:`meshmode` has a convenient # function to compute cell orientations - from meshmode.mesh.processing import \ - find_volume_mesh_element_group_orientation + from meshmode.mesh.processing import ( + find_volume_mesh_element_group_orientation) orient = find_volume_mesh_element_group_orientation(vertices, unflipped_group) @@ -939,7 +934,7 @@ def export_mesh_to_firedrake(mesh, group_nr=None, comm=None): # Now make a coordinates function with ProcessLogger(logger, "Building firedrake function " "space for mesh coordinates"): - from firedrake import VectorFunctionSpace, Function + from firedrake import Function, VectorFunctionSpace coords_fspace = VectorFunctionSpace(top, "CG", group.order, dim=mesh.ambient_dim) coords = Function(coords_fspace) diff --git a/meshmode/interop/firedrake/reference_cell.py b/meshmode/interop/firedrake/reference_cell.py index f303fefb..b060434d 100644 --- a/meshmode/interop/firedrake/reference_cell.py +++ b/meshmode/interop/firedrake/reference_cell.py @@ -64,7 +64,9 @@ 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 import unit_vertices_for_shape, Simplex + + from modepy import Simplex, unit_vertices_for_shape + # 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 @@ -133,10 +135,9 @@ def get_finat_element_unit_nodes(finat_element): by the finat element's reference element (see its ``cell`` attribute) """ - from finat.fiat_elements import ( - Lagrange, DiscontinuousLagrange, CrouzeixRaviart) - from finat.spectral import GaussLobattoLegendre, GaussLegendre from FIAT.reference_element import Simplex + from finat.fiat_elements import CrouzeixRaviart, DiscontinuousLagrange, Lagrange + from finat.spectral import GaussLegendre, GaussLobattoLegendre allowed_finat_elts = (Lagrange, DiscontinuousLagrange, CrouzeixRaviart, GaussLobattoLegendre, GaussLegendre) if not isinstance(finat_element, allowed_finat_elts): diff --git a/meshmode/interop/nodal_dg.py b/meshmode/interop/nodal_dg.py index be36c2ae..ec539f91 100644 --- a/meshmode/interop/nodal_dg.py +++ b/meshmode/interop/nodal_dg.py @@ -34,9 +34,10 @@ import numpy as np import arraycontext -import meshmode.mesh + import meshmode.discretization import meshmode.dof_array +import meshmode.mesh class NodalDGContext: @@ -157,7 +158,7 @@ def get_discr(self, actx) -> meshmode.discretization.Discretization: from meshmode.discretization import Discretization from meshmode.discretization.poly_element import ( - PolynomialGivenNodesGroupFactory) + PolynomialGivenNodesGroupFactory) return Discretization(actx, mesh, PolynomialGivenNodesGroupFactory(order, unit_nodes)) diff --git a/meshmode/mesh/__init__.py b/meshmode/mesh/__init__.py index 5291d8d8..951038b6 100644 --- a/meshmode/mesh/__init__.py +++ b/meshmode/mesh/__init__.py @@ -21,7 +21,7 @@ """ from abc import ABC, abstractmethod -from dataclasses import dataclass, field, replace +from dataclasses import dataclass, field from typing import Any, ClassVar, Hashable, Optional, Sequence, Tuple, Type from warnings import warn diff --git a/meshmode/mesh/generation.py b/meshmode/mesh/generation.py index cc1a331d..453a625b 100644 --- a/meshmode/mesh/generation.py +++ b/meshmode/mesh/generation.py @@ -22,18 +22,19 @@ THE SOFTWARE. """ -from typing import Any, Callable, Dict, Optional, Tuple, Type, Union, Sequence +import logging +from typing import Any, Callable, Dict, Optional, Sequence, Tuple, Type, Union import numpy as np import numpy.linalg as la + import modepy as mp +from pytools import deprecate_keyword, log_process from meshmode.mesh import Mesh, MeshElementGroup from meshmode.mesh.refinement import Refiner -from pytools import log_process, deprecate_keyword -import logging logger = logging.getLogger(__name__) @@ -980,6 +981,7 @@ def sph_harm(m: int, n: int, pts: np.ndarray) -> np.ndarray: phi = np.arctan2(y, x) import scipy.special as sps + # Note: This matches the spherical harmonic # convention in the QBX3D paper: # https://arxiv.org/abs/1805.06106 @@ -1397,10 +1399,9 @@ def generate_box_mesh( is_conforming=True) if any(periodic): - from meshmode.mesh.processing import ( - glue_mesh_boundaries, BoundaryPairMapping) - from meshmode import AffineMap + from meshmode.mesh.processing import ( + BoundaryPairMapping, glue_mesh_boundaries) bdry_pair_mappings_and_tols = [] for idim in range(dim): if periodic[idim]: @@ -1601,7 +1602,7 @@ def transform(x: np.ndarray) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: aff_map = AffineMap(matrix, center - matrix @ center) from meshmode.mesh.processing import ( - glue_mesh_boundaries, BoundaryPairMapping) + BoundaryPairMapping, glue_mesh_boundaries) periodic_mesh = glue_mesh_boundaries( mesh, bdry_pair_mappings_and_tols=[ (BoundaryPairMapping("-theta", "+theta", aff_map), 1e-12)]) @@ -1631,9 +1632,10 @@ def warp_and_refine_until_resolved( .. versionadded:: 2018.1 """ - from modepy.modes import simplex_onb from modepy.matrices import vandermonde from modepy.modal_decay import simplex_interp_error_coefficient_estimator_matrix + from modepy.modes import simplex_onb + from meshmode.mesh.refinement import RefinerWithoutAdjacency if isinstance(unwarped_mesh_or_refiner, RefinerWithoutAdjacency): diff --git a/meshmode/mesh/io.py b/meshmode/mesh/io.py index 4eb52211..769d6350 100644 --- a/meshmode/mesh/io.py +++ b/meshmode/mesh/io.py @@ -23,10 +23,8 @@ import numpy as np from gmsh_interop.reader import ( # noqa: F401 - GmshMeshReceiverBase, ScriptSource, FileSource, LiteralSource, - ScriptWithFilesSource, - GmshSimplexElementBase, - GmshTensorProductElementBase) + FileSource, GmshMeshReceiverBase, GmshSimplexElementBase, + GmshTensorProductElementBase, LiteralSource, ScriptSource, ScriptWithFilesSource) __doc__ = """ @@ -166,8 +164,8 @@ def get_mesh(self, return_tag_to_elements_map=False): # }}} - from meshmode.mesh import (Mesh, - SimplexElementGroup, TensorProductElementGroup) + from meshmode.mesh import ( + Mesh, SimplexElementGroup, TensorProductElementGroup) bulk_el_types = set() @@ -329,8 +327,8 @@ def generate_gmsh(source, dimensions=None, order=None, other_options=None, recv = GmshMeshReceiver(mesh_construction_kwargs=mesh_construction_kwargs) - from gmsh_interop.runner import GmshRunner from gmsh_interop.reader import parse_gmsh + from gmsh_interop.runner import GmshRunner if target_unit is None: target_unit = "MM" @@ -416,8 +414,7 @@ def from_vertices_and_simplices(vertices, simplices, order=1, fix_orientation=Fa raise ValueError("can only fix orientation of volume meshes") from meshmode.mesh.processing import ( - find_volume_mesh_element_group_orientation, - flip_simplex_element_group) + find_volume_mesh_element_group_orientation, flip_simplex_element_group) orient = find_volume_mesh_element_group_orientation(vertices, grp) grp = flip_simplex_element_group(vertices, grp, orient < 0) diff --git a/meshmode/mesh/refinement/__init__.py b/meshmode/mesh/refinement/__init__.py index 2d04ce5d..e4bce613 100644 --- a/meshmode/mesh/refinement/__init__.py +++ b/meshmode/mesh/refinement/__init__.py @@ -20,10 +20,12 @@ THE SOFTWARE. """ -from meshmode.mesh.refinement.utils import Refiner +import logging + from meshmode.mesh.refinement.no_adjacency import RefinerWithoutAdjacency +from meshmode.mesh.refinement.utils import Refiner + -import logging logger = logging.getLogger(__name__) __doc__ = """ diff --git a/meshmode/mesh/refinement/no_adjacency.py b/meshmode/mesh/refinement/no_adjacency.py index ed859a0b..0c44278a 100644 --- a/meshmode/mesh/refinement/no_adjacency.py +++ b/meshmode/mesh/refinement/no_adjacency.py @@ -24,11 +24,13 @@ THE SOFTWARE. """ +import logging + import numpy as np from meshmode.mesh.refinement.utils import Refiner -import logging + logger = logging.getLogger(__name__) @@ -86,9 +88,8 @@ def refine(self, refine_flags): inew_vertex = mesh.nvertices from meshmode.mesh.refinement.tessellate import ( - get_group_tessellation_info, - get_group_midpoints, - get_group_tessellated_nodes) + get_group_midpoints, get_group_tessellated_nodes, + get_group_tessellation_info) for base_element_nr, grp in zip(mesh.base_element_nrs, mesh.groups): el_tess_info = get_group_tessellation_info(grp) diff --git a/meshmode/mesh/refinement/tessellate.py b/meshmode/mesh/refinement/tessellate.py index a5a180e1..64ecc572 100644 --- a/meshmode/mesh/refinement/tessellate.py +++ b/meshmode/mesh/refinement/tessellate.py @@ -24,18 +24,19 @@ THE SOFTWARE. """ +import logging from dataclasses import dataclass from functools import singledispatch +from typing import List, Optional, Tuple import numpy as np import modepy as mp + from meshmode.mesh import MeshElementGroup, _ModepyElementGroup -import logging -logger = logging.getLogger(__name__) -from typing import List, Tuple, Optional +logger = logging.getLogger(__name__) # {{{ interface diff --git a/meshmode/mesh/refinement/utils.py b/meshmode/mesh/refinement/utils.py index 24ff8544..9188be45 100644 --- a/meshmode/mesh/refinement/utils.py +++ b/meshmode/mesh/refinement/utils.py @@ -22,6 +22,7 @@ THE SOFTWARE. """ +import logging from abc import ABC, abstractmethod from functools import singledispatch from typing import Optional @@ -29,12 +30,9 @@ import numpy as np from meshmode.mesh import ( - Mesh, - MeshElementGroup, - SimplexElementGroup, - TensorProductElementGroup) + Mesh, MeshElementGroup, SimplexElementGroup, TensorProductElementGroup) + -import logging logger = logging.getLogger(__name__) diff --git a/meshmode/mesh/tools.py b/meshmode/mesh/tools.py index d2b56fe7..46bdbb41 100644 --- a/meshmode/mesh/tools.py +++ b/meshmode/mesh/tools.py @@ -24,8 +24,9 @@ import numpy.linalg as la from modepy.tools import hypercube_submesh -from pytools.spatial_btree import SpatialBinaryTreeBucket from pytools import MovedFunctionDeprecationWrapper +from pytools.spatial_btree import SpatialBinaryTreeBucket + __doc__ = """ .. currentmodule:: meshmode diff --git a/meshmode/mesh/visualization.py b/meshmode/mesh/visualization.py index 8a2854fb..6f32de7d 100644 --- a/meshmode/mesh/visualization.py +++ b/meshmode/mesh/visualization.py @@ -25,6 +25,7 @@ import numpy as np from arraycontext import ArrayContext + from meshmode.mesh import Mesh @@ -58,8 +59,8 @@ def draw_2d_mesh( """ assert mesh.ambient_dim == 2 - import matplotlib.pyplot as pt import matplotlib.patches as mpatches + import matplotlib.pyplot as pt from matplotlib.path import Path for igrp, grp in enumerate(mesh.groups): @@ -209,18 +210,12 @@ def write_vertex_vtk_file( mesh: Mesh, file_name: str, *, compressor: Optional[str] = None, overwrite: bool = False) -> None: - from pyvisfile.vtk import ( - UnstructuredGrid, DataArray, - AppendedDataXMLGenerator, - VF_LIST_OF_COMPONENTS) - # {{{ create cell_types - from pyvisfile.vtk import ( - VTK_LINE, VTK_TRIANGLE, VTK_TETRA, - VTK_QUAD, VTK_HEXAHEDRON) + VF_LIST_OF_COMPONENTS, VTK_HEXAHEDRON, VTK_LINE, VTK_QUAD, VTK_TETRA, + VTK_TRIANGLE, AppendedDataXMLGenerator, DataArray, UnstructuredGrid) - from meshmode.mesh import TensorProductElementGroup, SimplexElementGroup + from meshmode.mesh import SimplexElementGroup, TensorProductElementGroup cell_types = np.empty(mesh.nelements, dtype=np.uint8) cell_types.fill(255) @@ -345,9 +340,9 @@ def vtk_visualize_mesh( if not vtk_high_order: vis_order = None - from meshmode.discretization.poly_element import \ - InterpolatoryEdgeClusteredGroupFactory from meshmode.discretization import Discretization + from meshmode.discretization.poly_element import ( + InterpolatoryEdgeClusteredGroupFactory) discr = Discretization(actx, mesh, InterpolatoryEdgeClusteredGroupFactory(order)) from meshmode.discretization.visualization import make_visualizer @@ -412,8 +407,8 @@ def visualize_mesh_vertex_resampling_error( overwrite: bool = False) -> None: # {{{ comput resampling errors - from meshmode.mesh import _mesh_group_node_vertex_error from meshmode.dof_array import DOFArray + from meshmode.mesh import _mesh_group_node_vertex_error error = DOFArray(actx, tuple([ actx.from_numpy( np.sqrt(np.sum(_mesh_group_node_vertex_error(mesh, mgrp)**2, axis=0)) @@ -425,9 +420,9 @@ def visualize_mesh_vertex_resampling_error( # {{{ visualize - from meshmode.discretization.poly_element import \ - InterpolatoryEdgeClusteredGroupFactory from meshmode.discretization import Discretization + from meshmode.discretization.poly_element import ( + InterpolatoryEdgeClusteredGroupFactory) discr = Discretization(actx, mesh, InterpolatoryEdgeClusteredGroupFactory(1)) from meshmode.discretization.visualization import make_visualizer diff --git a/meshmode/transform_metadata.py b/meshmode/transform_metadata.py index f622310b..a352aecc 100644 --- a/meshmode/transform_metadata.py +++ b/meshmode/transform_metadata.py @@ -34,7 +34,7 @@ THE SOFTWARE. """ -from pytools.tag import Tag, tag_dataclass, UniqueTag +from pytools.tag import Tag, UniqueTag, tag_dataclass class FirstAxisIsElementsTag(Tag): diff --git a/setup.cfg b/setup.cfg index 0c76f1b7..aba7af88 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,6 +8,15 @@ docstring-quotes = """ multiline-quotes = """ # enable-flake8-bugbear +# enable-flake8-isort +# +[isort] +known_firstparty=pytools,pyopencl,loopy,arraycontext,gmsh_interop,pyvisfile,modepy,pytato,pymbolic,pymetis,firedrake +known_local_folder=meshmode +line_length = 85 +lines_after_imports = 2 +combine_as_imports = True +multi_line_output = 4 [mypy] python_version = 3.8 diff --git a/setup.py b/setup.py index 531bb003..c8a1d7e8 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ def main(): - from setuptools import setup, find_packages + from setuptools import find_packages, setup version_dict = {} init_filename = "meshmode/version.py" diff --git a/test/test_array.py b/test/test_array.py index 3be12d9b..f01e83ae 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -20,31 +20,30 @@ THE SOFTWARE. """ +import logging from dataclasses import dataclass -import pytest -import numpy as np -from meshmode import _acf # noqa: F401 -from meshmode.array_context import (PytestPyOpenCLArrayContextFactory, - PytestPytatoPyOpenCLArrayContextFactory) -from arraycontext import pytest_generate_tests_for_array_contexts -pytest_generate_tests = pytest_generate_tests_for_array_contexts( - [PytestPytatoPyOpenCLArrayContextFactory, - PytestPyOpenCLArrayContextFactory, - ]) +import numpy as np +import pytest from arraycontext import ( - dataclass_array_container, - with_container_arithmetic) + dataclass_array_container, pytest_generate_tests_for_array_contexts, + with_container_arithmetic) +from pytools.obj_array import make_obj_array +from meshmode import _acf # noqa: F401 +from meshmode.array_context import ( + PytestPyOpenCLArrayContextFactory, PytestPytatoPyOpenCLArrayContextFactory) from meshmode.discretization import Discretization from meshmode.discretization.poly_element import default_simplex_group_factory -from meshmode.dof_array import DOFArray, flat_norm, array_context_for_pickling +from meshmode.dof_array import DOFArray, array_context_for_pickling, flat_norm -from pytools.obj_array import make_obj_array -import logging logger = logging.getLogger(__name__) +pytest_generate_tests = pytest_generate_tests_for_array_contexts( + [PytestPytatoPyOpenCLArrayContextFactory, + PytestPyOpenCLArrayContextFactory, + ]) # {{{ test_flatten_unflatten @@ -172,7 +171,7 @@ def test_dof_array_pickling(actx_factory): actx = actx_factory() ary_dof, ary_of_dofs, mat_of_dofs, dc_of_dofs = _get_test_containers(actx) - from pickle import loads, dumps + from pickle import dumps, loads with array_context_for_pickling(actx): pkl = dumps((mat_of_dofs, dc_of_dofs)) @@ -201,7 +200,7 @@ class FooAxisTag2(Tag): def test_dof_array_pickling_tags(actx_factory): actx = actx_factory() - from pickle import loads, dumps + from pickle import dumps, loads state = DOFArray(actx, (actx.zeros((10, 10), "float64"), actx.zeros((10, 10), "float64"),)) diff --git a/test/test_chained.py b/test/test_chained.py index 4727eac6..9ee486f3 100644 --- a/test/test_chained.py +++ b/test/test_chained.py @@ -20,19 +20,21 @@ THE SOFTWARE. """ -import numpy as np +import logging +import numpy as np import pytest -from meshmode.array_context import PytestPyOpenCLArrayContextFactory -from arraycontext import pytest_generate_tests_for_array_contexts -pytest_generate_tests = pytest_generate_tests_for_array_contexts( - [PytestPyOpenCLArrayContextFactory]) -from arraycontext import flatten +from arraycontext import flatten, pytest_generate_tests_for_array_contexts + +from meshmode import _acf # noqa: F401 +from meshmode.array_context import PytestPyOpenCLArrayContextFactory from meshmode.dof_array import flat_norm -import logging + logger = logging.getLogger(__name__) +pytest_generate_tests = pytest_generate_tests_for_array_contexts( + [PytestPyOpenCLArrayContextFactory]) def create_discretization(actx, ndim, @@ -42,7 +44,8 @@ def create_discretization(actx, ndim, # construct mesh if ndim == 2: from functools import partial - from meshmode.mesh.generation import make_curve_mesh, ellipse, starfish + + from meshmode.mesh.generation import ellipse, make_curve_mesh, starfish if mesh_name is None: mesh_name = "ellipse" @@ -55,8 +58,8 @@ def create_discretization(actx, ndim, else: raise ValueError(f"unknown mesh name: {mesh_name}") elif ndim == 3: - from meshmode.mesh.generation import generate_torus - from meshmode.mesh.generation import generate_warped_rect_mesh + from meshmode.mesh.generation import ( + generate_torus, generate_warped_rect_mesh) if mesh_name is None: mesh_name = "torus" @@ -74,8 +77,8 @@ def create_discretization(actx, ndim, # create discretization from meshmode.discretization import Discretization - from meshmode.discretization.poly_element import \ - InterpolatoryQuadratureSimplexGroupFactory + from meshmode.discretization.poly_element import ( + InterpolatoryQuadratureSimplexGroupFactory) discr = Discretization(actx, mesh, InterpolatoryQuadratureSimplexGroupFactory(order)) @@ -83,10 +86,10 @@ def create_discretization(actx, ndim, def create_refined_connection(actx, discr, threshold=0.3): - from meshmode.mesh.refinement import RefinerWithoutAdjacency from meshmode.discretization.connection import make_refinement_connection - from meshmode.discretization.poly_element import \ - InterpolatoryQuadratureSimplexGroupFactory + from meshmode.discretization.poly_element import ( + InterpolatoryQuadratureSimplexGroupFactory) + from meshmode.mesh.refinement import RefinerWithoutAdjacency flags = np.random.rand(discr.mesh.nelements) < threshold refiner = RefinerWithoutAdjacency(discr.mesh) @@ -100,10 +103,10 @@ def create_refined_connection(actx, discr, threshold=0.3): def create_face_connection(actx, discr): - from meshmode.discretization.connection import FACE_RESTR_ALL - from meshmode.discretization.connection import make_face_restriction - from meshmode.discretization.poly_element import \ - InterpolatoryQuadratureSimplexGroupFactory + from meshmode.discretization.connection import ( + FACE_RESTR_ALL, make_face_restriction) + from meshmode.discretization.poly_element import ( + InterpolatoryQuadratureSimplexGroupFactory) discr_order = discr.groups[0].order connection = make_face_restriction(actx, discr, @@ -117,8 +120,8 @@ def create_face_connection(actx, discr): @pytest.mark.skip(reason="implementation detail") @pytest.mark.parametrize("ndim", [2, 3]) def test_chained_batch_table(actx_factory, ndim, visualize=False): - from meshmode.discretization.connection.chained import \ - _build_element_lookup_table + from meshmode.discretization.connection.chained import ( + _build_element_lookup_table) actx = actx_factory() @@ -146,8 +149,7 @@ def test_chained_batch_table(actx_factory, ndim, visualize=False): @pytest.mark.skip(reason="implementation detail") @pytest.mark.parametrize("ndim", [2, 3]) def test_chained_new_group_table(actx_factory, ndim, visualize=False): - from meshmode.discretization.connection.chained import \ - _build_new_group_table + from meshmode.discretization.connection.chained import _build_new_group_table actx = actx_factory() @@ -202,8 +204,7 @@ def test_chained_connection(actx_factory, ndim, visualize=False): conn = create_refined_connection(actx, conn.to_discr, threshold=np.inf) connections.append(conn) - from meshmode.discretization.connection import \ - ChainedDiscretizationConnection + from meshmode.discretization.connection import ChainedDiscretizationConnection chained = ChainedDiscretizationConnection(connections) def f(x): @@ -220,8 +221,7 @@ def f(x): @pytest.mark.parametrize("ndim", [2, 3]) def test_chained_full_resample_matrix(actx_factory, ndim, visualize=False): - from meshmode.discretization.connection.chained import \ - make_full_resample_matrix + from meshmode.discretization.connection.chained import make_full_resample_matrix actx = actx_factory() @@ -232,8 +232,7 @@ def test_chained_full_resample_matrix(actx_factory, ndim, visualize=False): conn = create_refined_connection(actx, conn.to_discr) connections.append(conn) - from meshmode.discretization.connection import \ - ChainedDiscretizationConnection + from meshmode.discretization.connection import ChainedDiscretizationConnection chained = ChainedDiscretizationConnection(connections) def f(x): @@ -257,8 +256,8 @@ def f(x): def test_chained_to_direct(actx_factory, ndim, chain_type, nelements=128, visualize=False): import time - from meshmode.discretization.connection.chained import \ - flatten_chained_connection + + from meshmode.discretization.connection.chained import flatten_chained_connection actx = actx_factory() @@ -284,8 +283,7 @@ def test_chained_to_direct(actx_factory, ndim, chain_type, else: raise ValueError("unknown test case") - from meshmode.discretization.connection import \ - ChainedDiscretizationConnection + from meshmode.discretization.connection import ChainedDiscretizationConnection chained = ChainedDiscretizationConnection(connections) t_start = time.time() @@ -362,11 +360,11 @@ def run(nelements, order): conn.to_discr, threshold=threshold) connections.append(conn) - from meshmode.discretization.connection import \ - ChainedDiscretizationConnection + from meshmode.discretization.connection import ( + ChainedDiscretizationConnection) chained = ChainedDiscretizationConnection(connections) - from meshmode.discretization.connection import \ - L2ProjectionInverseDiscretizationConnection + from meshmode.discretization.connection import ( + L2ProjectionInverseDiscretizationConnection) reverse = L2ProjectionInverseDiscretizationConnection(chained) # create test vector diff --git a/test/test_connection.py b/test/test_connection.py index e7029cf9..dbbd5d2a 100644 --- a/test/test_connection.py +++ b/test/test_connection.py @@ -20,34 +20,29 @@ THE SOFTWARE. """ +import logging from functools import partial -import numpy as np # noqa: F401 -import numpy.linalg as la # noqa: F401 -import meshmode # noqa: F401 +import pytest -from meshmode.array_context import PytestPyOpenCLArrayContextFactory from arraycontext import pytest_generate_tests_for_array_contexts -pytest_generate_tests = pytest_generate_tests_for_array_contexts( - [PytestPyOpenCLArrayContextFactory]) - -from meshmode.mesh import SimplexElementGroup, TensorProductElementGroup -from meshmode.discretization.poly_element import ( - PolynomialWarpAndBlend2DRestrictingGroupFactory, - PolynomialWarpAndBlend3DRestrictingGroupFactory, - PolynomialEquidistantSimplexGroupFactory, - LegendreGaussLobattoTensorProductGroupFactory, - PolynomialRecursiveNodesGroupFactory, - ) +import meshmode.mesh.generation as mgen +from meshmode import _acf # noqa: F401 +from meshmode.array_context import PytestPyOpenCLArrayContextFactory from meshmode.discretization import Discretization from meshmode.discretization.connection import FACE_RESTR_ALL -import meshmode.mesh.generation as mgen +from meshmode.discretization.poly_element import ( + LegendreGaussLobattoTensorProductGroupFactory, + PolynomialEquidistantSimplexGroupFactory, PolynomialRecursiveNodesGroupFactory, + PolynomialWarpAndBlend2DRestrictingGroupFactory, + PolynomialWarpAndBlend3DRestrictingGroupFactory) +from meshmode.mesh import SimplexElementGroup, TensorProductElementGroup -import pytest -import logging logger = logging.getLogger(__name__) +pytest_generate_tests = pytest_generate_tests_for_array_contexts( + [PytestPyOpenCLArrayContextFactory]) @pytest.mark.parametrize("group_factory", [ @@ -81,7 +76,7 @@ def test_bdry_restriction_is_permutation(actx_factory, group_factory, dim, order vol_discr = Discretization(actx, mesh, group_factory(order)) from meshmode.discretization.connection import ( - make_face_restriction, make_opposite_face_connection) + make_face_restriction, make_opposite_face_connection) bdry_connection = make_face_restriction( actx, vol_discr, group_factory(order), FACE_RESTR_ALL) diff --git a/test/test_discretization.py b/test/test_discretization.py index d583f187..3422fa3e 100644 --- a/test/test_discretization.py +++ b/test/test_discretization.py @@ -20,18 +20,18 @@ THE SOFTWARE. """ - import numpy as np -# import numpy.linalg as la + +from arraycontext import pytest_generate_tests_for_array_contexts import meshmode.mesh.generation as mgen +from meshmode import _acf # noqa: F401 +from meshmode.array_context import PytestPyOpenCLArrayContextFactory from meshmode.discretization import Discretization from meshmode.discretization.poly_element import ( - InterpolatoryQuadratureSimplexGroupFactory, - ) + InterpolatoryQuadratureSimplexGroupFactory) + -from meshmode.array_context import PytestPyOpenCLArrayContextFactory -from arraycontext import pytest_generate_tests_for_array_contexts pytest_generate_tests = pytest_generate_tests_for_array_contexts( [PytestPyOpenCLArrayContextFactory]) diff --git a/test/test_firedrake_interop.py b/test/test_firedrake_interop.py index 67e0a8dc..77ecbc4f 100644 --- a/test/test_firedrake_interop.py +++ b/test/test_firedrake_interop.py @@ -20,44 +20,36 @@ THE SOFTWARE. """ +import logging + import numpy as np +import pytest + import pyopencl as cl +from arraycontext import ( + PyOpenCLArrayContext, pytest_generate_tests_for_array_contexts) +from firedrake import ( + Function, FunctionSpace, SpatialCoordinate, TensorFunctionSpace, UnitCubeMesh, + UnitIntervalMesh, UnitSquareMesh, VectorFunctionSpace, as_tensor, sin) +from meshmode import _acf # noqa: F401 from meshmode.array_context import PytestPyOpenCLArrayContextFactory -from arraycontext import pytest_generate_tests_for_array_contexts -pytest_generate_tests = pytest_generate_tests_for_array_contexts( - [PytestPyOpenCLArrayContextFactory]) - -from arraycontext import PyOpenCLArrayContext - from meshmode.discretization import Discretization from meshmode.discretization.poly_element import ( InterpolatoryQuadratureSimplexGroupFactory) - from meshmode.dof_array import DOFArray - -from meshmode.mesh import ( - BTAG_ALL, BTAG_INDUCED_BOUNDARY, check_bc_coverage - ) - from meshmode.interop.firedrake import ( build_connection_from_firedrake, build_connection_to_firedrake, import_firedrake_mesh) +from meshmode.mesh import BTAG_ALL, BTAG_INDUCED_BOUNDARY, check_bc_coverage -import pytest -import logging logger = logging.getLogger(__name__) +pytest_generate_tests = pytest_generate_tests_for_array_contexts( + [PytestPyOpenCLArrayContextFactory]) # skip testing this module if cannot import firedrake firedrake = pytest.importorskip("firedrake") - -from firedrake import ( - UnitIntervalMesh, UnitSquareMesh, UnitCubeMesh, - FunctionSpace, VectorFunctionSpace, TensorFunctionSpace, - Function, SpatialCoordinate, as_tensor, sin) - - CLOSE_ATOL = 1e-12 @@ -393,6 +385,7 @@ def test_from_fd_transfer(ctx_factory, fspace_degree, """ # build estimate-of-convergence recorder from pytools.convergence import EOCRecorder + # (fd -> mm ? True : False, dimension projecting onto) eoc_recorders = {(True, d): EOCRecorder() for d in range(dim)} if not only_convert_bdy: @@ -427,15 +420,15 @@ def get_fdrake_mesh_and_h_from_par(mesh_par): fdrake_mesh = Mesh(f"{fdrake_mesh_name}-h{mesh_par}.msh", dim=dim) else: - from meshmode.mesh.io import read_gmsh from meshmode.interop.firedrake import export_mesh_to_firedrake + from meshmode.mesh.io import read_gmsh mm_mesh = read_gmsh(f"{fdrake_mesh_name}-h{mesh_par}.msh", force_ambient_dim=dim) fdrake_mesh, _, _ = export_mesh_to_firedrake(mm_mesh) h = float(mesh_par) elif fdrake_mesh_name == "warp": - from meshmode.mesh.generation import generate_warped_rect_mesh from meshmode.interop.firedrake import export_mesh_to_firedrake + from meshmode.mesh.generation import generate_warped_rect_mesh mm_mesh = generate_warped_rect_mesh(dim, order=4, nelements_side=mesh_par) fdrake_mesh, _, _ = export_mesh_to_firedrake(mm_mesh) @@ -514,6 +507,7 @@ def test_to_fd_transfer(ctx_factory, fspace_degree, mesh_name, mesh_pars, dim): """ # build estimate-of-convergence recorder from pytools.convergence import EOCRecorder + # dimension projecting onto -> EOCRecorder eoc_recorders = {d: EOCRecorder() for d in range(dim)} diff --git a/test/test_interop.py b/test/test_interop.py index cb1dc245..22956941 100644 --- a/test/test_interop.py +++ b/test/test_interop.py @@ -20,18 +20,21 @@ THE SOFTWARE. """ +import logging import numpy as np import pytest -from meshmode.array_context import PytestPyOpenCLArrayContextFactory from arraycontext import pytest_generate_tests_for_array_contexts -pytest_generate_tests = pytest_generate_tests_for_array_contexts( - [PytestPyOpenCLArrayContextFactory]) + +from meshmode import _acf # noqa: F401 +from meshmode.array_context import PytestPyOpenCLArrayContextFactory from meshmode.dof_array import flat_norm -import logging + logger = logging.getLogger(__name__) +pytest_generate_tests = pytest_generate_tests_for_array_contexts( + [PytestPyOpenCLArrayContextFactory]) @pytest.mark.parametrize("dim", [1, 2, 3]) diff --git a/test/test_mesh.py b/test/test_mesh.py index c3dadef4..1a17772d 100644 --- a/test/test_mesh.py +++ b/test/test_mesh.py @@ -23,38 +23,33 @@ THE SOFTWARE. """ -from functools import partial +import logging +import pathlib from dataclasses import replace +from functools import partial + import numpy as np import numpy.linalg as la import pytest -from meshmode import _acf # noqa: F401 -from meshmode.array_context import PytestPyOpenCLArrayContextFactory from arraycontext import pytest_generate_tests_for_array_contexts -pytest_generate_tests = pytest_generate_tests_for_array_contexts( - [PytestPyOpenCLArrayContextFactory]) -from meshmode.mesh import ( - Mesh, - SimplexElementGroup, - TensorProductElementGroup, - InteriorAdjacencyGroup, - BoundaryAdjacencyGroup) -from meshmode.discretization.poly_element import ( - default_simplex_group_factory, - LegendreGaussLobattoTensorProductGroupFactory, - ) import meshmode.mesh.generation as mgen import meshmode.mesh.io as mio +from meshmode import _acf # noqa: F401 +from meshmode.array_context import PytestPyOpenCLArrayContextFactory +from meshmode.discretization.poly_element import ( + LegendreGaussLobattoTensorProductGroupFactory, default_simplex_group_factory) +from meshmode.mesh import ( + BoundaryAdjacencyGroup, InteriorAdjacencyGroup, Mesh, SimplexElementGroup, + TensorProductElementGroup) from meshmode.mesh.tools import AffineMap -import modepy as mp -import logging logger = logging.getLogger(__name__) +pytest_generate_tests = pytest_generate_tests_for_array_contexts( + [PytestPyOpenCLArrayContextFactory]) -import pathlib thisdir = pathlib.Path(__file__).parent @@ -228,7 +223,7 @@ def test_box_mesh(actx_factory, visualize=False): # {{{ circle mesh def test_circle_mesh(visualize=False): - from meshmode.mesh.io import generate_gmsh, FileSource + from meshmode.mesh.io import FileSource, generate_gmsh logger.info("BEGIN GEN") mesh = generate_gmsh( FileSource(str(thisdir / "circle.step")), 2, order=2, @@ -458,7 +453,7 @@ def test_mesh_rotation(ambient_dim, visualize=False): # {{{ test_mesh_to_tikz def test_mesh_to_tikz(): - from meshmode.mesh.io import generate_gmsh, FileSource + from meshmode.mesh.io import FileSource, generate_gmsh h = 0.3 order = 1 @@ -509,7 +504,7 @@ def test_quad_single_element(visualize=False): TensorProductElementGroup ]) def test_merge_and_map(actx_factory, group_cls, visualize=False): - from meshmode.mesh.io import generate_gmsh, FileSource + from meshmode.mesh.io import FileSource, generate_gmsh order = 3 mesh_order = 3 @@ -532,7 +527,7 @@ def test_merge_and_map(actx_factory, group_cls, visualize=False): discr_grp_factory = LegendreGaussLobattoTensorProductGroupFactory(order) - from meshmode.mesh.processing import merge_disjoint_meshes, affine_map + from meshmode.mesh.processing import affine_map, merge_disjoint_meshes mesh2 = affine_map(mesh, A=np.eye(mesh.ambient_dim), b=np.array([2, 0, 0])[:mesh.ambient_dim]) @@ -557,7 +552,7 @@ def test_merge_and_map(actx_factory, group_cls, visualize=False): # {{{ element orientation def test_element_orientation_via_flipping(): - from meshmode.mesh.io import generate_gmsh, FileSource + from meshmode.mesh.io import FileSource, generate_gmsh mesh_order = 3 @@ -568,8 +563,8 @@ def test_element_orientation_via_flipping(): target_unit="MM", ) - from meshmode.mesh.processing import (perform_flips, - find_volume_mesh_element_orientations) + from meshmode.mesh.processing import ( + find_volume_mesh_element_orientations, perform_flips) mesh_orient = find_volume_mesh_element_orientations(mesh) assert (mesh_orient > 0).all() @@ -795,6 +790,7 @@ def test_lookup_tree(visualize=False): def test_boundary_tags(): from meshmode.mesh.io import read_gmsh + # ensure tags are read in mesh = read_gmsh(str(thisdir / "annulus.msh")) @@ -868,9 +864,7 @@ def test_box_boundary_tags(dim, nelem, mesh_type, group_cls, visualize=False): pytest.skip("mesh type not supported on tensor product elements") from meshmode.mesh import ( - mesh_has_boundary, - check_bc_coverage, - is_boundary_tag_empty) + check_bc_coverage, is_boundary_tag_empty, mesh_has_boundary) if dim == 1: a = (0,) @@ -950,7 +944,7 @@ def test_box_boundary_tags(dim, nelem, mesh_type, group_cls, visualize=False): @pytest.mark.parametrize(("ambient_dim", "filename"), [(2, "blob-2d.step"), (3, "ball-radius-1.step")]) def test_quad_mesh_2d(ambient_dim, filename, visualize=False): - from meshmode.mesh.io import generate_gmsh, ScriptWithFilesSource + from meshmode.mesh.io import ScriptWithFilesSource, generate_gmsh logger.info("BEGIN GEN") mesh = generate_gmsh( @@ -1222,8 +1216,7 @@ def gen_rect_mesh_with_perturbed_vertices( group_factory = default_simplex_group_factory(1, 1) vol_discr = Discretization(actx, vol_mesh, group_factory) from meshmode.discretization.connection import ( - FACE_RESTR_ALL, - make_face_restriction) + FACE_RESTR_ALL, make_face_restriction) make_face_restriction( actx, vol_discr, group_factory, FACE_RESTR_ALL, per_face_groups=False) @@ -1266,8 +1259,7 @@ def test_glued_mesh(use_tree): map_lower_to_upper = _get_rotation(np.pi/2, np.array([0, 0, 1]), center) map_upper_to_lower = _get_rotation(-np.pi/2, np.array([0, 0, 1]), center) - from meshmode.mesh.processing import ( - glue_mesh_boundaries, BoundaryPairMapping) + from meshmode.mesh.processing import BoundaryPairMapping, glue_mesh_boundaries mesh = glue_mesh_boundaries( orig_mesh, bdry_pair_mappings_and_tols=[ (BoundaryPairMapping("-theta", "+theta", map_lower_to_upper), 1e-12) @@ -1338,8 +1330,7 @@ def test_glued_mesh_matrix_only(): map_lower_to_upper = AffineMap(matrix=matrix_lower_to_upper) map_upper_to_lower = AffineMap(matrix=matrix_upper_to_lower) - from meshmode.mesh.processing import ( - glue_mesh_boundaries, BoundaryPairMapping) + from meshmode.mesh.processing import BoundaryPairMapping, glue_mesh_boundaries mesh = glue_mesh_boundaries( orig_mesh, bdry_pair_mappings_and_tols=[ (BoundaryPairMapping("-theta", "+theta", map_lower_to_upper), 1e-12) @@ -1366,8 +1357,7 @@ def test_glued_mesh_offset_only(): map_lower_to_upper = AffineMap(offset=offset_lower_to_upper) map_upper_to_lower = AffineMap(offset=offset_upper_to_lower) - from meshmode.mesh.processing import ( - glue_mesh_boundaries, BoundaryPairMapping) + from meshmode.mesh.processing import BoundaryPairMapping, glue_mesh_boundaries mesh = glue_mesh_boundaries( orig_mesh, bdry_pair_mappings_and_tols=[ (BoundaryPairMapping("-z", "+z", map_lower_to_upper), 1e-12) diff --git a/test/test_meshmode.py b/test/test_meshmode.py index c2981866..8415a9b2 100644 --- a/test/test_meshmode.py +++ b/test/test_meshmode.py @@ -20,45 +20,38 @@ THE SOFTWARE. """ +import logging +import pathlib from functools import partial import numpy as np import numpy.linalg as la +import pytest -import meshmode # noqa: F401 -from arraycontext import flatten +from arraycontext import flatten, pytest_generate_tests_for_array_contexts -from meshmode.array_context import (PytestPyOpenCLArrayContextFactory, - PytestPytatoPyOpenCLArrayContextFactory) -from arraycontext import pytest_generate_tests_for_array_contexts -pytest_generate_tests = pytest_generate_tests_for_array_contexts( - [PytestPytatoPyOpenCLArrayContextFactory, - PytestPyOpenCLArrayContextFactory, - ]) - -from meshmode.mesh import ( - MeshElementGroup, SimplexElementGroup, TensorProductElementGroup) +import meshmode.mesh.generation as mgen +from meshmode import _acf # noqa: F401 +from meshmode.array_context import ( + PytestPyOpenCLArrayContextFactory, PytestPytatoPyOpenCLArrayContextFactory) +from meshmode.discretization.connection import FACE_RESTR_ALL, FACE_RESTR_INTERIOR from meshmode.discretization.poly_element import ( - InterpolatoryQuadratureSimplexGroupFactory, - default_simplex_group_factory, - PolynomialWarpAndBlend2DRestrictingGroupFactory, - PolynomialWarpAndBlend3DRestrictingGroupFactory, - PolynomialRecursiveNodesGroupFactory, - PolynomialEquidistantSimplexGroupFactory, - LegendreGaussLobattoTensorProductGroupFactory - ) -from meshmode.mesh import Mesh, BTAG_ALL + InterpolatoryQuadratureSimplexGroupFactory, + LegendreGaussLobattoTensorProductGroupFactory, + PolynomialEquidistantSimplexGroupFactory, PolynomialRecursiveNodesGroupFactory, + PolynomialWarpAndBlend2DRestrictingGroupFactory, + PolynomialWarpAndBlend3DRestrictingGroupFactory, default_simplex_group_factory) from meshmode.dof_array import flat_norm -from meshmode.discretization.connection import \ - FACE_RESTR_ALL, FACE_RESTR_INTERIOR -import meshmode.mesh.generation as mgen +from meshmode.mesh import ( + BTAG_ALL, Mesh, MeshElementGroup, SimplexElementGroup, TensorProductElementGroup) -import pytest -import logging logger = logging.getLogger(__name__) +pytest_generate_tests = pytest_generate_tests_for_array_contexts( + [PytestPytatoPyOpenCLArrayContextFactory, + PytestPyOpenCLArrayContextFactory, + ]) -import pathlib thisdir = pathlib.Path(__file__).parent @@ -116,11 +109,11 @@ def test_boundary_interpolation(actx_factory, group_factory, boundary_tag, else: group_cls = SimplexElementGroup + from pytools.convergence import EOCRecorder + from meshmode.discretization import Discretization from meshmode.discretization.connection import ( - make_face_restriction, check_connection) - - from pytools.convergence import EOCRecorder + check_connection, make_face_restriction) eoc_rec = EOCRecorder() order = 4 @@ -184,8 +177,8 @@ def f(x): bdry_f_2 = bdry_connection(vol_f) if mesh_name == "blob" and dim == 2 and mesh.nelements < 500: - from meshmode.discretization.connection.direct import \ - make_direct_full_resample_matrix + from meshmode.discretization.connection.direct import ( + make_direct_full_resample_matrix) mat = actx.to_numpy( make_direct_full_resample_matrix(actx, bdry_connection)) bdry_f_2_by_mat = mat.dot(actx.to_numpy(flatten(vol_f, actx))) @@ -235,12 +228,11 @@ def test_all_faces_interpolation(actx_factory, group_factory, else: group_cls = SimplexElementGroup + from pytools.convergence import EOCRecorder + from meshmode.discretization import Discretization from meshmode.discretization.connection import ( - make_face_restriction, make_face_to_all_faces_embedding, - check_connection) - - from pytools.convergence import EOCRecorder + check_connection, make_face_restriction, make_face_to_all_faces_embedding) eoc_rec = EOCRecorder() order = 4 @@ -256,7 +248,7 @@ def f(x): h = mesh_par - from meshmode.mesh.io import generate_gmsh, FileSource + from meshmode.mesh.io import FileSource, generate_gmsh print("BEGIN GEN") mesh = generate_gmsh( FileSource(str(thisdir / "blob-2d.step")), 2, order=order, @@ -362,12 +354,11 @@ def test_opposite_face_interpolation(actx_factory, group_factory, else: group_cls = SimplexElementGroup + from pytools.convergence import EOCRecorder + from meshmode.discretization import Discretization from meshmode.discretization.connection import ( - make_face_restriction, make_opposite_face_connection, - check_connection) - - from pytools.convergence import EOCRecorder + check_connection, make_face_restriction, make_opposite_face_connection) eoc_rec = EOCRecorder() order = 5 @@ -391,7 +382,7 @@ def f(x): h = mesh_par - from meshmode.mesh.io import generate_gmsh, FileSource + from meshmode.mesh.io import FileSource, generate_gmsh print("BEGIN GEN") mesh = generate_gmsh( FileSource(str(thisdir / "blob-2d.step")), 2, order=order, @@ -701,7 +692,7 @@ def test_sanity_qhull_nd(actx_factory, dim, order): logging.basicConfig(level=logging.INFO) actx = actx_factory() - from scipy.spatial import Delaunay # pylint: disable=no-name-in-module + from scipy.spatial import Delaunay # pylint: disable=no-name-in-module verts = np.random.rand(1000, dim) dtri = Delaunay(verts) @@ -768,7 +759,7 @@ def test_sanity_balls(actx_factory, src_file, dim, mesh_order, visualize=False): from pytential import bind, sym for h in [0.2, 0.1, 0.05]: - from meshmode.mesh.io import generate_gmsh, FileSource + from meshmode.mesh.io import FileSource, generate_gmsh mesh = generate_gmsh( FileSource(src_file), dim, order=mesh_order, other_options=["-string", "Mesh.CharacteristicLengthMax = %g;" % h], @@ -962,10 +953,8 @@ def grp_factory(mesh_el_group: MeshElementGroup): # check face restrictions from meshmode.discretization.connection import ( - make_face_restriction, - make_face_to_all_faces_embedding, - make_opposite_face_connection, - check_connection) + check_connection, make_face_restriction, make_face_to_all_faces_embedding, + make_opposite_face_connection) for boundary_tag in [BTAG_ALL, FACE_RESTR_INTERIOR, FACE_RESTR_ALL]: conn = make_face_restriction(actx, discr, group_factory=grp_factory, diff --git a/test/test_modal.py b/test/test_modal.py index 36ff124d..4289f02e 100644 --- a/test/test_modal.py +++ b/test/test_modal.py @@ -22,42 +22,31 @@ from functools import partial + import numpy as np +import pytest -from meshmode.array_context import PytestPyOpenCLArrayContextFactory from arraycontext import pytest_generate_tests_for_array_contexts -pytest_generate_tests = pytest_generate_tests_for_array_contexts( - [PytestPyOpenCLArrayContextFactory]) - -from meshmode.dof_array import DOFArray, flat_norm -from meshmode.mesh import ( - SimplexElementGroup, - TensorProductElementGroup - ) +import meshmode.mesh.generation as mgen +from meshmode import _acf # noqa: F401 +from meshmode.array_context import PytestPyOpenCLArrayContextFactory +from meshmode.discretization import Discretization +from meshmode.discretization.connection.modal import ( + ModalToNodalDiscretizationConnection, NodalToModalDiscretizationConnection) from meshmode.discretization.poly_element import ( - # Simplex group factories - ModalSimplexGroupFactory, InterpolatoryQuadratureSimplexGroupFactory, - PolynomialWarpAndBlend2DRestrictingGroupFactory, - PolynomialWarpAndBlend3DRestrictingGroupFactory, + LegendreGaussLobattoTensorProductGroupFactory, ModalSimplexGroupFactory, + ModalTensorProductGroupFactory, PolynomialEquidistantSimplexGroupFactory, PolynomialRecursiveNodesGroupFactory, - PolynomialEquidistantSimplexGroupFactory, - # Tensor product group factories - ModalTensorProductGroupFactory, - LegendreGaussLobattoTensorProductGroupFactory, - # Quadrature-based (non-interpolatory) group factories - QuadratureSimplexGroupFactory - ) + PolynomialWarpAndBlend2DRestrictingGroupFactory, + PolynomialWarpAndBlend3DRestrictingGroupFactory, QuadratureSimplexGroupFactory) +from meshmode.dof_array import DOFArray, flat_norm +from meshmode.mesh import SimplexElementGroup, TensorProductElementGroup -from meshmode.discretization import Discretization -from meshmode.discretization.connection.modal import ( - NodalToModalDiscretizationConnection, - ModalToNodalDiscretizationConnection - ) -import meshmode.mesh.generation as mgen -import pytest +pytest_generate_tests = pytest_generate_tests_for_array_contexts( + [PytestPyOpenCLArrayContextFactory]) @pytest.mark.parametrize("nodal_group_factory", [ diff --git a/test/test_partition.py b/test/test_partition.py index 49ddd48c..d17b5ac1 100644 --- a/test/test_partition.py +++ b/test/test_partition.py @@ -23,30 +23,27 @@ THE SOFTWARE. """ +import logging +import os + import numpy as np -import pyopencl as cl +import pytest -from meshmode.dof_array import flat_norm +import pyopencl as cl +from arraycontext import flatten, pytest_generate_tests_for_array_contexts, unflatten -from arraycontext import flatten, unflatten +from meshmode import _acf # noqa: F401 from meshmode.array_context import PytestPyOpenCLArrayContextFactory -from arraycontext import pytest_generate_tests_for_array_contexts -pytest_generate_tests = pytest_generate_tests_for_array_contexts( - [PytestPyOpenCLArrayContextFactory]) - from meshmode.discretization.poly_element import default_simplex_group_factory +from meshmode.dof_array import flat_norm from meshmode.mesh import ( - BTAG_ALL, - InteriorAdjacencyGroup, - BoundaryAdjacencyGroup, - InterPartAdjacencyGroup -) + BTAG_ALL, BoundaryAdjacencyGroup, InteriorAdjacencyGroup, + InterPartAdjacencyGroup) -import pytest -import os -import logging logger = logging.getLogger(__name__) +pytest_generate_tests = pytest_generate_tests_for_array_contexts( + [PytestPyOpenCLArrayContextFactory]) # Is there a smart way of choosing this number? # Currently it is the same as the base from MPIBoundaryCommSetupHelper @@ -82,6 +79,7 @@ def f(x): if num_groups > 1: from meshmode.mesh.processing import split_mesh_groups + # Group every Nth element element_flags = np.arange(base_mesh.nelements, dtype=base_mesh.element_id_dtype) % num_groups @@ -115,10 +113,9 @@ def f(x): vol_discrs = [Discretization(actx, part_mesh, group_factory) for part_mesh in part_meshes.values()] + from meshmode.discretization.connection import ( + check_connection, make_face_restriction, make_partition_connection) from meshmode.mesh import BTAG_PARTITION - from meshmode.discretization.connection import (make_face_restriction, - make_partition_connection, - check_connection) for i_local_part, i_remote_part in connected_parts: # Mark faces within local_mesh that are connected to remote_mesh @@ -368,11 +365,11 @@ def count_tags(mesh, tag): # {{{ MPI test boundary swap def _test_mpi_boundary_swap(dim, order, num_groups): - from meshmode.distributed import (MPIBoundaryCommSetupHelper, - membership_list_to_map) - from meshmode.mesh.processing import partition_mesh - from mpi4py import MPI + + from meshmode.distributed import ( + MPIBoundaryCommSetupHelper, membership_list_to_map) + from meshmode.mesh.processing import partition_mesh mpi_comm = MPI.COMM_WORLD if mpi_comm.rank == 0: @@ -585,8 +582,8 @@ def test_mpi_communication(num_parts, order): pytest.importorskip("mpi4py") num_ranks = num_parts - from subprocess import check_call import sys + from subprocess import check_call check_call([ "mpiexec", "--oversubscribe", diff --git a/test/test_refinement.py b/test/test_refinement.py index 5f8cbd8b..e262a69f 100644 --- a/test/test_refinement.py +++ b/test/test_refinement.py @@ -21,33 +21,33 @@ """ import logging +import pathlib from functools import partial import numpy as np import pytest -from meshmode.array_context import PytestPyOpenCLArrayContextFactory from arraycontext import pytest_generate_tests_for_array_contexts -pytest_generate_tests = pytest_generate_tests_for_array_contexts( - [PytestPyOpenCLArrayContextFactory]) -from meshmode.dof_array import flat_norm -from meshmode.mesh.refinement import RefinerWithoutAdjacency import meshmode.mesh.generation as mgen - -from meshmode.mesh import SimplexElementGroup, TensorProductElementGroup +from meshmode import _acf # noqa: F401 +from meshmode.array_context import PytestPyOpenCLArrayContextFactory from meshmode.discretization.poly_element import ( + GaussLegendreTensorProductGroupFactory, InterpolatoryQuadratureSimplexGroupFactory, - PolynomialWarpAndBlend2DRestrictingGroupFactory, - PolynomialWarpAndBlend3DRestrictingGroupFactory, - PolynomialEquidistantSimplexGroupFactory, LegendreGaussLobattoTensorProductGroupFactory, - GaussLegendreTensorProductGroupFactory, -) + PolynomialEquidistantSimplexGroupFactory, + PolynomialWarpAndBlend2DRestrictingGroupFactory, + PolynomialWarpAndBlend3DRestrictingGroupFactory) +from meshmode.dof_array import flat_norm +from meshmode.mesh import SimplexElementGroup, TensorProductElementGroup +from meshmode.mesh.refinement import RefinerWithoutAdjacency + logger = logging.getLogger(__name__) +pytest_generate_tests = pytest_generate_tests_for_array_contexts( + [PytestPyOpenCLArrayContextFactory]) -import pathlib thisdir = pathlib.Path(__file__).parent @@ -70,7 +70,7 @@ def random_refine_flags(fract, mesh): all_els = list(range(mesh.nelements)) flags = np.zeros(mesh.nelements) - from random import shuffle, seed + from random import seed, shuffle seed(17) shuffle(all_els) for i in range(int(mesh.nelements * fract)): @@ -139,11 +139,11 @@ def test_refinement_connection( # discretization order order = 5 + from pytools.convergence import EOCRecorder + from meshmode.discretization import Discretization from meshmode.discretization.connection import ( - make_refinement_connection, check_connection) - - from pytools.convergence import EOCRecorder + check_connection, make_refinement_connection) eoc_rec = EOCRecorder() for mesh_par in mesh_pars: @@ -210,8 +210,8 @@ def f(x): f_true = f(x_fine) if visualize == "dots": - import matplotlib.pyplot as plt import matplotlib.cm as cm + import matplotlib.pyplot as plt x = x.get(actx.queue) err = np.array(np.log10( @@ -271,7 +271,7 @@ def test_conformity_of_uniform_mesh(refinement_rounds): assert mesh.is_conforming - from meshmode.mesh import is_boundary_tag_empty, BTAG_ALL + from meshmode.mesh import BTAG_ALL, is_boundary_tag_empty assert is_boundary_tag_empty(mesh, BTAG_ALL) diff --git a/test/test_visualization.py b/test/test_visualization.py index 32e3035e..0d7a435f 100644 --- a/test/test_visualization.py +++ b/test/test_visualization.py @@ -20,31 +20,30 @@ THE SOFTWARE. """ -from functools import partial -from dataclasses import dataclass import logging -logger = logging.getLogger(__name__) +import pathlib +from dataclasses import dataclass +from functools import partial import numpy as np -# import numpy.linalg as la import pytest +from arraycontext import pytest_generate_tests_for_array_contexts from pytools.obj_array import make_obj_array -from meshmode.mesh import SimplexElementGroup, TensorProductElementGroup -from meshmode.discretization.poly_element import ( - default_simplex_group_factory, - InterpolatoryQuadratureSimplexGroupFactory, - LegendreGaussLobattoTensorProductGroupFactory, - ) import meshmode.mesh.generation as mgen - +from meshmode import _acf # noqa: F401 from meshmode.array_context import PytestPyOpenCLArrayContextFactory -from arraycontext import pytest_generate_tests_for_array_contexts +from meshmode.discretization.poly_element import ( + InterpolatoryQuadratureSimplexGroupFactory, + LegendreGaussLobattoTensorProductGroupFactory, default_simplex_group_factory) +from meshmode.mesh import SimplexElementGroup, TensorProductElementGroup + + +logger = logging.getLogger(__name__) pytest_generate_tests = pytest_generate_tests_for_array_contexts( [PytestPyOpenCLArrayContextFactory]) -import pathlib thisdir = pathlib.Path(__file__).parent @@ -323,9 +322,8 @@ def _try_write_vtk(writer, obj): actx, mesh, InterpolatoryQuadratureSimplexGroupFactory(target_order)) - from meshmode.discretization.visualization import make_visualizer - from meshmode.discretization.visualization import \ - write_nodal_adjacency_vtk_file + from meshmode.discretization.visualization import ( + make_visualizer, write_nodal_adjacency_vtk_file) from meshmode.mesh.visualization import write_vertex_vtk_file vis = make_visualizer(actx, discr, 1)