示例#1
0
zs3 = hm.registered_surfaces()
hm.export_all_hmd("all.hmd", fmt="bin")
hm.remove_all()
hmdbg.check(not hm.registered_contours())
hmdbg.check(not hm.registered_grids())
hmdbg.check(not hm.registered_grids3d())
hmdbg.check(not hm.registered_surfaces())
a = hm.import_all_hmd("all.hmd")
hmdbg.check(len(a[0] + a[1] + a[3] + a[3]) == len(zc2 + zg2 + zg3 + zs3))
hmdbg.check(all(a == b for a, b in zip(zc2, hm.registered_contours())))
hmdbg.check(all(a == b for a, b in zip(zg2, hm.registered_grids())))
hmdbg.check(all(a == b for a, b in zip(zs3, hm.registered_surfaces())))
hmdbg.check(all(a == b for a, b in zip(zg3, hm.registered_grids3d())))

# save/load project
hm.add_boundary_type(15, "boundary15")
numcom = hm.flow.com_count()
hm.save_project("p.hmp", "bin")
hm.load_project("../external_files/empty.hmp")
hmdbg.check(not hm.registered_contours())
hmdbg.check(not hm.registered_grids())
hmdbg.check(not hm.registered_grids3d())
hmdbg.check(not hm.registered_surfaces())
hmdbg.check(hm.registered_btypes() == [(0, 'default-boundary')])

hm.load_project("p.hmp")
hmdbg.check(numcom == hm.flow.com_count())
hmdbg.check(all(a == b for a, b in zip(zc2, hm.registered_contours())))
hmdbg.check(all(a == b for a, b in zip(zg2, hm.registered_grids())))
hmdbg.check(all(a == b for a, b in zip(zs3, hm.registered_surfaces())))
hmdbg.check(all(a == b for a, b in zip(zg3, hm.registered_grids3d())))
示例#2
0
from hybmeshpack import hmscript as hm

# 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],
示例#3
0
文件: fullcyl.py 项目: cescjf/HybMesh
from hybmeshpack import hmscript as hm
hm.check_compatibility('0.4.6', 2)

# boundary features
brib = hm.add_boundary_type(1, "rib")
bbottom = hm.add_boundary_type(2, "bottom")
binput = hm.add_boundary_type(3, "input")
boutput = hm.add_boundary_type(4, "output")
btop = hm.add_boundary_type(5, "top")

# ===================== Options
# area sizes
Lx1 = 16.66
Lx2 = 25.
Ly = 3.33
Lz = 8.33
hcyl = 0.5

# auxiliary sizes
Lx1_rib_blay = 0.15
Lx2_rib_blay = 0.7
Ly_rib_blay = 0.3
Lx_wake_reg = 15.
Ly_wake_reg = 1.0

# step sizes
step0 = 0.03  # lowest step in the walls boundary layers
step1 = 0.03  # step in the boudary layer straight behind the rib
step2 = 0.02 # outer rib boundary region step
step3 = 0.15 # maximum wake region step, maximum wall boundary step
step4 = 0.25  # largest step
示例#4
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
示例#5
0
文件: rrj2.py 项目: cescjf/HybMesh
from hybmeshpack import hmscript as hm
import copy  # NOQA
import math  # NOQA
global hm, check  # NOQA
hm.check_compatibility("0.4.6")

# options
step_main = 20.
step_bl = 2.
bstep = [step_bl, 0, step_main, 0.1, step_main, 0.9, step_bl, 1]
bstep1 = [step_bl, 0, step_main, 0.1]
bstep_main = [step_bl, 0, step_main, 0.05, step_main, 0.95, step_bl, 1]

# boundary types
binput_left1 = hm.add_boundary_type(1, "input_left1")
binput_left2 = hm.add_boundary_type(2, "input_left2")
binput_right1 = hm.add_boundary_type(3, "input_right1")
binput_right2 = hm.add_boundary_type(4, "input_right2")
boutput_left = hm.add_boundary_type(5, "output_left")
boutput_right = hm.add_boundary_type(6, "output_right")

# importing
cont = hm.import_contour_hmc("../external_files/RRJ2.hmc")
hm.export_contour_vtk(cont, "cont.vtk")

# =characteristic points
# lower bnd
c = [None] * 100
c[0] = [-906.994, -42.374]
c[1] = [2099.83, -33.8302]
c[2] = [1913.45, 1508.89]
示例#6
0
文件: cave1.py 项目: cescjf/HybMesh
hm.check_compatibility('0.4.6', 2)
global x2, y2

#area = hm.import_contour_hmc('cave1.hmc')
#hm.export_contour_vtk(area, "init.vtk")

#p1 = hm.get_point(area, vclosest=[227, 0])
#p2 = hm.get_point(area, vclosest=[278, 0])
#p3 = hm.get_point(area, vclosest=[252, -50])
#a1 = [0, 0]
#a2 = [500, 0]
#a3 = [500, 50]
#a4 = [0, 50]

bcirc = hm.add_boundary_type(1, "cave")
binput = hm.add_boundary_type(2, "input")
boutput = hm.add_boundary_type(3, "outflow")
bbot = hm.add_boundary_type(4, "bottom")
btop = hm.add_boundary_type(5, "top")

# option 1
# circ = hm.add_circ_contour2(p1, p2, p3, 128, bcirc)
# [a, b] = hm.extract_subcontours(circ, [p1, p2, p1], "line")
# circ = hm.connect_subcontours([a, b])
# p1 = hm.get_point(circ, vclosest=p1)
# p2 = hm.get_point(circ, vclosest=p2)
# hm.export_contour_vtk(circ, "c1.vtk")

# grbase = hm.add_circ_rect_grid([0, 0], 1., 0.1, 1.0, 0.1, "orthogonal_circ")
# x = math.sqrt(1. - 0.5 * 0.5)
示例#7
0
from hybmeshpack import hmscript
from hybmeshpack.hmscript._dbg import check_ascii_file
import math
global math

# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
# register boundary types
global bx0, bx1, by0, by1, bz0, bz1, bcustom
bx0 = hmscript.add_boundary_type(1, "x0-boundary")
bx1 = hmscript.add_boundary_type(2, "x1-boundary")
by0 = hmscript.add_boundary_type(3, "y0-boundary")
by1 = hmscript.add_boundary_type(4, "y1-boundary")
bz0 = hmscript.add_boundary_type(5, "z0-boundary")
bz1 = hmscript.add_boundary_type(6, "z1-boundary")
bcustom = hmscript.add_boundary_type(7, "bcustom")

# unit square 2D grid
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
示例#8
0
from hybmeshpack import hmscript as hm
hm.check_compatibility("0.5.0", 2)

# === register boundary types
global bfoil, bcirc, binp, bout, bleft, bright, btop, bbot
bfoil = hm.add_boundary_type(1, "foil")
bcirc = hm.add_boundary_type(2, "vortex-generator")
binp = hm.add_boundary_type(3, "input")
bout = hm.add_boundary_type(4, "output")
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.