Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
__copyright__ = """
Copyright (C) 2021 University of Illinois Board of Trustees
"""
__license__ = """
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
import numpy as np
from arraycontext import ( # noqa
pytest_generate_tests_for_pyopencl_array_context
as pytest_generate_tests
)
from grudge import DiscretizationCollection
import grudge.op as op
import pytest
import logging
logger = logging.getLogger(__name__)
@pytest.mark.parametrize("name", ["interval", "box2d", "box3d"])
def test_geometric_factors_regular_refinement(actx_factory, name):
from grudge.dt_utils import dt_geometric_factors
actx = actx_factory()
# {{{ cases
if name == "interval":
from mesh_data import BoxMeshBuilder
builder = BoxMeshBuilder(ambient_dim=1)
elif name == "box2d":
from mesh_data import BoxMeshBuilder
builder = BoxMeshBuilder(ambient_dim=2)
elif name == "box3d":
from mesh_data import BoxMeshBuilder
builder = BoxMeshBuilder(ambient_dim=3)
else:
raise ValueError("unknown geometry name: %s" % name)
# }}}
min_factors = []
for resolution in builder.resolutions:
mesh = builder.get_mesh(resolution, builder.mesh_order)
dcoll = DiscretizationCollection(actx, mesh, order=builder.order)
min_factors.append(op.nodal_min(dcoll, "vol", dt_geometric_factors(dcoll)))
# Resolution is doubled each refinement, so the ratio of consecutive
# geometric factors should satisfy: gfi+1 / gfi = 2
min_factors = np.asarray(min_factors)
ratios = min_factors[:-1] / min_factors[1:]
assert np.all(np.isclose(ratios, 2))
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@pytest.mark.parametrize("name", ["interval", "box2d", "box3d"])
def test_non_geometric_factors(actx_factory, name):
from grudge.dt_utils import dt_non_geometric_factor, dt_geometric_factors
actx = actx_factory()
# {{{ cases
if name == "interval":
from mesh_data import BoxMeshBuilder
builder = BoxMeshBuilder(ambient_dim=1)
elif name == "box2d":
from mesh_data import BoxMeshBuilder
builder = BoxMeshBuilder(ambient_dim=2)
elif name == "box3d":
from mesh_data import BoxMeshBuilder
builder = BoxMeshBuilder(ambient_dim=3)
else:
raise ValueError("unknown geometry name: %s" % name)
# }}}
factors = []
geom_factors = []
degrees = list(range(1, 8))
for degree in degrees:
mesh = builder.get_mesh(1, degree)
dcoll = DiscretizationCollection(actx, mesh, order=degree)
factors.append(dt_non_geometric_factor(dcoll))
geom_factors.append(
op.nodal_min(dcoll, "vol", dt_geometric_factors(dcoll))
)
# Crude estimate, factors should behave like 1/N**2
factors = np.asarray(factors)
geom_factors = np.asarray(geom_factors)
lower_bounds = 1/(np.asarray(degrees)**2)
upper_bounds = geom_factors*lower_bounds
assert lower_bounds.all() <= factors.all() <= upper_bounds.all()