Unverified Commit a0b12591 authored by René Fritze's avatar René Fritze Committed by GitHub
Browse files

Merge pull request #1675 from pymor/issue_944

Issue #944
parents b768dcce 4e922683
Pipeline #152044 failed with stages
in 300 minutes and 44 seconds
......@@ -530,14 +530,13 @@ class Grid(CacheableObject):
def _check_domain(cls, domain):
ll, rr = np.array(domain[0]), np.array(domain[1])
sizes = rr - ll
too_large = (
np.linalg.norm(sizes) > cls.MAX_DOMAIN_WIDTH
or np.max(sizes) / np.min(sizes) > cls.MAX_DOMAIN_RATIO
)
if too_large:
logger = getLogger('pymor.discretizers.builtin.grid')
logger = getLogger('pymor.discretizers.builtin.grid')
if np.linalg.norm(sizes) > cls.MAX_DOMAIN_WIDTH:
logger.warning(f'Domain {domain} for {cls} exceeds width limit. Results may be inaccurate')
return False
if np.max(sizes) / np.min(sizes) > cls.MAX_DOMAIN_RATIO:
logger.warning(f'Domain {domain} for {cls} exceeds ratio limit. Results may be inaccurate')
return False
return True
......
......@@ -325,7 +325,6 @@ def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None,
if not config.HAVE_MATPLOTLIB:
raise ImportError('cannot visualize: import of matplotlib failed')
# TODO extract class
class MainWindow(PlotMainWindow):
def __init__(self, grid, U, bounding_box, codim, title, legend, separate_colorbars, rescale_colorbars, backend):
......
......@@ -17,8 +17,10 @@ def _scale_tols_if_domain_bad(g, atol=1e-05, rtol=1e-08):
# "badly" shaped domains produce excessive errors
# same for large differences in absolute coord values
bbox = g.bounding_box()
scale = 1.0
lower_left, upper_right = bbox[0], bbox[1]
magic_downscale = 1e-3
if g.dim == 2:
lower_left, upper_right = bbox[0], bbox[1]
upper_left = np.array([lower_left[0], upper_right[1]])
lower_right = np.array([lower_left[1], upper_right[0]])
h = np.linalg.norm(upper_left - lower_left)
......@@ -26,10 +28,15 @@ def _scale_tols_if_domain_bad(g, atol=1e-05, rtol=1e-08):
min_l = min(w, h)
max_l = max(w, h)
ll, rr = np.linalg.norm(lower_left), np.linalg.norm(upper_right)
scale = max(max_l / min_l, abs(rr-ll)*1e-2)
if scale > 100:
rtol *= scale / 10
atol *= scale / 10
scale = max(max_l / min_l, abs(rr - ll) * magic_downscale)
if g.dim == 1:
ratio = abs(upper_right) / abs(lower_left)
if not np.isfinite(ratio):
ratio = abs(upper_right)*magic_downscale
scale = max(ratio, abs(upper_right-lower_left)*magic_downscale)[0]
if scale > 10:
rtol *= scale
atol *= scale
assert np.isfinite(atol)
assert np.isfinite(rtol)
return atol, rtol
......@@ -347,7 +354,7 @@ def test_bounding_box(grid):
# compare with tolerance is necessary with very large domain boundaries values
# where the relative error in the centers computation introduces enough error to fail the test
# otherwise
rtol, atol = _scale_tols_if_domain_bad(g, rtol=1e-12, atol=1e-12)
rtol, atol = _scale_tols_if_domain_bad(g, rtol=2e-12, atol=2e-12)
assert np.all(almost_less(bbox[0], g.centers(g.dim), rtol=rtol, atol=atol))
assert np.all(almost_less(g.centers(g.dim), bbox[1], rtol=rtol, atol=atol))
......
......@@ -14,22 +14,24 @@ from pymor.discretizers.builtin.grids.tria import TriaGrid
from pymor.discretizers.builtin.grids.unstructured import UnstructuredTriangleGrid
def hy_domain_bounds(draw, grid_type):
def _hy_domain_bounds(draw, grid_type):
# domain points are limited to allow their norm2 computations
# TODO: allow negative coordinate points
max_abs = grid_type.MAX_DOMAIN_WIDTH / 2
min_abs = grid_type.MIN_DOMAIN_WIDTH / 2
domain_point = hyst.floats(allow_infinity=False, allow_nan=False, min_value=min_abs, max_value=max_abs)
max_val = grid_type.MAX_DOMAIN_WIDTH / 2
min_val = -grid_type.MAX_DOMAIN_WIDTH / 2
domain_point = hyst.floats(allow_infinity=False, allow_nan=False, allow_subnormal=False,
min_value=min_val, max_value=max_val)
ll = draw(hyst.tuples(*[domain_point] * grid_type.dim))
def _filter(d):
return all(l < r for l, r in zip(ll, d)) and grid_type._check_domain((ll, d))
return (all(l < r and abs(r - l) > grid_type.MIN_DOMAIN_WIDTH for l, r in zip(ll, d))
and grid_type._check_domain((ll, d)))
ll = draw(hyst.tuples(*[domain_point] * grid_type.dim))
rr = draw(hyst.tuples(*[domain_point] * grid_type.dim).filter(_filter))
return ll, rr
def hy_rect_tria_kwargs(draw, grid_type):
def _hy_rect_tria_kwargs(draw, grid_type):
identify_left_right = draw(hyst.booleans())
identify_bottom_top = draw(hyst.booleans())
interval_i = hyst.integers(min_value=1, max_value=42)
......@@ -38,19 +40,19 @@ def hy_rect_tria_kwargs(draw, grid_type):
num_intervals = draw(hyst.tuples(interval_i.map(lambda x: x if not identify_left_right else max(2, x)),
interval_i.map(lambda y: y if not identify_bottom_top else max(2, y))))
domain = hy_domain_bounds(draw, grid_type=grid_type)
domain = _hy_domain_bounds(draw, grid_type=grid_type)
return {"num_intervals": num_intervals, "domain": domain, "identify_left_right": identify_left_right,
"identify_bottom_top": identify_bottom_top}
@hyst.composite
def hy_rect_grid(draw):
return RectGrid(**hy_rect_tria_kwargs(draw, RectGrid))
return RectGrid(**_hy_rect_tria_kwargs(draw, RectGrid))
@hyst.composite
def hy_tria_grid(draw):
return TriaGrid(**hy_rect_tria_kwargs(draw, TriaGrid))
return TriaGrid(**_hy_rect_tria_kwargs(draw, TriaGrid))
@hyst.composite
......@@ -58,7 +60,7 @@ def hy_oned_grid(draw):
identify_left_right = draw(hyst.booleans())
interval_i = hyst.integers(min_value=1, max_value=10000)
num_intervals = draw(interval_i.filter(lambda x: (not identify_left_right) or x > 1))
domain = hy_domain_bounds(draw, grid_type=OnedGrid)
domain = _hy_domain_bounds(draw, grid_type=OnedGrid)
return OnedGrid(num_intervals=num_intervals, domain=[domain[0][0], domain[1][0]],
identify_left_right=identify_left_right)
......
......@@ -246,6 +246,12 @@ def valid_inds(v, length=None, random_module=None):
yield list(range(int(len(v)/2)))
yield list(range(len(v))) * 2
# TODO what's with the magic number here?
# Maybe related to this?
# pymortests/vectorarray.py:910: VisibleDeprecationWarning:
# Creating an ndarray from nested sequences exceeding
# the maximum number of dimensions of 32 is deprecated.
# If you mean to do this, you must specify
# 'dtype=object' when creating the ndarray.
length = 32
if len(v) > 0:
for ind in [-len(v), 0, len(v) - 1]:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment