Пример #1
0
hm.rotate_geom([tube_right], 45, [0.5, 0.5])

# exclude pentagon from base grid
cont5 = hm.create_contour([[0.3, 0.6], [0.35, 0.4], [0.65, 0.4],
                            [0.7, 0.6], [0.5, 0.7], [0.3, 0.6]])
exsqr = hm.exclude_contours(sqr, [cont5], "inner")
# ******* see fig2

# make series of grid superpositions with defined buffer sizes
imposed = hm.unite_grids(exsqr, [(tube_left, 0.05),
                                 (tube_right, 0.05),
                                 (tube_bot, 0.1)])
# ******* see fig3

# create a boundary grid prototype around the pentagon.
# 1) make partition of pentagon contour with constant step
cont5 = hm.partition_contour(cont5, "const", 0.02)
# 2) call build_boundary_grid1 procedure with explicitly defined perpendecular segmentation.
bnd1 = hm.build_boundary_grid1(cont5, [0, 0.01, 0.02, 0.03], "right")

# make final superposition
res = hm.unite_grids(imposed, [(bnd1, 0.05)])
# ******* see fig4

# now we can see the result in paraview
hm.export_grid_vtk(res, "pentagon.vtk")

# ^^^^^^^^^^^^^^^^^^^^^^^^^^^
if not hm.skewness(res)['ok']:
        raise Exception
Пример #2
0
shark = hm.unite_grids(body, [(fin1, 0.1), (fin3, 0.1), (fin4, 0.1)],
                       zero_angle_approx=10)

# all other grids have clear intersections and could be united as a chain.
# we use empty_holes=True in order to preserve hulls at eye and gills areas.
shark = hm.unite_grids(shark, [(gills, 0.1), (tail, 0.1), (eye, 0.1),
                               (jgrid, 0.1), (fin2, 0.15)],
                       empty_holes=True,
                       zero_angle_approx=10)

# leave only resulting grid
hm.remove_all_but(shark)

# boundary grids around gills contain hanging boundary nodes. To get rid of
# them we use heal_grid procedure with default parameters
hm.heal_grid(shark)

# check grid skewness
if not hm.skewness(shark)['ok']:
    print "Grid contains bad cells"

# exporting to vtk
hm.export_grid_vtk(shark, "shark.vtk")
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

if not hm.skewness(shark, 0.75)['ok']:
    print hm.skewness(shark)
    raise Exception
if not hm.info_grid(shark)['cell_types'].keys() == [3, 4]:
    raise Exception
Пример #3
0
hm.reflect_geom([mesh_wake_trans, mesh_blay], [0, 0], [1, 0])
mesh_around = hm.unite_grids(mesh_around, [(mesh_wake_trans, 0),
                                           (mesh_blay, 0)])
# 5.5 bottom wake part
cmesh_around = hm.grid_bnd_to_contour(mesh_around)
p1 = hm.get_point(cmesh_around, vclosest=[hcyl / 2 + Lx2_rib_blay, -Ly])
p2 = [Lx_wake_reg, p1[1]]
p3 = [p2[0], 0]
p4 = [hcyl / 2 + Lx2_rib_blay, 0]
[bl, bt] = hm.extract_subcontours(mesh_around, [p1, p4, p3])
bb = hm.create_contour([p1, p2])
br = hm.create_contour([p2, p3])
mesh_bot_wake = hm.add_custom_rect_grid("orthogonal", bt, bl, bb, br)
mesh_around = hm.unite_grids(mesh_around, [(mesh_bot_wake, 0)])

if not hm.skewness(mesh_around, 0.8)['ok']:
    raise Exception

# # 5.6 boundary layer under the wake
# p4 = hm.get_point(cmesh_around, vclosest=[-hcyl / 2, -Ly_rib_blay - hcyl / 2])
# p3 = p2
# p1 = [p4[0], -1.5 * hcyl]
# p2 = [Lx_wake_reg, p1[1]]
# [bt] = hm.extract_subcontours(mesh_around, [p4, p3])
# bl = hm.create_contour([p1, p4])
# bb = hm.create_contour([p1, p2])
# br = hm.create_contour([p2, p3])
# bl = hm.partition_contour(bl, "ref_weights", [step0, 0, step2, 1], start=p1)
# mesh_under = hm.add_custom_rect_grid("orthogonal", bt, bl, bb, br)
# mesh_around = hm.unite_grids(mesh_around, [(mesh_under, 0)])
Пример #4
0
[win_frame3] = hm.copy_geom([win_frame2])
hm.rotate_geom(win_frame2, 90)

# 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'
Пример #5
0
    for k in ct.keys():
        check(info['cell_types'][k] == ct[k])


def check_zero(a):
    check(abs(a) < 1e-8)


print "union of rect and ring"
g1 = hm.add_unf_rect_grid([-1, -1], [1, 1], 10, 10)
g2 = hm.add_unf_ring_grid([0, 0], 0.5, 0.8, 500, 7)
hm.move_geom([g2], 0, 1)

g3 = hm.unite_grids(g1, [(g2, 0.1)], empty_holes=False)
hm.export_grid_vtk(g3, "g3.vtk")
check(hm.skewness(g3)['ok'])
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)
Пример #6
0
                   zero_angle_approx=10,
                   empty_holes=True,
                   buffer_fill='4')
g = hm.unite_grids(g, [(g10, 10)],
                   zero_angle_approx=10,
                   empty_holes=True,
                   buffer_fill='4')
print "UNITE 2. input"
g = hm.unite_grids(g, [(g6, 10)], zero_angle_approx=10, buffer_fill='4')
g = hm.unite_grids(g, [(g3, 10)], zero_angle_approx=10, buffer_fill='4')
print "UNITE 3. middle and top"
g = hm.unite_grids(g, [(g12, 20)], zero_angle_approx=10, buffer_fill='4')
g = hm.unite_grids(g, [(g11, 0)])
print "UNITE 4. appendices"
g = hm.unite_grids(g, [(g4, 5)], zero_angle_approx=10, buffer_fill='4')
g = hm.unite_grids(g, [(g5, 5)], zero_angle_approx=10, buffer_fill='4')
print "UNITE 5. top zones"
g = hm.unite_grids(g, [(g7, 0)])
g = hm.unite_grids(g, [(g8, 0)])
print "UNITE 6. boundary zones"
g = hm.unite_grids(g, [(g13, 10)])
g = hm.unite_grids(g, [(g14, 10)])

hm.export_grid_vtk([g], "a.vtk")
hm.export_contour_vtk([g], "b.vtk")
if not hm.skewness(g, 0.999)['ok']:
    print "<<<<<<<<<<<< Grid contains degenerate cells"
    print hm.skewness(g, 0.999)
    raise Exception
hm.export_grid_msh(g, "rrj2.msh")
Пример #7
0
from hybmeshpack import hmscript

# START OF EXAMPLE

# lower level grid
g1 = hmscript.add_unf_rect_grid([0, 0], [10, 10], 10, 10)
# first imposition grid
g2 = hmscript.add_unf_rect_grid([0, 0], [3, 3], 7, 7)
# second imposition grid
g3 = hmscript.add_unf_circ_grid([5, 5], 1.5, 10, 4)
# impose grids
impgrid = hmscript.unite_grids(g1, [(g2, 2.0), (g3, 1.0)])

# END OF EXAMPLE

print "unite_grids example"
hmscript.export_grid_vtk(impgrid, "_g2.vtk")
if (abs(hmscript.domain_area(impgrid) - 100) > 1e-8):
    raise Exception
if (not hmscript.skewness(impgrid)['ok']):
    raise Exception
Пример #8
0
g1 = hm.triangulate_domain([c1, c3, c4], c2)
checkdict(hm.info_grid(g1), {'cell_types': {3: 824}})

c1 = hm.create_spline_contour([[-0.2, 0.35], [0.5, 0.1], [1.2, 0.35]])
c1 = hm.partition_contour(c1, "const", 0.05, crosses=[csqr])
c2 = hm.create_contour([[0.3, 0.5], [0.7, 0.5]])
c3 = hm.create_contour([[0.35, 0.4], [0.65, 0.6]])
c4 = hm.create_contour([[0.35, 0.6], [0.65, 0.4]])
c2 = hm.partition_contour(c2, "const", 0.02, crosses=[c3, c4])
c3 = hm.partition_contour(c3, "const", 0.02, crosses=[c2, c4])
c4 = hm.partition_contour(c4, "const", 0.02, crosses=[c2, c3])
c5 = hm.partition_contour(csqr, "const", 0.1, crosses=[c1])
g1 = hm.triangulate_domain(c5, [c1, c2, c3, c4])
# checkdict(hm.info_grid(g1), {'cell_types': {3: 1404}})
check(hm.info_grid(g1)['Ncells'] > 1000 and hm.skewness(g1, 0.75)['ok'])

c1 = hm.partition_contour(csqr, "const", 0.05)
g1 = hm.triangulate_domain(
    c1, pts=[0.3, [0.3, 0.7], 0.3, [0.7, 0.7], 0.005, [0.5, 0.1]])
# checkdict(hm.info_grid(g1), {'cell_types': {3: 524}})
check(hm.info_grid(g1)['Ncells'] > 500 and hm.skewness(g1)['ok'])

c1 = hm.create_spline_contour([[-0.2, 0.35], [0.5, 0.1], [1.2, 0.35]])
c1 = hm.partition_contour(c1, "const", 0.05, crosses=[csqr])
c2 = hm.partition_contour(csqr, "const", 0.05, crosses=[c1])
g1 = hm.triangulate_domain(c2, c1, pts=[0.3, [0.5, 0.7]])
g2 = hm.triangulate_domain(c2, c1, pts=[0.3, [0.5, 0.7]], fill='4')
# checkdict(hm.info_grid(g1), {'cell_types': {3: 484}})
# checkdict(hm.info_grid(g2), {'cell_types': {3: 4, 4: 225}})
check(hm.skewness(g2)['ok'])