From 00b6da03600c41e9c1d39f626661da5eb0818061 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 22 Feb 2021 01:19:51 -0600 Subject: [PATCH 1/4] Add Vtk mesh visualization --- meshmode/mesh/visualization.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/meshmode/mesh/visualization.py b/meshmode/mesh/visualization.py index dc4a3b3c6..29c31c18e 100644 --- a/meshmode/mesh/visualization.py +++ b/meshmode/mesh/visualization.py @@ -27,6 +27,7 @@ .. autofunction:: draw_curve .. autofunction:: write_vertex_vtk_file .. autofunction:: mesh_to_tikz +.. autofunction:: vtk_visualize_mesh """ @@ -299,4 +300,23 @@ def mesh_to_tikz(mesh): # }}} + +# {{{ visualize_mesh + +def vtk_visualize_mesh(actx, mesh, filename, vtk_high_order=True): + order = max(mgrp.order for mgrp in mesh.groups) + + from meshmode.discretization.poly_element import \ + PolynomialWarpAndBlendGroupFactory + from meshmode.discretization import Discretization + discr = Discretization(actx, mesh, PolynomialWarpAndBlendGroupFactory(order)) + + from meshmode.discretization.visualization import make_visualizer + vis = make_visualizer(actx, discr, order, force_equidistant=vtk_high_order) + + vis.write_vtk_file(filename, [], use_high_order=vtk_high_order) + +# }}} + + # vim: foldmethod=marker From f8602f6983e123dedf30276cceaf0a08bcd7db52 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 22 Feb 2021 01:20:22 -0600 Subject: [PATCH 2/4] Import mesh.generation as mgen in test_refinement --- test/test_refinement.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/test_refinement.py b/test/test_refinement.py index c88f7a148..0e234cecc 100644 --- a/test/test_refinement.py +++ b/test/test_refinement.py @@ -36,6 +36,7 @@ generate_icosahedron, generate_box_mesh, make_curve_mesh, ellipse) from meshmode.mesh.refinement.utils import check_nodal_adj_against_geometry from meshmode.mesh.refinement import Refiner, RefinerWithoutAdjacency +import meshmode.mesh.generation as mgen from meshmode.mesh import SimplexElementGroup, TensorProductElementGroup from meshmode.discretization.poly_element import ( @@ -224,8 +225,7 @@ def test_refinement_connection( mesh = get_blob_mesh(mesh_par, mesh_order) h = float(mesh_par) elif mesh_name == "warp": - from meshmode.mesh.generation import generate_warped_rect_mesh - mesh = generate_warped_rect_mesh(dim, order=mesh_order, n=mesh_par, + mesh = mgen.generate_warped_rect_mesh(dim, order=mesh_order, n=mesh_par, group_cls=group_cls) h = 1/mesh_par else: @@ -321,8 +321,7 @@ def test_uniform_refinement(group_cls, with_adjacency): @pytest.mark.parametrize("refinement_rounds", [0, 1, 2]) def test_conformity_of_uniform_mesh(refinement_rounds): - from meshmode.mesh.generation import generate_icosphere - mesh = generate_icosphere(r=1.0, order=4, + mesh = mgen.generate_icosphere(r=1.0, order=4, uniform_refinement_rounds=refinement_rounds) assert mesh.is_conforming From 334d138cba0261f9974f8bce5c19e209e13da4cf Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 22 Feb 2021 01:20:36 -0600 Subject: [PATCH 3/4] Add test_refine_surfaces --- test/test_refinement.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/test_refinement.py b/test/test_refinement.py index 0e234cecc..5b5e5a9bd 100644 --- a/test/test_refinement.py +++ b/test/test_refinement.py @@ -330,6 +330,30 @@ def test_conformity_of_uniform_mesh(refinement_rounds): assert is_boundary_tag_empty(mesh, BTAG_ALL) +@pytest.parametrize("mesh_name", ["torus", "icosphere"]) +def test_refine_surfaces(actx_factory, mesh_name, visualize=False): + if mesh_name == "torus": + mesh = mgen.generate_torus(10, 1, 40, 4, order=4) + elif mesh_name == "icosphere": + mesh = mgen.generate_icosphere(1, order=4) + else: + raise ValueError(f"invalid mesh name '{mesh_name}'") + + if visualize: + actx = actx_factory() + from meshmode.mesh.visualization import vtk_visualize_mesh + vtk_visualize_mesh(actx, mesh, "surface.vtu") + + # check for absence of node-vertex consistency error + from meshmode.mesh.refinement import refine_uniformly + refined_mesh = refine_uniformly(mesh, 1) + + if visualize: + actx = actx_factory() + from meshmode.mesh.visualization import vtk_visualize_mesh + vtk_visualize_mesh(actx, refined_mesh, "surface-refined.vtu") + + if __name__ == "__main__": import sys if len(sys.argv) > 1: From 6fd66d13639677fdda855805b345dd39649cb43b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kl=C3=B6ckner?= Date: Mon, 22 Feb 2021 08:59:22 -0600 Subject: [PATCH 4/4] Add missing .mark in test_refine_surfaces Co-authored-by: Alex Fikl --- test/test_refinement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_refinement.py b/test/test_refinement.py index 5b5e5a9bd..1835edb3a 100644 --- a/test/test_refinement.py +++ b/test/test_refinement.py @@ -330,7 +330,7 @@ def test_conformity_of_uniform_mesh(refinement_rounds): assert is_boundary_tag_empty(mesh, BTAG_ALL) -@pytest.parametrize("mesh_name", ["torus", "icosphere"]) +@pytest.mark.parametrize("mesh_name", ["torus", "icosphere"]) def test_refine_surfaces(actx_factory, mesh_name, visualize=False): if mesh_name == "torus": mesh = mgen.generate_torus(10, 1, 40, 4, order=4)