.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/statphys/potts_model/plot_potts_order_of_transition.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_statphys_potts_model_plot_potts_order_of_transition.py: First- versus second-order transitions in the q-state Potts model ===================================================================== The Potts model generalizes the Ising model (:math:`q=2`) to :math:`q` discrete states per site: each site of a periodic :math:`L \times L` lattice carries a state :math:`s_i \in \{0, \ldots, q-1\}`, and the Hamiltonian rewards neighboring sites for matching, .. math:: H = -J \sum_{\langle i,j \rangle} \delta(s_i, s_j), where :math:`\delta` is the Kronecker delta. On the square lattice, the Baxter exact solution predicts that the transition, at the exact critical temperature :math:`T_C = J / (k_B \ln(1+\sqrt{q}))`, stays second order (continuous) for :math:`q \le 4` but becomes first order (discontinuous) for :math:`q > 4` -- the order parameter jumps abruptly rather than vanishing smoothly. This example compares :math:`q=3` (second order) against :math:`q=8` (first order) by sweeping temperature through each model's :math:`T_C`. .. GENERATED FROM PYTHON SOURCE LINES 23-29 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from physicskit.statphys.chapters.ising_lattice import PottsModel2D .. GENERATED FROM PYTHON SOURCE LINES 30-32 Sweep both models across their respective critical points ------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 32-49 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(10, 4), sharey=True) for ax, q in zip(axes, [3, 8]): model = PottsModel2D(L=32, q=q, J=1.0, kB=1.0, seed=0) temperatures = np.linspace(model.T_C + 0.6, max(model.T_C - 0.6, 0.05), 20) result = model.run_temperature_sweep(temperatures, n_equil=150, n_measure=200) ax.plot(result["T"], result["m"], marker="o", ms=3) ax.axvline(model.T_C, color="k", linestyle="--", linewidth=1, alpha=0.6, label="$T_C$") ax.set_xlabel("Temperature") ax.set_title(f"q = {q} ({'2nd' if q <= 4 else '1st'} order)") ax.legend() axes[0].set_ylabel("order parameter $m$") plt.suptitle("Potts model order parameter: continuous vs. discontinuous onset") plt.tight_layout() .. image-sg:: /api/gallery/statphys/potts_model/images/sphx_glr_plot_potts_order_of_transition_001.png :alt: Potts model order parameter: continuous vs. discontinuous onset, q = 3 (2nd order), q = 8 (1st order) :srcset: /api/gallery/statphys/potts_model/images/sphx_glr_plot_potts_order_of_transition_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 50-59 Energy histograms at T_C: the microscopic fingerprint of the order ------------------------------------------------------------------------ A first-order transition means the ordered and disordered phases coexist at T_C with a nonzero latent heat between them, so a system held exactly at T_C spends time in *both* phases and its energy histogram is bimodal (two peaks separated by a gap, one per phase). A continuous transition has no latent heat and no phase coexistence, so its energy histogram at T_C stays a single, unimodal peak. Sampling many energies at each model's own T_C makes this qualitative distinction directly visible. .. GENERATED FROM PYTHON SOURCE LINES 59-75 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(10, 4), sharey=True) for ax, q in zip(axes, [3, 8]): model = PottsModel2D(L=32, q=q, J=1.0, kB=1.0, seed=1) beta_c = 1.0 / model.T_C model.sweep(beta_c, n_sweeps=300) # equilibrate at T_C energies = np.empty(400) for i in range(400): model.sweep(beta_c, n_sweeps=5) energies[i] = model.energy() / model.n_sites ax.hist(energies, bins=30, color="steelblue", edgecolor="white") ax.set_xlabel("energy per site") ax.set_title(f"q = {q} ({'2nd order' if q <= 4 else '1st order'}) at $T_C$") axes[0].set_ylabel("count") plt.suptitle("Energy distribution at $T_C$: coexistence signature of a first-order transition") plt.tight_layout() plt.show() .. image-sg:: /api/gallery/statphys/potts_model/images/sphx_glr_plot_potts_order_of_transition_002.png :alt: Energy distribution at $T_C$: coexistence signature of a first-order transition, q = 3 (2nd order) at $T_C$, q = 8 (1st order) at $T_C$ :srcset: /api/gallery/statphys/potts_model/images/sphx_glr_plot_potts_order_of_transition_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.640 seconds) .. _sphx_glr_download_api_gallery_statphys_potts_model_plot_potts_order_of_transition.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_potts_order_of_transition.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_potts_order_of_transition.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_potts_order_of_transition.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_