A lens of glass¶
The field between two charges, drawn into a piece of glass that lies beside the straight way from one to the other.
import numpy as np
import sympy as sp
import pdemagic as pm
x, y = sp.symbols("x y", real=True)
phi = sp.Function("phi")(x, y)
charges = sp.exp(-((x - 3) ** 2 + y**2)) - sp.exp(-((x + 3) ** 2 + y**2))
glass = 1 + 9 * sp.exp(-(x**2 + (y - 1.5) ** 2 / 2))
lens = pm.Problem(
sp.Eq(pm.div(glass * pm.grad(phi)), -charges), domain=pm.FreeSpace(x, y)
)
bent = pm.solve(lens)
axes = bent.plot()
xs, ys = bent.axes
field_x, field_y = np.gradient(-bent[phi], xs, ys)
angles = np.linspace(0, 2 * np.pi, 24, endpoint=False)
starts = np.column_stack([3 + 1.2 * np.cos(angles), 1.2 * np.sin(angles)])
lines = {"color": "gray", "linewidth": 0.7, "broken_streamlines": False}
axes.streamplot(xs, ys, field_x.T, field_y.T, start_points=starts, **lines)
axes.set(xlim=(-6, 6), ylim=(-4.5, 4.5))
What it shows¶
Electrostatics in a medium: \(\nabla\cdot(\varepsilon\nabla\varphi) = -\rho\), with a permittivity \(\varepsilon\) that varies from place to place. It is one in vacuum and rises smoothly to ten in a lens of glass around the point \((0, 1.5)\), above the line that joins the two charges. The colours are the potential, and the lines follow the field from the positive charge to the negative one. They leave the charge evenly in all directions. Below the charges they run much as they would in vacuum. Above, the glass gathers them: a dielectric draws the field into itself.
What pdemagic decided¶
A permittivity that varies makes this an equation with coefficients
that vary, which is solved by an iteration on the solver for constant
coefficients (fourier_iterative). The planner put the box where the
charges have fallen off and the permittivity has settled to one, and
chose a grid of 256 by 230 points that resolves both. The picture shows
its middle. The iteration took 14 steps.