Skip to content

Commit

Permalink
Merge branch 'enh/meshtools' of github.com:jcanton/pymech into enh/me…
Browse files Browse the repository at this point in the history
…shtools
  • Loading branch information
guillaumechauvat committed Dec 26, 2022
2 parents 13943ff + 78e84e0 commit 062789a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pymech/meshtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,11 @@ def map2D(
# - the edge is a boundary edge and boundary_curvature=True or any edge and curvature=True. then we generate a new midpoint at the image of the centre of the original edge.
# otherwise, leave the edge without curvature.
for iedge in range(4):
if curvature or el.ccurv[iedge] != "" or (boundary_curvature and el.bcs[0][iedge][0] not in ["", "E"]):
if (
curvature
or el.ccurv[iedge] != ""
or (boundary_curvature and el.bcs[0][iedge][0] not in ["", "E"])
):
mapped_el.ccurv[iedge] = "m"
xm, ym, _ = edge_mid(el, iedge)
mapped_xm, mapped_ym = transformation(xm, ym)
Expand Down
25 changes: 22 additions & 3 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,23 +593,42 @@ def test_gen_box(test_data_dir):
assert box.check_connectivity()
assert box.nbc == 2


def test_map2D(test_data_dir):
import pymech.meshtools as mt

# make a very twisted mesh and check that it ends up the way we want
def mapping(x, y):
return (2 * x + 0.2 * y + 0.1 * math.sin(math.pi * y), 1.2 * y - 0.1 * x - 0.2 * math.sin(2 * math.pi * x))
return (
2 * x + 0.2 * y + 0.1 * math.sin(math.pi * y),
1.2 * y - 0.1 * x - 0.2 * math.sin(2 * math.pi * x),
)

n_centre = 5
n_bl = 6
s_param = 0.5
radius = 1
circle_mesh = mt.gen_circle(radius, s_param, n_centre, n_bl, var=[2, 2, 1, 1, 0], bc=['W', 'I'])
circle_mesh = mt.gen_circle(
radius, s_param, n_centre, n_bl, var=[2, 2, 1, 1, 0], bc=["W", "I"]
)
circle_mesh = mt.map2D(circle_mesh, mapping)
assert circle_mesh.check_connectivity()
math.isclose(circle_mesh.elem[35].curv[0, 0], 1.4794589904304334)
math.isclose(circle_mesh.elem[35].curv[3, 1], -0.2516125141385187)
assert circle_mesh.elem[38].ccurv == ['m', 'm', 'm', 'm', '', '', '', '', '', '', '', '']
assert circle_mesh.elem[38].ccurv == [
"m",
"m",
"m",
"m",
"",
"",
"",
"",
"",
"",
"",
"",
]

# test with a box without any curvature
# box of size 5×1
Expand Down

0 comments on commit 062789a

Please sign in to comment.