{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Simple beam - Stress and Strain\n", "In this first notebook, the stresses and strains inside the element are presented." ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "# Import the packages needed\n", "import math\n", "import numpy as np \n", "from bokeh.layouts import layout, column, row\n", "from bokeh.models.annotations import Label, Arrow\n", "from bokeh.models.arrow_heads import VeeHead\n", "from bokeh.models import Div, CustomJS, Slider, Spacer, Text\n", "from bokeh.models.widgets import RadioButtonGroup, CheckboxButtonGroup\n", "from bokeh.plotting import figure, show, ColumnDataSource\n", "from bokeh.io import output_notebook\n", "from cienpy import simplebeam as sb\n", "from cienpy import rectangular_section as beam_section\n", "from cienpy import stress_strain_elastic as stst\n", "from cienpy import models\n", "from cienpy import javascriptcodes as js\n", "\n", "# output_notebook()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the geometry and uniform load. Note that given the graphical nature of the notebook, extreme cases can cause the figures to not be displayed." ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "# Choose the dimensions\n", "L = 6 # [m]\n", "h = 200 # [mm]\n", "b = 100 # [mm]\n", "q = 4; # [kN/m]\n", "P = 10; # [kN]\n", "\n", "# Choose the material parameters\n", "E = 200e3 # [MPa]\n", "\n", "# compute the internal forces (at x=L)\n", "discr_NVM = 100\n", "x_discr = np.linspace(0, L, discr_NVM)\n", "N_discr = sb.compute_N(x_discr, P)\n", "V_discr = sb.compute_V(x_discr, q, L)\n", "M_discr = sb.compute_M(x_discr, q, L)\n", "N = N_discr[-1]\n", "V = V_discr[-1]\n", "M = M_discr[-1]\n", "\n", "# compute the parameters\n", "A = beam_section.compute_area(b, h) # [mm2]\n", "Iy = beam_section.compute_inertia_y(b, h) # [mm4] strong axis\n", "Iz = beam_section.compute_inertia_z(b, h) # [mm4] weak axis\n", "yG = beam_section.compute_centroid_y(h)\n", "y_n_axis = stst.compute_neutral_axis(N, A, Iy, M, yG)\n", "\n", "# compute the reactions\n", "Rx = sb.compute_Rx(P)\n", "Ry_l = sb.compute_Ry_l(q, L)\n", "Ry_r = sb.compute_Ry_r(q, L)\n", "\n", "\n", "# constants for the visualisation\n", "SCALE = 10\n", "OFFSET_Q = q\n", "MAX_B = 3*b\n", "MAX_H = 3*h\n", "MAX_Q = q/4*5\n", "\n", "# store the values in a specific format\n", "data_beam = dict(\n", " x=[0, L],\n", " y=[0, 0]\n", ")\n", "\n", "data_scheme_beam = dict(\n", " x=[0, L*SCALE],\n", " y=[0, 0]\n", ")\n", "\n", "data_scheme_q = dict(\n", " x=[0, 0, L*SCALE, L*SCALE],\n", " y=[OFFSET_Q, OFFSET_Q+q, OFFSET_Q+q, OFFSET_Q],\n", " x_fade=[0, 0, L*SCALE, L*SCALE]\n", ")\n", "\n", "data_section_scheme = dict(\n", " x=[0, 0], \n", " y=[0, h]\n", ")\n", "\n", "initial_position = L\n", "initial_state = 'IDLE' # possible cases: IDLE, R_SEC, L_SEC\n", "initial_FBD = 0 # right=0 left=1\n", "data = dict( # stores every useful single variable\n", " state=[initial_state], \n", " FBD=[initial_FBD],\n", " SCALE=[SCALE],\n", " L=[L],\n", " b=[b],\n", " h=[h],\n", " E=[E],\n", " A=[A],\n", " Iy=[Iy],\n", " Iz=[Iz],\n", " yG=[yG],\n", " y_n_axis=[y_n_axis],\n", " P=[P],\n", " x=[initial_position],\n", " y=[0],\n", " q=[q],\n", " Rx=[Rx],\n", " Ry_l=[Ry_l],\n", " Ry_r=[Ry_r],\n", " N=[N],\n", " V=[V],\n", " M=[M],\n", " xF=[L*SCALE]\n", ")\n", "\n", "source_beam = ColumnDataSource(data_beam)\n", "source_scheme_beam = ColumnDataSource(data_scheme_beam)\n", "source_scheme_q = ColumnDataSource(data_scheme_q)\n", "source_section_scheme = ColumnDataSource(data_section_scheme)\n", "source = ColumnDataSource(data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create the figures, the plots and the widgets (same of Notebook 3 - Diagrams):" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "FIG_H_B = 200 # height figure beam\n", "FIG_B_B = 700 # width figure beam\n", "FIG_H_S = FIG_H_B # height figure scheme\n", "FIG_B_S = FIG_B_B # width figure scheme\n", "FIG_H_SEC = 600 # height figure section\n", "DIV_B_GEO = 170\n", "DIV_B_FORCES = 170\n", "\n", "options = dict(\n", " toolbar_location=None\n", ")\n", "\n", "# figure for the beam\n", "paddingx = 0.2*L\n", "int_x_b = (0-paddingx, L+paddingx)\n", "int_y_b = (-OFFSET_Q/SCALE, (MAX_Q+OFFSET_Q)/SCALE)\n", "fig_beam = sb.define_fig_beam(int_x_b, int_y_b, options,\n", " f_h=FIG_H_B, f_b=FIG_B_B)\n", "\n", "\n", "# figure for the cross-section\n", "fig_section = sb.define_fig_section(MAX_B*0.8, MAX_H*0.8, options, FIG_H_SEC)\n", "\n", "\n", "# Cat with salad for scale (if not visualized, remove this part because the browser don't support it correctly)\n", "h_img = 150 # mm\n", "fig_section.image_url(url=['https://stickerly.pstatic.net/sticker_pack/QFZXZVMOmb6NeoBCIzEqNw/01OWRN/4/ac6af3b7-d096-4359-b0df-480fd612b28a.png'], x=-h_img/2, y=-MAX_H/2*1.01, h=h_img, w=h_img)\n", "fig_section.text(x=[0], y=[-MAX_H/2-h_img*1.2], text_align=\"center\", text=[f\"Cat with salad for scale (h={h_img} mm)\"], text_font_size=\"10px\")\n", "\n", "\n", "# beam\n", "(beam, support_l, support_r) = sb.draw_beam(fig_beam, source_beam, L,\n", " ratio = (int_y_b[1]-int_y_b[0])/FIG_H_B*100)\n", "\n", "# section\n", "section = beam_section.draw_section(fig_section, b, h)\n", "\n", "\n", "# show mechanical parameters\n", "div_geo = Div(width= DIV_B_GEO, \n", " text=beam_section.div_text_geo(round(h), round(b), round(L),\n", " \"{:.2e}\".format(A),\n", " \"{:.2e}\".format(Iy),\n", " \"{:.2e}\".format(Iz)))\n", "\n", "\n", "# change geometry\n", "slider_b = Slider(\n", " title=\"Change the width b [mm]\",\n", " start=10,\n", " end=MAX_B,\n", " step=10,\n", " value=b\n", ")\n", "slider_h = Slider(\n", " title=\"Change the height h [mm]\",\n", " start=20,\n", " end=MAX_H,\n", " step=20,\n", " value=h\n", ")\n", "\n", "# reference system\n", "axis_arrow_length = 0.8\n", "axis_arrow_scale = 100\n", "models.force_vector(fig_section, axis_arrow_length*10, 0, 0, 0, axis_arrow_length*axis_arrow_scale*1.6, 'gray') # y axis\n", "fig_section.text(x=[0], y=[axis_arrow_length*axis_arrow_scale*1.7], text=[\"y\"], text_color='gray', text_baseline='middle', angle=math.pi/2)\n", "models.force_vector(fig_section, axis_arrow_length*10, 0, -axis_arrow_length*axis_arrow_scale, 0, 0, 'gray') # z axis\n", "fig_section.text(x=[-axis_arrow_length*axis_arrow_scale*1.1], y=[0], text=[\"z\"], text_color='gray', text_align='right', text_baseline='middle')\n", "\n", "\n", "# figure for the forces and moments\n", "fig_scheme = sb.define_figure_scheme(L, SCALE, MAX_Q, OFFSET_Q, options, FIG_H_S, FIG_B_S)\n", "\n", "\n", "# uniform load (beam)\n", "u_load = fig_beam.rect([L/2], [(q/2+OFFSET_Q)/SCALE], width=L, height=q/SCALE,\n", " fill_color='blue', color='navy', fill_alpha=0.6, alpha=0.6)\n", "label_u_load = fig_beam.text(x=[-0.2], y=[OFFSET_Q/SCALE], text=[\"q\"], text_color=\"blue\")\n", "\n", "\n", "# axial force (beam)\n", "axial_force = models.force_vector(fig_beam, P, L+P/SCALE, L, 0, 0, 'green')\n", "label_P_force = fig_beam.text(x=[L+P/2/SCALE], y=[OFFSET_Q/SCALE/2], text=[\"P\"], text_color=\"green\")\n", "\n", "\n", "# position point\n", "pos_opt = dict(\n", " source=source,\n", " size=10,\n", " fill_alpha=0.5,\n", " fill_color=\"magenta\",\n", " color=\"magenta\",\n", " alpha=0.5\n", ")\n", "beam_position = fig_beam.circle('x', 'y', **pos_opt)\n", "forces_position = fig_scheme.circle('xF', 'y', **pos_opt)\n", "\n", "\n", "# beam (scheme)\n", "scheme_beam = fig_scheme.line('x', 'y', source=source_scheme_beam, line_width=2, color='black')\n", "scheme_fade_beam = fig_scheme.line(x=[0, L*SCALE], y=[0, 0], line_width=2, color='black', alpha=0.2)\n", "# uniform load (scheme)\n", "scheme_u_load = fig_scheme.patch('x', 'y', source=source_scheme_q, fill_color='blue', color='navy',\n", " fill_alpha=0.3, alpha=0.3)\n", "scheme_fade_u_load = fig_scheme.patch('x_fade', 'y', source=source_scheme_q, fill_color='blue',\n", " color='navy', fill_alpha=0.3, alpha=0.3)\n", "# axial force (scheme)\n", "scheme_axial_force = models.force_vector(fig_scheme, P, L*SCALE+P, L*SCALE, 0, 0, 'green')\n", "# Reactions (scheme)\n", "scheme_Ry_r = models.force_vector(fig_scheme, Ry_r, L*SCALE, L*SCALE, -Ry_r, 0, 'orange')\n", "scheme_Ry_l = models.force_vector(fig_scheme, Ry_l, 0, 0, -Ry_l, 0, 'orange')\n", "scheme_Rx_l = models.force_vector(fig_scheme, Rx, -Rx, 0, 0, 0, 'orange')\n", "# force N\n", "scheme_N = models.force_vector(fig_scheme, 0, 0, 0, 0, 0, 'red')\n", "# force V\n", "scheme_V = models.force_vector(fig_scheme, 0, 0, 0, 0, 0, 'red')\n", "# moment M\n", "(scheme_M_line, scheme_M_head, source_M) = models.define_curvedArrow(fig_scheme, 0, 0, 0, size_head=0)\n", "\n", "\n", "# change the uniform load q\n", "slider_q = Slider(\n", " title=\"Change the uniform load q [kN/m]\",\n", " start=0.1,\n", " end=MAX_Q,\n", " step=0.1,\n", " value=q\n", ")\n", "\n", "\n", "# choose position of interest\n", "slider_position = Slider(\n", " title=\"Change the position x along the beam [m]\",\n", " start=0,\n", " end=L,\n", " step=0.02,\n", " value=L\n", ")\n", "\n", "\n", "# choose left or right FBD\n", "div_rg_FBD = Div(text=\"Free-body diagram (FBD):\")\n", "radiogroup_FBD = RadioButtonGroup(labels=['Right-hand', 'Left-hand'], active=initial_FBD)\n", "\n", "\n", "# choose axial force or not\n", "div_cb_P = Div(text=f\"Axial force P={P} kN (applied)\")\n", "checkbox_P = CheckboxButtonGroup(labels=['Apply or remove axial force P'], active=[0])\n", "\n", "\n", "# show values of forces and moments\n", "div_forces = Div(width=DIV_B_FORCES, \n", " text=sb.div_text_forces(P, P, Ry_l, Ry_r, \"No cross section analysed.\", 0, 0, 0))\n", "\n", "\n", "# figures for the diagrams\n", "options_diag = dict(\n", " toolbar_location=None,\n", " x_axis_label=\"Position [m]\",\n", " plot_width=FIG_B_B,\n", " x_range=fig_beam.x_range\n", ")\n", "fig_N = figure(**options_diag,\n", " tooltips= [(\"Position\", \"@x m\"),\n", " (\"Axial force\", \"@y kN\")],\n", " y_axis_label=\"Axial force N [kN]\",\n", " plot_height=int(FIG_H_B*0.8),\n", " title=\"N V M Diagrams\")\n", "fig_V = figure(**options_diag,\n", " tooltips= [(\"Position\", \"@x m\"),\n", " (\"Shear force\", \"@y kN\")],\n", " y_axis_label=\"Shear force V [kN]\",\n", " plot_height=int(FIG_H_B*0.8))\n", "fig_M = figure(**options_diag,\n", " tooltips= [(\"Position\", \"@x m\"),\n", " (\"Bending moment\", \"@y kNm\")],\n", " y_axis_label=\"Bending moment M [kNm]\",\n", " plot_height=FIG_H_B)\n", "fig_N.xaxis.visible = False\n", "fig_V.xaxis.visible = False\n", "\n", "\n", "# plot N V M\n", "N_diag = models.NVM_diagram(fig_N, x_discr, N_discr, L, source_beam)\n", "V_diag = models.NVM_diagram(fig_V, x_discr, V_discr, L, source_beam)\n", "M_diag = models.NVM_diagram(fig_M, x_discr, M_discr, L, source_beam)\n", "\n", "# point that shows the position that it's analyzed\n", "N_position = fig_N.circle('x', 'N', **pos_opt)\n", "V_position = fig_V.circle('x', 'V', **pos_opt)\n", "M_position = fig_M.circle('x', 'M', **pos_opt)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now define the new figures, renderers and widgets:" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "# figures for the stresses and strains\n", "FIG_B_ss = 200\n", "FIG_H_ss = 200\n", "options_stress_strain = dict(\n", " toolbar_location=None,\n", " y_axis_label=\"Height h [mm]\",\n", " plot_width=FIG_B_ss,\n", " plot_height=FIG_H_ss\n", ")\n", "fig_stress_N = figure(**options_stress_strain,\n", " tooltips= [(\"Stress\", \"@x MPa\"),\n", " (\"Height\", \"@y mm\")],\n", " title=\"Axial stress\",\n", " x_axis_label=\"Stress \\N{GREEK SMALL LETTER SIGMA}\\u2099 [MPa]\")\n", "fig_stress_N.yaxis.visible = False\n", "fig_axial_strain = figure(**options_stress_strain,\n", " tooltips= [(\"Strain\", \"@x %\"),\n", " (\"Height\", \"@y mm\")],\n", " title=\"Axial strain\",\n", " x_axis_label=\"Strain \\N{GREEK SMALL LETTER EPSILON}\\u2099 [%]\",\n", " y_range=fig_stress_N.y_range)\n", "fig_axial_strain.yaxis.visible = False\n", "fig_stress_M = figure(**options_stress_strain,\n", " tooltips= [(\"Stress\", \"@x MPa\"),\n", " (\"Height\", \"@y mm\")],\n", " title=\"Bending stress and centroid\",\n", " y_range=fig_stress_N.y_range,\n", " x_axis_label=\"Stress \\N{GREEK SMALL LETTER SIGMA}\\u2098 [MPa]\")\n", "fig_stress_M.yaxis.visible = False\n", "fig_bending_strain = figure(**options_stress_strain,\n", " tooltips= [(\"Strain\", \"@x %\"),\n", " (\"Height\", \"@y mm\")],\n", " title=\"Bending strain\",\n", " x_axis_label=\"Strain \\N{GREEK SMALL LETTER EPSILON}\\u2098 [%]\",\n", " y_range=fig_stress_N.y_range)\n", "fig_bending_strain.yaxis.visible = False\n", "fig_stress_V = figure(**options_stress_strain,\n", " tooltips= [(\"Stress\", \"@x MPa\"),\n", " (\"Height\", \"@y mm\")],\n", " title=\"Shear stress\",\n", " x_axis_label=\"Stress \\N{GREEK SMALL LETTER TAU}\\u1d65 [MPa]\")\n", "fig_stress_V.yaxis.visible = False\n", "fig_stress_sigma = figure(**options_stress_strain,\n", " tooltips= [(\"Stress\", \"@x MPa\"),\n", " (\"Height\", \"@y mm\")],\n", " title=\"Total stress \\N{GREEK SMALL LETTER SIGMA} and neutral axis\",\n", " y_range=fig_stress_N.y_range,\n", " y_axis_location=\"right\",\n", " x_axis_label=\"Stress \\N{GREEK SMALL LETTER SIGMA} [MPa]\")\n", "fig_stress_tau = figure(**options_stress_strain,\n", " tooltips= [(\"Stress\", \"@x MPa\"),\n", " (\"Height\", \"@y mm\")],\n", " title=\"Total stress \\N{GREEK SMALL LETTER TAU}\",\n", " y_range=fig_stress_V.y_range,\n", " y_axis_location=\"right\",\n", " x_axis_label=\"Stress \\N{GREEK SMALL LETTER TAU} [MPa]\")\n", "\n", "# plot stress N V M\n", "discr_stress_strain = 10\n", "scale_x = 25\n", "y_discr = np.linspace(0, h, discr_stress_strain)\n", "sigma_N = stst.compute_sigma_axial(y_discr, 0, A)\n", "N_stress_diag = models.stress_diagram(fig_stress_N, sigma_N, h,\n", " source_section_scheme, scale_x=scale_x/10)\n", "sigma_M = stst.compute_sigma_bending(y_discr, 0, Iy, yG)\n", "(M_stress_diag, centroid) = models.stress_diagram(fig_stress_M, sigma_M, h,\n", " source_section_scheme, True, yG, scale_x=scale_x)\n", "S_rect = beam_section.compute_first_moment_of_area(y_discr, b, h, yG)\n", "tau_V = stst.compute_tau_shear(y_discr, 0, S_rect, Iy, b)\n", "V_stress_diag = models.stress_diagram(fig_stress_V, tau_V, h, source_section_scheme, scale_x=1)\n", "\n", "# plot stress sigma and tau\n", "sigma_total = sigma_M + sigma_N\n", "(sigma_stress_diag, neutral_axis) = models.stress_diagram(fig_stress_sigma, sigma_total, h,\n", " source_section_scheme,True, yG, scale_x=scale_x)\n", "tau_total = tau_V\n", "tau_stress_diag = models.stress_diagram(fig_stress_tau, tau_total, h,\n", " source_section_scheme, scale_x=1)\n", "\n", "# plot strain N M\n", "strain_axial = stst.compute_epsilon_axial(y_discr, sigma_N, E)\n", "axial_strain_diag = models.strain_diagram(fig_axial_strain, strain_axial, h, source_section_scheme)\n", "strain_bending = stst.compute_epsilon_bending(y_discr, sigma_M, E)\n", "bending_strain_diag = models.strain_diagram(fig_bending_strain, strain_bending, h, source_section_scheme)\n", "\n", "\n", "# figures for NVM\n", "fig_NM_section = figure(**options_stress_strain,\n", " title=\"N and M at position x\",\n", " match_aspect=True)\n", "fig_NM_section.axis.visible = False\n", "fig_NM_section.grid.grid_line_alpha = 0\n", "\n", "fig_V_section = figure(**options_stress_strain,\n", " title=\"V at position x\",\n", " match_aspect=True)\n", "fig_V_section.axis.visible = False\n", "fig_V_section.grid.grid_line_alpha = 0\n", "\n", "# section with NVM\n", "models.section_diagram(fig_NM_section)\n", "models.section_diagram(fig_V_section)\n", "\n", "# NVM in section\n", "section_N = models.force_vector(fig_NM_section, 0, 0, 0, 0, 0, 'red')\n", "section_V = models.force_vector(fig_V_section, 0, 0, 0, 0, 0, 'red')\n", "(section_M_line, section_M_head, source_section_M) = models.define_curvedArrow(fig_NM_section, 0, 0, 0, size_head=0)\n", "\n", "# NVM label in section\n", "OFFSET_N = 1\n", "label_N_section = fig_NM_section.text(x=[P*1.1], y=[OFFSET_N], text=[\"\"], text_color=\"red\", text_baseline='bottom')\n", "label_M_section = fig_NM_section.text(x=[OFFSET_N*6], y=[-OFFSET_N*5], text=[\"\"], text_color=\"red\", text_baseline='top')\n", "label_V_section = fig_V_section.text(x=[OFFSET_N*5], y=[0], text=[\"\"], text_color=\"red\", text_baseline='middle')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Configure the logics:" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "args_slider_pos = dict(source=source,\n", " s_sb=source_scheme_beam,\n", " s_q=source_scheme_q,\n", " div_P=div_cb_P,\n", " div_f=div_forces,\n", " fP=scheme_axial_force,\n", " fRx=scheme_Rx_l,\n", " fRyl=scheme_Ry_l,\n", " fRyr=scheme_Ry_r,\n", " fN=scheme_N,\n", " fV=scheme_V,\n", " s_M=source_M,\n", " arr_head=scheme_M_head,\n", " centroid=centroid,\n", " neutral_axis=neutral_axis,\n", " N_stress_diag=N_stress_diag,\n", " axial_strain_diag=axial_strain_diag,\n", " V_stress_diag=V_stress_diag,\n", " M_stress_diag=M_stress_diag,\n", " bending_strain_diag=bending_strain_diag,\n", " sigma_stress_diag=sigma_stress_diag,\n", " tau_stress_diag=tau_stress_diag,\n", " section_N=section_N,\n", " section_V=section_V,\n", " section_M_head=section_M_head,\n", " s_section_M=source_section_M,\n", " label_N_section=label_N_section,\n", " label_V_section=label_V_section,\n", " label_M_section=label_M_section)\n", "code_slider_pos = f\"\"\"\n", "// retrieve data\n", "const db = source.data\n", "const data_sb = s_sb.data\n", "const data_q = s_q.data\n", "const FBD = db['FBD'][0]\n", "const pos = cb_obj.value\n", "const q = db['q'][0]\n", "const L = db['L'][0]\n", "\n", "// update data\n", "db['N'][0] = compute_N(db['P'][0])\n", "db['V'][0] = compute_V(pos, q, L)\n", "db['M'][0] = compute_M(pos, q, L)\n", "db['x'][0] = pos\n", "\n", "// check state\n", "check_state(db)\n", "\n", "// update:\n", "update_internal_forces(db, fN, fV, arr_head, s_M)\n", "update_scheme_position(db, data_sb, data_q)\n", "update_reactions(db, fRx, fRyl, fRyr)\n", "update_external_forces(db, fP, div_P)\n", "update_div_forces(db, div_f)\n", "update_axial_stress_strain(db, N_stress_diag, axial_strain_diag)\n", "update_bending_stress_strain(db, M_stress_diag, bending_strain_diag, centroid)\n", "update_shear_stress(db, V_stress_diag)\n", "update_total_stress(db, sigma_stress_diag, tau_stress_diag, neutral_axis)\n", "update_NVM_section(db, section_N, section_V, section_M_head, s_section_M, label_N_section, label_V_section, label_M_section)\n", "\n", "// apply the changes\n", "source.change.emit()\n", "s_sb.change.emit()\n", "s_q.change.emit()\n", "\n", "// declare functions\n", "{sb.implement_compute_NJS()}\n", "{sb.implement_compute_VJS()}\n", "{sb.implement_compute_MJS()}\n", "{sb.implement_update_internal_forcesJS()}\n", "{sb.implement_update_scheme_positionJS()}\n", "{sb.implement_update_reactionsJS()}\n", "{sb.implement_update_external_forcesJS()}\n", "{sb.implement_update_div_forcesJS()}\n", "{js.implement_linspaceJS()}\n", "{js.implement_parabolaJS()}\n", "{js.implement_arrow_alphaJS()}\n", "{js.implement_update_arrowJS()}\n", "{js.implement_arrow_growthJS()}\n", "{js.implement_update_curvedArrowJS()}\n", "{js.implement_update_NVM_diagramJS()}\n", "{models.implement_check_stateJS()}\n", "{js.implement_update_stress_diagramJS()}\n", "{js.implement_update_strain_diagramJS()}\n", "{beam_section.implement_compute_first_moment_of_areaJS()}\n", "{beam_section.implement_compute_first_moment_of_area_implicitJS()}\n", "{stst.implement_compute_sigma_axialJS()}\n", "{stst.implement_compute_sigma_bendingJS()}\n", "{stst.implement_compute_tau_shearJS()}\n", "{stst.implement_compute_epsilon_axialJS()}\n", "{stst.implement_compute_epsilon_bendingJS()}\n", "{stst.implement_compute_total_sigmaJS()}\n", "{stst.implement_compute_total_tauJS()}\n", "{stst.implement_compute_neutral_axisJS()}\n", "{js.implement_update_axial_stress_strainJS(discr_stress_strain)}\n", "{js.implement_update_bending_stress_strainJS(discr_stress_strain)}\n", "{js.implement_update_shear_stressJS(discr_stress_strain)}\n", "{js.implement_update_total_stressJS(discr_stress_strain)}\n", "{js.implement_update_NVM_sectionJS()}\n", "\"\"\"\n", "updade_slider_pos = CustomJS(args=args_slider_pos, code=code_slider_pos)\n", "\n", "\n", "args_slider_b = dict(source=source,\n", " s_b=source_beam,\n", " div=div_geo, \n", " section=section,\n", " support_r=support_r,\n", " centroid=centroid,\n", " neutral_axis=neutral_axis,\n", " N_stress_diag=N_stress_diag,\n", " axial_strain_diag=axial_strain_diag,\n", " V_stress_diag=V_stress_diag,\n", " M_stress_diag=M_stress_diag,\n", " bending_strain_diag=bending_strain_diag,\n", " sigma_stress_diag=sigma_stress_diag,\n", " tau_stress_diag=tau_stress_diag)\n", "code_change_b = f\"\"\"\n", "// retrieve data used\n", "const db = source.data\n", "const b = cb_obj.value // value of the slider\n", "const h = db['h'][0]\n", "const A = compute_area(b, h)\n", "const Iy = compute_inertia_y(b, h)\n", "const yG = db['yG'][0]\n", "const N = db['N'][0]\n", "const M = db['M'][0]\n", "\n", "// apply the changes\n", "db['b'][0] = b\n", "db['A'][0] = A\n", "db['Iy'][0] = Iy\n", "db['Iz'][0] = compute_inertia_z(b, h)\n", "db['y_n_axis'][0] = compute_neutral_axis(N, A, Iy, M, yG)\n", "\n", "// update\n", "update_div_geo(db, div)\n", "update_section(db, section)\n", "update_axial_stress_strain(db, N_stress_diag, axial_strain_diag)\n", "update_bending_stress_strain(db, M_stress_diag, bending_strain_diag, centroid)\n", "update_shear_stress(db, V_stress_diag)\n", "update_total_stress(db, sigma_stress_diag, tau_stress_diag, neutral_axis)\n", "\n", "// emit the changes\n", "source.change.emit()\n", "\n", "{beam_section.implement_update_div_geoJS()}\n", "{beam_section.implement_update_sectionJS()}\n", "{beam_section.implement_compute_areaJS()}\n", "{beam_section.implement_compute_inertia_yJS()}\n", "{beam_section.implement_compute_inertia_zJS()}\n", "{stst.implement_compute_neutral_axisJS()}\n", "{js.implement_update_axial_stress_strainJS(discr_stress_strain)}\n", "{js.implement_update_bending_stress_strainJS(discr_stress_strain)}\n", "{js.implement_update_shear_stressJS(discr_stress_strain)}\n", "{js.implement_update_total_stressJS(discr_stress_strain)}\n", "{js.implement_linspaceJS()}\n", "{stst.implement_compute_epsilon_axialJS()}\n", "{stst.implement_compute_epsilon_bendingJS()}\n", "{stst.implement_compute_sigma_axialJS()}\n", "{js.implement_update_stress_diagramJS()}\n", "{js.implement_update_strain_diagramJS()}\n", "{stst.implement_compute_sigma_bendingJS()}\n", "{stst.implement_compute_total_sigmaJS()}\n", "{stst.implement_compute_total_tauJS()}\n", "{beam_section.implement_compute_first_moment_of_areaJS()}\n", "{beam_section.implement_compute_first_moment_of_area_implicitJS()}\n", "{stst.implement_compute_tau_shearJS()}\n", "{beam_section.implement_compute_centroid_yJS()}\n", "{stst.implement_compute_neutral_axisJS()}\n", "\"\"\"\n", "update_b = CustomJS(args=args_slider_b, code=code_change_b)\n", "\n", "\n", "args_slider_h = dict(source=source,\n", " s_b=source_beam,\n", " s_ss=source_section_scheme,\n", " div=div_geo, \n", " section=section,\n", " support_r=support_r,\n", " centroid=centroid,\n", " neutral_axis=neutral_axis,\n", " N_stress_diag=N_stress_diag,\n", " axial_strain_diag=axial_strain_diag,\n", " V_stress_diag=V_stress_diag,\n", " M_stress_diag=M_stress_diag,\n", " bending_strain_diag=bending_strain_diag,\n", " sigma_stress_diag=sigma_stress_diag,\n", " tau_stress_diag=tau_stress_diag)\n", "code_change_h = f\"\"\"\n", "// retrieve data used\n", "const db = source.data\n", "const data_ss = s_ss.data\n", "const b = db['b'][0]\n", "const h = cb_obj.value // value of the slider\n", "const A = compute_area(b, h)\n", "const Iy = compute_inertia_y(b, h)\n", "const N = db['N'][0]\n", "const M = db['M'][0]\n", "const yG = compute_centroid_y(h)\n", "\n", "// apply the changes\n", "db['h'][0] = h\n", "db['A'][0] = A\n", "db['Iy'][0] = Iy\n", "db['Iz'][0] = compute_inertia_z(b, h)\n", "db['yG'][0] = yG\n", "db['y_n_axis'][0] = compute_neutral_axis(N, A, Iy, M, yG)\n", "data_ss['y'][1] = h // change the height of the section in the diagrams\n", "\n", "// update\n", "update_div_geo(db, div)\n", "update_section(db, section)\n", "update_axial_stress_strain(db, N_stress_diag, axial_strain_diag)\n", "update_bending_stress_strain(db, M_stress_diag, bending_strain_diag, centroid)\n", "update_shear_stress(db, V_stress_diag)\n", "update_total_stress(db, sigma_stress_diag, tau_stress_diag, neutral_axis)\n", "\n", "// emit the changes\n", "source.change.emit()\n", "s_ss.change.emit()\n", "\n", "{beam_section.implement_update_div_geoJS()}\n", "{beam_section.implement_update_sectionJS()}\n", "{beam_section.implement_compute_areaJS()}\n", "{beam_section.implement_compute_inertia_yJS()}\n", "{beam_section.implement_compute_inertia_zJS()}\n", "{beam_section.implement_compute_centroid_yJS()}\n", "{stst.implement_compute_neutral_axisJS()}\n", "{js.implement_update_axial_stress_strainJS(discr_stress_strain)}\n", "{js.implement_update_bending_stress_strainJS(discr_stress_strain)}\n", "{js.implement_update_shear_stressJS(discr_stress_strain)}\n", "{js.implement_update_total_stressJS(discr_stress_strain)}\n", "{js.implement_linspaceJS()}\n", "{stst.implement_compute_epsilon_axialJS()}\n", "{stst.implement_compute_epsilon_bendingJS()}\n", "{stst.implement_compute_sigma_axialJS()}\n", "{js.implement_update_stress_diagramJS()}\n", "{js.implement_update_strain_diagramJS()}\n", "{stst.implement_compute_sigma_bendingJS()}\n", "{stst.implement_compute_total_sigmaJS()}\n", "{stst.implement_compute_total_tauJS()}\n", "{beam_section.implement_compute_first_moment_of_areaJS()}\n", "{beam_section.implement_compute_first_moment_of_area_implicitJS()}\n", "{stst.implement_compute_tau_shearJS()}\n", "\"\"\"\n", "update_h = CustomJS(args=args_slider_h, code=code_change_h)\n", "\n", "\n", "args_checkbox_P = dict(source=source,\n", " s_M=source_M,\n", " div_P=div_cb_P,\n", " div_f=div_forces,\n", " fP=scheme_axial_force, \n", " fRx=scheme_Rx_l,\n", " fRyl=scheme_Ry_l,\n", " fRyr=scheme_Ry_r, \n", " fN=scheme_N,\n", " fV=scheme_V, \n", " arr_head=scheme_M_head,\n", " N_diag=N_diag,\n", " neutral_axis=neutral_axis,\n", " N_stress_diag=N_stress_diag,\n", " axial_strain_diag=axial_strain_diag,\n", " sigma_stress_diag=sigma_stress_diag,\n", " tau_stress_diag=tau_stress_diag,\n", " section_N=section_N,\n", " section_V=section_V,\n", " section_M_head=section_M_head,\n", " s_section_M=source_section_M,\n", " label_N_section=label_N_section,\n", " label_V_section=label_V_section,\n", " label_M_section=label_M_section)\n", "code_checkbox_P = f\"\"\"\n", "// retrieve var from the object that uses callback\n", "var f = cb_obj.active // checkbox P\n", "if (f.length==0) f = [1]\n", "const db = source.data\n", "\n", "// apply the changes\n", "db['P'][0] = {P}*(1-f)\n", "db['N'][0] = compute_N(db['P'][0])\n", "db['Rx'][0] = compute_Rx(db['P'][0])\n", "\n", "// update\n", "update_reactions(db, fRx, fRyl, fRyr)\n", "update_external_forces(db, fP, div_P)\n", "update_N_diagram(db, N_diag)\n", "update_internal_forces(db, fN, fV, arr_head, s_M)\n", "update_div_forces(db, div_f)\n", "update_axial_stress_strain(db, N_stress_diag, axial_strain_diag)\n", "update_total_stress(db, sigma_stress_diag, tau_stress_diag, neutral_axis)\n", "update_NVM_section(db, section_N, section_V, section_M_head, s_section_M, label_N_section, label_V_section, label_M_section)\n", "\n", "// emit the changes\n", "source.change.emit()\n", "\n", "// declare functions\n", "{sb.implement_update_external_forcesJS()}\n", "{sb.implement_update_reactionsJS()}\n", "{sb.implement_compute_RxJS()}\n", "{js.implement_update_arrowJS()}\n", "{js.implement_arrow_alphaJS()}\n", "{js.implement_update_NVM_diagramJS()}\n", "{sb.implement_compute_NJS()}\n", "{sb.implement_update_N_diagramJS(discr_NVM)}\n", "{sb.implement_update_internal_forcesJS()}\n", "{js.implement_update_curvedArrowJS()}\n", "{js.implement_update_axial_stress_strainJS(discr_stress_strain)}\n", "{js.implement_update_total_stressJS(discr_stress_strain)}\n", "{js.implement_linspaceJS()}\n", "{stst.implement_compute_epsilon_axialJS()}\n", "{stst.implement_compute_sigma_axialJS()}\n", "{js.implement_update_stress_diagramJS()}\n", "{js.implement_update_strain_diagramJS()}\n", "{stst.implement_compute_neutral_axisJS()}\n", "{stst.implement_compute_sigma_bendingJS()}\n", "{stst.implement_compute_total_sigmaJS()}\n", "{stst.implement_compute_total_tauJS()}\n", "{beam_section.implement_compute_first_moment_of_areaJS()}\n", "{beam_section.implement_compute_first_moment_of_area_implicitJS()}\n", "{stst.implement_compute_tau_shearJS()}\n", "{sb.implement_update_div_forcesJS()}\n", "{js.implement_update_NVM_sectionJS()}\n", "{js.implement_arrow_growthJS()}\n", "\"\"\"\n", "update_checkbox_P = CustomJS(args=args_checkbox_P, code=code_checkbox_P)\n", "\n", "\n", "args_radiogroup_FBD = dict(source=source, \n", " s_sb=source_scheme_beam,\n", " s_q=source_scheme_q,\n", " s_M=source_M, \n", " div_P=div_cb_P,\n", " fP=scheme_axial_force,\n", " fRx=scheme_Rx_l,\n", " fRyl=scheme_Ry_l,\n", " fRyr=scheme_Ry_r,\n", " fN=scheme_N, \n", " fV=scheme_V,\n", " arr_head=scheme_M_head,\n", " tau_stress_diag=tau_stress_diag,\n", " section_N=section_N,\n", " section_V=section_V,\n", " section_M_head=section_M_head,\n", " s_section_M=source_section_M,\n", " label_N_section=label_N_section,\n", " label_V_section=label_V_section,\n", " label_M_section=label_M_section)\n", "code_radiogroup_FBD = f\"\"\"\n", "// retrieve data\n", "const db = source.data\n", "const FBD = cb_obj.active\n", "const data_sb = s_sb.data\n", "const data_q = s_q.data\n", "const pos = db['x'][0]\n", "\n", "// apply the changes\n", "db['FBD'][0] = FBD\n", "\n", "// update\n", "check_state(db)\n", "update_internal_forces(db, fN, fV, arr_head, s_M)\n", "update_scheme_position(db, data_sb, data_q)\n", "update_reactions(db, fRx, fRyl, fRyr)\n", "update_external_forces(db, fP, div_P)\n", "update_NVM_section(db, section_N, section_V, section_M_head, s_section_M, label_N_section, label_V_section, label_M_section)\n", "\n", "// emit the changes\n", "source.change.emit()\n", "s_sb.change.emit()\n", "s_q.change.emit()\n", "\n", "{models.implement_check_stateJS()}\n", "{sb.implement_update_internal_forcesJS()}\n", "{sb.implement_update_scheme_positionJS()}\n", "{js.implement_update_curvedArrowJS()}\n", "{js.implement_update_arrowJS()}\n", "{sb.implement_update_reactionsJS()}\n", "{sb.implement_update_external_forcesJS()}\n", "{js.implement_arrow_alphaJS()}\n", "{js.implement_update_NVM_sectionJS()}\n", "{js.implement_arrow_growthJS()}\n", "\"\"\"\n", "update_radiogroup_FBD = CustomJS(args=args_radiogroup_FBD, code=code_radiogroup_FBD)\n", "\n", "\n", "args_slider_q = dict(source=source,\n", " s_q=source_scheme_q,\n", " s_M=source_M,\n", " div_f=div_forces,\n", " div_P=div_cb_P,\n", " fP=scheme_axial_force,\n", " fRx=scheme_Rx_l,\n", " fRyl=scheme_Ry_l,\n", " fRyr=scheme_Ry_r,\n", " fN=scheme_N,\n", " fV=scheme_V,\n", " arr_head=scheme_M_head,\n", " V_diag=V_diag,\n", " M_diag=M_diag,\n", " centroid=centroid,\n", " neutral_axis=neutral_axis,\n", " V_stress_diag=V_stress_diag,\n", " M_stress_diag=M_stress_diag,\n", " bending_strain_diag=bending_strain_diag,\n", " sigma_stress_diag=sigma_stress_diag,\n", " tau_stress_diag=tau_stress_diag,\n", " section_N=section_N,\n", " section_V=section_V,\n", " section_M_head=section_M_head,\n", " s_section_M=source_section_M,\n", " label_N_section=label_N_section,\n", " label_V_section=label_V_section,\n", " label_M_section=label_M_section)\n", "code_slider_q = f\"\"\"\n", "// retrieve data\n", "const db = source.data\n", "const q = cb_obj.value\n", "const pos = db['x'][0]\n", "const L = db['L'][0]\n", "\n", "// update q\n", "db['q'][0] = q\n", "db['V'][0] = compute_V(pos, q, L)\n", "db['M'][0] = compute_M(pos, q, L)\n", "db['Ry_l'][0] = compute_Ry_l(q, L)\n", "db['Ry_r'][0] = compute_Ry_r(q, L)\n", "\n", "// update\n", "update_u_load(db, s_q)\n", "update_reactions(db, fRx, fRyl, fRyr)\n", "update_external_forces(db, fP, div_P)\n", "update_V_diagram(db, V_diag)\n", "update_M_diagram(db, M_diag)\n", "update_internal_forces(db, fN, fV, arr_head, s_M)\n", "update_div_forces(db, div_f)\n", "update_bending_stress_strain(db, M_stress_diag, bending_strain_diag, centroid)\n", "update_shear_stress(db, V_stress_diag)\n", "update_total_stress(db, sigma_stress_diag, tau_stress_diag, neutral_axis)\n", "update_NVM_section(db, section_N, section_V, section_M_head, s_section_M, label_N_section, label_V_section, label_M_section)\n", "\n", "// apply changes\n", "source.change.emit()\n", "\n", "// declare functions\n", "{js.implement_update_arrowJS()}\n", "{js.implement_linspaceJS()}\n", "{js.implement_parabolaJS()}\n", "{js.implement_arrow_alphaJS()}\n", "{js.implement_update_arrowJS()}\n", "{sb.implement_compute_VJS()}\n", "{sb.implement_compute_MJS()}\n", "{sb.implement_compute_Ry_lJS()}\n", "{sb.implement_compute_Ry_rJS()}\n", "{js.implement_update_NVM_diagramJS()}\n", "{sb.implement_update_V_diagramJS(discr_NVM)}\n", "{sb.implement_update_M_diagramJS(discr_NVM)}\n", "{sb.implement_update_reactionsJS()}\n", "{sb.implement_update_external_forcesJS()}\n", "{sb.implement_update_u_loadJS(OFFSET_Q)}\n", "{sb.implement_update_internal_forcesJS()}\n", "{js.implement_update_curvedArrowJS()}\n", "{js.implement_update_axial_stress_strainJS(discr_stress_strain)}\n", "{js.implement_update_bending_stress_strainJS(discr_stress_strain)}\n", "{js.implement_update_shear_stressJS(discr_stress_strain)}\n", "{js.implement_update_total_stressJS(discr_stress_strain)}\n", "{stst.implement_compute_epsilon_bendingJS()}\n", "{stst.implement_compute_sigma_axialJS()}\n", "{js.implement_update_stress_diagramJS()}\n", "{js.implement_update_strain_diagramJS()}\n", "{stst.implement_compute_neutral_axisJS()}\n", "{beam_section.implement_compute_centroid_yJS()}\n", "{stst.implement_compute_sigma_bendingJS()}\n", "{stst.implement_compute_total_sigmaJS()}\n", "{stst.implement_compute_total_tauJS()}\n", "{beam_section.implement_compute_first_moment_of_areaJS()}\n", "{beam_section.implement_compute_first_moment_of_area_implicitJS()}\n", "{stst.implement_compute_tau_shearJS()}\n", "{sb.implement_update_div_forcesJS()}\n", "{js.implement_update_NVM_sectionJS()}\n", "{js.implement_arrow_growthJS()}\n", "\"\"\"\n", "update_slider_q = CustomJS(args=args_slider_q, code=code_slider_q)\n", "\n", "# apply the logics\n", "slider_b.js_on_change('value', update_b)\n", "slider_h.js_on_change('value', update_h)\n", "slider_position.js_on_change('value', updade_slider_pos)\n", "checkbox_P.js_on_click(update_checkbox_P)\n", "radiogroup_FBD.js_on_click(update_radiogroup_FBD)\n", "slider_q.js_on_change('value', update_slider_q)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Build the layout and show the figures. Note that the forces in the scheme are updated after moving the position of the point with the slider.\n", "Note that the value of the forces and moments shown below represents the intensity, thus is always positive. The direction is given by the vector in the scheme." ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Opening in existing browser session.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)\n" ] } ], "source": [ "padding_layout = 10\n", "layout1 = layout([\n", " [column(row(column(fig_scheme,\n", " row(fig_section, Spacer(width=padding_layout), column(Spacer(height=padding_layout),\n", " slider_b,\n", " slider_h,\n", " row(div_geo, div_forces),\n", " Spacer(height=padding_layout),\n", " slider_position,\n", " slider_q,\n", " div_rg_FBD,\n", " radiogroup_FBD,\n", " div_cb_P,\n", " checkbox_P))),\n", " column(fig_beam,\n", " Spacer(height=padding_layout),\n", " fig_N,\n", " fig_V,\n", " fig_M)),\n", " row(column(\n", " row(fig_NM_section, fig_axial_strain, fig_stress_N, fig_bending_strain, fig_stress_M, fig_stress_sigma),\n", " row(fig_V_section, Spacer(width=FIG_B_ss), fig_stress_V, Spacer(width=FIG_B_ss), Spacer(width=FIG_B_ss), fig_stress_tau),\n", " ))\n", " )],\n", "])\n", "\n", "show(layout1)" ] } ], "metadata": { "interpreter": { "hash": "f29f3a16a5c47811d2900cf82e6584cc83572ddcd5db25d9cf9bef77823b3d45" }, "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.8.10" } }, "nbformat": 4, "nbformat_minor": 2 }