예제 #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
import hybmeshpack.hmscript as hm

outercont = hm.create_contour([[0, 0], [0.2, -0.6], [1, -1.3], [2, -1.3],
                               [2.5, -0.3], [2.6, 0.4], [1.5, 1], [0.4, 0.4],
                               [0, 0]])

faultline = hm.create_contour([[0, 1], [1.5, -0.5]])
w1 = [0.64, -0.11]
w2 = [1.54, 0.4]
gw1 = hm.add_unf_circ_grid(w1, 0.05, 16, 5, 1.2, False)
gw2 = hm.add_unf_circ_grid(w2, 0.05, 16, 5, 1.2, False)

faultline = hm.partition_contour(faultline, "const", 0.01, crosses=[outercont])
outercont = hm.matched_partition(outercont, 0.05, 0.5, [faultline])

hm.export_contour_vtk([outercont, faultline], "outer.vtk")

g = hm.pebi_fill(outercont, [faultline])
g = hm.unite_grids(g, [(gw1, 0.01), (gw2, 0.01)], buffer_fill='4')

hm.export_grid_vtk([g], "grid.vtk")
예제 #3
0
파일: imex_test.py 프로젝트: cescjf/HybMesh
bbot = hm.add_boundary_type(3, "bbot")
btop = hm.add_boundary_type(4, "btop")
g1 = hm.add_unf_rect_grid([0, 0], [1, 1], 10, 10)
g2 = hm.add_triangle_grid([0.3, -0.4], [0.5, 0.2], [0.7, -0.4], 10)
[g3] = hm.copy_geom(g2)
hm.reflect_geom(g3, [0, 0.5], [1, 0.5])
g4 = hm.unite_grids(g1, [(g2, 0.05), (g3, 0.05)])
hm.set_boundary_type(g4,
                     bfun=lambda x0, y0, x1, y1, b: {
                         True: 0,
                         x0 + x1 == 0: 1,
                         x0 + x1 == 2: 2,
                         y0 + y1 == -0.8: 3,
                         y0 + y1 == 2.8: 4
                     }[True])
hm.export_grid_vtk(g4, "g1.vtk")
hm.export_contour_vtk(g4, "c1.vtk")
hmdbg.check_ascii_file(15697319238564148717, "g1.vtk", "dev")
hmdbg.check_ascii_file(16408920837426241157, "c1.vtk", "dev")
hm.export_grid_msh(g4, "g1.msh")
hmdbg.check_ascii_file(17685805227099775273, "g1.msh", "dev")

print "export 2d to fluent with periodic conditions"
hm.export_grid_msh(g4, "g1.msh", [bbot, btop, True])
hmdbg.check_ascii_file(3165188744058895474, "g1.msh", "dev")

print "export 2d to fluent with double periodic conditions"
hm.export_grid_msh(g4, "g1.msh", [bbot, btop, True, bleft, bright, True])
hmdbg.check_ascii_file(2759680993089544531, "g1.msh", "dev")

print "controlled fail on illegal periodic data"
예제 #4
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),
    {'btypes': {1: 40}, 'Nnodes': 40, 'subcont': [40], 'Nedges': 40})
예제 #5
0
# 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
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
예제 #7
0
from hybmeshpack import hmscript as hm

cn_bufsize = 0.100
dm_bufsize = 0.050
mr_min = [-3.500e+0, -5.000e+0]
mr_max = [3.500e+0, 5.000e+0]
mr_step = 0.050

with open("others/botscript1_adata/x1arr.dat") as f:
    x1arr = map(float, f.read().split())
with open("others/botscript1_adata/x2arr.dat") as f:
    x2arr = map(float, f.read().split())

cn = hm.add_unf_rect_grid([0, 0], [1, 1], 3, 3, x1arr, x2arr)
mr = hm.add_unf_rect_grid(mr_min, mr_max, 13, 13, mr_step, mr_step)
hm.export_grid_hmg([cn, mr], "op1.hmg")
cn = hm.unite_grids(cn, [(mr, cn_bufsize)], False, False, 0, "4")

dpath = "others/botscript1_adata/"
files = ["000.msh", "001.msh", "002.msh", "003.msh", "004.msh"]
for f in files:
    print(f)
    dimple = hm.import_grid_gmsh(dpath + f)
    hm.export_grid_hmg([cn, dimple], "op" + f[:3] + ".hmg")
    cn = hm.unite_grids(cn, [(dimple, dm_bufsize)], False, False, 0, "4")

hm.export_grid_vtk(cn, "g1.vtk")
예제 #8
0
    check(info['Ncells'] == nc)
    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")
예제 #9
0
파일: rrj2.py 프로젝트: cescjf/HybMesh
[bc, rc, t1, t2, t3, t4, t5, t6, t7, lc] = hm.extract_subcontours(
    c_bot, [c[i] for i in [0, 1, 2, 18, 17, 6, 5, 16, 15, 3, 0]])
t2 = hm.create_contour([c[18], c[17]])
t6 = hm.create_contour([c[16], c[15]])
tc = hm.unite_contours([t1, t2, t3, t4, t5, t6, t7])

lc = hm.partition_contour(lc, "ref_weights", bstep_main, 90, start=c[0])
tc = hm.partition_contour(tc,
                          "ref_weights",
                          bstep_main,
                          180,
                          start=c[2],
                          keep_pts=[c[0], c[1], c[2], c[3], c[5], c[6]])
g1 = hm.add_custom_rect_grid("orthogonal", lc, tc, rc, bc)
g1cont = hm.grid_bnd_to_contour(g1, False)
hm.export_grid_vtk(g1, "g1.vtk")

# left appendix: g4
bs = [0, step_bl, 2 * step_bl, 3 * step_bl]
[b1, b2] = hm.extract_subcontours(c_lappendix, [c[10], c[9], c[10]])
b1 = hm.partition_contour(b1,
                          "const",
                          3 * step_bl,
                          angle0=180,
                          keep_pts=[[286.399, 1647.06], [231.428, 1608.5]])
b1 = hm.unite_contours([b1, b2])
bgo = hm.BoundaryGridOptions(b1,
                             bs,
                             "left",
                             3 * step_bl,
                             "no",
예제 #10
0
파일: cave1.py 프로젝트: cescjf/HybMesh
left = hm.create_contour(left)
outh = hm.get_point(left,
                    vclosest=[0,
                              paft[1] + layheight + shiftlay + 2 * hmain])[1]
[right] = hm.copy_geom(left)
[top] = hm.copy_geom(bot)
hm.set_boundary_type(left, 2)
hm.set_boundary_type(right, 3)
hm.set_boundary_type(bot, 4)
hm.set_boundary_type(top, 5)
gmain = hm.add_custom_rect_grid("linear", left, bot, right, top)

outcont = hm.add_rect_contour(pbef, [paft[0], outh])
gmain = hm.exclude_contours(gmain, outcont, "inner")

#final unite
gout = hm.unite_grids(gmain, [(g2, 0)])
hm.export_contour_vtk(gout, "c2.vtk")
cc = hm.simplify_contour(gout, simplify=False, separate=True)
filler = hm.pick_contour([pc[0], outh], cc)
gg = hm.triangulate_domain(filler)
gout = hm.unite_grids(gout, [(gg, 0)])

#zcoords = hm.partition_segment(0, 50, 3, 3)
#gm3 = hm.extrude_grid(gout, zcoords)
#hm.export3d_grid_vtk(gm3, "gm3.vtk")

hm.export_grid_vtk(gout, "cave1_3.vtk")
hm.export_contour_vtk(gout, "cave1_3_cont.vtk")
hm.export_grid_msh(gout, "cave1_3.msh")
예제 #11
0
    hm.remove_geom([cont, grid])
    angle += diff_ac if angle < op.range_angles[0] else diff

print "doubly connected area: all outer"
inner_cont = hm.add_rect_contour([0, 0], [1, 1], 1)
outer_cont = hm.add_circ_contour([0, 0], 3, 16, 2)
full_cont = hm.unite_contours([inner_cont, outer_cont])
op = hm.BoundaryGridOptions(full_cont, [0, 0.01, 0.02, 0.03, 0.04], 'left',
                            0.01)
g5 = hm.build_boundary_grid(op)
check_grid(g5, 11440, 20592, 9152, {4: 9152})
check_cont(g5, 4576, 4576, [400, 432, 1872, 1872], {0: 2304, 1: 400, 2: 1872})

print "doubly connected area: all inner"
op.direction = 'right'
g6 = hm.build_boundary_grid(op)
hm.export_contour_vtk(full_cont, "_source6.vtk")
hm.export_grid_vtk(g6, "_g6.vtk")
hm.export_contour_vtk(g6, "_c6.vtk")
check_grid(g6, 11280, 20304, 9024, {4: 9024})
check_cont(g6, 4512, 4512, [400, 368, 1872, 1872], {0: 2240, 1: 400, 2: 1872})

print "doubly connected area: only single contour"
op.start_point = op.end_point = [0, 0]
g7 = hm.build_boundary_grid(op)
check_grid(g7, 1920, 3456, 1536, {4: 1536})
check_cont(g7, 768, 768, [400, 368], {0: 368, 1: 400})

check(len(hm.registered_contours()) == 4)
check(len(hm.registered_grids()) == 7)
예제 #12
0
vert = hm.partition_segment(-1, 1, 0.2, 0.2, [-0.2, 0.03, 0.15, 0.015])
horiz = hm.partition_segment(-1, 3, 0.2, 0.2, [-0.2, 0.03, 1.1, 0.03])
# then build rectangular grid on their basis.
substrate = hm.add_unf_rect_grid(custom_x=horiz, custom_y=vert)


# boundary types for back grid which will be later translated to 3d grid
def _substrate_bfun(x0, y0, x1, y1, bt):
    if abs(x0 - x1) < 1e-12:
        return binp if abs(x0 + 1) < 1e-12 else bout
    else:
        return bbot if abs(y0 + 1) < 1e-12 else btop


hm.set_boundary_type(substrate, bfun=_substrate_bfun)
hm.export_grid_vtk(substrate, "substrate.vtk")

# === build boundary grid around the foil
# First we make custom repartition of the foil to use
# all contour vertices for boundary grid.
# Assign recommended partition distance to points on foil contour:
foilpart = [
    0.01,
    [0.0, 0.0],  # frontal point
    0.03,
    [1.0, -0.17],  # backward point
    0.01,
    [0.25, 0.64],  # upper boundary below vortex generator (finer)
    0.05,
    [0.5, -0.17],  # lower boundary (coarser)
]
예제 #13
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