Skip to content

Commit 31173da

Browse files
committed
Add (partially passing) test that connections that should be permuations actually are
1 parent 5eb0b20 commit 31173da

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

test/test_connection.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
__copyright__ = "Copyright (C) 2020 Andreas Kloeckner"
2+
3+
__license__ = """
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.
21+
"""
22+
23+
from arraycontext import _acf # noqa: F401
24+
from functools import partial
25+
import numpy as np # noqa: F401
26+
import numpy.linalg as la # noqa: F401
27+
28+
import meshmode # noqa: F401
29+
from arraycontext import ( # noqa
30+
pytest_generate_tests_for_pyopencl_array_context
31+
as pytest_generate_tests)
32+
33+
from meshmode.mesh import SimplexElementGroup, TensorProductElementGroup
34+
from meshmode.discretization.poly_element import (
35+
PolynomialWarpAndBlend2DGroupFactory,
36+
PolynomialWarpAndBlend3DGroupFactory,
37+
PolynomialEquidistantSimplexGroupFactory,
38+
LegendreGaussLobattoTensorProductGroupFactory,
39+
PolynomialRecursiveNodesGroupFactory,
40+
)
41+
from meshmode.discretization import Discretization
42+
from meshmode.discretization.connection import FACE_RESTR_ALL
43+
import meshmode.mesh.generation as mgen
44+
45+
import pytest
46+
47+
import logging
48+
logger = logging.getLogger(__name__)
49+
50+
51+
def connection_is_permutation(actx, conn):
52+
for i_tgrp, cgrp in enumerate(conn.groups):
53+
for i_batch, batch in enumerate(cgrp.batches):
54+
if not len(batch.from_element_indices):
55+
continue
56+
57+
point_pick_indices = conn._resample_point_pick_indices(
58+
actx, i_tgrp, i_batch)
59+
60+
if point_pick_indices is None:
61+
return False
62+
63+
return True
64+
65+
66+
@pytest.mark.parametrize("group_factory", [
67+
"warp_and_blend",
68+
PolynomialEquidistantSimplexGroupFactory,
69+
LegendreGaussLobattoTensorProductGroupFactory,
70+
partial(PolynomialRecursiveNodesGroupFactory, family="lgl"),
71+
])
72+
@pytest.mark.parametrize("dim", [2, 3])
73+
@pytest.mark.parametrize("order", [1, 2, 3, 4, 5])
74+
def test_bdry_restriction_is_permutation(actx_factory, group_factory, dim, order):
75+
"""Check that restriction to the boundary and opposite-face swap
76+
for the element groups, orders and dimensions above is actually just
77+
indirect access.
78+
"""
79+
actx = actx_factory()
80+
81+
if group_factory == "warp_and_blend":
82+
group_factory = {
83+
2: PolynomialWarpAndBlend2DGroupFactory,
84+
3: PolynomialWarpAndBlend3DGroupFactory,
85+
}[dim]
86+
87+
if group_factory is LegendreGaussLobattoTensorProductGroupFactory:
88+
group_cls = TensorProductElementGroup
89+
else:
90+
group_cls = SimplexElementGroup
91+
92+
mesh = mgen.generate_warped_rect_mesh(dim, order=order, nelements_side=5,
93+
group_cls=group_cls)
94+
95+
vol_discr = Discretization(actx, mesh, group_factory(order))
96+
from meshmode.discretization.connection import (
97+
make_face_restriction, make_opposite_face_connection)
98+
bdry_connection = make_face_restriction(
99+
actx, vol_discr, group_factory(order),
100+
FACE_RESTR_ALL)
101+
102+
assert connection_is_permutation(actx, bdry_connection)
103+
104+
is_lgl = group_factory is LegendreGaussLobattoTensorProductGroupFactory
105+
106+
# FIXME: This should pass unconditionally
107+
should_pass = (
108+
(dim == 3 and order < 2)
109+
or (dim == 2 and not is_lgl)
110+
or (dim == 2 and is_lgl and order < 4)
111+
)
112+
113+
if should_pass:
114+
opp_face = make_opposite_face_connection(actx, bdry_connection)
115+
assert connection_is_permutation(actx, opp_face)
116+
else:
117+
pytest.xfail("https://github.com/inducer/meshmode/pull/105")
118+
119+
120+
if __name__ == "__main__":
121+
import sys
122+
if len(sys.argv) > 1:
123+
exec(sys.argv[1])
124+
else:
125+
from pytest import main
126+
main([__file__])
127+
128+
# vim: fdm=marker

0 commit comments

Comments
 (0)