# A cloud of ions in a dish A cloud of ions in a grounded dish with the shape of an ellipse, after it has pushed itself apart for half a unit of time. ```python import sympy as sp import pdemagic as pm from pdemagic import curves x, y, t = sp.symbols("x y t", real=True) n = sp.Function("n")(x, y, t) phi = sp.Function("phi")(x, y, t) dish = pm.Region(x, y, curves.Ellipse((0, 0), (2, 1))) drift = n.diff(x) * phi.diff(x) + n.diff(y) * phi.diff(y) - n**2 cloud = pm.Problem( sp.Eq(n.diff(t), pm.laplacian(n) / 4 + drift), sp.Eq(pm.laplacian(phi), -n), domain=dish, time=(t, 0, 0.5), initial={n: 8 * (1 - x**2 / 4 - y**2) ** 2 * sp.exp(-((x + 1) ** 2))}, boundary=[sp.Eq(n, 0), sp.Eq(phi, 0)], ) plan = pm.plan(cloud) plan.method.tolerance = 1e-5 pm.solve(cloud, plan).plot(unknown=n, time=0.5) ``` ## What it shows The [cloud of ions between two plates](cloud-of-ions.md), in a dish of any shape. Ions of one sign diffuse and drift in their own field: the potential $\varphi$ obeys Poisson's equation with their density $n$ as its source at every instant, and the rim is grounded and takes the ions that reach it. The drift of the ions is $\nabla\cdot(n\,\nabla\varphi)$, which is $\nabla n\cdot\nabla\varphi + n\,\nabla^2\varphi$, and with Poisson's equation $\nabla n\cdot\nabla\varphi - n^2$: that is how the example writes it, because a term that is stepped on a shape holds first derivatives at most. The cloud starts near the left end with a peak of 5.7. It repels itself, and at the time 0.5 it has spread over half of the dish, with a peak of 1.2, and leans towards the middle, away from the rim that is close to it. ## What pdemagic decided One equation in time and a constraint on a shape are stepped together (`element_stepping`), on 36 quadrilaterals of the degree 6 with 1 357 points. Each unknown has its own modes of the shape, from a dense eigenproblem. The diffusion of $n$ is exact in its modes, the drift is stepped, and at every evaluation of it the constraint is solved for $\varphi$ in the modes of $\varphi$. The plan says that this is the finest mesh on which the planner has a system stepped, and that it holds the start to $5\cdot10^{-3}$ of its size. The example loosens the tolerance of a step to $10^{-5}$, which is in keeping with that and takes 20 steps. ## More - [Systems of equations](../topics/systems.md) - [Shapes in the plane](../topics/regions.md) - [Elements in time, the method](../methods/elements-in-time.md) - [What is solved on regions](../ref/equations-regions.md)