def front_mesh_symmetric(res=0.025): """ Creates a donut mesh with symmetry line through y = c_y """ geometry = Geometry() mesh_r = width_scale*res c = geometry.add_point((c_x,c_y,0)) # Elliptic obstacle p1 = geometry.add_point((c_x-r_x, c_y,0)) p2 = geometry.add_point((c_x+r_x, c_y,0)) # embed() arc_1 = geometry.add_circle_arc(p1, c, p2) arc_2 = geometry.add_circle_arc(p2, c, p1) # Surrounding mesh p3 = geometry.add_point((c_x-r_x-mesh_r, c_y,0)) p4 = geometry.add_point((c_x+r_x+mesh_r, c_y,0)) arc_5 = geometry.add_circle_arc(p3, c, p4) arc_6 = geometry.add_circle_arc(p4, c, p3) line_front = geometry.add_line(p3, p1) line_back = geometry.add_line(p2, p4) surface_top = geometry.add_line_loop([line_front, arc_1, line_back, -arc_5]) surface_bottom = geometry.add_line_loop([line_front, -arc_2, line_back, arc_6]) obstacle_loop = geometry.add_line_loop([arc_1, arc_2]) outer_loop = geometry.add_line_loop([arc_5,arc_6]) top = geometry.add_plane_surface(surface_top) bottom = geometry.add_plane_surface(surface_bottom) geometry.add_physical_surface([top, bottom],label=12) geometry.add_physical_line(obstacle_loop.lines, label=inner_marker) geometry.add_physical_line(outer_loop.lines, label=outer_marker) # Create refined mesh around geometry field = geometry.add_boundary_layer(edges_list=obstacle_loop.lines, hfar=res, hwall_n=res/3, thickness=0.1*mesh_r) geometry.add_background_field([field]) # Generate mesh (points, cells, point_data, cell_data, field_data) = generate_mesh(geometry, prune_z_0=True, geo_filename="meshes/test.geo") # Save mesh and mesh-function to file meshio.write("multimesh_1.xdmf", meshio.Mesh( points=points, cells={"triangle": cells["triangle"]})) meshio.write("mf_1.xdmf", meshio.Mesh( points=points, cells={"line": cells["line"]}, cell_data={"line": {"name_to_read": cell_data["line"]["gmsh:physical"]}})) import os os.system("mv multimesh_1.* meshes/") os.system("mv mf_1.* meshes/")
def background_mesh(res=0.025): """ Create rectangular background mesh for the Poisson problem """ geo = Geometry() # Create points for square with two inlets and one outlet points = [] points.append(geo.add_point((0, 0, 0), res)) points.append(geo.add_point((1, 0, 0), res)) points.append(geo.add_point((1, 1, 0), res)) points.append(geo.add_point(outlet[1], res)) points.append(geo.add_point(outlet[0], res)) points.append(geo.add_point((0, 1, 0), res)) points.append(geo.add_point(inlet1[1], res)) points.append(geo.add_point(inlet1[0], res)) points.append(geo.add_point(inlet0[1], res)) points.append(geo.add_point(inlet0[0], res)) # Connect points as lines lines = [] for i in range(len(points) - 1): lines.append(geo.add_line(points[i], points[i + 1])) lines.append(geo.add_line(points[-1], points[0])) # Create geometry line_loop = geo.add_line_loop(lines) square = geo.add_plane_surface(line_loop) # Create cell and facet function wall_lines = lines[0:3] + lines[4:6] + [lines[7]] + [lines[9]] inlet0_lines = [lines[8]] inlet1_lines = [lines[6]] outlet_lines = [lines[3]] geo.add_physical_surface([square], label=12) geo.add_physical_line(inlet0_lines, label=inlet0_marker) geo.add_physical_line(inlet1_lines, label=inlet1_marker) geo.add_physical_line(outlet_lines, label=outlet_marker) geo.add_physical_line(wall_lines, label=wall_marker) # Create mesh (points, cells, point_data, cell_data, field_data) = generate_mesh(geo, prune_z_0=True) #, #geo_filename="meshes/tmp.geo") meshio.write( "meshes/multimesh_0.xdmf", meshio.Mesh(points=points, cells={"triangle": cells["triangle"]})) meshio.write( "meshes/mf_0.xdmf", meshio.Mesh(points=points, cells={"line": cells["line"]}, cell_data={ "line": { "name_to_read": cell_data["line"]["gmsh:physical"] } }))
from dolfin.fem import assemble_scalar from dolfin import FunctionSpace, TrialFunction, TestFunction, DirichletBC, Function, solve, cpp, fem geom = Geometry() mesh_ele_size = .02 p1 = geom.add_point([0.0, 0.0, 0], lcar=mesh_ele_size) p2 = geom.add_point([0.0, 1.0, 0], lcar=mesh_ele_size) p3 = geom.add_point([1.0, 1.0, 0], lcar=mesh_ele_size) p4 = geom.add_point([1.0, 0.0, 0], lcar=mesh_ele_size) p5 = geom.add_point([0.2, 0.5, 0], lcar=mesh_ele_size) p6 = geom.add_point([0.2, 0.7, 0], lcar=mesh_ele_size) p7 = geom.add_point([1.0, 0.5, 0], lcar=mesh_ele_size) p8 = geom.add_point([1.0, 0.7, 0], lcar=mesh_ele_size) l1 = geom.add_line(p1, p4) l2 = geom.add_line(p3, p2) l3 = geom.add_line(p2, p1) l4 = geom.add_line(p7, p5) l5 = geom.add_line(p5, p6) l6 = geom.add_line(p6, p8) l7 = geom.add_line(p4, p7) l8 = geom.add_line(p7, p8) l9 = geom.add_line(p8, p3) ll1 = geom.add_line_loop(lines=[l2, l3, l1, l7, l4, l5, l6, l9]) ps1 = geom.add_plane_surface(ll1) ll2 = geom.add_line_loop(lines=[l6, -l8, l4, l5]) ps2 = geom.add_plane_surface(ll2)
from pygmsh.built_in.geometry import Geometry from pygmsh import generate_mesh import meshio import dolfin import dolfin.io geom = Geometry() mesh_ele_size = .1 p0 = geom.add_point([0, 0, 0], lcar=mesh_ele_size) p1 = geom.add_point([1, 0, 0], lcar=mesh_ele_size) p2 = geom.add_point([1, 1, 0], lcar=mesh_ele_size) p3 = geom.add_point([0, 1, 0], lcar=mesh_ele_size) l0 = geom.add_line(p0, p1) l1 = geom.add_line(p1, p2) l2 = geom.add_line(p2, p3) l3 = geom.add_line(p3, p0) ll = geom.add_line_loop(lines=[l0, l1, l2, l3]) ps = geom.add_plane_surface(ll) # Tag line and surface geom.add_physical(l3, label=444) geom.add_physical(ps, label=456) print("\n".join(geom._GMSH_CODE)) mesh = generate_mesh(geom) points, cells, cell_data = mesh.points, mesh.cells, mesh.cell_data meshio.write("input/mesh_2d.xdmf",
def front_mesh(res=0.025): geometry = Geometry() mesh_r = width_scale * res c = geometry.add_point((c_x, c_y, 0)) # Elliptic obstacle p1 = geometry.add_point((c_x - r_x, c_y, 0)) p2 = geometry.add_point((c_x + r_x, c_y, 0)) p12 = geometry.add_point((c_x, c_y + 1.4 * r_x, 0)) p21 = geometry.add_point((c_x, c_y - 1.4 * r_x, 0)) arc_1 = geometry.add_spline([p1, p12, p2]) arc_2 = geometry.add_spline([p2, p21, p1]) # arc_1 = geometry.add_circle_arc(p1, c, p2) # arc_2 = geometry.add_circle_arc(p2, c, p1) # Surrounding mesh p3 = geometry.add_point((c_x - r_x - mesh_r, c_y, 0)) p4 = geometry.add_point((c_x + r_x + mesh_r, c_y, 0)) p34 = geometry.add_point((c_x, c_y + 1.4 * r_x + mesh_r, 0)) p43 = geometry.add_point((c_x, c_y - 1.4 * r_x - mesh_r, 0)) arc_5 = geometry.add_spline([p3, p34, p4]) arc_6 = geometry.add_spline([p4, p43, p3]) # arc_5 = geometry.add_circle_arc(p3, c, p4) # arc_6 = geometry.add_circle_arc(p4, c, p3) line_front = geometry.add_line(p3, p1) line_back = geometry.add_line(p2, p4) surface_top = geometry.add_line_loop( [line_front, arc_1, line_back, -arc_5]) surface_bottom = geometry.add_line_loop( [line_front, -arc_2, line_back, arc_6]) obstacle_loop = geometry.add_line_loop([arc_1, arc_2]) top = geometry.add_plane_surface(surface_top) bottom = geometry.add_plane_surface(surface_bottom) geometry.add_physical_surface([top, bottom], label=12) geometry.add_physical_line(obstacle_loop.lines, label=inner_marker) # Create refined mesh around geometry field = geometry.add_boundary_layer(edges_list=obstacle_loop.lines, hfar=res, hwall_n=res / 3, thickness=2 * res) geometry.add_background_field([field]) # Generate mesh (points, cells, point_data, cell_data, field_data) = generate_mesh(geometry, prune_z_0=True, geo_filename="meshes/test.geo") # Save mesh and mesh-function to file meshio.write( "meshes/multimesh_1.xdmf", meshio.Mesh(points=points, cells={"triangle": cells["triangle"]})) meshio.write( "meshes/mf_1.xdmf", meshio.Mesh(points=points, cells={"line": cells["line"]}, cell_data={ "line": { "name_to_read": cell_data["line"]["gmsh:physical"] } }))