{
 "nbformat": 4,
 "nbformat_minor": 5,
 "metadata": {
  "kernelspec": {
   "name": "python3",
   "language": "python",
   "display_name": "Python 3"
  },
  "language_info": {
   "name": "python"
  },
  "fundamentals": {
   "title": "Can two ohmic layers imitate a relaxing dielectric?",
   "lead": "Model a film and its contact layer in series. Derive the frequency scale of interfacial charge accumulation and decide which features of a measured spectrum can arise from geometry alone.",
   "unit_slug": "interfacial-polarisation-in-leaky-layers"
  }
 },
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5a3394ac32d6",
   "metadata": {},
   "source": [
    "# Can two ohmic layers imitate a relaxing dielectric?\n",
    "\n",
    "Model a film and its contact layer in series. Derive the frequency scale of interfacial charge accumulation and decide which features of a measured spectrum can arise from geometry alone."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fed07aa9844d",
   "metadata": {
    "fundamentals": {
     "section": "derive-the-model"
    }
   },
   "source": [
    "## Match total current at a leaky interface\n",
    "\n",
    "Take harmonic fields proportional to $e^{i\\omega t}$. In layer $j$, Ohm's law and Maxwell's displacement current give $J=Y_j E_j$ with $Y_j=\\sigma_j+i\\omega\\epsilon_j$. Use absolute permittivity in SI units. Total current is continuous across the interface. If the first layer occupies thickness fraction $f$, the imposed mean field is\n",
    "\n",
    "$$\n",
    "\\bar E=fE_1+(1-f)E_2.\n",
    "$$\n",
    "\n",
    "Eliminating the layer fields yields\n",
    "\n",
    "$$Y_{\\rm eff}=\\frac{Y_1Y_2}{fY_2+(1-f)Y_1},\\qquad\n",
    "\\tau=\\frac{f\\epsilon_2+(1-f)\\epsilon_1}{f\\sigma_2+(1-f)\\sigma_1}.$$\n",
    "\n",
    "The denominator is proportional to $1+i\\omega\\tau$. A pole has appeared even though each material has frequency-independent conductivity and permittivity. The free interfacial charge per unit area is $\\epsilon_2 E_2-\\epsilon_1 E_1$ with the normal from layer 1 to layer 2. At low frequency the less conducting layer takes a larger field. At high frequency the displacement currents determine the field sharing."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5618848f88e2",
   "metadata": {
    "fundamentals": {
     "section": "worked-prediction"
    }
   },
   "source": [
    "## Separate dielectric storage from direct conduction\n",
    "\n",
    "Infer the relative storage permittivity as $\\operatorname{Im}(Y_{\\rm eff})/(\\omega\\epsilon_0)$. A DC current is real and drops out of this quantity. For layers with the same relative permittivity, their high-frequency effective value must equal that common value. In the DC limit the effective conductivity is the thickness-weighted harmonic mean. These two checks are independent. The interface can nevertheless produce a large rise in apparent storage on the low-frequency side.\n",
    "Use a first layer that fills 20% of the gap and has conductivity $10^{-8}$ S/m. Give the other layer conductivity $10^{-6}$ S/m and both layers relative permittivity 4. The DC conductivity is $4.81\\times10^{-8}$ S/m. An applied mean field of 1000 V/m therefore drives $4.81\\times10^{-5}$ A/m². The weakly conducting layer needs about 4808 V/m to carry it and the second layer only 48.1 V/m. Their thickness-weighted mean recovers the imposed field.\n",
    "\n",
    "The time constant is 0.170 ms, corresponding to 935 Hz. Expanding the two complex conductivities to first order in frequency gives the low-frequency relative storage permittivity\n",
    "\n",
    "$$4[f\\sigma_2^2+(1-f)\\sigma_1^2]/[f\\sigma_2+(1-f)\\sigma_1]^2=18.50.$$\n",
    "\n",
    "At high frequency it falls to 4. Make the conductivities equal in the notebook and predict the interfacial charge before running it. The denominator still defines a time scale algebraically but its pole cancels out of the measured admittance."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db478ec3199f",
   "metadata": {
    "fundamentals": {
     "section": "choose-inputs",
     "notebook_only": true
    }
   },
   "source": [
    "## Set the experimental inputs\n",
    "\n",
    "Edit these values, then run the calculation and both figures again."
   ]
  },
  {
   "cell_type": "code",
   "id": "142930ac6fc4",
   "metadata": {},
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "teal, orange, blue = \"#19596a\", \"#aa462a\", \"#3868a0\"\n",
    "def axes(xlabel, ylabel):\n",
    "    fig, ax = plt.subplots(figsize=(7, 4), constrained_layout=True)\n",
    "    ax.set(xlabel=xlabel, ylabel=ylabel)\n",
    "    ax.grid(alpha=0.2)\n",
    "    return fig, ax"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "id": "23a0c773f1ba",
   "metadata": {},
   "source": [
    "fraction = .20\n",
    "sigma1, sigma2 = 1.e-8, 1.e-6   # S/m\n",
    "er1, er2 = 4., 4.\n",
    "mean_field = 1000.                # V/m"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "id": "7dfa96a95f5e",
   "metadata": {},
   "source": [
    "eps0=8.8541878128e-12\n",
    "eps1,eps2=er1*eps0,er2*eps0\n",
    "assert 0<fraction<1 and min(sigma1,sigma2,eps1,eps2)>0\n",
    "tau=(fraction*eps2+(1-fraction)*eps1)/(fraction*sigma2+(1-fraction)*sigma1)\n",
    "f_relax=1/(2*np.pi*tau)\n",
    "def layers(freq):\n",
    "    w=2*np.pi*np.asarray(freq)\n",
    "    y1,y2=sigma1+1j*w*eps1,sigma2+1j*w*eps2\n",
    "    eff=1/(fraction/y1+(1-fraction)/y2)\n",
    "    return eff,eff*mean_field/y1,eff*mean_field/y2\n",
    "assert np.isclose(layers(0)[0].real,1/(fraction/sigma1+(1-fraction)/sigma2),atol=1e-16)\n",
    "print(f\"Interfacial relaxation frequency {f_relax:.2f} Hz\")"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "id": "8871137a3766",
   "metadata": {
    "fundamentals": {
     "figure": {
      "file": "electrodynamics-material-response-1.png",
      "alt": "The apparent relative permittivity passes from a large low-frequency plateau to the series capacitance limit.",
      "caption": "Use the measured transition frequency and a thickness series to distinguish interfacial storage from an intrinsic molecular relaxation."
     }
    }
   },
   "source": [
    "freq=f_relax*np.geomspace(.001,1000,300)\n",
    "eff,e1,e2=layers(freq)\n",
    "fig,ax=axes(\"Frequency (Hz)\",\"Apparent storage permittivity / ε₀\")\n",
    "ax.semilogx(freq,eff.imag/(2*np.pi*freq*eps0),color=teal)\n",
    "ax.axvline(f_relax,color=orange,ls=\"--\",label=\"Interfacial relaxation\")\n",
    "ax.legend()\n",
    "plt.show()"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "id": "e3df87edc5e6",
   "metadata": {
    "fundamentals": {
     "notebook_only": true
    }
   },
   "source": [
    "Use the measured transition frequency and a thickness series to distinguish interfacial storage from an intrinsic molecular relaxation."
   ]
  },
  {
   "cell_type": "code",
   "id": "c4e7b2ee4d2d",
   "metadata": {
    "fundamentals": {
     "figure": {
      "file": "electrodynamics-material-response-2.png",
      "alt": "The electric field is divided unequally between two leaky layers at low frequency and repartitions at high frequency.",
      "caption": "Each curve is an amplitude. Add the complex fields with their phases before checking that the thickness-weighted average equals the applied field."
     }
    }
   },
   "source": [
    "fig,ax=axes(\"Frequency (Hz)\",\"Layer field amplitude / imposed amplitude\")\n",
    "ax.semilogx(freq,abs(e1/mean_field),label=\"Layer 1\",color=teal)\n",
    "ax.semilogx(freq,abs(e2/mean_field),label=\"Layer 2\",color=orange)\n",
    "ax.legend()\n",
    "assert np.allclose(fraction*e1+(1-fraction)*e2,mean_field)\n",
    "plt.show()"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "id": "cdc03ace36e1",
   "metadata": {
    "fundamentals": {
     "notebook_only": true
    }
   },
   "source": [
    "Each curve is an amplitude. Add the complex fields with their phases before checking that the thickness-weighted average equals the applied field."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ace651af624",
   "metadata": {
    "fundamentals": {
     "section": "problem-1"
    }
   },
   "source": [
    "## Exercise · remove the relaxation\n",
    "\n",
    "Which choice of layer properties makes the interfacial charge vanish for every frequency?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "684b107acf51",
   "metadata": {
    "fundamentals": {
     "solution": true
    }
   },
   "source": [
    "The charge vanishes if $\\epsilon_2/Y_2=\\epsilon_1/Y_1$. The imaginary terms cancel identically after cross multiplication, leaving $\\epsilon_2\\sigma_1=\\epsilon_1\\sigma_2$. The two dielectric relaxation times are then equal. Check the limit by making both layers identical."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f33212e34345",
   "metadata": {
    "fundamentals": {
     "section": "problem-2"
    }
   },
   "source": [
    "## Exercise · exchange the materials\n",
    "\n",
    "Relabel the layers and their thickness fractions. Which measurements can distinguish the order of this stack?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99de1e3e2c44",
   "metadata": {
    "fundamentals": {
     "solution": true
    }
   },
   "source": [
    "The two-terminal admittance is unchanged under $(1,2,f)\\mapsto(2,1,1-f)$. It cannot identify which material is nearer the upper electrode. A local field measurement at a known depth or a contact-specific measurement can distinguish the configurations."
   ]
  }
 ]
}
