コード例 #1
0
def check_cont(cont, nn, ne, scont, btypes):
    info = hm.info_contour(cont)
    check(info['Nnodes'] == nn)
    check(info['Nedges'] == ne)
    check(cmp(sorted(info['subcont']), sorted(scont)) == 0)
    for k in btypes.keys():
        check(info['btypes'][k] == btypes[k])
コード例 #2
0
ファイル: mapping_test.py プロジェクト: cescjf/HybMesh
    cont.append([p[0], p[1] + 1.0])
cont.append(cont[0])
c1 = hm.create_contour(cont)
hm.set_boundary_type(c1, 2)

print "rectangle to square with sine edges: no, from_contour"
a1 = hm.map_grid(
    g1, c1,
    [[0, 0], [5, 0], [5, 1], [0, 1]],
    [[0, 0], [1, 0], [1, 1], [0, 1]],
    snap="no", btypes="from_contour")
checkdict(
    hm.info_grid(a1),
    {'cell_types': {4: 100}, 'Nnodes': 121, 'Nedges': 220, 'Ncells': 100})
checkdict(
    hm.info_contour(a1),
    {'btypes': {2: 40}, 'Nnodes': 40, 'subcont': [40], 'Nedges': 40})
hm.export_grid_vtk(a1, "g1.vtk")

print "rectangle to square with sine edges: no, from_grid"
a2 = hm.map_grid(
    g1, c1,
    [[0, 0], [5, 0], [5, 1], [0, 1]],
    [[0, 0], [1, 0], [1, 1], [0, 1]],
    algo="direct_laplace",
    snap="no", btypes="from_grid")
checkdict(
    hm.info_grid(a2),
    {'cell_types': {4: 100}, 'Nnodes': 121, 'Nedges': 220, 'Ncells': 100})
checkdict(
    hm.info_contour(a2),
コード例 #3
0
ファイル: imex_test.py プロジェクト: cescjf/HybMesh
hm.remove_all()
g7 = hm.import_grid_hmg("g4.hmg", "Grid2D_3")
hmdbg.check(g7 == "Grid2D_3" and len(hm.registered_grids()) == 1)
hmdbg.check(hm.info_grid(g7)['Ncells'] == 30)

# export/import contours 2d to native
c1 = hm.add_rect_contour([0, 0], [1, 1], 1)
c2 = hm.add_rect_contour([0, 0], [2, 2], 2)
hm.export_contour_hmc(c1, "c1.hmc")
hm.export_contour_hmc(c2, "c2.hmc", "bin")
hm.export_contour_hmc([c1, c2], "c3.hmc", "bin")
c3 = hm.import_contour_hmc("c1.hmc", "Contour2D_1")
[c4, c5] = hm.import_contour_hmc("c3.hmc", allconts=True)
c6 = hm.import_contour_hmc("c3.hmc")
hmdbg.check(len(hm.registered_contours()) == 6)
hmdbg.check(1 in hm.info_contour(c3)['btypes'])
hmdbg.check(1 in hm.info_contour(c4)['btypes'])
hmdbg.check(2 in hm.info_contour(c5)['btypes'])
hmdbg.check(1 in hm.info_contour(c6)['btypes'])

# export/import grids 3d to native
gg1 = hm.extrude_grid(g7, [0, 1])
gg2 = hm.extrude_grid(g7, [0, 1, 2])
hm.export3d_grid_hmg(gg1, "gg1.hmg", "ascii")
hm.export3d_grid_hmg([gg1, gg2], "gg2.hmg", "bin")
[gg3] = hm.import3d_grid_hmg("gg1.hmg", allgrids=True)
[gg4, gg5] = hm.import3d_grid_hmg("gg2.hmg", allgrids=True)
gg6 = hm.import3d_grid_hmg("gg2.hmg", "Grid3D_2")
hmdbg.check(len(hm.registered_grids3d()) == 6)
hmdbg.check(hm.info_grid3d(gg3)['Ncells'] == 30)
hmdbg.check(hm.info_grid3d(gg4)['Ncells'] == 30)
コード例 #4
0
ファイル: fullcyl.py プロジェクト: cescjf/HybMesh
# 5. meshing wake region
# 5.1 separation into transitional traingle and main region
p1 = [hcyl / 2 + Lx2_rib_blay, 0]
p2 = [p1[0] + hcyl / 2, Ly_wake_reg]
ctmp = hm.create_contour([p1, p2])
region_wake = hm.unite_contours([region_wake, ctmp])
rr = hm.decompose_contour(region_wake)
region_wake_trans = hm.pick_contour(pcross, rr)
region_wake_main = hm.pick_contour([Lx2, 0], rr)
p2 = hm.get_point(region_wake_trans, vclosest=[Lx2, Ly])
[b1, b2, b3] = hm.extract_subcontours(region_wake_trans, [p1, p2, pcross, p1])
[b3] = hm.extract_subcontours(mesh_blay, [p1, pcross])
region_wake_trans = hm.connect_subcontours([b1, b2, b3])
# 5.2 meshing transitional triangle
[b3] = hm.extract_subcontours(region_wake_trans, [pcross, p1])
nedges = hm.info_contour(b3)['Nedges']
b3pts = [hm.get_point(b3, i) for i in range(nedges + 1)]
b3pts.sort(key=lambda a: a[1])
b3pts_source = [[0., float(i) / nedges] for i in range(nedges + 1)]
b3pts.append(p2)
b3pts_source.append([1., 0.])
tri = hm.add_triangle_grid([0, 0], [1, 0], [0, 1], nedges)
mesh_wake_trans = hm.map_grid(
    tri, region_wake_trans, b3pts_source, b3pts, snap="shift_vertices")
# 5.3 meshing main wake region
[b1, b2, b3, b4] = hm.extract_subcontours(
    region_wake_main,
    [p1, [Lx_wake_reg, 0.], [Lx_wake_reg, Ly_wake_reg], p2, p1])
[b4] = hm.extract_subcontours(mesh_wake_trans, [p1, p2])
b1 = hm.partition_contour(b1, "ref_weights", [step2, 0, step3, 1], start=p1)
mesh_wake_main = hm.add_custom_rect_grid("orthogonal", b4, b1, b2, b3)
コード例 #5
0
ファイル: intro_house.py プロジェクト: cescjf/HybMesh
# to assemble a window we make an superposition of internal frames to outer one
# and assigns 'Window' boundary type to the whole resulting grid.
window = hm.unite_grids(win_frame1, [(win_frame2, 0.02), (win_frame3, 0.02)])
hm.set_boundary_type(window, bwindow)

# finally we move window to its position according to house and
# impose it to it. Note that in order to purge area within window spans
# option 'empty_holes=True' is used.
hm.move_geom(window, 0.5, 0.4)
house_final = hm.unite_grids(house_wtube, [(window, 0.05)], empty_holes=True)

# now we can check quality of resulting grid by calculating its skewness
skew = hm.skewness(house_final)
print 'maximum skew value is %f' % skew['max_skew']
if (skew['ok']):
    print 'resulting grid has no bad cells'
else:
    print '%i cells have large skew coefficient' % len(skew['bad_cells'])

# save grid and contour with boundary features to vtk
hm.export_grid_vtk(house_final, "house_grid.vtk")
hm.export_contour_vtk(house_final, "house_contour.vtk")

# ^^^^^^^^^^^^^^^^^^^^^^^^
if (not skew['ok']):
    raise Exception
if (hm.info_contour(house_final)['btypes'] != {0: 122, 1: 25, 2: 77, 3: 160}):
    print hm.info_contour(house_final)['btypes'], 'vs'
    print {0: 122, 1: 25, 2: 77, 3: 160}
    raise Exception
コード例 #6
0
fular = hm.domain_area(g3) - 0.5 * hm.domain_area(g2) - hm.domain_area(g1)
check(abs(fular) < 1e-6)

print "two squares: with/without fix_bnd, bc check"
g4 = hm.add_unf_rect_grid([10, 10], [15, 15], 5, 5)
g5 = hm.add_unf_rect_grid([10, 10], [11, 11], 30, 30)
hm.move_geom(g5, -0.05, -0.05)
hm.set_boundary_type(g4, 3)
hm.set_boundary_type(g5,
                     bfun=lambda x0, y0, x1, y1, b: 1
                     if max(y0, y1) < 10.8 else 2)
hm.export_grid_vtk(g4, "g4.vtk")
hm.export_grid_vtk(g5, "g5.vtk")
hm.export_contour_vtk(g5, "gc5.vtk")
g6 = hm.unite_grids(g5, [(g4, 0.5)], fix_bnd=False)
check(hm.info_contour(g6)['btypes'] == {1: 3, 2: 1, 3: 18})

# hm.export_grid_vtk(g4, "g4.vtk")
# hm.export_grid_vtk(g5, "g5.vtk")
# hm.export_grid_vtk(g6, "g6.vtk")
# hm.export_contour_vtk(g4, "c4.vtk")
# hm.export_contour_vtk(g5, "c5.vtk")
# hm.export_contour_vtk(g6, "c6.vtk")
# quit()

g7 = hm.unite_grids(g5, [(g4, 0.5)], fix_bnd=True)
check(hm.info_contour(g7)['btypes'] == {1: 57, 2: 7, 3: 20})


def cosine_boundary(n):
    import math
コード例 #7
0
ファイル: ex_setbtype.py プロジェクト: cescjf/HybMesh
# START OF EXAMPLE
# mark b1, b2 as globals so binfo function can find them
global b1, b2
# register boundary types
b1 = hmscript.add_boundary_type(1, "vertical")
b2 = hmscript.add_boundary_type(2, "horizontal")
# create rectangular contours
cont1 = hmscript.add_rect_contour([0, 0], [1, 1])
# mark contour using `btps`
hmscript.set_boundary_type(cont1, btps=[b2, b1, b2, b1])
# same effect using `bfun`
cont2 = hmscript.add_rect_contour([0, 0], [1, 1])


def binfo(x0, y0, x1, y1, bold):
    return b1 if x0 == x1 else b2


hmscript.set_boundary_type(cont2, bfun=binfo)
# END OF EXAMPLE

print "set_boundary_type example"
hmscript.export_contour_vtk(cont1, "_c1.vtk")
hmscript.export_contour_vtk(cont2, "_c2.vtk")
f1, f2 = open("_c1.vtk", "r"), open("_c2.vtk", "r")
if hash(f1.read()) != hash(f2.read()):
    raise Exception
if (hmscript.info_contour(cont1)['btypes'] != {1: 2, 2: 2}):
    raise Exception
コード例 #8
0
ファイル: rrj2.py プロジェクト: cescjf/HybMesh
# 2. sqr
c0 = hm.create_contour([c[8], c[13]])
c1 = hm.create_contour([c[13], c[19]])
c2 = hm.create_contour([c[21], c[22]])
c3 = hm.create_contour([c[20], c[23]])
c4 = hm.create_contour([c[19], c[32]])
[c5, c6, c81, c82, c83, c9, c10] = hm.extract_subcontours(
    c_ltop,
    [c[8], c[32], c[23], c[22], c[21], [117, 1924.7], [156, 1924.7], c[20]],
    "line")
c7 = hm.create_contour([c[19], c[20]])
c82 = hm.create_contour([c[22], c[21]])
c8 = hm.connect_subcontours([c81, c82, c83])

c0 = hm.partition_contour(c0, "const", step_bl, angle0=180, start=c[8])
nc0 = hm.info_contour(c0)['Nedges']
c1 = hm.partition_contour(c1, "const", step_bl, angle0=180)
nc1 = hm.info_contour(c1)['Nedges']
c3 = hm.partition_contour(c3,
                          "const",
                          step_bl,
                          angle0=180,
                          start=c[20],
                          nedges=nc0)
c4 = hm.partition_contour(c4,
                          "const",
                          step_bl,
                          angle0=180,
                          start=c[19],
                          nedges=nc0)
c5 = hm.partition_contour(c5, "const", 1, angle0=180, start=c[32], nedges=nc1)
コード例 #9
0
from hybmeshpack import hmscript

# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
# unit segment
linear_segment = hmscript.create_contour([[0, 0], [1, 0]])

# divide into segments of length 0.03.
# part1 has 33 equal segments
part1 = hmscript.partition_contour(linear_segment, "const", step=0.03)

# partition with refinement towards the center of input line
# segments near end points have length 0.1, at the center - 0.01,
# and between them linear size transition is applied
part2 = hmscript.partition_contour(
    linear_segment,
    "ref_points",
    step=[0.1, [0, 0], 0.01, [0.5, 0], 0.1, [1.0, 0]])
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

print "partition contour example"
if hmscript.info_contour(part1)['Nedges'] != 33:
    raise Exception
if hmscript.info_contour(part2)['Nedges'] != 26:
    raise Exception
コード例 #10
0
ファイル: cont_test.py プロジェクト: cescjf/HybMesh
g3 = hm.add_unf_ring_grid([0, 0], 1, 2, 10, 5, 1.4)


def bfun3(x0, y0, x1, y1, bo):
    xc, yc = (x0 + x1) / 2, (y0 + y1) / 2
    if yc > 0:
        return 1
    if (xc * xc + yc * yc) < 1.5:
        return 2
    else:
        return 3


hm.set_boundary_type(g3, bfun=bfun3)
print hm.info_contour(g3)
check_cont(g3, 20, 20, [10, 10], {1: 10, 2: 5, 3: 5})

print "separate/simplify"
[c7, c8] = hm.simplify_contour(g3, separate=True)
check_cont(c7, 10, 10, [10], {1: 5, 3: 5})
check_cont(c8, 10, 10, [10], {1: 5, 2: 5})

c9 = hm.create_contour(
    [[0, 0], [3, 1], [6, 0], [9, 0], [9, 3], [8, 6], [9, 9], [9, 12]],
    [1, 1, 1, 1, 1, 2, 1])
[c10] = hm.simplify_contour(c9, simplify=True, angle=60, separate=True)
check_cont(c10, 5, 4, [4], {1: 3, 2: 1})
# hm.export_contour_vtk(c9, "c1.vtk")
# hm.export_contour_vtk(c10, "c2.vtk")
# print hm.info_contour(c10)