Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some simple gmsh reading tests #413

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions test/3x3.msh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
$MeshFormat
2.2 0 8
$EndMeshFormat
$PhysicalNames
1
2 10 "fluid"
$EndPhysicalNames
$Nodes
16
1 0 0 0
2 1 0 0
3 1 0.5 0
4 0 0.5 0
5 0.3333333333333333 0 0
6 0.6666666666666666 0 0
7 1 0.1666666666666667 0
8 1 0.3333333333333333 0
9 0.6666666666666667 0.5 0
10 0.3333333333333334 0.5 0
11 0 0.3333333333333334 0
12 0 0.1666666666666667 0
13 0.3333333333333334 0.1666666666666667 0
14 0.3333333333333334 0.3333333333333333 0
15 0.6666666666666667 0.1666666666666667 0
16 0.6666666666666667 0.3333333333333333 0
$EndNodes
$Elements
9
1 3 2 10 1 1 5 13 12
2 3 2 10 1 12 13 14 11
3 3 2 10 1 11 14 10 4
4 3 2 10 1 5 6 15 13
5 3 2 10 1 13 15 16 14
6 3 2 10 1 14 16 9 10
7 3 2 10 1 6 2 7 15
8 3 2 10 1 15 7 8 16
9 3 2 10 1 16 8 3 9
$EndElements
54 changes: 54 additions & 0 deletions test/3x3_bound.msh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
$MeshFormat
2.2 0 8
$EndMeshFormat
$PhysicalNames
5
1 2 "Left"
1 3 "Right"
1 4 "Bottom"
1 5 "Top"
2 1 "fluid"
$EndPhysicalNames
$Nodes
16
1 0 0 0
2 1 0 0
3 1 0.5 0
4 0 0.5 0
5 0.3333333333333333 0 0
6 0.6666666666666666 0 0
7 1 0.1666666666666667 0
8 1 0.3333333333333333 0
9 0.6666666666666667 0.5 0
10 0.3333333333333334 0.5 0
11 0 0.3333333333333334 0
12 0 0.1666666666666667 0
13 0.3333333333333334 0.1666666666666667 0
14 0.3333333333333334 0.3333333333333333 0
15 0.6666666666666667 0.1666666666666667 0
16 0.6666666666666667 0.3333333333333333 0
$EndNodes
$Elements
21
1 1 2 2 1 1 12
2 1 2 2 1 12 11
3 1 2 2 1 11 4
4 1 2 3 1 7 2
5 1 2 3 1 8 7
6 1 2 3 1 3 8
7 1 2 4 1 5 1
8 1 2 4 1 6 5
9 1 2 4 1 2 6
10 1 2 5 1 3 9
11 1 2 5 1 9 10
12 1 2 5 1 10 4
13 3 2 1 1 12 13 5 1
14 3 2 1 1 11 14 13 12
15 3 2 1 1 4 10 14 11
16 3 2 1 1 13 15 6 5
17 3 2 1 1 14 16 15 13
18 3 2 1 1 10 9 16 14
19 3 2 1 1 15 7 2 6
20 3 2 1 1 16 8 7 15
21 3 2 1 1 9 3 8 16
$EndElements
38 changes: 38 additions & 0 deletions test/3x3_minus.msh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
$MeshFormat
2.2 0 8
$EndMeshFormat
$PhysicalNames
1
2 10 "fluid"
$EndPhysicalNames
$Nodes
16
1 0 0 0
2 1 0 0
3 1 0.5 0
4 0 0.5 0
5 0.3333333333333333 0 0
6 0.6666666666666666 0 0
7 1 0.1666666666666667 0
8 1 0.3333333333333333 0
9 0.6666666666666667 0.5 0
10 0.3333333333333334 0.5 0
11 0 0.3333333333333334 0
12 0 0.1666666666666667 0
13 0.3333333333333334 0.1666666666666667 0
14 0.3333333333333334 0.3333333333333333 0
15 0.6666666666666667 0.1666666666666667 0
16 0.6666666666666667 0.3333333333333333 0
$EndNodes
$Elements
9
1 3 2 10 1 12 13 5 1
2 3 2 10 1 14 13 12 11
3 3 2 10 1 10 14 11 4
4 3 2 10 1 13 15 6 5
5 3 2 10 1 14 16 15 13
6 3 2 10 1 16 14 10 9
7 3 2 10 1 6 15 7 2
8 3 2 10 1 15 16 8 7
9 3 2 10 1 8 16 9 3
$EndElements
38 changes: 38 additions & 0 deletions test/3x3_twisted.msh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
$MeshFormat
2.2 0 8
$EndMeshFormat
$PhysicalNames
1
2 10 "fluid"
$EndPhysicalNames
$Nodes
16
1 0 0 0
2 1 0 0
3 1 0.5 0
4 0 0.5 0
5 0.3333333333333333 0 0
6 0.6666666666666666 0 0
7 1 0.1666666666666667 0
8 1 0.3333333333333333 0
9 0.6666666666666667 0.5 0
10 0.3333333333333334 0.5 0
11 0 0.3333333333333334 0
12 0 0.1666666666666667 0
13 0.3333333333333334 0.1666666666666667 0
14 0.3333333333333334 0.3333333333333333 0
15 0.6666666666666667 0.1666666666666667 0
16 0.6666666666666667 0.3333333333333333 0
$EndNodes
$Elements
9
1 3 2 10 1 1 5 13 12
2 3 2 10 1 11 12 13 14
3 3 2 10 1 4 11 14 10
4 3 2 10 1 5 6 15 13
5 3 2 10 1 13 15 16 14
6 3 2 10 1 9 10 14 16
7 3 2 10 1 2 7 15 6
8 3 2 10 1 7 8 16 15
9 3 2 10 1 3 9 16 8
$EndElements
66 changes: 64 additions & 2 deletions test/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,14 @@ def test_merge_and_map(actx_factory, group_cls, visualize=False):

# {{{ element orientation

@pytest.mark.parametrize("case", ["blob", "gh-394"])
@pytest.mark.parametrize("case", ["blob", "gh-394", "3x3", "3x3_twisted",
"3x3_minus", "3x3_bound"])
def test_element_orientation_via_flipping(case):
from meshmode.mesh.io import FileSource, generate_gmsh

mesh_order = 3

meshfile = f"{thisdir}/{case}.msh"
if case == "blob":
mesh = generate_gmsh(
FileSource(str(thisdir / "blob-2d.step")), 2, order=mesh_order,
Expand All @@ -593,13 +595,73 @@ def test_element_orientation_via_flipping(case):
)
elif case == "gh-394":
mesh = mio.read_gmsh(
str(thisdir / "gh-394.msh"),
meshfile,
force_ambient_dim=2,
mesh_construction_kwargs={"skip_tests": True})
elif case == "3x3": # regular ole rectangular 3x3 tensor product els (TPE)
mesh = mio.read_gmsh(
meshfile,
force_ambient_dim=2,
mesh_construction_kwargs={"skip_tests": True})
elif case == "3x3_twisted": # TPEs, rotated connectivities, all positive
mesh = mio.read_gmsh(
meshfile,
force_ambient_dim=2,
mesh_construction_kwargs={"skip_tests": True})
elif case == "3x3_minus": # TPEs with negative orientation (clockwise conn)
mesh = mio.read_gmsh(
meshfile,
force_ambient_dim=2,
mesh_construction_kwargs={"skip_tests": True})
elif case == "3x3_bound": # TPEs (clockwise conn, w/boundaries)
mesh = mio.read_gmsh(
meshfile,
force_ambient_dim=2,
mesh_construction_kwargs={"skip_tests": True})
else:
raise ValueError(f"unknown case: {case}")

boundary_tags = set()
for igrp in range(len(mesh.groups)):
print(f"{meshfile=} Boundaries:")
bdry_fagrps = [
fagrp for fagrp in mesh.facial_adjacency_groups[igrp]
if isinstance(fagrp, BoundaryAdjacencyGroup)]
for bdry_fagrp in bdry_fagrps:
print(f"Boundary tag: {bdry_fagrp.boundary_tag}")
boundary_tags.add(bdry_fagrp.boundary_tag)
# print(f"----{bdry_fagrp.elements=}")
# if bdry_fagrp.boundary_tag == "outer_bdy":
# num_marked_outer_bdy += len(bdry_fagrp.elements)
#if bdry_fagrp.boundary_tag == "inner_bdy":
# num_marked_inner_bdy += len(bdry_fagrp.elements)

mesh_orient = mproc.find_volume_mesh_element_orientations(mesh)
if not (mesh_orient > 0).all():
print(f"Mesh({meshfile}) is negative, trying to reorient.")
mesh = mio.read_gmsh(
meshfile,
force_ambient_dim=2,
mesh_construction_kwargs={
"skip_tests": True,
"force_positive_orientation": True})
mesh_orient = mproc.find_volume_mesh_element_orientations(mesh)
boundary_tags_reoriented = set()
for igrp in range(len(mesh.groups)):
print(f"{meshfile=} Reoriented Boundaries:")
bdry_fagrps = [
fagrp for fagrp in mesh.facial_adjacency_groups[igrp]
if isinstance(fagrp, BoundaryAdjacencyGroup)]
for bdry_fagrp in bdry_fagrps:
print(f"Boundary tag: {bdry_fagrp.boundary_tag}")
boundary_tags_reoriented.add(bdry_fagrp.boundary_tag)
# print(f"----{bdry_fagrp.elements=}")
# if bdry_fagrp.boundary_tag == "outer_bdy":
# num_marked_outer_bdy += len(bdry_fagrp.elements)
#if bdry_fagrp.boundary_tag == "inner_bdy":
# num_marked_inner_bdy += len(bdry_fagrp.elements)
# Make sure rotation doesn't lose boundaries
assert boundary_tags == boundary_tags_reoriented

assert (mesh_orient > 0).all()

Expand Down
Loading