{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1aed742e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-03T17:10:43.205910Z",
     "iopub.status.busy": "2022-04-03T17:10:43.204912Z",
     "iopub.status.idle": "2022-04-03T17:10:43.410912Z",
     "shell.execute_reply": "2022-04-03T17:10:43.409917Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "np.set_printoptions(precision=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0748c666",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-03T17:10:43.414915Z",
     "iopub.status.busy": "2022-04-03T17:10:43.414915Z",
     "iopub.status.idle": "2022-04-03T17:10:46.004908Z",
     "shell.execute_reply": "2022-04-03T17:10:46.004908Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 16704 characters]\n",
      "text/plain": [
       "<Figure size 864x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "filenames": {
       "image/png": "C:\\Users\\David\\OneDrive\\Desktop\\imwspy\\stanpy\\stanpy\\docs\\_build\\jupyter_execute\\user_guide\\straight_beam_non_constant_cs_1_0.png"
      },
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import sympy as sym\n",
    "import matplotlib.pyplot as plt\n",
    "import stanpy as stp\n",
    "\n",
    "x_sym = sym.Symbol(\"x\")\n",
    "E = 3e7  # kN/m2\n",
    "b = 0.2  # m\n",
    "ha = hb = 0.3  # m\n",
    "hc = 0.4  # m\n",
    "l1 = 4  # m\n",
    "l2 = 3  # m\n",
    "hx = ha + (hc - hb) / l2 * x_sym\n",
    "\n",
    "cs_props1 = stp.cs(b=b, h=ha)\n",
    "s1 = {\"E\": E, \"cs\": cs_props1, \"q\": 10, \"l\": l1, \"bc_i\": {\"w\": 0, \"M\": 0, \"H\": 0}}\n",
    "\n",
    "cs_props2 = stp.cs(b=b, h=hx)\n",
    "s2 = {\"E\": E, \"cs\": cs_props2, \"q\": 10, \"l\": l2, \"bc_k\": {\"w\": 0, \"phi\": 0}}\n",
    "\n",
    "s = [s1,s2]\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(12, 5))\n",
    "stp.plot_system(ax, *s)\n",
    "stp.plot_load(ax, *s)\n",
    "ax.grid(linestyle=\":\")\n",
    "ax.set_axisbelow(True)\n",
    "ax.set_ylim(-0.75, 1.0)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b3b0d4f4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-03T17:10:46.008910Z",
     "iopub.status.busy": "2022-04-03T17:10:46.008910Z",
     "iopub.status.idle": "2022-04-03T17:10:46.049905Z",
     "shell.execute_reply": "2022-04-03T17:10:46.049905Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Z_a = [0.00000e+00 4.31611e-03 0.00000e+00 2.42922e+01 1.00000e+00]\n",
      "Z_c = [ -0.       -0.      -74.9543  -45.70776   1.     ]\n"
     ]
    }
   ],
   "source": [
    "x = np.linspace(0, l1+l2, 1000)\n",
    "x_annoation = [0,l1, l1+l2, (l1+l2)/2]\n",
    "x = np.sort(np.append(x, x_annoation))\n",
    "F_xa = stp.tr(*s, x=x)\n",
    "Z_a, Z_c = stp.solve_tr(F_xa[-1], bc_i=s1[\"bc_i\"], bc_k=s2[\"bc_k\"])\n",
    "\n",
    "Z_x = F_xa.dot(Z_a)\n",
    "\n",
    "print(\"Z_a =\", Z_a)\n",
    "print(\"Z_c =\", Z_c)\n",
    "\n",
    "w_x = Z_x[:, 0]\n",
    "phi_x = Z_x[:, 1]\n",
    "M_x = Z_x[:, 2]\n",
    "V_x = Z_x[:, 3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "586c9ec1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-03T17:10:46.053907Z",
     "iopub.status.busy": "2022-04-03T17:10:46.052909Z",
     "iopub.status.idle": "2022-04-03T17:10:46.274906Z",
     "shell.execute_reply": "2022-04-03T17:10:46.274906Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 28312 characters]\n",
      "text/plain": [
       "<Figure size 864x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "filenames": {
       "image/png": "C:\\Users\\David\\OneDrive\\Desktop\\imwspy\\stanpy\\stanpy\\docs\\_build\\jupyter_execute\\user_guide\\straight_beam_non_constant_cs_3_0.png"
      },
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "scale = 0.5\n",
    "fig, ax = plt.subplots(figsize=(12, 5))\n",
    "stp.plot_system(ax, *s)\n",
    "stp.plot_M(ax, x=x, Mx=M_x, annotate_x=np.append(x_annoation, x[M_x==np.max(M_x)]), fill_p=\"red\", fill_n=\"blue\", scale=scale, alpha=0.2)\n",
    "ax.grid(linestyle=\":\")\n",
    "ax.set_axisbelow(True)\n",
    "ax.set_ylim(-1.5, 1.5)\n",
    "ax.set_ylabel(\"M/Mmax*{}\".format(scale))\n",
    "ax.set_title(\"[M] = kNm\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "48375c1b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-03T17:10:46.278910Z",
     "iopub.status.busy": "2022-04-03T17:10:46.278910Z",
     "iopub.status.idle": "2022-04-03T17:10:46.484903Z",
     "shell.execute_reply": "2022-04-03T17:10:46.484903Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 26840 characters]\n",
      "text/plain": [
       "<Figure size 864x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "filenames": {
       "image/png": "C:\\Users\\David\\OneDrive\\Desktop\\imwspy\\stanpy\\stanpy\\docs\\_build\\jupyter_execute\\user_guide\\straight_beam_non_constant_cs_4_0.png"
      },
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "scale = 0.5\n",
    "fig, ax = plt.subplots(figsize=(12, 5))\n",
    "stp.plot_system(ax, *s)\n",
    "stp.plot_solution(ax, x=x, y=V_x, annotate_x=x_annoation, fill_p=\"red\", fill_n=\"blue\", scale=scale, alpha=0.2)\n",
    "ax.grid(linestyle=\":\")\n",
    "ax.set_axisbelow(True)\n",
    "ax.set_ylim(-1.5, 1.5)\n",
    "ax.set_ylabel(\"V/Vmax*{}\".format(scale))\n",
    "ax.set_title(\"[V] = kN\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "405e790d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-03T17:10:46.488906Z",
     "iopub.status.busy": "2022-04-03T17:10:46.488906Z",
     "iopub.status.idle": "2022-04-03T17:10:46.785419Z",
     "shell.execute_reply": "2022-04-03T17:10:46.785419Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 20596 characters]\n",
      "text/plain": [
       "<Figure size 864x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "filenames": {
       "image/png": "C:\\Users\\David\\OneDrive\\Desktop\\imwspy\\stanpy\\stanpy\\docs\\_build\\jupyter_execute\\user_guide\\straight_beam_non_constant_cs_5_0.png"
      },
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "scale = 0.2\n",
    "fig, ax = plt.subplots(figsize=(12, 5))\n",
    "stp.plot_system(ax, *s, lw=1, linestyle=\":\", c=\"#111111\")\n",
    "stp.plot_w(ax, x=x, wx=w_x, scale=scale, linestyle=\"-\")\n",
    "ax.grid(linestyle=\":\")\n",
    "ax.set_axisbelow(True)\n",
    "ax.set_ylim(-1.5, 1.5)\n",
    "ax.set_ylabel(\"w/wmax*{}\".format(scale))\n",
    "ax.set_title(\"[w] = m\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ed3a9783",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-03T17:10:46.789424Z",
     "iopub.status.busy": "2022-04-03T17:10:46.788422Z",
     "iopub.status.idle": "2022-04-03T17:10:46.800417Z",
     "shell.execute_reply": "2022-04-03T17:10:46.800417Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import sympy as sp\n",
    "import matplotlib.pyplot as plt\n",
    "import stanpy as stp\n",
    "\n",
    "E = 210000000  # kN/m^2\n",
    "E = 21e7  # kN/m^2\n",
    "l1, l3 = 0.99, 0.99  # m\n",
    "l2 = 0.51  # m\n",
    "ha, hb, hd = 0.25, 0.25, 0.25  # m\n",
    "hc = 0.15  # m\n",
    "b = 0.2  # m\n",
    "t = 0.02  # m\n",
    "s = 0.015  # m\n",
    "q = 3.04  # kN/m\n",
    "P = 9.96  # kN\n",
    "Ag = b * t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "bf0d4087",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-03T17:10:46.804421Z",
     "iopub.status.busy": "2022-04-03T17:10:46.803422Z",
     "iopub.status.idle": "2022-04-03T17:10:46.950417Z",
     "shell.execute_reply": "2022-04-03T17:10:46.950417Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Z_a = [0.00000e+00 1.04236e-04 0.00000e+00 4.88429e+00 1.00000e+00]\n",
      "Z_b = [ 0.       0.      -6.19812 -9.63571  1.     ]\n"
     ]
    }
   ],
   "source": [
    "x_sym = sym.Symbol(\"x\")\n",
    "\n",
    "hx2 = hb - (hb - hc) / l2 * x_sym\n",
    "hx3 = hc + (hd - hc) / l3 * x_sym\n",
    "\n",
    "b_vec = np.array([b, s, b])\n",
    "h1_vec = np.array([t, ha - t, t])\n",
    "h2_vec = np.array([t, hx2 - t, t])\n",
    "h3_vec = np.array([t, hx3 - t, t])\n",
    "\n",
    "cs_props1 = stp.cs(b=b_vec, h=h1_vec)\n",
    "s1 = {\"E\": E, \"cs\": cs_props1, \"l\": l1, \"P\": (P, l1), \"bc_i\": {\"w\": 0, \"M\": 0, \"H\": 0}}\n",
    "\n",
    "cs_props2 = stp.cs(b=b_vec, h=h2_vec)\n",
    "s2 = {\"E\": E, \"cs\": cs_props2, \"q\": q, \"l\": l2}\n",
    "\n",
    "cs_props3 = stp.cs(b=b_vec, h=h3_vec)\n",
    "s3 = {\"E\": E, \"cs\": cs_props3, \"q\": q, \"l\": l3, \"bc_k\": {\"w\": 0, \"phi\": 0}}\n",
    "\n",
    "s = [s1, s2, s3]\n",
    "\n",
    "dx = 1e-10\n",
    "x_annotate = np.cumsum(np.array([0, l1, l2, l3]))\n",
    "x = np.linspace(0, l1 + l2 + l3, 500)\n",
    "x = np.sort(np.append(x, x_annotate))\n",
    "Fxa = stp.tr(*s, x=x)\n",
    "\n",
    "Z_a, Z_d = stp.solve_tr(Fxa[-1], bc_i=s1[\"bc_i\"], bc_k=s3[\"bc_k\"])\n",
    "Z_x = Fxa.dot(Z_a)\n",
    "\n",
    "print(\"Z_a =\", Z_a)\n",
    "print(\"Z_b =\", Z_d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "7a86d73c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-03T17:10:46.953419Z",
     "iopub.status.busy": "2022-04-03T17:10:46.953419Z",
     "iopub.status.idle": "2022-04-03T17:10:47.161424Z",
     "shell.execute_reply": "2022-04-03T17:10:47.160422Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 30936 characters]\n",
      "text/plain": [
       "<Figure size 864x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "filenames": {
       "image/png": "C:\\Users\\David\\OneDrive\\Desktop\\imwspy\\stanpy\\stanpy\\docs\\_build\\jupyter_execute\\user_guide\\straight_beam_non_constant_cs_8_0.png"
      },
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "w_x = Z_x[:, 0]\n",
    "phi_x = Z_x[:, 1]\n",
    "M_x = Z_x[:, 2]\n",
    "V_x = Z_x[:, 3]\n",
    "\n",
    "scale = 0.5\n",
    "fig, ax = plt.subplots(figsize=(12, 5))\n",
    "stp.plot_system(ax, *s)\n",
    "# plt.show()\n",
    "# quit()\n",
    "stp.plot_M(ax, x=x, Mx=M_x, annotate_x=x_annotate, fill_p=\"red\", fill_n=\"blue\", scale=scale, alpha=0.2)\n",
    "ax.grid(linestyle=\":\")\n",
    "ax.set_axisbelow(True)\n",
    "ax.set_ylim(-0.8, 0.8)\n",
    "ax.set_ylabel(\"M/Mmax*{}\".format(scale))\n",
    "ax.set_title(\"[M] = kNm\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "4213fe4f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-03T17:10:47.164422Z",
     "iopub.status.busy": "2022-04-03T17:10:47.164422Z",
     "iopub.status.idle": "2022-04-03T17:10:47.355417Z",
     "shell.execute_reply": "2022-04-03T17:10:47.355417Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 26440 characters]\n",
      "text/plain": [
       "<Figure size 864x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "filenames": {
       "image/png": "C:\\Users\\David\\OneDrive\\Desktop\\imwspy\\stanpy\\stanpy\\docs\\_build\\jupyter_execute\\user_guide\\straight_beam_non_constant_cs_9_0.png"
      },
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "scale = 0.5\n",
    "fig, ax = plt.subplots(figsize=(12, 5))\n",
    "stp.plot_system(ax, *s)\n",
    "stp.plot_solution(ax, x=x, y=V_x, annotate_x=x_annotate, fill_p=\"red\", fill_n=\"blue\", scale=scale, alpha=0.2)\n",
    "ax.grid(linestyle=\":\")\n",
    "ax.set_axisbelow(True)\n",
    "ax.set_ylim(-0.8, 0.8)\n",
    "ax.set_ylabel(\"V/Vmax*{}\".format(scale))\n",
    "ax.set_title(\"[M] = kNm\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b8c97574",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-03T17:10:47.359425Z",
     "iopub.status.busy": "2022-04-03T17:10:47.359425Z",
     "iopub.status.idle": "2022-04-03T17:10:47.595421Z",
     "shell.execute_reply": "2022-04-03T17:10:47.595421Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 19316 characters]\n",
      "text/plain": [
       "<Figure size 864x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "filenames": {
       "image/png": "C:\\Users\\David\\OneDrive\\Desktop\\imwspy\\stanpy\\stanpy\\docs\\_build\\jupyter_execute\\user_guide\\straight_beam_non_constant_cs_10_0.png"
      },
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "scale = 0.2\n",
    "fig, ax = plt.subplots(figsize=(12, 5))\n",
    "stp.plot_system(ax, s1,s2,s3, lw=1, linestyle=\":\", c=\"#111111\")\n",
    "stp.plot_w(ax, x=x, wx=w_x, scale=scale, linestyle=\"-\")\n",
    "ax.grid(linestyle=\":\")\n",
    "ax.set_axisbelow(True)\n",
    "ax.set_ylim(-1.5, 1.5)\n",
    "ax.set_ylabel(\"w/wmax*{}\".format(scale))\n",
    "ax.set_title(\"[w] = m\")\n",
    "plt.show()"
   ]
  }
 ],
 "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.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}