Exemple #1
0
from hybmeshpack import hmscript as hm
from hybmeshpack.hmscript import _dbg as hmdbg
hm.check_compatibility("0.4.0")

g1 = hm.add_unf_rect_grid([0, 0], [1, 1], 10, 10)
hm.set_boundary_type(g1,
                     bfun=lambda x0, y0, x1, y1, bt: {
                         y0 + y1 == 0: 1,
                         x0 + x1 == 2: 2,
                         y0 + y1 == 2: 3,
                         x0 + x1 == 0: 4
                     }[1])
print "extrusion with zero bc"
s1 = hm.extrude_grid(g1, [0, 0.1, 0.2], 0, 0, 0)
hm.export3d_grid_vtk(s1, "s1.vtk", "s2.vtk")
hmdbg.check_ascii_file(9760293401399903439, "s1.vtk")
hmdbg.check_ascii_file(9133727113521198898, "s2.vtk")
hm.remove_geom(s1)

print "extrusion with side bc from contour"
s1 = hm.extrude_grid(g1, [0, 0.1], 0, 0, None)
hm.export3d_grid_vtk(s1, None, "s2.vtk")
hmdbg.check_ascii_file(17055111601829986000, "s2.vtk")
hm.remove_geom(s1)

print "extrusion with non-zero at zfaces and side bc from contour"
s1 = hm.extrude_grid(g1, [-0.1, 0.1, 22], 8, 10, None)
hm.export3d_grid_vtk(s1, None, "s2.vtk")
hmdbg.check_ascii_file(4721469755399912982, "s2.vtk")

print "extrusion with function at bottom z face"
Exemple #2
0
hm.load_project("../external_files/empty.hmp")

print "export 2d to fluent"
bleft = hm.add_boundary_type(1, "bleft")
bright = hm.add_boundary_type(2, "bright")
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"
Exemple #3
0
from hybmeshpack import hmscript as hm
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})
Exemple #4
0
def check_grid(grid, nn, ne, nc, ct):
    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 "exclude intersecting domain"
g1 = hm.add_unf_circ_grid([0, 0], 1, 20, 10, 1.2, False)
hm.set_boundary_type(g1, 1)
c1 = hm.add_rect_contour([0, 0], [1, 1], [2, 3, 4, 5])
g2 = hm.exclude_contours(g1, c1, "outer")
g3 = hm.exclude_contours(g1, c1, "inner")

check_grid(g1, 200, 380, 181, {20: 1, 4: 180})
check_grid(g2, 61, 106, 46, {7: 1, 4: 45})
check_grid(g3, 161, 296, 136, {17: 1, 4: 135})
check_cont(g2, 25, 25, [25], {1: 5, 5: 10, 2: 10})
check_cont(g3, 35, 35, [35], {1: 15, 5: 10, 2: 10})
check_zero(hm.domain_area(g2) + hm.domain_area(g3) - hm.domain_area(g1))

print "exclude internal domain"
g4 = hm.add_unf_rect_grid([0, 0], [0.3, 0.3], 2, 2)
hm.set_boundary_type(g4, 6)
hm.move_geom(g4, -0.5, 0.03)
Exemple #5
0
# 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')
op1.uniform_partition(0.03, 2)
win_frame1 = hm.build_boundary_grid([op1])

# now we create a internal window frames
win_frame2 = hm.add_unf_rect_grid([-0.02, -0.15], [0.02, 0.15], 3, 30)
Exemple #6
0
from hybmeshpack import hmscript

# 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
Exemple #7
0
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)
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")
Exemple #8
0
bs = [0, step_bl / 2, 2. * step_bl / 2, 3. * step_bl / 2, 4. * step_bl / 2]
bgo = hm.BoundaryGridOptions(sa1,
                             bs,
                             "left",
                             step_bl,
                             "no",
                             start_point=c[19],
                             end_point=c[13])
g74 = hm.build_boundary_grid(bgo)

# 4. input
[cl, cb, cr, ct] = hm.extract_subcontours(
    c_ltop, [[105, 1968], [103, 1962], c[21], c[22], [105, 1968]])
[cr] = hm.extract_subcontours(g723, [c[22], c[21]], "line")
hm.set_boundary_type(cl, binput_left1)
nic = hm.connect_subcontours([cb, cl, ct, cr], [1, 3], "yes")
cl = hm.partition_contour(cl, "const", 1, nedges=3)
cb = hm.partition_contour(cb, "const", 1, nedges=3)
cr = hm.partition_contour(cr, "const", 1, nedges=3)
ct = hm.partition_contour(ct, "const", 1, nedges=3)
g75 = hm.add_custom_rect_grid("linear", cr, cb, cl, ct)

# 5. unite all
g7 = hm.unite_grids(g721, [(g722, 0), (g723, 0), (g73, 0)], buffer_fill='4')
g7 = hm.unite_grids(g7, [(g74, 1), (g75, 1)], buffer_fill='4')
g7 = hm.unite_grids(g7, [(g71, 1.2)], empty_holes=True, buffer_fill='4')

# right top zone: g8
# 1. hole
u = hm.partition_contour(c_rhole, "const", step_bl)
Exemple #9
0
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]
[right] = hm.copy_geom(left)
Exemple #10
0
square = hmscript.add_unf_rect_grid([0, 0], [1, 1], 5, 5)


# assign boundary types to 2D geometry so it could be inherited by 3D object
def assign_boundary2d(x0, y0, x1, y1, b):
    if x0 == 0 and x1 == 0:
        return bx0
    if x0 == 1 and x1 == 1:
        return bx1
    if y0 == 0 and y1 == 0:
        return by0
    if y0 == 1 and y1 == 1:
        return by1


hmscript.set_boundary_type(square, bfun=assign_boundary2d)

# calculate z coordinates with sine refinement towards z=0
minz, maxz, nz = 0.0, 1.0, 10


# refinement function [0, 1] -> [0, 1]
def reffun(t):
    return 1.0 + math.sin(0.5 * math.pi * (t - 1))


zcoords = []
for i in range(nz + 1):
    t = reffun(float(i) / nz)
    zcoords.append(minz + (maxz - minz) * t)
Exemple #11
0
# 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):
    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)
Exemple #12
0
check_cont(c1, 4, 4, [4], {1: 4})
check_cont(c2, 44, 44, [4, 40], {0: 40, 1: 4})
check_cont(g2, 16, 16, [16], {0: 16})
check_cont(c3, 60, 60, [4, 16, 40], {0: 56, 1: 4})
check_cont(c4, 60, 60, [4, 16, 40], {0: 56, 1: 4})
check(area_full == 96.64)
check(area_full == area_c1 - area_g1 + area_g2)

print "grid contours to user contours"
c5 = hm.grid_bnd_to_contour(g1, True)
c6 = hm.grid_bnd_to_contour(g2, False)
check_cont(c5, 4, 4, [4], {0: 4})
check_cont(c6, 16, 16, [16], {0: 16})

print "set boundary types"
hm.set_boundary_type(c1, btps=[1, 2, 3, 4])
check_cont(c1, 4, 4, [4], {1: 1, 2: 1, 3: 1, 4: 1})
hm.set_boundary_type(c1,
                     bfun=lambda x0, y0, x1, y1, bo: {
                         1: 0,
                         2: 0,
                         3: 0,
                         4: 15
                     }[bo])
check_cont(c1, 4, 4, [4], {0: 3, 15: 1})

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