.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/fields/matter/plot_dielectric_and_magnetized_spheres.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_fields_matter_plot_dielectric_and_magnetized_spheres.py: Faraday's polarized dielectric: bound charge in a sphere, and its magnetic twin =============================================================================== Faraday's picture of a dielectric (1837) was a material whose particles become small dipoles in an applied field. Mossotti (1850) and Clausius (1879) made it quantitative. The dipoles add up to a polarization :math:`\mathbf P`, which acts like a *bound charge* :math:`\rho_b = -\nabla\cdot\mathbf P` that partly screens the applied field. A sphere of permittivity :math:`\varepsilon_r` in a uniform field :math:`E_0` is the classic case (Griffiths Example 4.7). Its interior field is uniform and reduced, .. math:: E_{\rm in} = \frac{3E_0}{\varepsilon_r + 2}, and outside it adds the field of a point dipole :math:`p = 4\pi\varepsilon_0 a^3\,\frac{\varepsilon_r - 1}{\varepsilon_r + 2}\,E_0`. The local field the Clausius–Mossotti relation rests on is this same :math:`(\varepsilon_r + 2)/3` factor. The magnetic counterpart is a uniformly magnetized sphere (Griffiths Example 6.1). Its bound "magnetic charge" :math:`\nabla\cdot\mathbf M` on the surface gives a uniform interior :math:`\mathbf H = -\mathbf M/3`, so :math:`\mathbf B = \tfrac23\mu_0\mathbf M`. Here :func:`~physicskit.fields.solve_poisson_dielectric`, :func:`~physicskit.fields.bound_charge_density` and :func:`~physicskit.fields.magnetized_body_field` reproduce all three. .. GENERATED FROM PYTHON SOURCE LINES 32-40 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from physicskit.fields import bound_charge_density, magnetized_body_field, solve_poisson_dielectric from physicskit.fields.electrodynamics import EPS0, MU0 from physicskit.fields.electrostatics import electric_field_from_potential .. GENERATED FROM PYTHON SOURCE LINES 41-45 A dielectric sphere in a uniform field -------------------------------------- The box faces hold the exact exterior potential, and the grid solves for everything inside. .. GENERATED FROM PYTHON SOURCE LINES 45-64 .. code-block:: Python E0, a, eps_r = 1.0, 0.5, 4.0 x = np.linspace(-1, 1, 49) h = x[1] - x[0] X, Y, Z = np.meshgrid(x, x, x, indexing="ij") r = np.sqrt(X**2 + Y**2 + Z**2) eps = np.where(r < a, eps_r, 1.0) K = (eps_r - 1) / (eps_r + 2) phi0 = -E0 * Z + K * E0 * a**3 * Z / np.maximum(r, 1e-12) ** 3 sol = solve_poisson_dielectric(np.zeros_like(X), eps, h, phi0=phi0, tol=1e-10) E = electric_field_from_potential(sol.phi, h) inside = r < 0.35 E_in = np.mean(E[2][inside]) rho_b = bound_charge_density(sol.phi, eps, h) p = np.sum(Z * rho_b) * h**3 p_exact = 4 * np.pi * EPS0 * a**3 * K * E0 print(f"interior E_z = {E_in:.4f}, 3 E0/(eps_r + 2) = {3 * E0 / (eps_r + 2):.4f}") print(f"bound-charge dipole p = {p:.4e} C m, closed form {p_exact:.4e}") .. rst-class:: sphx-glr-script-out .. code-block:: none interior E_z = 0.5054, 3 E0/(eps_r + 2) = 0.5000 bound-charge dipole p = 7.2581e-12 C m, closed form 6.9541e-12 .. GENERATED FROM PYTHON SOURCE LINES 65-67 A uniformly magnetized sphere ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 67-103 .. code-block:: Python xm = np.linspace(-1, 1, 65) hm = xm[1] - xm[0] Xm, Ym, Zm = np.meshgrid(xm, xm, xm, indexing="ij") rm = np.sqrt(Xm**2 + Ym**2 + Zm**2) M0, R = 1e5, 0.3 M = np.zeros((3, *Xm.shape)) M[2] = np.where(rm < R, M0, 0.0) B, H = magnetized_body_field(M, hm) inside_m = rm < 0.2 B_in = np.mean(B[2][inside_m]) H_in = np.mean(H[2][inside_m]) print(f"interior B_z / (mu0 M) = {B_in / (MU0 * M0):.4f} (2/3), H_z / M = {H_in / M0:.4f} (-1/3)") fig, axes = plt.subplots(1, 3, figsize=(15, 4.5)) k = len(x) // 2 axes[0].imshow(rho_b[:, k, :].T, origin="lower", extent=[-1, 1, -1, 1], cmap="RdBu_r") axes[0].add_patch(plt.Circle((0, 0), a, fill=False, color="k", ls="--")) axes[0].set_title(r"bound charge $\rho_b = -\nabla\cdot P$ (y = 0)") axes[1].plot(x, E[2][k, k, :], "o", ms=4, label=r"grid $E_z$ on the z axis") Ez_exact = np.where(np.abs(x) < a, 3 * E0 / (eps_r + 2), E0 * (1 + 2 * K * a**3 / np.maximum(np.abs(x), 1e-12) ** 3)) axes[1].plot(x, Ez_exact, "k-", label="Griffiths Ex. 4.7") axes[1].set_xlabel("z") axes[1].set_title(rf"dielectric sphere, $\varepsilon_r = {eps_r:g}$") axes[1].legend(fontsize=8) km = len(xm) // 2 axes[2].plot(xm, B[2][km, km, :] / (MU0 * M0), "o", ms=4, label=r"$B_z/\mu_0M$") axes[2].plot(xm, H[2][km, km, :] / M0, "s", ms=4, label=r"$H_z/M$") axes[2].axhline(2 / 3, color="k", ls=":") axes[2].axhline(-1 / 3, color="k", ls=":") axes[2].set_xlabel("z") axes[2].set_title("magnetized sphere") axes[2].legend(fontsize=8) fig.tight_layout() plt.show() .. image-sg:: /api/gallery/fields/matter/images/sphx_glr_plot_dielectric_and_magnetized_spheres_001.png :alt: bound charge $\rho_b = -\nabla\cdot P$ (y = 0), dielectric sphere, $\varepsilon_r = 4$, magnetized sphere :srcset: /api/gallery/fields/matter/images/sphx_glr_plot_dielectric_and_magnetized_spheres_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none interior B_z / (mu0 M) = 0.6728 (2/3), H_z / M = -0.3272 (-1/3) .. GENERATED FROM PYTHON SOURCE LINES 104-109 Check ----- Interior field 3 E0/(eps_r + 2); the bound charge is neutral and carries the closed-form dipole; the magnetized sphere has B = (2/3) mu0 M and H = -M/3 inside. .. GENERATED FROM PYTHON SOURCE LINES 109-115 .. code-block:: Python assert sol.converged assert abs(E_in / (3 * E0 / (eps_r + 2)) - 1) < 0.03 assert abs(np.sum(rho_b) * h**3) < 1e-6 * p_exact / a assert abs(p / p_exact - 1) < 0.05 assert abs(B_in / (2 / 3 * MU0 * M0) - 1) < 0.03 assert abs(H_in / (-M0 / 3) - 1) < 0.05 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.341 seconds) .. _sphx_glr_download_api_gallery_fields_matter_plot_dielectric_and_magnetized_spheres.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_dielectric_and_magnetized_spheres.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_dielectric_and_magnetized_spheres.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_dielectric_and_magnetized_spheres.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_