.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_gallery/accuracy/plot_density_scaling.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_auto_gallery_accuracy_plot_density_scaling.py: Linear density scaling against Lorentz-Lorenz ============================================= The refractive index of a gas at number density :math:`N` follows from the per-particle polarizability :math:`\alpha` through the Lorentz-Lorenz relation. The linear scaling :math:`\chi = N\alpha/\varepsilon_0` is its dilute limit. This figure shows the relative error of linear scaling in :math:`\chi = n^2 - 1` against pressure, for a polarizability typical of each gas. The polarizabilities are illustrative round numbers (atomic units), not curated data: the error depends only on :math:`\chi` itself, :math:`1/(1-y) - 1` with :math:`y = N\alpha/(3\varepsilon_0)`. .. GENERATED FROM PYTHON SOURCE LINES 21-44 .. image-sg:: /auto_gallery/accuracy/images/sphx_glr_plot_density_scaling_001.svg :alt: plot density scaling :srcset: /auto_gallery/accuracy/images/sphx_glr_plot_density_scaling_001.svg :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from optmat.conditions import State from optmat.constants import AU_POLARIZABILITY, BAR from optmat.gas.eos import number_density from optmat.gas.lorentz_lorenz import susceptibility, susceptibility_dilute pressures = np.geomspace(0.1, 150.0, 60) # bar fig, ax = plt.subplots(figsize=(6, 4), layout="constrained") for gas, alpha_au in [("He", 1.4), ("Ar", 11.1), ("Xe", 27.3)]: errors = [] for p in pressures: density = number_density(gas, State(p * BAR, 293.15)) alpha = alpha_au * AU_POLARIZABILITY exact = susceptibility(alpha, density) errors.append(1 - susceptibility_dilute(alpha, density) / exact) ax.loglog(pressures, errors, label=f"{gas} (alpha = {alpha_au} a.u.)") ax.set_xlabel("pressure (bar), 20 °C, real gas") ax.set_ylabel("relative error of linear scaling in χ") ax.legend() ax.grid(which="both", alpha=0.3) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.437 seconds) .. _sphx_glr_download_auto_gallery_accuracy_plot_density_scaling.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_density_scaling.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_density_scaling.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_density_scaling.zip `