def make_geom(length: float, lcar: float) -> Geometry: # Barkley et al (2002, figure 3 a - c) geom = Geometry() points = [] for point in [[0, -1, 0], [length, -1, 0], [length, 1, 0], [-1, 1, 0], [-1, 0, 0], [0, 0, 0]]: points.append(geom.add_point(point, lcar)) lines = [] for termini in zip(points, islice(cycle(points), 1, None)): lines.append(geom.add_line(*termini)) for k, label in [([1], 'outlet'), ([2], 'ceiling'), ([3], 'inlet'), ([0, 4, 5], 'floor')]: geom.add_physical(list(np.array(lines)[k]), label) geom.add_physical( geom.add_plane_surface(geom.add_line_loop(lines)), 'domain') return geom
def make_mesh(halfheight: float, # mm length: float, thickness: float) -> MeshTri: geom = Geometry() points = [] lines = [] lcar = halfheight / 2**2 for xy in [(0., halfheight), (0., -halfheight), (length, -halfheight), (length, halfheight), (0., -halfheight - thickness), (length, -halfheight - thickness)]: points.append(geom.add_point([*xy, 0.], lcar)) lines.append(geom.add_line(*points[:2])) geom.add_physical(lines[-1], 'fluid-inlet') lines.append(geom.add_line(*points[1:3])) lines.append(geom.add_line(*points[2:4])) geom.add_physical(lines[-1], 'fluid-outlet') lines.append(geom.add_line(points[3], points[0])) geom.add_physical(geom.add_plane_surface(geom.add_line_loop(lines)), 'fluid') lines.append(geom.add_line(points[1], points[4])) geom.add_physical(lines[-1], 'solid-inlet') lines.append(geom.add_line(*points[4:6])) geom.add_physical(lines[-1], 'heated') lines.append(geom.add_line(points[5], points[2])) geom.add_physical(lines[-1], 'solid-outlet') geom.add_physical(geom.add_plane_surface(geom.add_line_loop( [*lines[-3:], -lines[1]])), 'solid') return from_meshio(generate_mesh(geom, dim=2))
try: m = from_file(mesh_file) except FileNotFoundError: from pygmsh import generate_mesh from pygmsh.built_in import Geometry geom = Geometry() points = [] lines = [] points.append(geom.add_point([0., 0., 0.], .1)) points.append(geom.add_point([0., 1., 0.], .1)) points.append(geom.add_point([0., -1., 0.], .1)) lines.append(geom.add_circle_arc(points[2], points[0], points[1])) geom.add_physical(lines[-1], 'contact') lines.append(geom.add_line(points[1], points[2])) geom.add_physical(lines[-1], 'dirichlet') geom.add_physical(geom.add_plane_surface(geom.add_line_loop(lines)), 'domain') m = from_meshio(generate_mesh(geom, dim=2)) to_file(m, mesh_file) M = MeshLine(np.linspace(0, 1, 6)) * MeshLine(np.linspace(-1, 1, 10)) M.translate((1.0, 0.0)) M.refine() # define elements and bases e1 = ElementTriP2() e = ElementVectorH1(e1) E1 = ElementQuad2() E = ElementVectorH1(E1)
lines = [] radii = [1., 2.] lcar = .1 points.append(geom.add_point([0.] * 3, lcar)) # centre for x in radii: points.append(geom.add_point([x, 0., 0.], lcar)) for y in reversed(radii): points.append(geom.add_point([0., y, 0.], lcar)) lines.append(geom.add_line(*points[1:3])) geom.add_physical_line(lines[-1], 'ground') lines.append(geom.add_circle_arc(points[2], points[0], points[3])) lines.append(geom.add_line(points[3], points[4])) geom.add_physical_line(lines[-1], 'positive') lines.append(geom.add_circle_arc(points[4], points[0], points[1])) geom.add_physical_surface( geom.add_plane_surface(geom.add_line_loop(lines)), 'domain') pts, cells, _, cell_data, field_data = generate_mesh( geom, prune_vertices=False) mesh = MeshTri(pts[:, :2].T, cells['triangle'].T) boundaries = {bc: np.unique(cells['line'][cell_data['line']['gmsh:physical'] == field_data[bc][0]]) for bc in field_data if field_data[bc][1] == 1} elements = ElementTriP1() basis = InteriorBasis(mesh, elements, MappingAffine(mesh), 2) A = asm(laplace, basis) b = asm(unit_load, basis)