Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
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(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(lines[-1], 'positive')
lines.append(geom.add_circle_arc(points[4], points[0], points[1]))
geom.add_physical(geom.add_plane_surface(geom.add_line_loop(lines)), 'domain')

mesh = from_meshio(generate_mesh(geom, dim=2))

elements = ElementTriP2()
basis = InteriorBasis(mesh, elements)
A = asm(laplace, basis)

boundary_dofs = basis.get_dofs(mesh.boundaries)
interior_dofs = basis.complement_dofs(boundary_dofs)

u = np.zeros(basis.N)
u[boundary_dofs['positive'].all()] = 1.
u = solve(*condense(A, 0.*u, u, interior_dofs))

M = asm(mass, basis)
u_exact = 2 * np.arctan2(*basis.doflocs[::-1]) / np.pi
u_error = u - u_exact