{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 7756 characters]",
      "text/plain": [
       "<Figure size 864x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import stanpy as stp\n",
    "\n",
    "\n",
    "EI = 32000  # kN/m2\n",
    "P = 5  # kN\n",
    "q = 4  # kN/m\n",
    "l = 4  # m\n",
    "\n",
    "roller_support = {\"w\": 0, \"M\": 0, \"H\": 0}\n",
    "fixed_support = {\"w\": 0, \"phi\": 0}\n",
    "hinge = {\"M\": 0}\n",
    "\n",
    "s1 = {\"EI\": EI, \"l\": l, \"bc_i\": fixed_support, \"bc_k\": {\"w\": 0}}\n",
    "s2 = {\"EI\": EI, \"l\": l, \"bc_k\": hinge, \"q\": q}\n",
    "s3 = {\"EI\": EI, \"l\": l, \"bc_k\": roller_support, \"P\": (P, l / 2)}\n",
    "\n",
    "s = [s1, s2, s3]\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(12, 5))\n",
    "stp.plot_system(ax, *s)\n",
    "stp.plot_load(ax, *s)\n",
    "ax.set_ylim(-0.5,1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "dx = 1e-9\n",
    "x_annotate = np.array([dx, l-dx, l, 2 * l, 5 * l / 2 - dx, 5 * l / 2])\n",
    "x = np.sort(np.append(np.linspace(0, 3 * l, 1000), x_annotate))\n",
    "Zi, Zk = stp.tr_solver(*s)\n",
    "Fxx = stp.tr(*s, x=x)\n",
    "Z_x = Fxx.dot(Zi).round(10)\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": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 29692 characters]",
      "text/plain": [
       "<Figure size 864x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "scale = 0.5\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(12, 5))\n",
    "stp.plot_system(ax, *s)\n",
    "stp.plot_solution(\n",
    "    ax,\n",
    "    x=x,\n",
    "    y=M_x,\n",
    "    annotate_x=[0, l, 2 * l, 5 * l/2],\n",
    "    fill_p=\"red\",\n",
    "    fill_n=\"blue\",\n",
    "    scale=scale,\n",
    "    alpha=0.2,\n",
    "    flip_y=True\n",
    ")\n",
    "\n",
    "ax.grid(linestyle=\":\")\n",
    "ax.set_axisbelow(True)\n",
    "ax.set_ylim(-1.0, 1)\n",
    "ax.set_ylabel(\"M/Mmax*{}\".format(scale))\n",
    "ax.set_title(\"[M] = kNm\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 27244 characters]",
      "text/plain": [
       "<Figure size 864x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "scale = 0.5\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(12, 5))\n",
    "stp.plot_system(ax, *s)\n",
    "stp.plot_solution(\n",
    "    ax,\n",
    "    x=x,\n",
    "    y=V_x,\n",
    "    annotate_x=[dx, l-dx, l, 2*l, 5*l/2-dx, 5*l/2, 3*l],\n",
    "    fill_p=\"red\",\n",
    "    fill_n=\"blue\",\n",
    "    scale=scale,\n",
    "    alpha=0.2,\n",
    ")\n",
    "\n",
    "ax.grid(linestyle=\":\")\n",
    "ax.set_axisbelow(True)\n",
    "ax.set_ylim(-1.0, 1)\n",
    "ax.set_ylabel(\"V/Vmax*{}\".format(scale))\n",
    "ax.set_title(\"[V] = kN\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 20724 characters]",
      "text/plain": [
       "<Figure size 864x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "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": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "f5354a90490d57e8f54e2da6f5a8495dbad4b45dd4b1c233df3651b61c2b5d04"
  },
  "kernelspec": {
   "display_name": "Python 3.9.7 ('stanpy')",
   "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"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
