{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib widget"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from pysketcher import *"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import HTML, SVG, display, clear_output"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"myfig={}\n",
"sketch = Sketch(myfig)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sketch.file2Sketch(\"drainingtank.yml\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{\n",
"'frame': {\n",
" 'shell': {\n",
" 'rectangle': \"5 (x,y) coords linecolor='k' linewidth=2\",},\n",
" 'tube': {\n",
" 'rectangle': \"5 (x,y) coords linecolor='k' linewidth=2\",},},\n",
"'contenu': {\n",
" 'interieur': {\n",
" 'rectangle': \"5 (x,y) coords linecolor='b' linewidth=1 fillcolor='b' fillpattern=''\",},\n",
" 'vidange': {\n",
" 'rectangle': \"5 (x,y) coords linecolor='b' linewidth=2 fillcolor='b' fillpattern=''\",},},\n",
"'dim': {\n",
" 'hauteur': {\n",
" 'arrow': {\n",
" 'arrow': {\n",
" 'line': \"2 (x,y) coords linecolor='k' linewidth=1 arrow='<->'\",},},\n",
" 'text': \"Text at (-0.776,0)\",},\n",
" 'hc': {\n",
" 'arrow': {\n",
" 'arrow': {\n",
" 'line': \"2 (x,y) coords linecolor='k' linewidth=1 arrow='<->'\",},},\n",
" 'text': \"Text at (-1.21,-0.5)\",},\n",
" 'largeur': {\n",
" 'arrow': {\n",
" 'arrow': {\n",
" 'line': \"2 (x,y) coords linecolor='k' linewidth=1 arrow='<->'\",},},\n",
" 'text': \"Text at (0,1.27)\",},},\n",
"'jet': \"20 (x,y) coords linecolor='blue' linewidth=2\",}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sketch.container['tank'].draw()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"interieur = Rectangle( point(-(l/2)+e,-(H/2)), l-2*e, h)\\ninterieur.set_linecolor('blue')\\ninterieur.set_linewidth(1)\\ninterieur.set_filled_curves(color='blue')\\n\""
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sketch.container['formulas']['interieur']"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"sketch.container['h'] =1.5"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"exec(sketch.container['formulas']['interieur'],sketch.container)\n",
"exec(sketch.container['formulas']['contenu'],sketch.container)\n",
"exec(sketch.container['formulas']['tank'],sketch.container)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"drawing_tool.erase()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{\n",
"'frame': {\n",
" 'shell': {\n",
" 'rectangle': \"5 (x,y) coords linecolor='k' linewidth=2\",},\n",
" 'tube': {\n",
" 'rectangle': \"5 (x,y) coords linecolor='k' linewidth=2\",},},\n",
"'contenu': {\n",
" 'interieur': {\n",
" 'rectangle': \"5 (x,y) coords linecolor='b' linewidth=1 fillcolor='b' fillpattern=''\",},\n",
" 'vidange': {\n",
" 'rectangle': \"5 (x,y) coords linecolor='b' linewidth=2 fillcolor='b' fillpattern=''\",},},\n",
"'dim': {\n",
" 'hauteur': {\n",
" 'arrow': {\n",
" 'arrow': {\n",
" 'line': \"2 (x,y) coords linecolor='k' linewidth=1 arrow='<->'\",},},\n",
" 'text': \"Text at (-0.776,0)\",},\n",
" 'hc': {\n",
" 'arrow': {\n",
" 'arrow': {\n",
" 'line': \"2 (x,y) coords linecolor='k' linewidth=1 arrow='<->'\",},},\n",
" 'text': \"Text at (-1.21,-0.5)\",},\n",
" 'largeur': {\n",
" 'arrow': {\n",
" 'arrow': {\n",
" 'line': \"2 (x,y) coords linecolor='k' linewidth=1 arrow='<->'\",},},\n",
" 'text': \"Text at (0,1.27)\",},},\n",
"'jet': \"20 (x,y) coords linecolor='blue' linewidth=2\",}"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sketch.container['tank'].draw()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"b\"!!omap\\n- name: tank\\n- parts:\\n - name: head\\n shapes:\\n libraries: ['from math import sqrt, tan, radians, degrees, sin, cos, atan2,\\n pi', import numpy as np, from pysketcher import *]\\n - name: constants\\n shapes: # MKS system in use\\n H: 2.0 # Total Tank heigth\\n l: 1.0 # Tank width\\n ratio: 0.3 # ratio (elipsis small radius = 30% of big radius)\\n d_l: 0.2 # draining tub length\\n d_d: 0.05 # draining tube diameter\\n d_o: 0.1 # tube offset from tank base\\n e: 0.01 # for filling effect\\n g: 9.81 # gravity constant \\n - name: variables\\n shapes:\\n h: 1.0 # Current tank heigth\\n V: sqrt(2*g*(h-d_o))\\n X: np.linspace(0.0, 2.0, 20)\\n Y: -g/2*(X/V)**2\\n - name: frame\\n shapes:\\n setframe:\\n action: drawing_tool.set_coordinate_system(xmin=-l*1.2, xmax=l*3, ymin=-H,\\n ymax= H, axis=False)\\n - name: scene\\n shapes:\\n shell:\\n formula: Rectangle( point(-(l/2),-(H/2)), l, H)\\n style:\\n linecolor: black\\n linewidth: 2\\n tube:\\n formula: Rectangle( point( +(l/2), -(H/2)+d_o), d_l, d_d )\\n style:\\n linecolor: black\\n linewidth: 2\\n interieur:\\n formula: Rectangle( point(-(l/2)+e,-(H/2)), l-2*e, h)\\n style:\\n linecolor: blue\\n linewidth: 1\\n filled_curves:\\n color: blue\\n vidange:\\n formula: Rectangle( point( +(l/2), -(H/2)+d_o+e), d_l, d_d-2*e )\\n style:\\n linecolor: blue\\n linewidth: 2\\n filled_curves:\\n color: blue\\n hauteur:\\n formula: Distance_wText(Point(-(l/2)*1.3,-(H/2)),Point(-(l/2)*1.3,H/2),r'$H$',\\n alignment = 'right', text_spacing=-0.03)\\n style:\\n linecolor: black\\n linewidth: 1\\n hc:\\n formula: Distance_wText(Point(-(l/2)*2,-(H/2)),Point(-(l/2)*2,h-(H/2)),r'$h$',\\n alignment = 'right', text_spacing=-0.05)\\n style:\\n linecolor: black\\n linewidth: 1\\n largeur:\\n formula: Distance_wText(Point(-(l/2),+(H/2)*1.2),Point((l/2),(H/2)*1.2),r'$l$',\\n alignment = 'left', text_spacing=1/60)\\n style:\\n linecolor: black\\n linewidth: 1\\n jet:\\n formula: Curve(X+(l/2+d_l),Y-(H/2)+d_o+d_d/2)\\n style:\\n linecolor: blue\\n linewidth: 2\\n contenu: |\\n Composition({ 'interieur': interieur, 'vidange': vidange})\\n frame: |\\n Composition({ 'shell':shell, 'tube': tube })\\n dim: |\\n Composition({ 'hauteur': hauteur, 'hc': hc, 'largeur': largeur})\\n tank: |-\\n Composition({ 'frame':frame, 'contenu': contenu, 'dim':dim, 'jet':jet })\\n\""
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sketch.sketch2String()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import interact"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "52ea2e5a7bb846a58412931cd91f152a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=0.91, description='h', max=2.0, min=0.01), Output()), _dom_classes=('w…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"@interact(h=(0.01,2.0,0.1))\n",
"def tank(h):\n",
" sketch.container['h'] = h\n",
" sketch.refresh('interieur')\n",
" sketch.refresh('contenu')\n",
" sketch.refresh('hc')\n",
" sketch.refresh('V')\n",
" sketch.refresh('Y')\n",
" sketch.refresh('jet')\n",
" sketch.refresh('dim')\n",
" sketch.refresh('tank')\n",
" drawing_tool.erase()\n",
" sketch.container['tank'].draw()\n",
" display(SVG(Sketch.matplotlib2SVG()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"V = 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"g=9.81"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"X = np.linspace(0.0, 1.0, 10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Y = -g*(X /V)**2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Y"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"X + 0.1"
]
}
],
"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.8.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}