Skip to content

Instantly share code, notes, and snippets.

@eleni198
Created December 5, 2019 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eleni198/df98317ce814641e8b148a056634055b to your computer and use it in GitHub Desktop.
Save eleni198/df98317ce814641e8b148a056634055b to your computer and use it in GitHub Desktop.
EarthPressure
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# HIDDEN\n",
"from ipywidgets import interact, interactive, fixed, interact_manual\n",
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.path import Path\n",
"import matplotlib.patches as patches\n",
"#%matplotlib inline\n",
"\n",
"import pandas as pd\n",
"\n",
"from scipy.optimize import curve_fit as cf\n",
"\n",
"from IPython.display import display, Math, Latex\n",
"\n",
"from matplotlib.patches import Polygon\n",
"from ipywidgets import widgets"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"# HIDDEN\n",
"def slope(sh,phi):\n",
" \"\"\"Plot 2D slope\"\"\"\n",
" plt.subplot(1, 2, 1)\n",
" #slope angle in radians\n",
" ar=90/180.*np.pi\n",
"\n",
" #friction angle in radians\n",
" phir=phi/180.*np.pi\n",
" #prepare data for sketching\n",
" poly = np.random.rand(4, 2)\n",
"\n",
"\n",
" poly[0,0]=0\n",
" poly[0,1]=0\n",
" poly[1,0]=1.*np.cos(ar)\n",
" poly[1,1]=1.*np.sin(ar)\n",
"\n",
"\n",
" \n",
" Kp = (1.0+np.sin(phir))/(1.0-np.sin(phir))\n",
" if (sh<1):\n",
" shlim = 1/Kp\n",
" if (sh<shlim):\n",
" sf='unsafe'\n",
" br=(np.pi/4+phir/2)\n",
" else:\n",
" sf='safe'\n",
" br=np.pi/2\n",
" color='r'\n",
" else:\n",
" shlim = Kp\n",
" if (sh>shlim):\n",
" sf='unsafe'\n",
" br=(np.pi/4-phir/2)\n",
" else:\n",
" sf='safe'\n",
" br =np.pi/2\n",
" color='g'\n",
"\n",
" \n",
" x1=0\n",
" y1=0\n",
" y2=3.\n",
" x2=y2*np.cos(br)/np.sin(br) \n",
" \n",
"\n",
" xy0=(0,0)\n",
" polg = plt.Rectangle(xy0, 5, 3, angle=0.0, facecolor='#cce885',lw=3, edgecolor='#5c8037')\n",
" line = plt.Line2D((x1, x2), (y1, y2), lw=2.5)\n",
"\n",
" plt.axis('image')\n",
" ax = plt.gca() \n",
" ax.add_artist(polg)\n",
" ax.add_line(line)\n",
" ax.set_xlim(0, 5)\n",
" ax.set_ylim(0, 3) \n",
" plt.xlabel(r\"x\", size=18)\n",
" plt.ylabel(r\"y\", size=18) \n",
" plt.show()\n",
" \n",
" plt.subplot(1, 2, 2)\n",
" xy1=(-1.5,-0.5)\n",
" rect1 = plt.Rectangle(xy1, 1, 1, angle=0.0, facecolor=color, lw=3,edgecolor=color) \n",
" plt.axis('image')\n",
" ax = plt.gca() \n",
" ax.add_artist(rect1)\n",
" ax.set_xlim(-2.1, 2.1)\n",
" ax.set_ylim(-1, 1) \n",
" #au= np.cos(ang)/np.sin(ang)*b\n",
" #bu=-np.sin(ang)/np.cos(ang)*a\n",
" #plt.plot([-au, au], [bu, -bu], 'ko')\n",
" #plt.plot([-au, au], [bu, -bu], 'k')\n",
" #plt.xlabel(r\"$\\sigma$\", size=18)\n",
" #plt.ylabel(r\"$\\tau$\", size=18) \n",
" plt.text(1, 0, sf)\n",
" #plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2065bf7fcb7d4d94b7d1cb0ecf337d34",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=2.9000100000000004, description='sh', max=6.0, min=1e-05), IntSlider(v…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<function __main__.slope(sh, phi)>"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"interact(slope,sh=(0.00001,6.0,0.1),phi=(20,50,1))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
ipywidgets
IPython
numpy
scipy
pandas
matplotlib
ipywidgets
IPython
numpy
scipy
pandas
matplotlib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment