コード例 #1
0
ファイル: unite_grids1.py プロジェクト: cescjf/HybMesh
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")
コード例 #2
0
ファイル: mapping_test.py プロジェクト: cescjf/HybMesh
from hybmeshpack.hmscript._dbg import check, check_ascii_file, checkdict
import math
global hm, check, checkdict, math
hm.check_compatibility("0.4.3")

g1 = hm.add_unf_rect_grid([0, 0], [5, 1], 10, 10)
hm.set_boundary_type(g1, 1)
cont = []
for i in range(100):
    x = float(i) / 99.0
    y = 0.1 * math.sin(6 * math.pi * x)
    cont.append([x, y])
for p in cont[::-1]:
    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")
コード例 #3
0
# create a substrate 20x20 square grid
sqr = hm.add_unf_rect_grid([0, 0], [1, 1], 20, 20)

# create tube grids
# 1) create a prototype
tube_proto = hm.add_unf_rect_grid([0, 0], [0.15, 0.5], 10, 20)
# 2) copy, replace and rotate to build left, right, bottom tubes.
[tube_left, tube_right, tube_bot] = hm.copy_geom([tube_proto] * 3)
hm.move_geom([tube_left, tube_right], 0.425, 1.0)
hm.move_geom([tube_bot], 0.425, -0.5)
hm.rotate_geom([tube_left], -45, [0.5, 0.5])
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")
コード例 #4
0
ファイル: fullcyl.py プロジェクト: cescjf/HybMesh
[bcyl] = hm.copy_geom([cyl])
xpc = 100. * (hcyl + Lx1_rib_blay + Lx2_rib_blay) / (hcyl)
ypc = 100. * (hcyl + 2 * Ly_rib_blay) / (hcyl)
hm.scale_geom(bcyl, xpc, ypc)
xmv = (Lx2_rib_blay - Lx1_rib_blay) / 2.
hm.move_geom(bcyl, xmv, 0.)
region_blay = hm.unite_contours([cyl, bcyl])
region_blay = hm.clip_domain(region_blay, region_channel, "intersection")

# 3. wake region
x0 = 1.1 * hcyl / 2
x1 = Lx_wake_reg
y0 = 0
y10 = 0.9 * (Ly_rib_blay + hcyl / 2)
y11 = Ly_wake_reg
region_wake = hm.create_contour([[x0, y0], [x1, y0], [x1, y11], [x0, y10],
                                 [x0, y0]])
region_wake = hm.clip_domain(region_wake, bcyl, "difference")
pcross = hm.get_point(region_wake, vclosest=[-Lx1, Ly])

# 4. meshing bcyl region
p1 = hm.get_point(region_blay, vclosest=[-Lx1, 0])
p2 = hm.get_point(region_blay, vclosest=[-hcyl / 2, 0])
p3 = hm.get_point(region_blay, vclosest=[hcyl / 2, 0])
p4 = hm.get_point(region_blay, vclosest=[Lx2, 0])
[b1, b2, b3, b4] = hm.extract_subcontours(region_blay, [p1, p2, p3, p4, p1])
b3 = hm.partition_contour(
    b3, "ref_weights", [step1, 0, step2, 1], start=p3)
b4 = hm.partition_contour(
    b4, "ref_points", [step2, p4, step2, pcross, step2, p1],
    keep_pts=[pcross])
mesh_blay = hm.add_custom_rect_grid("orthogonal", b3, b4, b1, b2)
コード例 #5
0
ファイル: imex_test.py プロジェクト: cescjf/HybMesh
print "controlled fail on illegal periodic data"
try:
    hm.export_grid_msh(g4, "g1.msh", [bbot, 0, True])
    hmdbg.check(False)
except hm.ExecError:
    hmdbg.check(True)

print "export to gmsh file"
hm.export_grid_gmsh(g4, "g1.msh")
hmdbg.check_ascii_file(15544215273974397325, "g1.msh", "dev")

print "import from gmsh file"
hm.remove_all()
p1, p2, p3, p4, p5 = [0, 0], [1, -1], [5, -1], [5, 1], [1, 1]
c1 = hm.create_contour([p1, p2, p3, p4, p5, p1], [0, 1, 2, 3, 4])
g1 = hm.add_triangle_grid(p1, p2, p5, 5)
g2 = hm.add_unf_rect_grid(p2, p4, 10, 5)
g = hm.unite_grids(g1, [(g2, 0)])
g = hm.exclude_contours(g, c1, 'outer')
hm.export_grid_gmsh(g, "g1.msh")
hm.add_boundary_type(1, "b1")
hm.add_boundary_type(3, "b3")
g2 = hm.import_grid_gmsh("g1.msh")
hm.export_grid_gmsh(g2, "g2.msh")
hmdbg.check_ascii_file(1848074108755753273, "g1.msh")
hmdbg.check_ascii_file(14301170686345005483, "g2.msh")
hm.remove_all()

print "import from fluent msh file"
g1 = hm.import_grid_msh("../external_files/input1.msh")
コード例 #6
0
ファイル: intro_house.py プロジェクト: cescjf/HybMesh
# This script was created for hybmesh 0.2.1.
# If running version of hybmesh is not compatible with this version
# an exception will be raised at this line.
hm.check_compatibility("0.2.1", 2)

# Register separate boundary types for edges on tube, roof and window.
# All other boundary edges will get default 0 boundary type
btube = hm.add_boundary_type(1, "Tube")
broof = hm.add_boundary_type(2, "Roof")
bwindow = hm.add_boundary_type(3, "Window")

# First we create a house silhouette and assign boundary types for it.
# They will be carried to all grids derived from this contour
house_cont = hm.create_contour(
    [[0, 0], [1, 0], [1, 0.7], [0.5, 1.3], [0, 0.7], [0, 0]],
    [0, 0, broof, broof, 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],
コード例 #7
0
ファイル: intro_shark.py プロジェクト: cescjf/HybMesh
fin34c = hm.clip_domain(d1, body, "difference")
g3 = hm.add_triangle_grid([1, 0], [0, 0], [0, 1], 5)
fin3 = hm.map_grid(g3,
                   fin34c, [[1, 0], [0, 0], [0, 1]],
                   [[-4, 0.5], [-5.1, 0.3], [-5.1, 1]],
                   project_to="corner",
                   snap="no")
fin4 = hm.map_grid(g3,
                   fin34c, [[0, 0], [1, 0], [0, 1]],
                   [[-5.2, -0.3], [-5.1, -1], [-4.1, -0.7]],
                   project_to="corner",
                   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)
コード例 #8
0
ファイル: rrj2.py プロジェクト: cescjf/HybMesh
c[42] = [1626.44, 598.872]
c[43] = [1675.87, 599.006]
c[44] = [2069.82, 1079.89]
c[45] = [2138.76, 600.276]
c[46] = [2187.77, 600.41]
c[47] = [2147.26, 457.037]
c[48] = [2188.22, 457.037]
c[49] = [2147.59, 302.028]

for i, p in enumerate(c):
    if p is not None:
        c[i] = hm.get_point(cont, vclosest=p)

# closed contours assembling
cn = [cont]
cn.append(hm.create_contour([c[9], c[10]]))
cn.append(hm.create_contour([c[11], c[12]]))
cn.append(hm.create_contour([c[11], c[12]]))
cn.append(hm.create_contour([c[8], c[13]]))
cn.append(hm.create_contour([c[7], c[14]]))
cn.append(hm.create_contour([c[13], c[14]]))
cn.append(hm.create_contour([c[5], c[6]]))
d = hm.unite_contours(cn)
dcm = hm.decompose_contour(d)
c_ltop = hm.pick_contour(c[21], dcm)
c_rtop = hm.pick_contour(c[38], dcm)
c_lhole = hm.pick_contour([140, 1936], dcm)
c_rhole = hm.pick_contour([1254, 1940], dcm)
c_top = hm.pick_contour([687, 2096], dcm)
c_mid = hm.pick_contour([282, 1803], dcm)
c_lappendix = hm.pick_contour([252, 1617], dcm)
コード例 #9
0

def cosine_boundary(n):
    import math
    ret = []
    for i in range(n):
        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)
コード例 #10
0
ファイル: cave1.py プロジェクト: cescjf/HybMesh
for b in list(reversed(blay))[1:]:
    rads.append(rad - b)

g = hm.add_unf_circ_grid(pc, custom_arcs=arc, custom_rads=rads, is_trian=False)

gfiller = hm.add_circ_rect_grid(pc, rad - 1.3 * layheight, internal_step)
g = hm.unite_grids(g, [(gfiller, buf)])

chord = hm.add_circ_contour2(p2, [pc[0], p1[1] + shiftlay], p1, 512)
mapping_area = hm.clip_domain(chord, g, "intersection")
hm.export_contour_vtk(mapping_area, "c1.vtk")

g2 = hm.map_grid(g, mapping_area, [p1, p2], [p1, p2], algo="direct_laplace")

pbef, paft = [p1[0] - layheight, 0], [p2[0] + layheight, 0]
c1 = hm.create_contour([pbef, p1])
c1 = hm.partition_contour(c1,
                          "ref_weights", [hblayer, 1, hhormin, 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",
コード例 #11
0
g3 = hm.build_boundary_grid([op1, op2, op3, op4])
op1.direction = op2.direction = op3.direction = op4.direction = "right"
g4 = hm.build_boundary_grid([op1, op2, op3, op4])

check_cont(g3, 220, 220, [126, 94], {0: 94, 5: 126})
check_cont(g4, 244, 244, [106, 138], {0: 138, 5: 106})
check_grid(g3, 576, 1042, 466, {4: 466})
check_grid(g4, 632, 1142, 510, {4: 510})

print "increasing angle"
start, end, diff_ac, diff = 20, 350, 2, 50
angle = start
while angle < end:
    print "angle =", angle
    a = angle / 360.0 * 2 * math.pi
    cont = hm.create_contour([[-1, 0], [0, 0], [-math.cos(a), math.sin(a)]])
    op = hm.BoundaryGridOptions(cont, [0, 0.005, 0.01, 0.017, 0.027, 0.04],
                                'left', 0.01)
    grid = hm.build_boundary_grid(op)
    if (angle == 20):
        check_zero(hm.domain_area(grid) - 0.0709330292)
    if (angle == 30):
        check_zero(hm.domain_area(grid) - 0.0740306424)
    if (angle == 40):
        check_zero(hm.domain_area(grid) - 0.0705479267)
    if (angle == 90):
        check_zero(hm.domain_area(grid) - 0.0784)
    if (angle == 190):
        check_zero(hm.domain_area(grid) - 0.080136924)
    if (angle == 340):
        check_zero(hm.domain_area(grid) - 0.082187350)
コード例 #12
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
コード例 #13
0
ファイル: intro_naca4415.py プロジェクト: cescjf/HybMesh
bleft = hm.add_boundary_type(5, "left")
bright = hm.add_boundary_type(6, "right")
btop = hm.add_boundary_type(7, "top")
bbot = hm.add_boundary_type(8, "bottom")

# load 2d airfoil coordinates from external file
# to xy float array as [ [x0, y0], [x1, y1], ..... ]
with open('../external_files/naca4415.dat', 'r') as f:
    data = map(float, f.read().split())
    it = iter(data)
    xy = [[x, y] for x, y in zip(it, it)]

# build a contour from read points.
# xy[0] = xy[-1] hence resulting contour will be closed.
# Otherwise we'd have to call xy.append(xy[0][:]) manually.
foil = hm.create_contour(xy, bfoil)

# rotate at 10 degrees
hm.rotate_geom(foil, -10, [0, 0])

# === build substrate grid
# Here we need a rectangular grid with refinement at foil location.
# First we create two list of doubles defining x and y coordinates,
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):
コード例 #14
0
ファイル: cont_test.py プロジェクト: cescjf/HybMesh
        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)
# quit()
c11 = hm.create_contour(
    [[0, 0], [3, 1], [6, 0], [9, 0], [9, 3], [8, 6], [9, 9], [9, 12], [0, 0]],
    [1, 1, 1, 1, 1, 2, 1, 0])
c12 = hm.create_contour(
    [[-20, -20], [20, -20], [20, 20], [-20, 20], [-20, 0], [-20, -20]], 22)
c13 = hm.unite_contours([c11, c12])
[c14] = hm.simplify_contour(c13, simplify=True, angle=60, separate=False)
[c15, c16] = hm.simplify_contour(c13, simplify=True, angle=60, separate=True)