{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0b852abb",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import os\n",
    "from matplotlib import rcParams\n",
    "\n",
    "def read_file(filename):\n",
    "    return np.loadtxt(filename, dtype=float)\n",
    "\n",
    "def calculate_max_principal_stress(sigma_xx, sigma_yy, tau_xy):\n",
    "    term1 = (sigma_xx + sigma_yy) / 2\n",
    "    term2 = np.sqrt(((sigma_xx - sigma_yy) / 2) ** 2 + tau_xy ** 2)\n",
    "    return term1 + term2\n",
    "\n",
    "def normalize_stresses(max_stresses, coordinates):\n",
    "    max_y = np.max(coordinates[:, 1])\n",
    "    top_indices = np.where(coordinates[:, 1] >= 0.99*max_y)\n",
    "    average_stress_at_top = np.mean(max_stresses[top_indices])\n",
    "    normalized_stresses = max_stresses / average_stress_at_top\n",
    "    return normalized_stresses\n",
    "\n",
    "def plot_stress_map(coordinates, stress_values, max_value,save_path):\n",
    "    plt.figure(figsize=(4, 3))\n",
    "    sc = plt.scatter(coordinates[:, 0], coordinates[:, 1], c=stress_values, cmap='viridis', marker='o', vmin=0, vmax=max_value,s=0.5)\n",
    "    plt.colorbar(sc)\n",
    "    #plt.xticks([])  # Disable x-axis labels\n",
    "    #plt.yticks([])  # Disable y-axis labels\n",
    "    #plt.savefig(save_path, format='pdf')  # Save the figure as a PDF\n",
    "    plt.show()  # Display the figure\n",
    "    plt.close()  # Close the figure to free memory\n",
    "    \n",
    "def plot_stress_map_2(coordinates, stress_values, max_value,midpoints,midpoints_2):\n",
    "    xdata=np.transpose(midpoints)[0]\n",
    "    ydata=np.transpose(midpoints)[1]\n",
    "    xdata_2=np.transpose(midpoints_2)[0]\n",
    "    ydata_2=np.transpose(midpoints_2)[1]\n",
    "    zdata=np.ones(len(xdata))\n",
    "    \n",
    "    plt.figure(figsize=(4, 3))\n",
    "    sc = plt.scatter(coordinates[:, 0], coordinates[:, 1], c=stress_values, cmap='viridis', marker='o', vmin=0, vmax=max_value,s=0.5)\n",
    "    plt.colorbar(sc)\n",
    "    plt.scatter(xdata,ydata,c=zdata,cmap='viridis',marker='o',s=5)\n",
    "    plt.scatter(xdata_2,ydata_2,c=zdata,cmap='Reds',marker='o',s=5)\n",
    "    #plt.xticks([])  # Disable x-axis labels\n",
    "    #plt.yticks([])  # Disable y-axis labels\n",
    "    #plt.savefig(save_path, format='pdf')  # Save the figure as a PDF\n",
    "    plt.show()  # Display the figure\n",
    "    #plt.close()  # Close the figure to free memory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "05b6e142",
   "metadata": {},
   "outputs": [],
   "source": [
    "delta_list=np.array([0.01,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5])*5\n",
    "theta_list = np.array([0,15,30,45,60,75,90])*np.pi/180\n",
    "midpoint_list = []\n",
    "midpoint_list_2 = []\n",
    "for delta in delta_list:\n",
    "    for theta in theta_list:\n",
    "        point = calculate_midpoints(delta,theta)\n",
    "        point_2 = calculate_midpoints_2(delta,theta)\n",
    "        midpoint_list.append(point)\n",
    "        midpoint_list_2.append(point_2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "338acc56",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 62064 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62040 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62508 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62672 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62504 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62848 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62760 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62416 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62656 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62776 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62736 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 63012 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62848 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 63192 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62856 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62832 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62944 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 63684 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64208 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64008 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 63928 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62476 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62844 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64392 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64404 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64624 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64508 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64508 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 61320 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62556 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 63376 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64984 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64452 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64568 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64496 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 60612 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 61292 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 63000 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 63600 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 65100 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64432 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64668 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 60232 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 61324 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 61968 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 63896 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64372 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64588 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64316 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 60264 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 60564 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62812 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 63564 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64948 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64252 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64496 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 59712 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 60940 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 61944 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64312 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64196 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64112 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 63816 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 60120 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 61292 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62824 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 63404 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 65320 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64224 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 63964 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 60092 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62140 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 61980 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64220 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64652 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64132 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 63032 characters]",
      "text/plain": [
       "<Figure size 400x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "for i in range(len(midpoint_list)):\n",
    "    coord_file = coord_files[i+1]\n",
    "    data_file = data_files[i+1]\n",
    "    \n",
    "    coordinates = read_file(coord_file)\n",
    "    data = read_file(data_file)\n",
    "    \n",
    "    # Extracting stress components\n",
    "    sigma_xx = data[:, 0]\n",
    "    sigma_yy = data[:, 1]\n",
    "    tau_xy = data[:, 3]\n",
    "    \n",
    "    # Calculating max principal stress\n",
    "    max_stress = calculate_max_principal_stress(sigma_xx, sigma_yy, tau_xy)\n",
    "    \n",
    "    # Normalizing the max principal stresses\n",
    "    normalized_stress = normalize_stresses(max_stress, coordinates)\n",
    "    \n",
    "    # Define save path for the PDF\n",
    "    save_path = os.path.join(folder_3, f'{os.path.splitext(os.path.basename(coord_file))[0]}_stress_map.pdf')\n",
    "    \n",
    "    # Plotting with interpolated color scale and saving to PDF\n",
    "    plot_stress_map_2(coordinates, normalized_stress, MAXVALUE, midpoint_list[i],midpoint_list_2[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "61d8152f",
   "metadata": {},
   "outputs": [],
   "source": [
    "dlist = [1,2,2,1,1,1,1,2,1,1,2,1,1,1,1,2,1,2,1,2,1,1,2,1,2,1,2,1,2,1,2,1,2,1,1,1,2,1,2,1,2,1,2,1,2,1,2,1,1,1,2,1,2,1,2,1,2,1,2,1,2,2,1,1,2,1,2,1,2,1,2,1,2,1,2,1,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "a224b3c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "stress_max = []\n",
    "rtest=0.5\n",
    "for i in range(len(midpoint_list)):\n",
    "    coord_file = coord_files[i+1]\n",
    "    data_file = data_files[i+1]\n",
    "    \n",
    "    coordinates = read_file(coord_file)\n",
    "    data = read_file(data_file)\n",
    "    \n",
    "    # Extracting stress components\n",
    "    sigma_xx = data[:, 0]\n",
    "    sigma_yy = data[:, 1]\n",
    "    tau_xy = data[:, 3]\n",
    "    \n",
    "    # Calculating max principal stress\n",
    "    max_stress = calculate_max_principal_stress(sigma_xx, sigma_yy, tau_xy)\n",
    "    \n",
    "    # First, calculate averages within r = 0.1 around points in midpoint_list[i]\n",
    "    midpoints = midpoint_list[i]\n",
    "    midpoint_stress_list_small_r = []\n",
    "    for midpoint in midpoints:\n",
    "        stress = calculate_stresses(midpoint[0], midpoint[1], 0.1, max_stress, coordinates)\n",
    "        midpoint_stress_list_small_r.append(stress)\n",
    "    \n",
    "    # Check if any of the averages are NaN\n",
    "    if np.any(np.isnan(midpoint_stress_list_small_r)):\n",
    "        # Use midpoint_list_2[i] and calculate averages within r = 0.5\n",
    "        midpoints_alt = midpoint_list_2[i]\n",
    "        midpoint_stress_list_large_r = []\n",
    "        for midpoint in midpoints_alt:\n",
    "            stress = calculate_stresses(midpoint[0], midpoint[1], rtest, max_stress, coordinates)\n",
    "            midpoint_stress_list_large_r.append(stress)\n",
    "        # Calculate the maximum stress from the alternative list\n",
    "        stress_max_1 = np.max(midpoint_stress_list_large_r)\n",
    "    else:\n",
    "        # No NaNs in the first calculation, recalculate averages within r = 0.5 around original points\n",
    "        midpoint_stress_list_large_r = []\n",
    "        for midpoint in midpoints:\n",
    "            stress = calculate_stresses(midpoint[0], midpoint[1], rtest, max_stress, coordinates)\n",
    "            midpoint_stress_list_large_r.append(stress)\n",
    "        # Calculate the maximum stress from the original list\n",
    "        stress_max_1 = np.max(midpoint_stress_list_large_r)\n",
    "    \n",
    "    # Append the maximum stress to the stress_max list\n",
    "    stress_max.append(44500000/stress_max_1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "835b1f05",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "77\n"
     ]
    }
   ],
   "source": [
    "print(len(stress_max))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "f7a34a75",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.01 0.05 0.1  0.15 0.2  0.25 0.3  0.35 0.4  0.45 0.5 ]\n"
     ]
    }
   ],
   "source": [
    "test_data = np.repeat(delta_list/[5,5,5,5,5,5,5,5,5,5,5], 7)\n",
    "test_data = delta_list/[5,5,5,5,5,5,5,5,5,5,5]\n",
    "print(test_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "f5263a1d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11\n"
     ]
    }
   ],
   "source": [
    "z_data=[]\n",
    "for i in range(7):\n",
    "    z1=stress_max[i::7]\n",
    "    z_data.append(z1)\n",
    "print(len(z_data[6]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "e47e0c22",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 116724 characters]",
      "text/plain": [
       "<Figure size 800x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "markersize=400\n",
    "plt.figure(figsize=(8, 8))\n",
    "plt.scatter(test_data,z_data[0], marker='o',color='darkblue',label='0º',s=markersize)\n",
    "plt.scatter(test_data,z_data[1], marker='o',color='darkred',label='15º',s=markersize)\n",
    "plt.scatter(test_data,z_data[2], marker='o',color='indigo',label='30º',s=markersize)\n",
    "plt.scatter(test_data,z_data[3], marker='o',color='darkgreen',label='45º',s=markersize)\n",
    "plt.scatter(test_data,z_data[4], marker='o',color='goldenrod',label='60º',s=markersize)\n",
    "plt.scatter(test_data,z_data[5], marker='o',color='mediumvioletred',label='75º',s=markersize)\n",
    "plt.scatter(test_data,z_data[6], marker='o',color='cornflowerblue',label='90º',s=markersize)\n",
    "\n",
    "rcParams['font.family'] = 'serif'\n",
    "rcParams['font.serif'] = ['Latin Modern Roman']\n",
    "plt.tick_params(axis='both', which='major', labelsize=26)\n",
    "plt.tick_params(axis='both', which='minor', labelsize=26)\n",
    "plt.xlabel(\"Disorder, $\\delta$\", fontsize = 26)\n",
    "plt.ylabel(\"Relative Strength\", fontsize = 26)\n",
    "plt.gca().set_xlim(right=0.42)\n",
    "plt.tight_layout()\n",
    "plt.legend(fontsize = 26)\n",
    "plt.show()  # Display the figure\n",
    "#plt.close()  # Close the figure to free memory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "id": "a03196d9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "40\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 133548 characters]",
      "text/plain": [
       "<Figure size 800x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.9887001398484953, 0.9451209132114439, 0.8960859866268847, 0.8550764472608462, 0.8204351462097782, 0.7924861085551079, 0.7719425009557404, 0.7582016493536698, 0.7536861421373298, 0.7575663166050984, 0.7691308284326167]\n",
      "[0.9895647831571761, 0.9441132156856272, 0.892945124674415, 0.8492689024364728, 0.8112302848906482, 0.7798163790883179, 0.7550089195747725, 0.7361339482375139, 0.7231089887494221, 0.7172068598058232, 0.7139758109706291]\n",
      "[0.9901565855293519, 0.9464830831285075, 0.895749628074539, 0.8512317927145413, 0.8128771893964998, 0.7786189625083831, 0.7489551310507484, 0.7234719776109512, 0.7024398848414914, 0.6838671804065388, 0.6685042180214765]\n",
      "[0.9915330807121043, 0.9515883330624754, 0.9063468948794515, 0.8644382965270565, 0.8266546849353095, 0.7921787610935028, 0.7615256288464956, 0.7320495931553219, 0.7056769424039738, 0.6804062665930929, 0.6561908047999317]\n",
      "[0.9929057707879816, 0.9618223669128848, 0.9246911540972591, 0.8888929787254163, 0.8565262536609289, 0.8258021606183735, 0.7962434130932909, 0.7710012555341477, 0.746313955812092, 0.7219220548624051, 0.6966380156978841]\n",
      "[0.9960362862785681, 0.9740974554864664, 0.9471872228126178, 0.9238477676898513, 0.8997722001454893, 0.8750075048970278, 0.8577792188891246, 0.8367115147412754, 0.8189732132071591, 0.7993242953212248, 0.7855376027037673]\n",
      "[0.9991029998276575, 0.9898097173869707, 0.9787101192307788, 0.9662445591782632, 0.9572785899932774, 0.9458330702025788, 0.9395559136925765, 0.9292258344502262, 0.9224057708505706, 0.9143419426783894, 0.9076347829689686]\n",
      "[0.01 0.05 0.1  0.15 0.2  0.25 0.3  0.35 0.4  0.45 0.5 ]\n",
      "[0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4]\n",
      "[0.99215, 0.98346, 0.973788, 0.962959, 0.95075, 0.936881, 0.920988, 0.902594, 0.984913, 0.968396, 0.950234, 0.930171, 0.907889, 0.883, 0.855019, 0.82333, 0.97884, 0.956069, 0.931497, 0.904902, 0.876022, 0.84455, 0.810121, 0.772297, 0.971317, 0.940939, 0.908712, 0.874463, 0.837994, 0.799083, 0.757475, 0.712881, 0.970275, 0.938728, 0.905187, 0.869456, 0.831315, 0.790511, 0.746754, 0.699711]\n"
     ]
    }
   ],
   "source": [
    "markersize=400\n",
    "plt.figure(figsize=(8, 8))\n",
    "test_data_2=[0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.05, 0.1, 0.15, 0.2,0.25, 0.3, 0.35, 0.4, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4,0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.05, 0.1, 0.15, 0.2,0.25, 0.3, 0.35, 0.4]\n",
    "model_data=[0.99215, 0.98346, 0.973788, 0.962959, 0.95075, 0.936881, 0.920988, 0.902594, 0.984913, 0.968396, 0.950234, 0.930171, 0.907889, 0.883, 0.855019, 0.82333, 0.97884, 0.956069, 0.931497, 0.904902, 0.876022, 0.84455, 0.810121, 0.772297, 0.971317, 0.940939, 0.908712, 0.874463, 0.837994, 0.799083, 0.757475, 0.712881, 0.970275, 0.938728, 0.905187, 0.869456, 0.831315, 0.790511, 0.746754, 0.699711]\n",
    "print(len(model_data))\n",
    "plt.scatter(test_data,z_data[0], marker='o',color='darkblue',label='0º',s=markersize)\n",
    "plt.scatter(test_data,z_data[1], marker='o',color='darkred',label='15º',s=markersize)\n",
    "plt.scatter(test_data,z_data[2], marker='o',color='indigo',label='30º',s=markersize)\n",
    "plt.scatter(test_data,z_data[3], marker='o',color='darkgreen',label='45º',s=markersize)\n",
    "plt.scatter(test_data,z_data[4], marker='o',color='goldenrod',label='60º',s=markersize)\n",
    "plt.scatter(test_data,z_data[5], marker='o',color='mediumvioletred',label='75º',s=markersize)\n",
    "plt.scatter(test_data,z_data[6], marker='o',color='cornflowerblue',label='90º',s=markersize)\n",
    "plt.scatter(test_data_2,model_data, marker='o',color='black',label='Theory',s=markersize)\n",
    "\n",
    "rcParams['font.family'] = 'serif'\n",
    "rcParams['font.serif'] = ['Latin Modern Roman']\n",
    "plt.tick_params(axis='both', which='major', labelsize=26)\n",
    "plt.tick_params(axis='both', which='minor', labelsize=26)\n",
    "plt.xlabel(\"Disorder, $\\delta$\", fontsize = 26)\n",
    "plt.ylabel(\"Relative Strength\", fontsize = 26)\n",
    "plt.gca().set_xlim(right=0.42)\n",
    "plt.tight_layout()\n",
    "plt.legend(fontsize = 26)\n",
    "plt.show()  # Display the figure\n",
    "#plt.close()  # Close the figure to free memory\n",
    "print(z_data[0])\n",
    "print(z_data[1])\n",
    "print(z_data[2])\n",
    "print(z_data[3])\n",
    "print(z_data[4])\n",
    "print(z_data[5])\n",
    "print(z_data[6])\n",
    "print(test_data)\n",
    "print(test_data_2)\n",
    "print(model_data)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
