Example #1
0
                   snap="no")

# jaw is constructed by excluding triangle from the body grid area and
# constructing a boundary grid to get rid of badly shaped cells near the cut
jcont = hm.create_contour([[4, -0.3], [8, -1.3], [8, -0.3], [4, -0.3]])
body = hm.exclude_contours(body, jcont, "inner")
btopt = hm.BoundaryGridOptions(body, [0, 0.07],
                               "left",
                               0.1,
                               start_point=[5, -0.5],
                               end_point=[5.45, -0.36],
                               project_to="corner")
# shut down acute angle algorithm in order to obtain grid which lies strictly
# within body contour at the bottom point
btopt.range_angles[0] = 0
jgrid = hm.build_boundary_grid(btopt)

# gills areas are constructed by a boundary grid built around
# contours which are constructed by two circles intersection
circ1 = hm.add_circ_contour3([2.7, -0.4], [2.7, 0.4], 0.4, ncirc)
circ2 = hm.add_circ_contour3([2.7, -0.4], [2.7, 0.4], 1.2, ncirc)
gillc = hm.clip_domain(circ2, circ1, "difference")
gillc = hm.partition_contour(gillc, "const", 0.1)
gills = hm.build_boundary_grid1(gillc, [0, 0.1], "right")
[gills2, gills3] = hm.copy_geom([gills] * 2)
hm.move_geom(gills2, -0.5, 0)
hm.move_geom(gills3, 0.5, 0)
# since gills grids have no intersection area, their union
# does nothing but assembling three grids into single connectivity table.
gills = hm.unite_grids(gills, [(gills2, 0), (gills3, 0)])
Example #2
0
        x = float(i) / (n - 1)
        ret.append([x, 0.2 * math.sin(2 * math.pi * x)])
    ret.append([0.5, 1])
    ret.append(ret[0])
    return ret


print "union of with a boundary grid"
plist = cosine_boundary(20)
c1 = hm.create_contour(plist, [1] * (len(plist) - 3) + [2, 2])
hm.rotate_geom(c1, 17)
g8 = hm.add_unf_rect_grid([-0.1, -0.1], [1.3, 1.3], 20, 20)
g9 = hm.exclude_contours(g8, c1, "outer")
op1 = hm.BoundaryGridOptions(c1, bnd_stepping="keep_all", bnd_step=0.05)
op1.uniform_partition(0.1, 5)
g10 = hm.build_boundary_grid(op1)
g11 = hm.unite_grids(g9, [(g10, 0.05)])
check(len(hm.skewness(g11)['bad_cells']) <= 4)

print "union of detached grids"
g12 = hm.add_unf_ring_grid([0, 0], 20, 10, 300, 10)
g13 = hm.add_unf_circ_grid([0, 0], 9.5, 50, 5)
g14 = hm.unite_grids(g12, [(g13, 5)])
check(len(hm.info_contour(g14)['subcont']) == 3)

print "union of grids with common boundary segments"
g15 = hm.add_unf_circ_grid([0, 0], 1, 16, 5)
g16 = hm.add_unf_rect_grid([-1, -2], [1, -1], 10, 10)
g17 = hm.add_unf_rect_grid([-0.7, -3], [0.3, -2], 20, 20)
g18 = hm.unite_grids(g15, [(g16, 0.3), (g17, 0.3)], fix_bnd=True)
check(hm.skewness(g18)['ok'] and hm.info_grid(g18)['cell_types'][4] == 540)
Example #3
0
# Build a background rectangular mesh and cut a house silhouette from it.
# Now 'house' grid bears boundary features of 'house_cont'
back_grid = hm.add_unf_rect_grid([0, 0], [1, 2], 50, 100)
house = hm.exclude_contours(back_grid, house_cont, "outer")

# A set of ugly cells near the roof appeared as a result of previous operation.
# To get rid of 'em we build a short single layered boundary grid near the
# roof section and make a union. 'roof' grid inherits its boundary types
# from 'house_cont' which is its source and delivers 'em to 'house_wroof' object.
oproof = hm.BoundaryGridOptions(house_cont,
                                start_point=[1, 0.7],
                                end_point=[0, 0.7],
                                partition=[0, 0.01],
                                bnd_step=0.02)
roof = hm.build_boundary_grid([oproof])
house_wroof = hm.unite_grids(house, [(roof, 0.03)])

# Build a tube rectangle and set all boundary edges to 'Roof' type
gtube = hm.add_unf_rect_grid([0, 0], [0.1, 0.3], 4, 16)
hm.set_boundary_type(gtube, btube)
hm.move_geom(gtube, 0.7, 0.9)

# after combining of 'house_wroof' and 'gtube' the resulting grid
# boundary edges will get their features from both parent grids
house_wtube = hm.unite_grids(house_wroof, [(gtube, 0.05)])

# first we create an outer window frame by building an external
# boundary grid around square contour
win_cont = hm.add_rect_contour([-0.15, -0.15], [0.15, 0.15])
op1 = hm.BoundaryGridOptions(win_cont, bnd_step=0.02, direction='right')
Example #4
0
# basic options for vertical segments
# It differs from horizontal segments by cross and lengthwise
# boundary grid partition
ophoriz = hmscript.BoundaryGridOptions(
    cont, partition=[0, 0.01, 0.02, 0.03, 0.05, 0.1], bnd_step=0.02)
# option for bottom segment. Using deepcopy so that changes in one
# inctance do not affect the others.
op1 = copy.deepcopy(ophoriz)
op1.start_point = [0, 0]
op1.end_point = [1, 0]
# option for left segment
op2 = copy.deepcopy(opvert)
op2.start_point = [1, 0]
op2.end_point = [1, 1]
# option for top segment
op3 = copy.deepcopy(ophoriz)
op3.start_point = [1, 1]
op3.end_point = [0, 1]
# option for right segment
op4 = copy.deepcopy(opvert)
op4.start_point = [0, 1]
op4.end_point = [0, 0]
# building boundary grid
bgrid = hmscript.build_boundary_grid([op1, op2, op3, op4])

# END OF EXAMPLE

print "build_boundary_grid example"
if abs(hmscript.domain_area(bgrid) - 0.248) > 1e-7:
    raise Exception
Example #5
0
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",
                             start_point=c[10],
                             end_point=c[9])
g41 = hm.build_boundary_grid(bgo)
ctri = hm.clip_domain(b1, g41, "difference", False)
[c1, c2] = hm.extract_subcontours(ctri, [c[9], c[10], c[9]])
c1 = hm.partition_contour(c1, "const", 4 * step_bl)
ctri = hm.unite_contours([c1, c2])
g42 = hm.triangulate_domain(ctri, fill='4')
g4 = hm.unite_grids(g41, [(g42, 0)])

# right appendix: g5
g5 = hm.map_grid(g4,
                 c_rappendix,
                 [c[9], c[10], [231.5, 1608.5], [286.399, 1647.06]],
                 [c[11], c[12], [1164, 1611], [1109.88, 1649.44]],
                 "no",
                 "vertex",
                 is_reversed=True)
Example #6
0
                          start=p1)
c2 = hm.create_contour([p2, paft])
c2 = hm.partition_contour(c2,
                          "ref_weights", [hhormin, 0, hblayer, 1],
                          start=p2)
[c3] = hm.extract_subcontours(g2, [p2, p1])
c4 = hm.create_contour([pbef, [pbef[0], 100]])
c5 = hm.create_contour([[paft[0], 100], paft])
c3 = hm.connect_subcontours([c4, c1, c3, c2, c5], [2], shiftnext=False)
[c3] = hm.decompose_contour(c3)
bopt = hm.BoundaryGridOptions(c3,
                              blay,
                              bnd_stepping="no",
                              start_point=pbef,
                              end_point=paft)
g3 = hm.build_boundary_grid([bopt])
hm.set_boundary_type(g2, 1)
hm.set_boundary_type(g3, 4)
g2 = hm.unite_grids(g2, [(g3, 0)])

# main area
bot = hm.create_contour([[0, 0], pbef, paft, [x2, 0]])
bot = hm.partition_contour(bot, algo="const", step=hmain, angle0=-1)
left = map(
    lambda x: [0, x], blay[:-1] +
    hm.partition_segment(layheight, y2, hblayer, hmin,
                         [y2 / 2., hmain, y2 - layheight, hblayer]))
left = hm.create_contour(left)
outh = hm.get_point(left,
                    vclosest=[0,
                              paft[1] + layheight + shiftlay + 2 * hmain])[1]
Example #7
0
    info = hm.info_grid(grid)
    check(info['Nnodes'] == nn)
    check(info['Nedges'] == ne)
    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 "simple bgrid around a square"
c1 = hm.add_rect_contour([0, 0], [1, 1], 5)
op1 = hm.BoundaryGridOptions(c1, [0, 0.01, 0.02], "left", 0.1)
g1 = hm.build_boundary_grid(op1)
op2 = hm.BoundaryGridOptions(c1, [0, 0.01, 0.02], "right", 0.1)
g2 = hm.build_boundary_grid(op2)

check_grid(g1, 144, 240, 96, {4: 96})
check_cont(g1, 96, 96, [56, 40], {0: 40, 5: 56})
check_grid(g2, 144, 240, 96, {4: 96})
check_cont(g2, 96, 96, [56, 40], {0: 56, 5: 40})

print "set of options for a square source"
ophoriz = hm.BoundaryGridOptions(c1, [0, 0.01, 0.02, 0.03], "left", 0.05)
opvert = hm.BoundaryGridOptions(c1, [0, 0.01, 0.02, 0.03, 0.05, 0.1], "left",
                                0.03)
op1 = copy.deepcopy(ophoriz)
op1.start_point, op1.end_point = [0, 0], [1, 0]
op2 = copy.deepcopy(opvert)
Example #8
0
    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)
]
foil = hm.partition_contour(foil, "ref_points", foilpart)

# create boundary grid around foil using contour partition
# obtained above as a horizontal boundary grid partition
foilgrid_bo = hm.BoundaryGridOptions(foil,
                                     direction="right",
                                     bnd_stepping="no")
foilgrid_bo.incremental_partition(0.002, 1.5, 7)
foilgrid = hm.build_boundary_grid(foilgrid_bo)

# === boundary grid around vortex generator
vgen = hm.add_circ_contour([0.25, 0.12], 0.015, 32, bcirc)
# build boundary grid
vgen_bo = hm.BoundaryGridOptions(vgen,
                                 direction="right",
                                 bnd_step=0.006,
                                 bnd_stepping="const")
vgen_bo.incremental_partition(0.002, 1.2, 4)
vgengrid = hm.build_boundary_grid(vgen_bo)
hm.heal_grid(vgengrid)  # get rid of hanging boundary nodes

# === union
res2d = hm.unite_grids(substrate, [(foilgrid, 0.02), (vgengrid, 0.02)], True)