|
| 1 | +import numpy as np |
| 2 | +from ui_logger import log_message |
| 3 | +from ui_labels import ( |
| 4 | + SIGMA1_LABEL, SIGMA3_LABEL, SIGMA1_SIGMA3_DIFF_LABEL, VERTICAL_STRAIN_LABEL, |
| 5 | + VOLUMETRIC_STRAIN_LABEL, SHEAR_STRAIN_LABEL, SHEAR_STRESS_LABEL, EFFECTIVE_STRESS_LABEL, |
| 6 | + MOBILIZED_SHEAR_STRESS_LABEL, P_STRESS_LABEL, Q_STRESS_LABEL, TITLE_SIGMA1_VS_SIGMA3, |
| 7 | + TITLE_DIFF_PRINCIPAL_SIGMA_VS_STRAIN, TITLE_VOL_VS_VERT_STRAIN, TITLE_MOHR, TITLE_P_VS_Q, TITLE_SHEAR_VS_STRAIN, |
| 8 | + LEGEND_MC, LEGEND_MC_FAILURE |
| 9 | +) |
| 10 | + |
| 11 | + |
| 12 | +def plot_principal_stresses_triaxial(ax, sigma_1, sigma_3): |
| 13 | + ax.plot(sigma_3, sigma_1, '-', color='blue', label=TITLE_SIGMA1_VS_SIGMA3) |
| 14 | + ax.set_title(TITLE_SIGMA1_VS_SIGMA3) |
| 15 | + ax.set_xlabel(SIGMA3_LABEL) |
| 16 | + ax.set_ylabel(SIGMA1_LABEL) |
| 17 | + ax.grid(True) |
| 18 | + ax.locator_params(nbins=8) |
| 19 | + |
| 20 | + min_val = 0 |
| 21 | + max_val_x = max(sigma_3) |
| 22 | + max_val_y = min(sigma_1) |
| 23 | + padding_x = 0.1 * (max_val_x - min_val) |
| 24 | + padding_y = 0.1 * (max_val_y - min_val) |
| 25 | + ax.set_xlim(min_val, max_val_x + padding_x) |
| 26 | + ax.set_ylim(min_val, max_val_y + padding_y) |
| 27 | + ax.minorticks_on() |
| 28 | + |
| 29 | +def plot_delta_sigma_triaxial(ax, vertical_strain, sigma_diff): |
| 30 | + ax.plot(vertical_strain, sigma_diff, '-', color='blue', label=SIGMA1_SIGMA3_DIFF_LABEL) |
| 31 | + ax.set_title(TITLE_DIFF_PRINCIPAL_SIGMA_VS_STRAIN) |
| 32 | + ax.set_xlabel(VERTICAL_STRAIN_LABEL) |
| 33 | + ax.set_ylabel(SIGMA1_SIGMA3_DIFF_LABEL) |
| 34 | + ax.grid(True) |
| 35 | + ax.invert_xaxis() |
| 36 | + ax.locator_params(nbins=8) |
| 37 | + ax.minorticks_on() |
| 38 | + |
| 39 | +def plot_volumetric_vertical_strain_triaxial(ax, vertical_strain, volumetric_strain): |
| 40 | + ax.plot(vertical_strain, volumetric_strain, '-', color='blue', label=TITLE_VOL_VS_VERT_STRAIN) |
| 41 | + ax.set_title(TITLE_VOL_VS_VERT_STRAIN) |
| 42 | + ax.set_xlabel(VERTICAL_STRAIN_LABEL) |
| 43 | + ax.set_ylabel(VOLUMETRIC_STRAIN_LABEL) |
| 44 | + ax.grid(True) |
| 45 | + ax.invert_xaxis() |
| 46 | + ax.invert_yaxis() |
| 47 | + ax.locator_params(nbins=8) |
| 48 | + ax.minorticks_on() |
| 49 | + |
| 50 | +def plot_mohr_coulomb_triaxial(ax, sigma_1, sigma_3, cohesion=None, friction_angle=None): |
| 51 | + if np.isclose(sigma_1, sigma_3): |
| 52 | + log_message("σ₁ is equal to σ₃. Mohr circle collapses to a point.", "warn") |
| 53 | + center = (sigma_1 + sigma_3) / 2 |
| 54 | + radius = (sigma_1 - sigma_3) / 2 |
| 55 | + theta = np.linspace(0, np.pi, 200) |
| 56 | + sigma = center + radius * np.cos(theta) |
| 57 | + tau = -radius * np.sin(theta) |
| 58 | + |
| 59 | + ax.plot(sigma, tau, label=LEGEND_MC, color='blue') |
| 60 | + |
| 61 | + if cohesion is not None and friction_angle is not None: |
| 62 | + phi_rad = np.radians(friction_angle) |
| 63 | + x_line = np.linspace(0, sigma_1, 200) |
| 64 | + y_line = x_line * np.tan(phi_rad) - cohesion |
| 65 | + ax.plot(x_line, -y_line, 'r--', label=LEGEND_MC_FAILURE) |
| 66 | + ax.legend(loc='upper left') |
| 67 | + |
| 68 | + ax.set_title(LEGEND_MC) |
| 69 | + ax.set_xlabel(EFFECTIVE_STRESS_LABEL) |
| 70 | + ax.set_ylabel(MOBILIZED_SHEAR_STRESS_LABEL) |
| 71 | + ax.grid(True) |
| 72 | + ax.invert_xaxis() |
| 73 | + ax.set_xlim(left=0, right= 1.2*np.max(sigma_1)) |
| 74 | + ax.set_ylim(bottom=0, top = -0.6*np.max(sigma_1)) |
| 75 | + ax.minorticks_on() |
| 76 | + |
| 77 | +def plot_p_q_triaxial(ax, p_list, q_list): |
| 78 | + ax.plot(p_list, q_list, '-', color='blue', label=TITLE_P_VS_Q) |
| 79 | + ax.set_title(TITLE_P_VS_Q) |
| 80 | + ax.set_xlabel(P_STRESS_LABEL) |
| 81 | + ax.set_ylabel(Q_STRESS_LABEL) |
| 82 | + ax.grid(True) |
| 83 | + ax.invert_xaxis() |
| 84 | + ax.locator_params(nbins=8) |
| 85 | + ax.minorticks_on() |
| 86 | + |
| 87 | +def plot_principal_stresses_direct_shear(ax, sigma_1, sigma_3): |
| 88 | + ax.plot(sigma_3, sigma_1, '-', color='blue', label=TITLE_SIGMA1_VS_SIGMA3) |
| 89 | + ax.set_title(TITLE_SIGMA1_VS_SIGMA3) |
| 90 | + ax.set_xlabel(SIGMA3_LABEL) |
| 91 | + ax.set_ylabel(SIGMA1_LABEL) |
| 92 | + ax.grid(True) |
| 93 | + ax.locator_params(nbins=8) |
| 94 | + |
| 95 | + min_x, max_x = min(sigma_3), max(sigma_3) |
| 96 | + min_y, max_y = min(sigma_1), max(sigma_1) |
| 97 | + x_padding = 0.1 * (max_x - min_x) if max_x > min_x else 1.0 |
| 98 | + y_padding = 0.1 * (max_y - min_y) if max_y > min_y else 1.0 |
| 99 | + ax.set_xlim(min_x - x_padding, max_x + x_padding) |
| 100 | + ax.set_ylim(min_y - y_padding, max_y + y_padding) |
| 101 | + |
| 102 | + ax.invert_xaxis() |
| 103 | + ax.invert_yaxis() |
| 104 | + ax.minorticks_on() |
| 105 | + |
| 106 | +def plot_strain_stress_direct_shear(ax, shear_strain_xy, shear_stress_xy): |
| 107 | + gamma_xy = 2 * np.array(shear_strain_xy) |
| 108 | + ax.plot(np.abs(gamma_xy), np.abs(shear_stress_xy), '-', color='blue', label=TITLE_SHEAR_VS_STRAIN) |
| 109 | + ax.set_title(TITLE_SHEAR_VS_STRAIN) |
| 110 | + ax.set_xlabel(SHEAR_STRAIN_LABEL) |
| 111 | + ax.set_ylabel(SHEAR_STRESS_LABEL) |
| 112 | + ax.grid(True) |
| 113 | + ax.locator_params(nbins=8) |
| 114 | + ax.minorticks_on() |
| 115 | + |
| 116 | +def plot_mohr_coulomb_direct_shear(ax, sigma_1, sigma_3, cohesion=None, friction_angle=None): |
| 117 | + if np.isclose(sigma_1, sigma_3): |
| 118 | + log_message("σ₁ is equal to σ₃. Mohr circle collapses to a point.", "warn") |
| 119 | + center = (sigma_1 + sigma_3) / 2 |
| 120 | + radius = (sigma_1 - sigma_3) / 2 |
| 121 | + theta = np.linspace(0, np.pi, 400) |
| 122 | + sigma = center + radius * np.cos(theta) |
| 123 | + tau = -radius * np.sin(theta) |
| 124 | + |
| 125 | + ax.plot(sigma, tau, label=LEGEND_MC, color='blue') |
| 126 | + |
| 127 | + if cohesion is not None and friction_angle is not None: |
| 128 | + phi_rad = np.radians(friction_angle) |
| 129 | + max_sigma = center + radius |
| 130 | + x_line = np.linspace(0, max_sigma * 1.5, 400) |
| 131 | + y_line = x_line * np.tan(phi_rad) - cohesion |
| 132 | + ax.plot(x_line, -y_line, 'r--', label=LEGEND_MC_FAILURE) |
| 133 | + ax.legend(loc='upper left') |
| 134 | + |
| 135 | + ax.set_title(LEGEND_MC) |
| 136 | + ax.set_xlabel(EFFECTIVE_STRESS_LABEL) |
| 137 | + ax.set_ylabel(MOBILIZED_SHEAR_STRESS_LABEL) |
| 138 | + ax.grid(True) |
| 139 | + ax.invert_xaxis() |
| 140 | + |
| 141 | + epsilon = 0.1 |
| 142 | + relative_diff = np.abs(sigma_1 - sigma_3) / max(np.abs(sigma_1), 1e-6) |
| 143 | + |
| 144 | + if relative_diff < epsilon: |
| 145 | + ax.set_xlim(center - (1.2 * radius), center + (1.2 * radius)) |
| 146 | + ax.set_ylim(bottom=0, top = -0.9*(np.max(sigma_1) - np.max(sigma_3))) |
| 147 | + |
| 148 | + else: |
| 149 | + if sigma_1 > 0 or sigma_3 > 0: |
| 150 | + ax.set_xlim(left=1.2*np.max(sigma_3), right=1.2*np.max(sigma_1)) |
| 151 | + ax.set_ylim(bottom=0, top = -0.9*(np.max(sigma_1) - np.max(sigma_3))) |
| 152 | + else: |
| 153 | + ax.set_xlim(left=0, right=1.2*np.max(sigma_1)) |
| 154 | + ax.set_ylim(bottom=0, top = -0.9*np.max(sigma_1)) |
| 155 | + |
| 156 | + |
| 157 | + ax.minorticks_on() |
| 158 | + |
| 159 | +def plot_p_q_direct_shear(ax, p_list, q_list): |
| 160 | + ax.plot(p_list, q_list, '-', color='blue', label=TITLE_P_VS_Q) |
| 161 | + ax.set_title(TITLE_P_VS_Q) |
| 162 | + ax.set_xlabel(P_STRESS_LABEL) |
| 163 | + ax.set_ylabel(Q_STRESS_LABEL) |
| 164 | + ax.grid(True) |
| 165 | + ax.invert_xaxis() |
| 166 | + ax.set_xlim(left=0, right=1.2*np.max(p_list)) |
| 167 | + ax.locator_params(nbins=8) |
| 168 | + ax.minorticks_on() |
0 commit comments