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

Fix passing a function as boundary_types argument to PolygonalDomain (#1422)

Fixes #1421.
parents c5c25e2a c85e77ca
Pipeline #103472 passed with stages
in 35 minutes and 51 seconds
......@@ -2,7 +2,8 @@
# Copyright 2013-2021 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)
import collections
from collections import defaultdict
from itertools import chain
import numpy as np
......@@ -307,18 +308,16 @@ class PolygonalDomain(DomainDescription):
# if the boundary types are not given as a dict, try to evaluate at
# the edge centers to get a dict.
else:
points = [points]
points.extend(holes)
# shift points 1 entry to the left.
points_deque = [collections.deque(ps) for ps in points]
for ps_d in points_deque:
ps_d.rotate(-1)
# compute edge centers.
centers = [[(p0[0]+p1[0])/2, (p0[1]+p1[1])/2] for ps, ps_d in zip(points, points_deque)
for p0, p1 in zip(ps, ps_d)]
# evaluate the boundary at the edge centers and save the boundary types together
# with the corresponding edge id.
boundary_types = dict(zip([boundary_types(centers)], [list(range(1, len(centers)+1))]))
segment_id = 0
boundary_types_dict = defaultdict(list)
for curve in chain([points], holes):
for index in range(len(curve)):
p0, p1 = curve[index], curve[index % len(curve)]
center = [(p0[0]+p1[0])/2, (p0[1]+p1[1])/2]
boundary_types_dict[boundary_types(center)].append(segment_id)
segment_id += 1
boundary_types = dict(boundary_types_dict)
for bt in boundary_types.keys():
if bt is not None and bt not in KNOWN_BOUNDARY_TYPES:
......
from pymor.analyticalproblems.domaindescriptions import PolygonalDomain
from pymortests.base import runmodule
def _determine_boundary_type(point):
y = point[1]
if y == 0:
return "neumann"
return "dirichlet"
def test_polygonal_chain_boundary_function():
chain = [
[2, 0], [4, 0], [3, 2]
]
reference_boundary_types = {
"neumann":
[0, 1],
"dirichlet":
[2]
}
domain = PolygonalDomain(points=chain, boundary_types=_determine_boundary_type)
print(domain.boundary_types)
assert domain.boundary_types == reference_boundary_types
if __name__ == "__main__":
runmodule(filename=__file__)
Markdown is supported
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