# Give each face its own condition Use this when the faces of a box or a round domain differ: one is heated, another is insulated, a third is kept cold. ## Steps 1. Look up the faces: `domain.faces`. A face is named by the coordinate that is constant on it and the end it lies at, so `(x, 0)` is the face where `x` is 0. 2. Write one equation for each face: the value `sp.Eq(u, g)`, the slope `sp.Eq(u.diff(x), g)`, or a mix of both. 3. Pass them as a mapping from each face to its equation, as `boundary=`. ## Example A plate that is insulated on its left and right side, kept cold at the bottom, and heated along the top: ```python import numpy as np import sympy as sp import pdemagic as pm x, y = sp.symbols("x y", real=True) u = sp.Function("u")(x, y) box = pm.Box({x: (0, 1), y: (0, 1)}) assert box.faces == ((x, 0.0), (x, 1.0), (y, 0.0), (y, 1.0)) conditions = { (x, 0): sp.Eq(u.diff(x), 0), # the slope: nothing flows through (x, 1): sp.Eq(u.diff(x), 0), (y, 0): sp.Eq(u, 0), # the value (y, 1): sp.Eq(u, sp.cos(sp.pi * x)), } plate = pm.Problem(sp.Eq(pm.laplacian(u), 0), domain=box, boundary=conditions) heated = pm.solve(plate) heated.plot() X, Y = heated.mesh() exact = np.cos(np.pi * X) * np.sinh(np.pi * Y) / np.sinh(np.pi) assert abs(heated[u] - exact).max() < 1e-12 ``` ## Notes - Every face needs a condition. A face that is left out is refused, and so is a key that is no face: the message lists the faces. - When most faces share a condition, start from `dict.fromkeys(box.faces, sp.Eq(u, 0))` and replace the others. - `u.diff(x)` is the slope along the coordinate, not along the outward normal. At an upper face the two agree, at a lower face they differ in sign. `pm.normal_derivative(u)` is the slope along the outward normal on every face. - A condition has the form $a\,u + b\,\partial u/\partial x = g$ with numbers $a$ and $b$. What is given, $g$, is a number, a formula in the coordinates or an array, and in a problem in time it may depend on the time. - A disk has the one face `(r, radius)`, a ring two, and a cylinder a wall and two caps. - On a shape in the plane the keys are curves and their pieces: see [Name the pieces of a boundary](name-the-pieces-of-a-boundary.md). - [Boundary conditions](../topics/boundary-conditions.md) and [Boxes with walls](../topics/boxes.md) explain more, and the gallery has [a heated plate](../gallery/heated-plate.md).