# Draw a shape with holes Use this when the domain is a plate with a hole, the cross section of a cable, or any other shape in the plane that a box or a disk does not describe. ## Steps 1. Draw the outer boundary as a closed curve from `pdemagic.curves`: a `Polygon` through its corners, a `Circle`, an `Ellipse`, or a `Curve` of lines and arcs. 2. Draw each hole as a closed curve inside it. 3. Hand all of them to `pm.Region(x, y, outer, hole, ...)`. A point belongs to the region if it lies inside an odd number of the curves. 4. Give each curve its condition, in a mapping from the curve to its equation. ## Example A square plate that is kept cold along its edge, with a round hole whose rim is kept warm: ```python import numpy as np import sympy as sp import pdemagic as pm from pdemagic import curves x, y = sp.symbols("x y", real=True) u = sp.Function("u")(x, y) edge = curves.Polygon((-1, -1), (1, -1), (1, 1), (-1, 1), name="edge") hole = curves.Circle((0.3, 0.2), 0.4, name="hole") plate = pm.Region(x, y, edge, hole) warmed = pm.Problem( sp.Eq(pm.laplacian(u), 0), domain=plate, boundary={edge: sp.Eq(u, 0), hole: sp.Eq(u, 1)}, ) around = pm.solve(warmed) around.plot() assert abs(around(0.7, 0.2) - 1) < 1e-10 # on the rim of the hole assert abs(around(1.0, 0.0)) < 1e-10 # on the edge assert np.isnan(around(0.3, 0.2)) # in the hole ``` ## Notes - The values come on a grid over the rectangle that holds the shape. A point of the grid in a hole or beside the shape holds `nan`: use `np.nanmax` and its relatives, or the mask `np.isfinite(around[u])`. - In which sense a curve runs does not matter. Curves must not touch or cross, each other or themselves. - A hole through which nothing flows takes `sp.Eq(pm.normal_derivative(u), 0)`. At the rim of a hole the outward normal points into the hole. - An equation alone as `boundary=` holds on all curves. - At a corner that points into the region the solution has a singularity. pdemagic lets the mesh shrink towards such a corner, and the plan says so. - A boundary is made of lines and of arcs of circles and ellipses. Shapes in space are not taken. - [Shapes in the plane](../topics/regions.md) explains regions, and [the reference](../ref/regions.md) lists the curves. The gallery has [a plate with a hole](../gallery/plate-with-a-hole.md), and the method is [spectral elements](../methods/spectral-elements.md).