Skip to content

Commit b143bfd

Browse files
MTCaminducer
authored andcommitted
Add some simple gmsh reading tests
1 parent da0e628 commit b143bfd

File tree

5 files changed

+232
-2
lines changed

5 files changed

+232
-2
lines changed

test/3x3.msh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
$MeshFormat
2+
2.2 0 8
3+
$EndMeshFormat
4+
$PhysicalNames
5+
1
6+
2 10 "fluid"
7+
$EndPhysicalNames
8+
$Nodes
9+
16
10+
1 0 0 0
11+
2 1 0 0
12+
3 1 0.5 0
13+
4 0 0.5 0
14+
5 0.3333333333333333 0 0
15+
6 0.6666666666666666 0 0
16+
7 1 0.1666666666666667 0
17+
8 1 0.3333333333333333 0
18+
9 0.6666666666666667 0.5 0
19+
10 0.3333333333333334 0.5 0
20+
11 0 0.3333333333333334 0
21+
12 0 0.1666666666666667 0
22+
13 0.3333333333333334 0.1666666666666667 0
23+
14 0.3333333333333334 0.3333333333333333 0
24+
15 0.6666666666666667 0.1666666666666667 0
25+
16 0.6666666666666667 0.3333333333333333 0
26+
$EndNodes
27+
$Elements
28+
9
29+
1 3 2 10 1 1 5 13 12
30+
2 3 2 10 1 12 13 14 11
31+
3 3 2 10 1 11 14 10 4
32+
4 3 2 10 1 5 6 15 13
33+
5 3 2 10 1 13 15 16 14
34+
6 3 2 10 1 14 16 9 10
35+
7 3 2 10 1 6 2 7 15
36+
8 3 2 10 1 15 7 8 16
37+
9 3 2 10 1 16 8 3 9
38+
$EndElements

test/3x3_bound.msh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
$MeshFormat
2+
2.2 0 8
3+
$EndMeshFormat
4+
$PhysicalNames
5+
5
6+
1 2 "Left"
7+
1 3 "Right"
8+
1 4 "Bottom"
9+
1 5 "Top"
10+
2 1 "fluid"
11+
$EndPhysicalNames
12+
$Nodes
13+
16
14+
1 0 0 0
15+
2 1 0 0
16+
3 1 0.5 0
17+
4 0 0.5 0
18+
5 0.3333333333333333 0 0
19+
6 0.6666666666666666 0 0
20+
7 1 0.1666666666666667 0
21+
8 1 0.3333333333333333 0
22+
9 0.6666666666666667 0.5 0
23+
10 0.3333333333333334 0.5 0
24+
11 0 0.3333333333333334 0
25+
12 0 0.1666666666666667 0
26+
13 0.3333333333333334 0.1666666666666667 0
27+
14 0.3333333333333334 0.3333333333333333 0
28+
15 0.6666666666666667 0.1666666666666667 0
29+
16 0.6666666666666667 0.3333333333333333 0
30+
$EndNodes
31+
$Elements
32+
21
33+
1 1 2 2 1 1 12
34+
2 1 2 2 1 12 11
35+
3 1 2 2 1 11 4
36+
4 1 2 3 1 7 2
37+
5 1 2 3 1 8 7
38+
6 1 2 3 1 3 8
39+
7 1 2 4 1 5 1
40+
8 1 2 4 1 6 5
41+
9 1 2 4 1 2 6
42+
10 1 2 5 1 3 9
43+
11 1 2 5 1 9 10
44+
12 1 2 5 1 10 4
45+
13 3 2 1 1 12 13 5 1
46+
14 3 2 1 1 11 14 13 12
47+
15 3 2 1 1 4 10 14 11
48+
16 3 2 1 1 13 15 6 5
49+
17 3 2 1 1 14 16 15 13
50+
18 3 2 1 1 10 9 16 14
51+
19 3 2 1 1 15 7 2 6
52+
20 3 2 1 1 16 8 7 15
53+
21 3 2 1 1 9 3 8 16
54+
$EndElements

test/3x3_minus.msh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
$MeshFormat
2+
2.2 0 8
3+
$EndMeshFormat
4+
$PhysicalNames
5+
1
6+
2 10 "fluid"
7+
$EndPhysicalNames
8+
$Nodes
9+
16
10+
1 0 0 0
11+
2 1 0 0
12+
3 1 0.5 0
13+
4 0 0.5 0
14+
5 0.3333333333333333 0 0
15+
6 0.6666666666666666 0 0
16+
7 1 0.1666666666666667 0
17+
8 1 0.3333333333333333 0
18+
9 0.6666666666666667 0.5 0
19+
10 0.3333333333333334 0.5 0
20+
11 0 0.3333333333333334 0
21+
12 0 0.1666666666666667 0
22+
13 0.3333333333333334 0.1666666666666667 0
23+
14 0.3333333333333334 0.3333333333333333 0
24+
15 0.6666666666666667 0.1666666666666667 0
25+
16 0.6666666666666667 0.3333333333333333 0
26+
$EndNodes
27+
$Elements
28+
9
29+
1 3 2 10 1 12 13 5 1
30+
2 3 2 10 1 14 13 12 11
31+
3 3 2 10 1 10 14 11 4
32+
4 3 2 10 1 13 15 6 5
33+
5 3 2 10 1 14 16 15 13
34+
6 3 2 10 1 16 14 10 9
35+
7 3 2 10 1 6 15 7 2
36+
8 3 2 10 1 15 16 8 7
37+
9 3 2 10 1 8 16 9 3
38+
$EndElements

test/3x3_twisted.msh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
$MeshFormat
2+
2.2 0 8
3+
$EndMeshFormat
4+
$PhysicalNames
5+
1
6+
2 10 "fluid"
7+
$EndPhysicalNames
8+
$Nodes
9+
16
10+
1 0 0 0
11+
2 1 0 0
12+
3 1 0.5 0
13+
4 0 0.5 0
14+
5 0.3333333333333333 0 0
15+
6 0.6666666666666666 0 0
16+
7 1 0.1666666666666667 0
17+
8 1 0.3333333333333333 0
18+
9 0.6666666666666667 0.5 0
19+
10 0.3333333333333334 0.5 0
20+
11 0 0.3333333333333334 0
21+
12 0 0.1666666666666667 0
22+
13 0.3333333333333334 0.1666666666666667 0
23+
14 0.3333333333333334 0.3333333333333333 0
24+
15 0.6666666666666667 0.1666666666666667 0
25+
16 0.6666666666666667 0.3333333333333333 0
26+
$EndNodes
27+
$Elements
28+
9
29+
1 3 2 10 1 1 5 13 12
30+
2 3 2 10 1 11 12 13 14
31+
3 3 2 10 1 4 11 14 10
32+
4 3 2 10 1 5 6 15 13
33+
5 3 2 10 1 13 15 16 14
34+
6 3 2 10 1 9 10 14 16
35+
7 3 2 10 1 2 7 15 6
36+
8 3 2 10 1 7 8 16 15
37+
9 3 2 10 1 3 9 16 8
38+
$EndElements

test/test_mesh.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,14 @@ def test_merge_and_map(actx_factory, group_cls, visualize=False):
578578

579579
# {{{ element orientation
580580

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

585586
mesh_order = 3
586587

588+
meshfile = f"{thisdir}/{case}.msh"
587589
if case == "blob":
588590
mesh = generate_gmsh(
589591
FileSource(str(thisdir / "blob-2d.step")), 2, order=mesh_order,
@@ -593,13 +595,73 @@ def test_element_orientation_via_flipping(case):
593595
)
594596
elif case == "gh-394":
595597
mesh = mio.read_gmsh(
596-
str(thisdir / "gh-394.msh"),
598+
meshfile,
599+
force_ambient_dim=2,
600+
mesh_construction_kwargs={"skip_tests": True})
601+
elif case == "3x3": # regular ole rectangular 3x3 tensor product els (TPE)
602+
mesh = mio.read_gmsh(
603+
meshfile,
604+
force_ambient_dim=2,
605+
mesh_construction_kwargs={"skip_tests": True})
606+
elif case == "3x3_twisted": # TPEs, rotated connectivities, all positive
607+
mesh = mio.read_gmsh(
608+
meshfile,
609+
force_ambient_dim=2,
610+
mesh_construction_kwargs={"skip_tests": True})
611+
elif case == "3x3_minus": # TPEs with negative orientation (clockwise conn)
612+
mesh = mio.read_gmsh(
613+
meshfile,
614+
force_ambient_dim=2,
615+
mesh_construction_kwargs={"skip_tests": True})
616+
elif case == "3x3_bound": # TPEs (clockwise conn, w/boundaries)
617+
mesh = mio.read_gmsh(
618+
meshfile,
597619
force_ambient_dim=2,
598620
mesh_construction_kwargs={"skip_tests": True})
599621
else:
600622
raise ValueError(f"unknown case: {case}")
601623

624+
boundary_tags = set()
625+
for igrp in range(len(mesh.groups)):
626+
print(f"{meshfile=} Boundaries:")
627+
bdry_fagrps = [
628+
fagrp for fagrp in mesh.facial_adjacency_groups[igrp]
629+
if isinstance(fagrp, BoundaryAdjacencyGroup)]
630+
for bdry_fagrp in bdry_fagrps:
631+
print(f"Boundary tag: {bdry_fagrp.boundary_tag}")
632+
boundary_tags.add(bdry_fagrp.boundary_tag)
633+
# print(f"----{bdry_fagrp.elements=}")
634+
# if bdry_fagrp.boundary_tag == "outer_bdy":
635+
# num_marked_outer_bdy += len(bdry_fagrp.elements)
636+
#if bdry_fagrp.boundary_tag == "inner_bdy":
637+
# num_marked_inner_bdy += len(bdry_fagrp.elements)
638+
602639
mesh_orient = mproc.find_volume_mesh_element_orientations(mesh)
640+
if not (mesh_orient > 0).all():
641+
print(f"Mesh({meshfile}) is negative, trying to reorient.")
642+
mesh = mio.read_gmsh(
643+
meshfile,
644+
force_ambient_dim=2,
645+
mesh_construction_kwargs={
646+
"skip_tests": True,
647+
"force_positive_orientation": True})
648+
mesh_orient = mproc.find_volume_mesh_element_orientations(mesh)
649+
boundary_tags_reoriented = set()
650+
for igrp in range(len(mesh.groups)):
651+
print(f"{meshfile=} Reoriented Boundaries:")
652+
bdry_fagrps = [
653+
fagrp for fagrp in mesh.facial_adjacency_groups[igrp]
654+
if isinstance(fagrp, BoundaryAdjacencyGroup)]
655+
for bdry_fagrp in bdry_fagrps:
656+
print(f"Boundary tag: {bdry_fagrp.boundary_tag}")
657+
boundary_tags_reoriented.add(bdry_fagrp.boundary_tag)
658+
# print(f"----{bdry_fagrp.elements=}")
659+
# if bdry_fagrp.boundary_tag == "outer_bdy":
660+
# num_marked_outer_bdy += len(bdry_fagrp.elements)
661+
#if bdry_fagrp.boundary_tag == "inner_bdy":
662+
# num_marked_inner_bdy += len(bdry_fagrp.elements)
663+
# Make sure rotation doesn't lose boundaries
664+
assert boundary_tags == boundary_tags_reoriented
603665

604666
assert (mesh_orient > 0).all()
605667

0 commit comments

Comments
 (0)