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) g5 = hm.exclude_contours(g1, g4, "outer") g6 = hm.exclude_contours(g1, g4, "inner") [c2] = hm.simplify_contour(g5) [c3] = hm.simplify_contour(g6) check_grid(g5, 29, 43, 15, {3: 3, 4: 7, 5: 3, 6: 2}) check_grid(g6, 215, 395, 180, {3: 2, 4: 169, 5: 3, 6: 4, 7: 1, 20: 1}) check_cont(g5, 22, 22, [22], {6: 22}) check_cont(c2, 4, 4, [4], {6: 4}) check_cont(g6, 42, 42, [20, 22], {1: 20, 6: 22})
check(info['cell_types'][k] == ct[k]) def check_zero(a): check(abs(a) < 1e-8) 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})
# 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
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) hm.remove_geom([cont, grid]) angle += diff_ac if angle < op.range_angles[0] else diff print "doubly connected area: all outer"
from hybmeshpack import hmscript # START OF EXAMPLE # lower level grid g1 = hmscript.add_unf_rect_grid([0, 0], [10, 10], 10, 10) # first imposition grid g2 = hmscript.add_unf_rect_grid([0, 0], [3, 3], 7, 7) # second imposition grid g3 = hmscript.add_unf_circ_grid([5, 5], 1.5, 10, 4) # impose grids impgrid = hmscript.unite_grids(g1, [(g2, 2.0), (g3, 1.0)]) # END OF EXAMPLE print "unite_grids example" hmscript.export_grid_vtk(impgrid, "_g2.vtk") if (abs(hmscript.domain_area(impgrid) - 100) > 1e-8): raise Exception if (not hmscript.skewness(impgrid)['ok']): raise Exception
info = hm.info_contour(cont) check(info['Nnodes'] == nn) check(info['Nedges'] == ne) check(cmp(sorted(info['subcont']), sorted(scont)) == 0) for k in btypes.keys(): check(info['btypes'][k] == btypes[k]) print "contours unite" g1 = hm.add_unf_rect_grid([-1, -1], [1, 1], 10, 10) c1 = hm.add_rect_contour([-5, -5], [5, 5], [1, 1, 1, 1]) c2 = hm.unite_contours([c1, g1]) g2 = hm.add_unf_rect_grid([-0.4, -0.4], [0.4, 0.4], 4, 4) c3 = hm.unite_contours([c2, g2]) c4 = hm.unite_contours([c1, g1, g2]) area_g1 = hm.domain_area(g1) area_c1 = hm.domain_area(c1) area_g2 = hm.domain_area(g2) area_full = hm.domain_area(c4) check_cont(g1, 40, 40, [40], {0: 40}) 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)