mirosh111000

Мірошниченко_ГЙМ_ПР№14-16

Dec 19th, 2025
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.70 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from scipy.signal import find_peaks
  4.  
  5. class ModelParams:
  6.     def __init__(self, tau_hg=1.0e-6):
  7.         self.phi_0g_star = 0.4
  8.         self.g_g = 12.0
  9.         self.M_g = 2.5e5
  10.         self.mu_g = 3.0e5
  11.         self.phi_1g_star = 3.0e-6
  12.         self.e_g = 3.6e-4
  13.         self.phi_2g = 5.6e-13
  14.         self.phi_3g = 3.0e-20
  15.         self.phi_0D_star = 5.0e-9
  16.         self.g_D = 2.0e-8
  17.         self.M_D = 0.0
  18.         self.mu_D = 1.65e-4
  19.         self.phi_1D_star = 1.0e-24
  20.         self.e_D = 6.0e-23
  21.         self.phi_gD = 1.0e-16
  22.         self.psi_gD = 1.0e-23
  23.         self.tau_hg = tau_hg
  24.  
  25. def _phi0_partial(phi0_star, g_m, M_m, eps):
  26.     return phi0_star + g_m * eps + 0.5 * M_m * (eps**2)
  27.  
  28. def _phi1(phi1_star, e_m, eps):
  29.     return phi1_star + 2.0 * e_m * eps
  30.  
  31. def calculate_I2_critical(h_g, epsilon_ii_e, N_D, p):
  32.     phi0g_part = _phi0_partial(p.phi_0g_star, p.g_g, p.M_g, epsilon_ii_e)
  33.     phi0D_part = _phi0_partial(p.phi_0D_star, p.g_D, p.M_D, epsilon_ii_e)
  34.  
  35.     phi1g = _phi1(p.phi_1g_star, p.e_g, epsilon_ii_e)
  36.     phi1D = _phi1(p.phi_1D_star, p.e_D, epsilon_ii_e)
  37.     if abs(phi1D) < 1e-50:
  38.         phi1D = 1e-50
  39.  
  40.     h = np.asarray(h_g, dtype=float)
  41.  
  42.     ratio_phi = p.phi_gD / phi1D
  43.     ratio_psi = p.psi_gD / phi1D
  44.  
  45.     term_h3 = (2.0 * (p.psi_gD**2) / phi1D - p.phi_3g) * (h**3)
  46.     term_h2 = (p.phi_2g - 3.0 * ratio_psi * p.phi_gD) * (h**2)
  47.  
  48.     term_h1_coeff = (
  49.         (p.phi_gD**2) / phi1D
  50.         - phi1g
  51.         - 2.0 * ratio_psi * phi0D_part
  52.         - 4.0 * (p.psi_gD**2) / (p.tau_hg * (phi1D**2)) * N_D
  53.     )
  54.     term_h1 = term_h1_coeff * h
  55.  
  56.     term_h0 = (
  57.         phi0g_part
  58.         + ratio_phi * phi0D_part
  59.         + 2.0 * p.psi_gD * p.phi_gD / (p.tau_hg * (phi1D**2)) * N_D
  60.     )
  61.  
  62.     numerator = -(term_h3 + term_h2 + term_h1 + term_h0)
  63.     denominator = 2.0 * p.mu_D * (ratio_phi - 2.0 * ratio_psi * h) + 2.0 * p.mu_g
  64.  
  65.     with np.errstate(divide="ignore", invalid="ignore", over="ignore"):
  66.         I2 = numerator / denominator
  67.  
  68.     invalid = (~np.isfinite(I2)) | (np.abs(denominator) < 1e-20) | (np.abs(I2) > 1e10)
  69.     if np.ndim(I2) == 0:
  70.         return float(I2) if not bool(invalid) else float("nan")
  71.     I2 = I2.astype(float, copy=False)
  72.     I2[invalid] = np.nan
  73.     return I2
  74.  
  75. def _pick_extrema(y, mode):
  76.     if y.size < 3:
  77.         return float("nan"), float("nan")
  78.  
  79.     y_safe = np.where(np.isfinite(y), y, -1e30)
  80.     peaks, _ = find_peaks(y_safe)
  81.     valleys, _ = find_peaks(-y_safe)
  82.  
  83.     y_max = float("nan")
  84.     y_min = float("nan")
  85.  
  86.     if peaks.size:
  87.         idx = int(peaks[0]) if mode == "first" else int(peaks[np.argmax(y_safe[peaks])])
  88.         y_max = float(y[idx]) if np.isfinite(y[idx]) else float("nan")
  89.  
  90.     if valleys.size:
  91.         idx = int(valleys[0]) if mode == "first" else int(valleys[np.argmin(y_safe[valleys])])
  92.         y_min = float(y[idx]) if np.isfinite(y[idx]) else float("nan")
  93.  
  94.     return y_max, y_min
  95.  
  96. def compute_diagram_a(eps_range, h_grid, p, extrema_mode):
  97.     upper = np.full_like(eps_range, np.nan, dtype=float)
  98.     lower = np.full_like(eps_range, np.nan, dtype=float)
  99.     hg0 = np.full_like(eps_range, np.nan, dtype=float)
  100.  
  101.     for i, eps in enumerate(eps_range):
  102.         y = calculate_I2_critical(h_grid, epsilon_ii_e=float(eps), N_D=0.0, p=p)
  103.         y_max, y_min = _pick_extrema(y, mode=extrema_mode)
  104.         upper[i] = y_max
  105.         lower[i] = y_min
  106.         hg0[i] = calculate_I2_critical(0.0, epsilon_ii_e=float(eps), N_D=0.0, p=p)
  107.  
  108.     return upper, lower, hg0
  109.  
  110. def compute_diagram_b(nd_range, epsilon_fixed, h_grid, p, extrema_mode):
  111.     upper = np.full_like(nd_range, np.nan, dtype=float)
  112.     lower = np.full_like(nd_range, np.nan, dtype=float)
  113.     hg0 = np.full_like(nd_range, np.nan, dtype=float)
  114.  
  115.     for i, nd in enumerate(nd_range):
  116.         y = calculate_I2_critical(h_grid, epsilon_ii_e=epsilon_fixed, N_D=float(nd), p=p)
  117.         y_max, y_min = _pick_extrema(y, mode=extrema_mode)
  118.         upper[i] = y_max
  119.         lower[i] = y_min
  120.         hg0[i] = calculate_I2_critical(0.0, epsilon_ii_e=epsilon_fixed, N_D=float(nd), p=p)
  121.  
  122.     return upper, lower, hg0
  123.  
  124. def build_figure_2_2(tau_hg, eps_min, eps_max, eps_points, nd_min, nd_max, nd_points, epsilon_fixed, hg_max, hg_points, extrema_mode, y_limit_a, y_limit_b):
  125.     p = ModelParams(tau_hg=tau_hg)
  126.  
  127.     eps_range = np.linspace(eps_min, eps_max, eps_points)
  128.     nd_range = np.linspace(nd_min, nd_max, nd_points)
  129.     h_grid = np.linspace(0.0, hg_max, hg_points)
  130.  
  131.     upper_a, lower_a, hg0_a = compute_diagram_a(
  132.         eps_range=eps_range,
  133.         h_grid=h_grid,
  134.         p=p,
  135.         extrema_mode=extrema_mode,
  136.     )
  137.     upper_b, lower_b, hg0_b = compute_diagram_b(
  138.         nd_range=nd_range,
  139.         epsilon_fixed=epsilon_fixed,
  140.         h_grid=h_grid,
  141.         p=p,
  142.         extrema_mode=extrema_mode,
  143.     )
  144.  
  145.     fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(11, 5.5), constrained_layout=True)
  146.  
  147.     x_a = eps_range * 1e3
  148.     ax1.plot(x_a, upper_a, color="tab:blue", linewidth=2.0)
  149.     ax1.plot(x_a, lower_a, color="tab:green", linewidth=2.0)
  150.     ax1.plot(x_a, hg0_a, color="tab:blue", linestyle=":", linewidth=2.0)
  151.     ax1.set_title("а)")
  152.     ax1.set_xlabel(r"$\epsilon_{ii}^e,\ \times 10^{-3}$")
  153.     ax1.set_ylabel(r"$I_2$")
  154.     ax1.set_ylim(-y_limit_a, y_limit_a)
  155.     ax1.grid(False)
  156.     ax1.ticklabel_format(style="sci", axis="y", scilimits=(0, 0))
  157.     ax1.ticklabel_format(style="sci", axis="x", scilimits=(0, 0))
  158.  
  159.     ax1.text(float(x_a.min() + 0.15 * (x_a.max() - x_a.min())), 0.55 * y_limit_a, "B", fontsize=14)
  160.     ax1.text(float(x_a.min() + 0.20 * (x_a.max() - x_a.min())), 0.15 * y_limit_a, "A", fontsize=14)
  161.     ax1.text(float(x_a.min() + 0.10 * (x_a.max() - x_a.min())), -0.45 * y_limit_a, "A*", fontsize=14)
  162.     ax1.text(float(x_a.min() + 0.25 * (x_a.max() - x_a.min())), -0.75 * y_limit_a, "B*", fontsize=14)
  163.  
  164.     x_b = nd_range * 1e15
  165.     ax2.plot(x_b, upper_b, color="tab:blue", linewidth=2.0)
  166.     ax2.plot(x_b, lower_b, color="tab:green", linewidth=2.0)
  167.     ax2.plot(x_b, hg0_b, color="tab:blue", linestyle=":", linewidth=2.0)
  168.     ax2.set_title("б)")
  169.     ax2.set_xlabel(r"$N_D,\ \mathrm{Дж}^2\cdot\mathrm{с}\cdot\mathrm{м}^{-2}\ \times 10^{-15}$")
  170.     ax2.set_ylabel(r"$I_2$")
  171.     ax2.set_ylim(-y_limit_b, y_limit_b)
  172.     ax2.grid(False)
  173.     ax2.ticklabel_format(style="sci", axis="y", scilimits=(0, 0))
  174.  
  175.     ax2.text(float(x_b.min() + 0.28 * (x_b.max() - x_b.min())), 0.55 * y_limit_b, "B", fontsize=14)
  176.     ax2.text(float(x_b.min() + 0.45 * (x_b.max() - x_b.min())), -0.01 * y_limit_b, "A", fontsize=14)
  177.     ax2.text(float(x_b.min() + 0.02 * (x_b.max() - x_b.min())), -0.35 * y_limit_b, "A*", fontsize=14)
  178.     ax2.text(float(x_b.min() + 0.45 * (x_b.max() - x_b.min())), -0.85 * y_limit_b, "B*", fontsize=14)
  179.  
  180.     plt.show()
  181.  
  182. def main():
  183.     CONFIG = {
  184.         "tau_hg": 1.0e-6,
  185.         "eps_min": -1.5e-3,
  186.         "eps_max": 1.0e-3,
  187.         "eps_points": 220,
  188.         "nd_min": 0.0,
  189.         "nd_max": 3.0e-15,
  190.         "nd_points": 180,
  191.         "eps_fixed": -1.0e-3,
  192.         "hg_max": 3.0e7,
  193.         "hg_points": 6000,
  194.         "extrema_mode": "best",
  195.         "y_limit_a": 1.5e-5,
  196.         "y_limit_b": 1.0e-5,
  197.     }
  198.  
  199.     build_figure_2_2(
  200.         tau_hg=CONFIG["tau_hg"],
  201.         eps_min=CONFIG["eps_min"],
  202.         eps_max=CONFIG["eps_max"],
  203.         eps_points=CONFIG["eps_points"],
  204.         nd_min=CONFIG["nd_min"],
  205.         nd_max=CONFIG["nd_max"],
  206.         nd_points=CONFIG["nd_points"],
  207.         epsilon_fixed=CONFIG["eps_fixed"],
  208.         hg_max=CONFIG["hg_max"],
  209.         hg_points=CONFIG["hg_points"],
  210.         extrema_mode=CONFIG["extrema_mode"],
  211.         y_limit_a=CONFIG["y_limit_a"],
  212.         y_limit_b=CONFIG["y_limit_b"],
  213.     )
  214.  
  215. if __name__ == "__main__":
  216.     main()
Advertisement
Add Comment
Please, Sign In to add comment