{ "cells": [ { "cell_type": "code", "execution_count": 14, "id": "2bf0892d-3c59-4424-a251-bf3a01db2d71", "metadata": {}, "outputs": [], "source": [ "from IPython.display import display, clear_output\n", "import matplotlib.pyplot as plt\n", "\n", "import SIMBBAAT_fct as smbt\n", "\n", "import ipywidgets as widgets\n", "import ipyvuetify as v\n", "\n", "from datetime import datetime\n", "import webbrowser\n", "import requests\n", "import tempfile\n", "\n", "GitHub_repo_url = 'https://github.com/mluyat/SIMBBAAT'\n", "GitHub_repo_python_url = 'https://github.com/mluyat/SIMBBAAT/blob/main/SIMBBAAT_fct.py'\n", "TI_url = 'https://www.techniques-ingenieur.fr/base-documentaire/ingenierie-des-transports-th14/structures-et-materiaux-pour-l-aeronautique-42632210/solutions-analytiques-pour-l-assemblage-colle-en-simple-cisaillement-trp4038/'" ] }, { "cell_type": "code", "execution_count": 15, "id": "99734b3f-05b4-495d-a252-19a501daddbc", "metadata": {}, "outputs": [], "source": [ "# App bar buttons definition\n", "GitHub_button = v.Btn(children=[v.Icon(children=['mdi-github-circle'])], href=GitHub_repo_url, target='_blank', style_='width: 70px;')\n", "Python_button = v.Btn(children=[v.Icon(children=['mdi-language-python'])], href=GitHub_repo_python_url, target='_blank', class_='mx-1', style_='width: 70px;')\n", "TI_button = v.Btn(children=[v.Icon(children=['mdi-file-outline'])], href=TI_url, target='_blank', style_='width: 70px;')\n", "\n", "\n", "# Menu bar definition\n", "Menu_bar = v.AppBar(children=[\n", " v.ToolbarTitle(children=['SIMBBAAT'], style_='font-size: 32px; font-weight: bold;'),\n", " v.Spacer(),\n", " GitHub_button,\n", " Python_button,\n", " TI_button],\n", " style_='background-color: #f6f8fa;')\n", "\n", "\n", "# User input buttons definition\n", "GR_active_button = v.Btn(v_model=False,children=['Goland & Reissner'], class_='flex-grow-1',outlined=True,style_='background-color: #F0F0F0; color: black; width: 100px;')\n", "GR_active_button.kwargs={'id':'GR','active_color':'#0072BD'}\n", "GR_plot_param_button = v.Btn(children=[v.Icon(children=['mdi-palette'])], class_='ml-1', style_='width: 70px;', outlined=True)\n", "\n", "HS_active_button = v.Btn(v_model=False,children=['Hart-Smith'], class_='flex-grow-1',outlined=True,style_='background-color: #F0F0F0; color: black;')\n", "HS_active_button.kwargs={'active_color':'#D95319'}\n", "HS_plot_param_button = v.Btn(children=[v.Icon(children=['mdi-palette'])], class_='ml-1', style_='width: 70px;', outlined=True)\n", "\n", "OE_active_button = v.Btn(v_model=False,children=['Ojalvo and Eidinoff'], class_='flex-grow-1',outlined=True,style_='background-color: #F0F0F0; color: black;')\n", "OE_active_button.kwargs={'active_color':'#EDB120'}\n", "OE_plot_param_button = v.Btn(children=[v.Icon(children=['mdi-palette'])], class_='ml-1', style_='width: 70px;', outlined=True)\n", "\n", "O_active_button = v.Btn(v_model=False,children=['Oplinger'], class_='flex-grow-1',outlined=True,style_='background-color: #F0F0F0; color: black;')\n", "O_active_button.kwargs={'active_color':'#7E2F8E'}\n", "O_plot_param_button = v.Btn(children=[v.Icon(children=['mdi-palette'])], class_='ml-1', style_='width: 70px;', outlined=True)\n", "\n", "LT_active_button = v.Btn(v_model=False,children=['Luo & Tong'], class_='flex-grow-1',outlined=True,style_='background-color: #F0F0F0; color: black;')\n", "LT_active_button.kwargs={'active_color':'#77AC30'}\n", "LT_plot_param_button = v.Btn(children=[v.Icon(children=['mdi-palette'])], class_='ml-1', style_='width: 70px;', outlined=True)\n", "\n", "Z_active_button = v.Btn(v_model=False,children=['Zaho'], class_='flex-grow-1',outlined=True,style_='background-color: #F0F0F0; color: black;')\n", "Z_active_button.kwargs={'active_color':'#4DBEEE'}\n", "Z_plot_param_button = v.Btn(children=[v.Icon(children=['mdi-palette'])], class_='ml-1', style_='width: 70px;', outlined=True)\n", "\n", "\n", "# User input fields definition \n", "f_field = v.TextField(v_model=4000, label='Force', type='number', style_='max-width : 200px;')\n", "L_field = v.TextField(v_model=12.5, label='Overlap length', type='number', style_='max-width : 200px;')\n", "w_field = v.TextField(v_model=25, label='Overlap width', type='number', class_='mx-10', style_='max-width : 200px;')\n", "lr_field = v.TextField(v_model=50, label='Free length', type='number', style_='max-width : 200px;')\n", "er_field = v.TextField(v_model=1.6, label='Substrats thickness', type='number', style_='max-width : 200px;')\n", "ec_field = v.TextField(v_model=0.2, label='Adhesive thickness', type='number', style_='max-width : 200px;')\n", "Er_field = v.TextField(v_model=70000, label=\"Substrats Young's modulus\", type='number', class_='mx-10', style_='max-width : 200px;')\n", "Ec_field = v.TextField(v_model=2800, label=\"Adhesive Young's modulus\", type='number', class_='mx-10', style_='max-width : 200px;')\n", "nur_field = v.TextField(v_model=0.31, label=\"Substrats Poisson's ratio\", type='number', style_='max-width : 200px;')\n", "nuc_field = v.TextField(v_model=0.4, label=\"Adhesive Poisson's ratio\", type='number', style_='max-width : 200px;')\n", "kb_field = v.TextField(v_model=1, label='kb', type='number', style_='max-width : 200px;')\n", "k_field = v.Select(v_model='GR', label='k', items=['GR','HS'], class_='mx-10', style_='max-width : 200px;')\n", "npts_field = v.TextField(v_model=501, label='Number of query point', type='number', style_='max-width : 200px;')\n", "\n", "\n", "# Pop-up elements definition\n", "color_picker = v.ColorPicker(width=400)\n", "save_button = v.Btn(v_model=False,children=['Save'], color='success', class_='d-flex flex-grow-1')\n", "discard_button = v.Btn(v_model=False,children=['Discard'], color='error', class_='d-flex flex-grow-1')" ] }, { "cell_type": "code", "execution_count": 16, "id": "9c1560f8-059b-4090-9f4f-b528cb4cb924", "metadata": {}, "outputs": [], "source": [ "# Callback functions definition\n", "def on_field_change(change):\n", " field_list = [f_field.v_model, \n", " L_field.v_model, w_field.v_model, lr_field.v_model, \n", " er_field.v_model, ec_field.v_model, Er_field.v_model, Ec_field.v_model, nur_field.v_model, nuc_field.v_model, \n", " kb_field.v_model, k_field.v_model, \n", " npts_field.v_model]\n", " if not ('' in field_list): \n", " fct_plot_display()\n", "\n", "def on_model_button_click(widget, event, data):\n", " widget.v_model = not widget.v_model\n", " widget.outlined = not widget.outlined\n", " if widget.v_model:\n", " widget.style_ = 'background-color: '+widget.kwargs['active_color']+'; color: white;'\n", " fct_plot_display()\n", " else:\n", " widget.style_ = 'background-color: #F0F0F0; color: black;'\n", " fct_plot_display()\n", " \n", "def on_save_change_click(button, widget, event, data):\n", " button.kwargs['active_color'] = color_picker.v_model\n", " if button.v_model:\n", " button.style_ = 'background-color: '+button.kwargs['active_color']+'; color: white;'\n", " else:\n", " button.style_ = 'background-color: #F0F0F0; color: black;'\n", " plot_param_popup.v_model = False\n", " fct_plot_display()\n", " \n", "\n", "def on_plot_param_button_click(button, widget, event, data):\n", " color_picker.v_model=button.kwargs.get('active_color')\n", " plot_param_popup.v_model=True\n", " save_button.on_event('click', lambda widget, event, data: on_save_change_click(button, widget, event, data))\n", " discard_button.on_event('click', lambda *args: setattr(plot_param_popup, 'v_model', False))\n", "\n", "def fetch_display_data(url):\n", " with tempfile.NamedTemporaryFile('w', delete=False, suffix='.html') as temp_file:\n", " temp_file.write(requests.get(url).text)\n", " temp_file_path = temp_file.name\n", " webbrowser.open(temp_file_path)\n", "\n", "def fct_plot_display():\n", " f = f_field.v_model\n", " L = float(L_field.v_model)\n", " w = float(w_field.v_model)\n", " lr = float(lr_field.v_model)\n", " er = float(er_field.v_model)\n", " ec = float(ec_field.v_model)\n", " Er = float(Er_field.v_model)\n", " Ec = float(Ec_field.v_model)\n", " nur = float(nur_field.v_model)\n", " nuc = float(nuc_field.v_model)\n", " kb = float(kb_field.v_model)\n", " k = k_field.v_model\n", " npts = int(npts_field.v_model)\n", " \n", " T_GR = smbt.Fct_T_GR(f,L,w,lr,er,ec,Er,Ec,nur,nuc,npts)\n", " S_GR = smbt.Fct_S_GR(f,L,w,lr,er,ec,Er,Ec,nur,nuc,npts)\n", " \n", " T_HS = smbt.Fct_T_HS(f,L,w,lr,er,ec,Er,Ec,nur,nuc,npts,kb)\n", " S_HS = smbt.Fct_S_HS(f,L,w,lr,er,ec,Er,Ec,nur,nuc,npts,kb)\n", " \n", " T_OE = smbt.Fct_T_OE(f,L,w,lr,er,ec,Er,Ec,nur,nuc,npts,kb,k)\n", " S_OE = smbt.Fct_S_OE(f,L,w,lr,er,ec,Er,Ec,nur,nuc,npts,kb,k)\n", " \n", " T_O = smbt.Fct_T_O(f,L,w,lr,er,ec,Er,Ec,nur,nuc,npts)\n", " S_O = smbt.Fct_S_O(f,L,w,lr,er,ec,Er,Ec,nur,nuc,npts)\n", " \n", " T_LT = smbt.Fct_T_LT(f,L,w,lr,er,ec,Er,Ec,nur,nuc,npts)\n", " S_LT = smbt.Fct_S_LT(f,L,w,lr,er,ec,Er,Ec,nur,nuc,npts)\n", " \n", " T_Z = smbt.Fct_T_Z(f,L,w,lr,er,ec,Er,Ec,nur,nuc,npts)\n", " S_Z = smbt.Fct_S_Z(f,L,w,lr,er,ec,Er,Ec,nur,nuc,npts)\n", "\n", " with output:\n", " clear_output(wait=True)\n", " plt.figure(figsize=(20, 7))\n", " \n", " X = smbt.Fct_X(L, npts)\n", " X = X/max(X)\n", " \n", " # Plotting\n", " plt.subplot(221)\n", " if GR_active_button.v_model:\n", " plt.plot(X, T_GR, color=GR_active_button.kwargs['active_color'])\n", " if HS_active_button.v_model:\n", " plt.plot(X, T_HS, color=HS_active_button.kwargs['active_color'])\n", " if OE_active_button.v_model:\n", " plt.plot(X, T_OE, color=OE_active_button.kwargs['active_color'])\n", " if O_active_button.v_model:\n", " plt.plot(X, T_O, color=O_active_button.kwargs['active_color'])\n", " if LT_active_button.v_model:\n", " plt.plot(X, T_LT, color=LT_active_button.kwargs['active_color'])\n", " if Z_active_button.v_model:\n", " plt.plot(X, T_Z, color=Z_active_button.kwargs['active_color'])\n", " plt.title('T')\n", " plt.grid(True)\n", " plt.xlim([-1, +1])\n", " \n", " plt.subplot(222)\n", " max_list = []\n", " if GR_active_button.v_model:\n", " plt.plot(X, T_GR, color=GR_active_button.kwargs['active_color'])\n", " max_list.append(max(T_GR))\n", " if HS_active_button.v_model:\n", " plt.plot(X, T_HS, color=HS_active_button.kwargs['active_color'])\n", " max_list.append(max(T_HS))\n", " if OE_active_button.v_model:\n", " plt.plot(X, T_OE, color=OE_active_button.kwargs['active_color'])\n", " max_list.append(max(T_OE))\n", " if O_active_button.v_model:\n", " plt.plot(X, T_O, color=O_active_button.kwargs['active_color'])\n", " max_list.append(max(T_O))\n", " if LT_active_button.v_model:\n", " plt.plot(X, T_LT, color=LT_active_button.kwargs['active_color'])\n", " max_list.append(max(T_LT))\n", " if Z_active_button.v_model:\n", " plt.plot(X, T_Z, color=Z_active_button.kwargs['active_color'])\n", " max_list.append(max(T_Z))\n", " plt.title('T')\n", " plt.grid(True)\n", " plt.xlim([-1, -0.95])\n", " if len(max_list)!=0:\n", " plt.ylim([min(max_list)-5, max(max_list)+5])\n", " \n", " plt.subplot(223)\n", " if GR_active_button.v_model:\n", " plt.plot(X, S_GR, color=GR_active_button.kwargs['active_color'])\n", " if HS_active_button.v_model:\n", " plt.plot(X, S_HS, color=HS_active_button.kwargs['active_color'])\n", " if OE_active_button.v_model:\n", " plt.plot(X, S_OE, color=OE_active_button.kwargs['active_color'])\n", " if O_active_button.v_model:\n", " plt.plot(X, S_O, color=O_active_button.kwargs['active_color'])\n", " if LT_active_button.v_model:\n", " plt.plot(X, S_LT, color=LT_active_button.kwargs['active_color'])\n", " if Z_active_button.v_model:\n", " plt.plot(X, S_Z, color=Z_active_button.kwargs['active_color'])\n", " plt.title('S')\n", " plt.grid(True)\n", " plt.xlim([-1, +1])\n", " \n", " plt.subplot(224)\n", " max_list = []\n", " if GR_active_button.v_model:\n", " plt.plot(X, S_GR, color=GR_active_button.kwargs['active_color'])\n", " max_list.append(max(S_GR))\n", " if HS_active_button.v_model:\n", " plt.plot(X, S_HS, color=HS_active_button.kwargs['active_color'])\n", " max_list.append(max(S_HS))\n", " if OE_active_button.v_model:\n", " plt.plot(X, S_OE, color=OE_active_button.kwargs['active_color'])\n", " max_list.append(max(S_OE))\n", " if O_active_button.v_model:\n", " plt.plot(X, S_O, color=O_active_button.kwargs['active_color'])\n", " max_list.append(max(S_O))\n", " if LT_active_button.v_model:\n", " plt.plot(X, S_LT, color=LT_active_button.kwargs['active_color'])\n", " max_list.append(max(S_LT))\n", " if Z_active_button.v_model:\n", " plt.plot(X, S_Z, color=Z_active_button.kwargs['active_color'])\n", " max_list.append(max(S_Z))\n", " plt.title('S')\n", " plt.grid(True)\n", " plt.xlim([-1, -0.95])\n", " if len(max_list)!=0:\n", " plt.ylim([min(max_list)-5, max(max_list)+5])\n", " \n", " # Adjusting the layout\n", " plt.tight_layout()\n", " plt.show()" ] }, { "cell_type": "code", "execution_count": 17, "id": "99fb7d1d-ea41-4754-86f9-9ef04443c455", "metadata": {}, "outputs": [], "source": [ "# Callback functions definition\n", "f_field.observe(on_field_change, names='v_model')\n", "L_field.observe(on_field_change, names='v_model')\n", "w_field.observe(on_field_change, names='v_model')\n", "lr_field.observe(on_field_change, names='v_model')\n", "er_field.observe(on_field_change, names='v_model')\n", "ec_field.observe(on_field_change, names='v_model')\n", "Er_field.observe(on_field_change, names='v_model')\n", "Ec_field.observe(on_field_change, names='v_model')\n", "nur_field.observe(on_field_change, names='v_model')\n", "nuc_field.observe(on_field_change, names='v_model')\n", "kb_field.observe(on_field_change, names='v_model')\n", "k_field.observe(on_field_change, names='v_model')\n", "npts_field.observe(on_field_change, names='v_model')\n", "\n", "\n", "# Model buttons callback\n", "GR_active_button.on_event('click', on_model_button_click)\n", "HS_active_button.on_event('click', on_model_button_click)\n", "OE_active_button.on_event('click', on_model_button_click)\n", "O_active_button.on_event('click', on_model_button_click)\n", "LT_active_button.on_event('click', on_model_button_click)\n", "Z_active_button.on_event('click', on_model_button_click)\n", "\n", "\n", "# Plot param buttons callback\n", "GR_plot_param_button.on_event('click', lambda widget, event, data: on_plot_param_button_click(GR_active_button, widget, event, data))\n", "HS_plot_param_button.on_event('click', lambda widget, event, data: on_plot_param_button_click(HS_active_button, widget, event, data))\n", "OE_plot_param_button.on_event('click', lambda widget, event, data: on_plot_param_button_click(OE_active_button, widget, event, data))\n", "O_plot_param_button.on_event('click', lambda widget, event, data: on_plot_param_button_click(O_active_button, widget, event, data))\n", "LT_plot_param_button.on_event('click', lambda widget, event, data: on_plot_param_button_click(LT_active_button, widget, event, data))\n", "Z_plot_param_button.on_event('click', lambda widget, event, data: on_plot_param_button_click(Z_active_button, widget, event, data))" ] }, { "cell_type": "code", "execution_count": 32, "id": "2fb099cd-d334-4579-8ef2-8c5640ea81a8", "metadata": {}, "outputs": [], "source": [ "# Plot display definition\n", "output = widgets.Output()\n", "Plot_layout = v.Html(tag='div', style_='display: flex; justify-content: center; align-items: center; width: 100%;', children=[output])\n", "\n", "# Buttons display definition\n", "Buttons_Layout = v.Html(tag='div', class_='d-flex flex-column', style_='padding-top: 50px;', children=[\n", " v.Html(tag='div', class_='d-flex flex-row mb-2', children=[GR_active_button,GR_plot_param_button]),\n", " v.Html(tag='div', class_='d-flex flex-row my-2', children=[HS_active_button,HS_plot_param_button]),\n", " v.Html(tag='div', class_='d-flex flex-row my-2', children=[OE_active_button,OE_plot_param_button]),\n", " v.Html(tag='div', class_='d-flex flex-row my-2', children=[O_active_button,O_plot_param_button]),\n", " v.Html(tag='div', class_='d-flex flex-row my-2', children=[LT_active_button,LT_plot_param_button]),\n", " v.Html(tag='div', class_='d-flex flex-row mt-2', children=[Z_active_button,Z_plot_param_button]),\n", "])\n", "\n", "\n", "# Fields display definition\n", "Parameter_fields_Layout = v.Html(tag='div', class_='d-flex flex-column', style_='padding-top: 50px;', children=[\n", " v.Html(tag='div', class_='d-flex flex-row justify-space-around', children=[L_field,w_field,lr_field]),\n", " v.Html(tag='div', class_='d-flex flex-row justify-space-around', children=[er_field,Er_field,nur_field]),\n", " v.Html(tag='div', class_='d-flex flex-row justify-space-around', children=[ec_field,Ec_field,nuc_field]),\n", " v.Html(tag='div', class_='d-flex flex-row justify-space-around', children=[f_field, k_field,kb_field]),\n", " v.Html(tag='div', class_='d-flex flex-row justify-space-around', children=[npts_field]),\n", "])\n", "\n", "# Buttons and field assembly\n", "Assembly_button_fields_Layout = v.Html(tag='div', class_='d-flex flex-column', children=[\n", " v.Html(tag='div', class_='d-flex flex-row justify-space-around', children=[Buttons_Layout, Parameter_fields_Layout])\n", "])\n", "\n", "# Plot parameter pop-up display definition\n", "plot_param_popup = v.Dialog(v_model=False, width='400',children=[v.Card(children=[\n", " v.Html(tag='div', children=[color_picker]),\n", " v.Html(tag='div', style_='width: 400px', class_='d-flex', children=[save_button,discard_button]),\n", " ])\n", "])\n", "\n", "# Display assembly definition\n", "Content_layout = v.Html(tag='div', class_='d-flex flex-column', children=[Plot_layout,Assembly_button_fields_Layout])\n", "\n", "\n", "# Footer\n", "footer_layout = v.Footer(\n", " class_=\" text-center d-flex flex-column\",\n", " style_=\"background-color: white;\",\n", " children=[\n", " v.Col(\n", " class_=\"text-center mt-4\",\n", " children=[\n", " f\"{datetime.now().year} — \",\n", " v.Html(tag=\"strong\", children=['maxime.luyat@isae-supaero.fr']), \n", " f\" — \",\n", " v.Html(tag=\"strong\", children=['GNU General Public License v3.0']),\n", " ],\n", " )\n", " ],\n", ")\n", "\n", "# Display the AppBar\n", "app = v.App(children=[Menu_bar,Content_layout,v.Divider(vertical=False),footer_layout],style_='background-color: white; pa-0 ma-0;')" ] }, { "cell_type": "code", "execution_count": 33, "id": "042e5507-b09f-4cdb-869f-6c404600ecc2", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b8bdb94fc6c8415b9e7cccefeabdec51", "version_major": 2, "version_minor": 0 }, "text/plain": [ "App(children=[AppBar(children=[ToolbarTitle(children=['SIMBBAAT'], layout=None, style_='font-size: 32px; font-…" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "40382a04c477460698b34ac3aa90c2a6", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Dialog(children=[Card(children=[Html(children=[ColorPicker(layout=None, width=400.0)], layout=None, tag='div')…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Render the App\n", "GR_active_button.fire_event('click', None)\n", "display(app,plot_param_popup)" ] }, { "cell_type": "code", "execution_count": null, "id": "cb5b9597-8ce6-45c7-a498-b760d9b9fa55", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "76be773b-18a7-4cf5-8d69-1702bf9f822c", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "ef2328a4-000a-49dd-86fd-f9c7ef9ec581", "metadata": {}, "outputs": [], "source": [] } ], "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.11.9" } }, "nbformat": 4, "nbformat_minor": 5 }