x = 2 * float(i) / 99 y = 1 + 0.1 * math.sin(8.0 * math.pi * i / 99) - 0.1 * x pts.append([x, y]) top_line2 = hm.create_contour(pts, 8) top_line_part2 = hm.partition_contour( top_line2, "ref_points", [0.005, [0, 1], 0.23, [2, 1]], angle0=180. ) left_line_part = hm.partition_contour(left_line, "const", 0.05) g1 = hm.add_custom_rect_grid( "inverse_laplace", left_line_part, bottom_line_part, None, top_line_part2) hm.export_grid_vtk(g1, "g1.vtk") check_ascii_file(16985162519033738007, "g1.vtk") check(hm.info_contour(g1)['btypes'] == {8: 45, 1: 40, 2: 45}) g1 = hm.add_custom_rect_grid( "orthogonal", top_line_part2, left_line_part, bottom_line_part, None) hm.export_grid_vtk(g1, "g1.vtk") check_ascii_file(17680407579251078528, "g1.vtk") check(hm.info_contour(g1)['btypes'] == {8: 45, 1: 40, 2: 45}) left_line_part2 = hm.partition_contour( left_line, "ref_points", [0.1, [0, 1], 0.01, [0, 0.5], 0.1, [0, 0]]) g1 = hm.add_custom_rect_grid( "direct_laplace", top_line_part2, left_line_part2, None, None)
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"
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" try: hm.export_grid_msh(g4, "g1.msh", [bbot, 0, True])
from hybmeshpack import hmscript as hm from hybmeshpack.hmscript._dbg import check_ascii_file, checkdict, check hm.check_compatibility("0.4.5") print "add_unf_rect_grid" g1 = hm.add_unf_rect_grid([0.01, -0.2], [1, 1], 15, 10) checkdict(hm.info_grid(g1), {'Ncells': 150}) hm.export_grid_vtk(g1, "g1.vtk") check_ascii_file(13180744078971206337, "g1.vtk") g1 = hm.add_unf_rect_grid([0, 0], [1, 1], 15, 10, custom_x=0.5) checkdict(hm.info_grid(g1), {'Ncells': 20}) g1 = hm.add_unf_rect_grid([1, 1], [2, 2], 15, 10, custom_y=0.2) checkdict(hm.info_grid(g1), {'Ncells': 75}) g1 = hm.add_unf_rect_grid([1, 1], [2, 2], 3, 3, custom_x=0.1, custom_y=0.2) checkdict(hm.info_grid(g1), {'Ncells': 50}) g1 = hm.add_unf_rect_grid([1, 1], [2, 2], custom_x=[0, 1], custom_y=[0, 1]) checkdict(hm.info_grid(g1), {'Ncells': 1}) g1 = hm.add_unf_rect_grid([1, 1], [2, 2], custom_x=[1, 1.9, 2], custom_y=[-1, -0.2, 2.2]) hm.export_grid_vtk(g1, "g1.vtk") check_ascii_file(3572940205872809425, "g1.vtk") print "add_unf_circ_grid" g1 = hm.add_unf_circ_grid([1, 1], 1, 13, 3, is_trian=True) hm.export_grid_vtk(g1, "g1.vtk") check_ascii_file(16381562878152009782, "g1.vtk") g1 = hm.add_unf_circ_grid([0, 0], 1, 5, 5, 0.3, is_trian=False) hm.export_grid_vtk(g1, "g1.vtk") check_ascii_file(419969290668673427, "g1.vtk")
t = reffun(float(i) / nz) zcoords.append(minz + (maxz - minz) * t) # case 1: extrude without any boundary assignment res1 = hmscript.extrude_grid(square, zcoords, 0, 0, 0) # case 2: assign all boundary types: # x0, x1, y0, y1 are inherited from 2d geometry, # z0, z1 are defined explicitly res2 = hmscript.extrude_grid(square, zcoords, bz0, bz1) # case 3: same as case 2 but select central face within z=0 # surface and assign it with bcustom boundary type def assign_boundary3d_z0(x, y, b): if (x - 0.5)**2 + (y - 0.5)**2 < 1e-6: return bcustom else: return bz0 res3 = hmscript.extrude_grid(square, zcoords, assign_boundary3d_z0, bz1) # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ print "extrude example" hmscript.export3d_grid_vtk(res1, None, "res1.vtk") hmscript.export3d_grid_vtk(res2, None, "res2.vtk") hmscript.export3d_grid_vtk(res3, None, "res3.vtk") check_ascii_file(3143265997463261162, "res1.vtk") check_ascii_file(16095103046228725270, "res2.vtk") check_ascii_file(12414162256708599695, "res3.vtk")
def testf(): from hybmeshpack.hmscript import _dbg as hmdbg hmdbg.check_ascii_file(2556162334104726686, "res3d.msh", "dev")
c2 = hm.partition_contour(i4, "ref_points", [1.0, [0, 0], 1.0, [1, 0], 0.01, [1, 1]], angle0=-1) check(hm.info_contour(c1)['Nedges'] == 5) check(hm.info_contour(c2)['Nedges'] == 6) hm.remove_all() print "contour partition with given nedges" cont = hm.create_contour([[0, 5], [1, 5], [0.5, 5.5]]) cont2 = hm.partition_contour(cont, "const", 1, nedges=2) check(hm.info_contour(cont2)['Nedges'] == 2) cont2 = hm.partition_contour(cont, "const", 1, nedges=6) check(hm.info_contour(cont2)['Nedges'] == 6) hm.export_contour_vtk(cont2, "c.vtk") check_ascii_file(13813652183113259463, "c.vtk") ccirc = hm.add_circ_contour([0, 0], 1, 16) hm.export_contour_vtk(ccirc, "c2.vtk") cont2 = hm.partition_contour(ccirc, "const", 1, nedges=3, angle0=180.) hm.export_contour_vtk(cont2, "c3.vtk") check( hm.info_contour(cont2)['Nedges'] == 3 and abs(hm.info_contour(cont2)['length'] - 5.137) < 0.01) cont2 = hm.partition_contour(ccirc, "const", 1, nedges=22) check(hm.info_contour(cont2)['Nedges'] == 22) contcom = hm.unite_contours([ccirc, cont]) cont2 = hm.partition_contour(contcom, "const", 1, nedges=5, angle0=180.)