Page MenuHomec4science

hidden_code_nb_mohr.py
No OneTemporary

File Metadata

Created
Sat, May 4, 16:26

hidden_code_nb_mohr.py

import math
import numpy as np
from bokeh.layouts import layout, column, row
from bokeh.models.annotations import Label, Arrow
from bokeh.models.arrow_heads import VeeHead
from bokeh.models import Div, CustomJS, Slider, Spacer, HoverTool
from bokeh.models.widgets import RadioButtonGroup, CheckboxButtonGroup
from bokeh.plotting import figure, show, ColumnDataSource, output_file, save
from bokeh.io import output_notebook
from cienpy import simplebeam as sb
from cienpy import rectangular_section as beam_section
from cienpy import stress_strain_elastic as stst
from cienpy import models
from cienpy import javascriptcodes as js
from cienpy import mohrcircle
output_notebook()
def main_code(L, h, b, A, Iy, Iz, yG, y_n_axis, q, P, E, N, V, M, Rx, Ry_l, Ry_r, discr_NVM, x_discr, N_discr, V_discr, M_discr, initial_y, initial_theta_element, sigma_axial, sigma_bending, sigma_tau, sigma_x0, sigma_y0, tau_0, sigma_average_mohr, r_circle_mohr, theta_principal, initial_theta, new_state):
########################################################
# Initialisation
########################################################
# constants for the visualisation
SCALE = 10
OFFSET_Q = q
MAX_B = 2*b
MAX_H = 2*h
MAX_Q = q/4*5
MAX_STRESS = 60
MAX_STRESS_MOHR = 10
MAX_DIM_STRESS_STATE = MAX_STRESS*2.5
# store the values in a specific format
data_beam = dict(
x=[0, L],
y=[0, 0]
)
data_scheme_beam = dict(
x=[0, L*SCALE],
y=[0, 0]
)
data_scheme_q = dict(
x=[0, 0, L*SCALE, L*SCALE],
y=[OFFSET_Q, OFFSET_Q+q, OFFSET_Q+q, OFFSET_Q],
x_fade=[0, 0, L*SCALE, L*SCALE]
)
data_section_scheme = dict(
x=[0, 0],
y=[0, h]
)
initial_position = L
initial_state = 'IDLE' # possible cases: IDLE, R_SEC, L_SEC
initial_FBD = 0 # right=0 left=1
data = dict( # stores every useful single variable
state=[initial_state],
FBD=[initial_FBD],
SCALE=[SCALE],
L=[L],
b=[b],
h=[h],
E=[E],
A=[A],
Iy=[Iy],
Iz=[Iz],
yG=[yG],
y_n_axis=[y_n_axis],
P=[P],
x=[initial_position],
y=[0],
y_var=[initial_y],
theta_element=[initial_theta_element], # rad
theta=[initial_theta], # rad
sigma_x0=[sigma_x0],
sigma_y0=[sigma_y0],
tau_0=[tau_0],
sigma_average=[sigma_average_mohr],
r_circle_mohr=[r_circle_mohr],
sigma_x=[new_state[0]],
sigma_y=[new_state[1]],
tau=[new_state[2]],
q=[q],
Rx=[Rx],
Ry_l=[Ry_l],
Ry_r=[Ry_r],
N=[N],
V=[V],
M=[M],
xF=[L*SCALE]
)
source_beam = ColumnDataSource(data_beam)
source_scheme_beam = ColumnDataSource(data_scheme_beam)
source_scheme_q = ColumnDataSource(data_scheme_q)
source_section_scheme = ColumnDataSource(data_section_scheme)
source = ColumnDataSource(data)
# Constants
FIG_H_B = 200 # height figure beam
FIG_B_B = 600 # width figure beam
FIG_H_S = FIG_H_B # height figure scheme
FIG_B_S = FIG_B_B # width figure scheme
FIG_H_SEC = 500 # height figure section
DIV_B_GEO = 170
DIV_B_FORCES = 170
FIG_MOHR = 600
FIG_STRESS_STATE = 600
########################################################
# Define figures, widgets and renderers as from the previous notebook
########################################################
options = dict(
toolbar_location=None
)
######################## Start modifications
# figure for the beam
paddingx = 0.2*L
int_x_b = (0-paddingx, L+paddingx)
int_y_b = (-MAX_H*0.2, MAX_H*1.4)
fig_beam = sb.define_fig_beam(int_x_b, int_y_b, options,
f_h=FIG_H_B, f_b=FIG_B_B)
# modify beam
#TODO: add to cienpy
def draw_beam_2D(fig, L: float, h: float, b_supp=0.25, ratio = 1.0):
"""
Function that draws the simple beam in a figure.
@param fig (bokeh.plotting.figure.Figure): Figure that will be the canvas for the plot.
@param src (bokeh.models.sources.ColumnDataSource): Source of the coordinates.
@param L (float): Length of the beam in m.
@param x (str): Key for the x values. Defaults to 'x'.
@param y (str): Key for the y values. Defaults to 'y'.
@param b_supp (float, optional): Size of the supports in x. Defaults to 0.3.
@param ratio (float, optional): Ratio of the figure (interval_y/height*100). Defaults to 1.0 (axis equal).
@return tuple: Tuple with the renderers of the beam and supports.
"""
beam = fig.rect([L/2], [h/2], width=L, height=h,
fill_color='lightgray', color='black', line_width=1)
supp_opt = dict(
fill_color='white',
line_color='black'
)
support_l = models.define_pinned(fig, 0, 0, b_supp, ratio, supp_opt)
support_r = models.define_roller(fig, L, 0, b_supp, ratio, supp_opt)
return (beam, support_l, support_r)
(beam, support_l, support_r) = draw_beam_2D(fig_beam, L, h,
ratio = (int_y_b[1]-int_y_b[0])/FIG_H_B*100)
# uniform load (beam)
if q!=0:
fig_beam.rect([L/2], [(int_y_b[1]+MAX_H)/2], width=L, height=(0.99*(int_y_b[1]-MAX_H)),
fill_color='blue', color='navy', fill_alpha=0.6, alpha=0.6)
fig_beam.text(x=[-0.2], y=[MAX_H], text=["q"], text_color="blue")
####################### End modification
# figure for the cross-section
fig_section = sb.define_fig_section(MAX_B*0.8, MAX_H*0.8, options, FIG_H_SEC)
# section
section = beam_section.draw_section(fig_section, b, h)
# show mechanical parameters
div_geo = Div(width= DIV_B_GEO,
text=beam_section.div_text_geo(round(h), round(b), round(L),
"{:.2e}".format(A),
"{:.2e}".format(Iy),
"{:.2e}".format(Iz)))
# change geometry
slider_b = Slider(
title="Change the width b [mm]",
start=10,
end=MAX_B,
step=10,
value=b
)
slider_h = Slider(
title="Change the height h [mm]",
start=20,
end=MAX_H,
step=20,
value=h
)
# reference system
axis_arrow_length = 0.8
axis_arrow_scale = 100
models.force_vector(fig_section, axis_arrow_length*10, 0, 0, 0, axis_arrow_length*axis_arrow_scale*1.6, 'gray') # y axis
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)
models.force_vector(fig_section, axis_arrow_length*10, 0, -axis_arrow_length*axis_arrow_scale, 0, 0, 'gray') # z axis
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')
# figure for the forces and moments
fig_scheme = sb.define_figure_scheme(L, SCALE, MAX_Q, OFFSET_Q, options, FIG_H_S, FIG_B_S)
# axial force (beam)
axial_force = models.force_vector(fig_beam, P, L+P/SCALE, L, 0, 0, 'green')
label_P_force = fig_beam.text(x=[L+P/2/SCALE], y=[OFFSET_Q/SCALE/2], text=["P"], text_color="green")
# position point
pos_opt = dict(
source=source,
size=10,
fill_alpha=0.5,
fill_color="magenta",
color="magenta",
alpha=0.5
)
forces_position = fig_scheme.circle('xF', 'y', **pos_opt)
# beam (scheme)
scheme_beam = fig_scheme.line('x', 'y', source=source_scheme_beam, line_width=2, color='black')
scheme_fade_beam = fig_scheme.line(x=[0, L*SCALE], y=[0, 0], line_width=2, color='black', alpha=0.2)
# uniform load (scheme)
scheme_u_load = fig_scheme.patch('x', 'y', source=source_scheme_q, fill_color='blue', color='navy',
fill_alpha=0.3, alpha=0.3)
scheme_fade_u_load = fig_scheme.patch('x_fade', 'y', source=source_scheme_q, fill_color='blue',
color='navy', fill_alpha=0.3, alpha=0.3)
# axial force (scheme)
scheme_axial_force = models.force_vector(fig_scheme, P, L*SCALE+P, L*SCALE, 0, 0, 'green')
# Reactions (scheme)
scheme_Ry_r = models.force_vector(fig_scheme, Ry_r, L*SCALE, L*SCALE, -Ry_r, 0, 'orange')
scheme_Ry_l = models.force_vector(fig_scheme, Ry_l, 0, 0, -Ry_l, 0, 'orange')
scheme_Rx_l = models.force_vector(fig_scheme, Rx, -Rx, 0, 0, 0, 'orange')
# force N
scheme_N = models.force_vector(fig_scheme, 0, 0, 0, 0, 0, 'red')
# force V
scheme_V = models.force_vector(fig_scheme, 0, 0, 0, 0, 0, 'red')
# moment M
(scheme_M_line, scheme_M_head, source_M) = models.define_curvedArrow(fig_scheme, 0, 0, 0, size_head=0)
# change the uniform load q
slider_q = Slider(
title="Change the uniform load q [kN/m]",
start=0.1,
end=MAX_Q,
step=0.1,
value=q
)
# choose position of interest
slider_position = Slider(
title="Change the position x along the beam [m]",
start=0,
end=L,
step=0.02,
value=L
)
# choose left or right FBD
div_rg_FBD = Div(text="Free-body diagram (FBD):")
radiogroup_FBD = RadioButtonGroup(labels=['Right-hand', 'Left-hand'], active=initial_FBD)
# choose axial force or not
div_cb_P = Div(text=f"Axial force P={P} kN (applied)")
checkbox_P = CheckboxButtonGroup(labels=['Apply or remove axial force P'], active=[0])
# show values of forces and moments
div_forces = Div(width=DIV_B_FORCES,
text=sb.div_text_forces(P, P, Ry_l, Ry_r, "No cross section analysed.", 0, 0, 0))
# figures for the diagrams
options_diag = dict(
toolbar_location=None,
x_axis_label="Position [m]",
plot_width=FIG_B_B,
x_range=fig_beam.x_range
)
fig_N = figure(**options_diag,
y_axis_label="Axial force N [kN]",
plot_height=int(FIG_H_B*0.8),
title="N V M Diagrams")
fig_V = figure(**options_diag,
y_axis_label="Shear force V [kN]",
plot_height=int(FIG_H_B*0.8))
fig_M = figure(**options_diag,
y_axis_label="Bending moment M [kNm]",
plot_height=FIG_H_B)
fig_N.xaxis.visible = False
fig_V.xaxis.visible = False
# plot N V M
N_diag = models.NVM_diagram(fig_N, x_discr, N_discr, L, source_beam)
fig_N.add_tools(HoverTool(renderers=[N_diag],
tooltips= [("Position", "@x m"), ("Axial force", "@y kN")]))
V_diag = models.NVM_diagram(fig_V, x_discr, V_discr, L, source_beam)
fig_V.add_tools(HoverTool(renderers=[V_diag],
tooltips= [("Position", "@x m"), ("Shear force", "@y kN")]))
M_diag = models.NVM_diagram(fig_M, x_discr, M_discr, L, source_beam)
fig_M.add_tools(HoverTool(renderers=[M_diag],
tooltips= [("Position", "@x m"), ("Bending moment", "@y kNm")]))
# point that shows the position that it's analyzed
N_position = fig_N.circle('x', 'N', **pos_opt)
V_position = fig_V.circle('x', 'V', **pos_opt)
M_position = fig_M.circle('x', 'M', **pos_opt)
# figures for the stresses and strains
FIG_B_ss = 200
FIG_H_ss = 200
options_stress_strain = dict(
toolbar_location=None,
y_axis_label="Height h [mm]",
plot_width=FIG_B_ss,
plot_height=FIG_H_ss
)
fig_stress_N = figure(**options_stress_strain,
title="Axial stress",
x_axis_label="Stress \N{GREEK SMALL LETTER SIGMA}\u2099 [MPa]")
fig_stress_N.yaxis.visible = False
fig_axial_strain = figure(**options_stress_strain,
title="Axial strain",
x_axis_label="Strain \N{GREEK SMALL LETTER EPSILON}\u2099 [%]",
y_range=fig_stress_N.y_range)
fig_axial_strain.yaxis.visible = False
fig_stress_M = figure(**options_stress_strain,
title="Bending stress and centroid",
y_range=fig_stress_N.y_range,
x_axis_label="Stress \N{GREEK SMALL LETTER SIGMA}\u2098 [MPa]")
fig_stress_M.yaxis.visible = False
fig_bending_strain = figure(**options_stress_strain,
title="Bending strain",
x_axis_label="Strain \N{GREEK SMALL LETTER EPSILON}\u2098 [%]",
y_range=fig_stress_N.y_range)
fig_bending_strain.yaxis.visible = False
fig_stress_V = figure(**options_stress_strain,
title="Shear stress",
x_axis_label="Stress \N{GREEK SMALL LETTER TAU}\u1d65 [MPa]")
fig_stress_V.yaxis.visible = False
fig_stress_sigma = figure(**options_stress_strain,
title="Total stress \N{GREEK SMALL LETTER SIGMA} and neutral axis",
y_range=fig_stress_N.y_range,
y_axis_location="right",
x_axis_label="Stress \N{GREEK SMALL LETTER SIGMA} [MPa]")
fig_stress_tau = figure(**options_stress_strain,
title="Total stress \N{GREEK SMALL LETTER TAU}",
y_range=fig_stress_V.y_range,
y_axis_location="right",
x_axis_label="Stress \N{GREEK SMALL LETTER TAU} [MPa]")
# plot stress N V M
discr_stress_strain = 201
scale_x = 25
y_discr = np.linspace(0, h, discr_stress_strain)
sigma_N = stst.compute_sigma_axial(y_discr, 0, A)
N_stress_diag = models.stress_diagram(fig_stress_N, sigma_N, h,
source_section_scheme, scale_x=scale_x/10)
fig_stress_N.add_tools(HoverTool(renderers=[N_stress_diag],
tooltips= [("Stress", "@x MPa"), ("Height", "@y mm")]))
sigma_M = stst.compute_sigma_bending(y_discr, 0, Iy, yG)
(M_stress_diag, centroid) = models.stress_diagram(fig_stress_M, sigma_M, h,
source_section_scheme, True, yG, scale_x=scale_x)
fig_stress_M.add_tools(HoverTool(renderers=[M_stress_diag],
tooltips= [("Stress", "@x MPa"), ("Height", "@y mm")]))
S_rect = beam_section.compute_first_moment_of_area(y_discr, b, h, yG)
tau_V = stst.compute_tau_shear(y_discr, 0, S_rect, Iy, b)
V_stress_diag = models.stress_diagram(fig_stress_V, tau_V, h, source_section_scheme, scale_x=1)
fig_stress_V.add_tools(HoverTool(renderers=[V_stress_diag],
tooltips= [("Stress", "@x MPa"), ("Height", "@y mm")]))
# plot stress sigma and tau
sigma_total = sigma_M + sigma_N
(sigma_stress_diag, neutral_axis) = models.stress_diagram(fig_stress_sigma, sigma_total, h,
source_section_scheme,True, yG, scale_x=scale_x)
fig_stress_sigma.add_tools(HoverTool(renderers=[sigma_stress_diag],
tooltips= [("Stress", "@x MPa"), ("Height", "@y mm")]))
tau_total = tau_V
tau_stress_diag = models.stress_diagram(fig_stress_tau, tau_total, h,
source_section_scheme, scale_x=1)
fig_stress_tau.add_tools(HoverTool(renderers=[tau_stress_diag],
tooltips= [("Stress", "@x MPa"), ("Height", "@y mm")]))
# plot strain N M
strain_axial = stst.compute_epsilon_axial(y_discr, sigma_N, E)
axial_strain_diag = models.strain_diagram(fig_axial_strain, strain_axial, h, source_section_scheme)
fig_axial_strain.add_tools(HoverTool(renderers=[axial_strain_diag],
tooltips= [("Strain", "@x %"), ("Height", "@y mm")]))
strain_bending = stst.compute_epsilon_bending(y_discr, sigma_M, E)
bending_strain_diag = models.strain_diagram(fig_bending_strain, strain_bending, h, source_section_scheme)
fig_bending_strain.add_tools(HoverTool(renderers=[bending_strain_diag],
tooltips= [("Strain", "@x %"), ("Height", "@y mm")]))
# figures for NVM
fig_NM_section = figure(**options_stress_strain,
title="N and M at position x",
match_aspect=True)
fig_NM_section.axis.visible = False
fig_NM_section.grid.grid_line_alpha = 0
fig_V_section = figure(**options_stress_strain,
title="V at position x",
match_aspect=True)
fig_V_section.axis.visible = False
fig_V_section.grid.grid_line_alpha = 0
# section with NVM
models.section_diagram(fig_NM_section)
models.section_diagram(fig_V_section)
# NVM in section
section_N = models.force_vector(fig_NM_section, 0, 0, 0, 0, 0, 'red')
section_V = models.force_vector(fig_V_section, 0, 0, 0, 0, 0, 'red')
(section_M_line, section_M_head, source_section_M) = models.define_curvedArrow(fig_NM_section, 0, 0, 0, size_head=0)
# NVM label in section
OFFSET_N = 1
label_N_section = fig_NM_section.text(x=[P*1.1], y=[OFFSET_N], text=[""], text_color="red", text_baseline='bottom')
label_M_section = fig_NM_section.text(x=[OFFSET_N*6], y=[-OFFSET_N*5], text=[""], text_color="red", text_baseline='top')
label_V_section = fig_V_section.text(x=[OFFSET_N*5], y=[0], text=[""], text_color="red", text_baseline='middle')
########################################################
# Define the new figures, widgets and renderers
########################################################
SCALE_TAU = 5
# Modify the beam figure and plots (see in the previous code cell)
# Modifiy focus point to square in beam
beam_position = fig_beam.square('x', 'y_var', **pos_opt)
# choose height of interest
slider_y = Slider(
title="Change the height y along the section [mm]",
start=0,
end=h,
step=1,
value=initial_y
)
# choose angle theta of interest
slider_theta_element = Slider(
title="Change the angle \N{GREEK SMALL LETTER THETA} of the element [°]",
start=0,
end=90,
step=0.5,
value=initial_theta_element
)
# figure Mohr circle
fig_Mohr_circle = figure(toolbar_location=None,
x_axis_label="Stress \N{GREEK SMALL LETTER SIGMA} [MPa]",
y_axis_label="Stress \N{GREEK SMALL LETTER TAU} [MPa]",
plot_height=FIG_MOHR,
plot_width=FIG_MOHR,
match_aspect=True,
# x_range=[-MAX_STRESS_MOHR, MAX_STRESS_MOHR],
title="Mohr circle, x axis: stress \N{GREEK SMALL LETTER SIGMA} [MPa], y axis: stress \N{GREEK SMALL LETTER TAU} [MPa]"
)
fig_Mohr_circle.axis.fixed_location = 0
# figure stress state element
fig_stress_state = figure(toolbar_location=None,
plot_height=FIG_STRESS_STATE,
plot_width=FIG_STRESS_STATE,
match_aspect=True,
title="Stress state"
)
fig_stress_state.grid.grid_line_alpha = 0
fig_stress_state.axis.visible = False
fig_stress_state.min_border_left = 0
fig_stress_state.rect([MAX_DIM_STRESS_STATE*0.4], [MAX_DIM_STRESS_STATE*0.4],
width=MAX_DIM_STRESS_STATE*1.2,
height=MAX_DIM_STRESS_STATE*1.2,
alpha=0,
fill_alpha=0)
# stress state (theta 0)
fig_stress_state.rect([0], [0],
width=MAX_STRESS/2,
height=MAX_STRESS/2,
angle=0,
fill_alpha=0, color='black', line_width=2)
fig_stress_state.text([0], [0],
text=["Fixed \nelement"],
text_align="center", text_baseline="middle",
text_font_size="14px")
# stress state variable
stress_state_theta = fig_stress_state.rect([MAX_STRESS*2], [0],
width=MAX_STRESS/2,
height=MAX_STRESS/2,
angle=initial_theta_element,
fill_alpha=0, color='black', line_width=2)
label_stress_state_theta = fig_stress_state.text([MAX_STRESS*2], [0],
text=["Rotating \nelement"],
text_align="center", text_baseline="middle",
text_font_size="14px")
# rotating axis
rotating_axis = fig_stress_state.line([0, MAX_DIM_STRESS_STATE], [0, 0],
line_dash="4 4", line_color="black", line_width=0.5)
# arc and label theta in stress state
arc_theta_element = fig_stress_state.arc(x=[0], y=[0],
radius=MAX_STRESS, start_angle=0, end_angle=0,
line_color="gray", line_dash="2 5")
label_theta_element = fig_stress_state.text([MAX_STRESS], [0],
text=[""],
text_baseline="middle", x_offset=5, text_font_size="14px")
# fixed axis
fig_stress_state.line([0, MAX_DIM_STRESS_STATE], [0, 0],
line_dash="4 4", line_color="black", line_width=0.5)
# stress state arrows
arrows_stress_state = models.set_arrows_stress_state(fig_stress_state, sigma_x0, sigma_y0, tau_0, MAX_STRESS/2,
SCALE_TAU)
# stress state theta arrows
arrows_stress_state_theta = models.set_arrows_stress_state(fig_stress_state, sigma_x0, sigma_y0, tau_0, MAX_STRESS/2,
SCALE_TAU, MAX_STRESS*2)
# Mohr circle
Mohr_circle = fig_Mohr_circle.circle([sigma_average_mohr], [0],
radius=r_circle_mohr,
fill_alpha=0, color="gray")
# arc and label theta in Mohr circle
arc_theta_Mohr = fig_Mohr_circle.arc(x=[sigma_average_mohr], y=[0],
radius=r_circle_mohr/2, start_angle=0, end_angle=0,
line_color="gray", line_dash="2 5")
label_theta_Mohr = fig_Mohr_circle.text([sigma_average_mohr+r_circle_mohr/2], [0],
text=[""],
text_baseline="middle", x_offset=5, text_font_size="14px")
arc_theta_p_Mohr = fig_Mohr_circle.arc(x=[sigma_average_mohr], y=[0],
radius=r_circle_mohr/2, start_angle=0, end_angle=0,
line_color="gray", line_dash="2 5")
label_theta_p_Mohr = fig_Mohr_circle.text([sigma_average_mohr+r_circle_mohr/5*2], [0],
text=[""],
text_baseline="middle", x_offset=5, text_font_size="14px")
# linking line and two points from current stress state
mohr_points_opt = dict(
size=5,
fill_alpha=0.5,
alpha=0.5
)
line_stress_state = fig_Mohr_circle.line([sigma_x0, tau_0], [sigma_y0, -tau_0],
line_dash="4 4", line_color="blue", line_width=0.5)
points_stress_state = fig_Mohr_circle.circle([sigma_x0, tau_0], [sigma_y0, -tau_0],
**mohr_points_opt, color="blue", fill_color="blue")
str_label_stress_state1 = "Fixed element \n(\N{GREEK SMALL LETTER SIGMA}\N{LATIN SUBSCRIPT SMALL LETTER X}\N{SUBSCRIPT ZERO}, \N{GREEK SMALL LETTER TAU}\N{SUBSCRIPT ZERO})"
# NB: no subscript of latin y, so use gamma (very similar in the display)
str_label_stress_state2 = "Fixed element \n(\N{GREEK SMALL LETTER SIGMA}\N{Greek Subscript Small Letter Gamma}\N{SUBSCRIPT ZERO}, -\N{GREEK SMALL LETTER TAU}\N{SUBSCRIPT ZERO})"
label_points_stress_state = fig_Mohr_circle.text([sigma_x0, tau_0], [sigma_y0, -tau_0],
text=[str_label_stress_state1, str_label_stress_state2],
color="blue", x_offset=5, y_offset=18, text_font_size="14px")
# linking line and two points from stress state in function of theta
line_stress_state_theta = fig_Mohr_circle.line([sigma_x0, tau_0], [sigma_y0, -tau_0],
line_dash="4 4", line_color="red", line_width=0.5)
points_stress_state_theta = fig_Mohr_circle.circle([sigma_x0, tau_0], [sigma_y0, -tau_0],
**mohr_points_opt, color="red", fill_color="red")
str_label_stress_state_theta1 = "Rotating element \n(\N{GREEK SMALL LETTER SIGMA}\N{LATIN SUBSCRIPT SMALL LETTER X}, \N{GREEK SMALL LETTER TAU})"
# NB: no subscript of latin y, so use gamma (very similar in the display)
str_label_stress_state_theta2 = "Rotating element \n(\N{GREEK SMALL LETTER SIGMA}\N{Greek Subscript Small Letter Gamma}, -\N{GREEK SMALL LETTER TAU})"
label_points_stress_state_theta = fig_Mohr_circle.text([sigma_x0, tau_0], [sigma_y0, -tau_0],
text=[str_label_stress_state_theta1, str_label_stress_state_theta2],
text_align="right",
color="red", x_offset=-5, y_offset=18, text_font_size="14px")
# add hover for 4 points
fig_Mohr_circle.add_tools(HoverTool(renderers=[points_stress_state, points_stress_state_theta],
tooltips= [("Sigma", "@x MPa"), ("Tau", "@y MPa")]))
########################################################
# Configurethe logics
########################################################
update_circle_mohr = f"""
const y_var = db['y_var'][0]
const A = db['A'][0]
const b = db['b'][0]
const h = db['h'][0]
const yG = db['yG'][0]
const Iy = db['Iy'][0]
const theta_element = db['theta_element'][0]
const sigma_x0 = compute_total_sigma(compute_sigma_axial(N, A), compute_sigma_bending(y_var, M, Iy, yG))
const sigma_y0 = 0
const tau_0 = compute_total_tau(compute_tau_shear(V, compute_first_moment_of_area(y_var, b, h, yG), Iy, b))
const sigma_average = compute_sigma_average_mohr(sigma_x0, sigma_y0)
const r_circle = compute_radius_mohr(sigma_x0, sigma_y0, tau_0)
const theta_principal = compute_principal_theta_mohr(sigma_x0, sigma_y0, tau_0)
const theta = compute_theta_mohr(theta_element, theta_principal)
const new_state = compute_stress_state_mohr(sigma_average, r_circle, theta)
// update data
db['sigma_x0'][0] = sigma_x0
db['sigma_y0'][0] = sigma_y0
db['tau_0'][0] = tau_0
db['sigma_average'][0] = sigma_average
db['r_circle_mohr'][0] = r_circle
db['sigma_x'][0] = new_state[0]
db['sigma_y'][0] = new_state[1]
db['tau'][0] = new_state[2]
db['theta'][0] = theta
update_circle_mohr(db, Mohr_circle, line_stress_state, points_stress_state, label_points_stress_state, line_stress_state_theta, points_stress_state_theta, label_points_stress_state_theta, arc_theta_Mohr, label_theta_Mohr, arc_theta_p_Mohr, label_theta_p_Mohr)
"""
args_slider_pos = dict(source=source,
s_sb=source_scheme_beam,
s_q=source_scheme_q,
div_P=div_cb_P,
div_f=div_forces,
fP=scheme_axial_force,
fRx=scheme_Rx_l,
fRyl=scheme_Ry_l,
fRyr=scheme_Ry_r,
fN=scheme_N,
fV=scheme_V,
s_M=source_M,
arr_head=scheme_M_head,
centroid=centroid,
neutral_axis=neutral_axis,
N_stress_diag=N_stress_diag,
axial_strain_diag=axial_strain_diag,
V_stress_diag=V_stress_diag,
M_stress_diag=M_stress_diag,
bending_strain_diag=bending_strain_diag,
sigma_stress_diag=sigma_stress_diag,
tau_stress_diag=tau_stress_diag,
section_N=section_N,
section_V=section_V,
section_M_head=section_M_head,
s_section_M=source_section_M,
label_N_section=label_N_section,
label_V_section=label_V_section,
label_M_section=label_M_section,
Mohr_circle=Mohr_circle,
line_stress_state=line_stress_state,
line_stress_state_theta=line_stress_state_theta,
points_stress_state=points_stress_state,
points_stress_state_theta=points_stress_state_theta,
label_points_stress_state=label_points_stress_state,
label_points_stress_state_theta=label_points_stress_state_theta,
arc_theta_Mohr=arc_theta_Mohr,
label_theta_Mohr=label_theta_Mohr,
arc_theta_p_Mohr=arc_theta_p_Mohr,
label_theta_p_Mohr=label_theta_p_Mohr,
arrow_sigma_x1=arrows_stress_state[0],
arrow_sigma_x2=arrows_stress_state[1],
arrow_sigma_y1=arrows_stress_state[2],
arrow_sigma_y2=arrows_stress_state[3],
arrow_tau_x1=arrows_stress_state[4],
arrow_tau_x2=arrows_stress_state[5],
arrow_tau_y1=arrows_stress_state[6],
arrow_tau_y2=arrows_stress_state[7],
arrow_sigma_x1_theta=arrows_stress_state_theta[0],
arrow_sigma_x2_theta=arrows_stress_state_theta[1],
arrow_sigma_y1_theta=arrows_stress_state_theta[2],
arrow_sigma_y2_theta=arrows_stress_state_theta[3],
arrow_tau_x1_theta=arrows_stress_state_theta[4],
arrow_tau_x2_theta=arrows_stress_state_theta[5],
arrow_tau_y1_theta=arrows_stress_state_theta[6],
arrow_tau_y2_theta=arrows_stress_state_theta[7])
code_slider_pos = f"""
// retrieve data
const db = source.data
const data_sb = s_sb.data
const data_q = s_q.data
const FBD = db['FBD'][0]
const pos = cb_obj.value
const q = db['q'][0]
const L = db['L'][0]
const N = compute_N(db['P'][0])
const V = compute_V(pos, q, L)
const M = compute_M(pos, q, L)
// update data
db['N'][0] = N
db['V'][0] = V
db['M'][0] = M
db['x'][0] = pos
// check state
check_state(db)
// update:
update_internal_forces(db, fN, fV, arr_head, s_M)
update_scheme_position(db, data_sb, data_q)
update_reactions(db, fRx, fRyl, fRyr)
update_external_forces(db, fP, div_P)
update_div_forces(db, div_f)
update_axial_stress_strain(db, N_stress_diag, axial_strain_diag)
update_bending_stress_strain(db, M_stress_diag, bending_strain_diag, centroid)
update_shear_stress(db, V_stress_diag)
update_total_stress(db, sigma_stress_diag, tau_stress_diag, neutral_axis)
update_NVM_section(db, section_N, section_V, section_M_head, s_section_M, label_N_section, label_V_section, label_M_section)
{update_circle_mohr}
update_sigmax_state(db, arrow_sigma_x1, arrow_sigma_x2)
update_sigmay_state(db, arrow_sigma_y1, arrow_sigma_y2)
update_tau_state(db, arrow_tau_x1, arrow_tau_x2, arrow_tau_y1, arrow_tau_y2)
update_sigmax_state_theta(db, arrow_sigma_x1_theta, arrow_sigma_x2_theta)
update_sigmay_state_theta(db, arrow_sigma_y1_theta, arrow_sigma_y2_theta)
update_tau_state_theta(db, arrow_tau_x1_theta,arrow_tau_x2_theta, arrow_tau_y1_theta, arrow_tau_y2_theta)
// apply the changes
source.change.emit()
s_sb.change.emit()
s_q.change.emit()
// declare functions
{sb.implement_compute_NJS()}
{sb.implement_compute_VJS()}
{sb.implement_compute_MJS()}
{sb.implement_update_internal_forcesJS()}
{sb.implement_update_scheme_positionJS()}
{sb.implement_update_reactionsJS()}
{sb.implement_update_external_forcesJS()}
{sb.implement_update_div_forcesJS()}
{js.implement_linspaceJS()}
{js.implement_parabolaJS()}
{js.implement_arrow_alphaJS()}
{js.implement_update_arrowJS()}
{js.implement_arrow_growthJS()}
{js.implement_update_curvedArrowJS()}
{js.implement_update_NVM_diagramJS()}
{models.implement_check_stateJS()}
{js.implement_update_stress_diagramJS()}
{js.implement_update_strain_diagramJS()}
{beam_section.implement_compute_first_moment_of_areaJS()}
{beam_section.implement_compute_first_moment_of_area_implicitJS()}
{stst.implement_compute_sigma_axialJS()}
{stst.implement_compute_sigma_bendingJS()}
{stst.implement_compute_tau_shearJS()}
{stst.implement_compute_epsilon_axialJS()}
{stst.implement_compute_epsilon_bendingJS()}
{stst.implement_compute_neutral_axisJS()}
{stst.implement_compute_total_sigmaJS()}
{stst.implement_compute_total_tauJS()}
{js.implement_update_axial_stress_strainJS(discr_stress_strain)}
{js.implement_update_bending_stress_strainJS(discr_stress_strain)}
{js.implement_update_shear_stressJS(discr_stress_strain)}
{js.implement_update_total_stressJS(discr_stress_strain)}
{js.implement_update_NVM_sectionJS()}
{mohrcircle.implement_compute_radius_mohrJS()}
{mohrcircle.implement_compute_sigma_average_mohrJS()}
{mohrcircle.implement_compute_stress_state_mohrJS()}
{mohrcircle.implement_compute_principal_theta_mohrJS()}
{mohrcircle.implement_compute_theta_mohrJS()}
{mohrcircle.implement_update_circle_mohrJS()}
{mohrcircle.implement_update_sigmax_stateJS(MAX_STRESS/2)}
{mohrcircle.implement_update_sigmay_stateJS(MAX_STRESS/2)}
{mohrcircle.implement_update_tau_stateJS(MAX_STRESS/2, SCALE_TAU)}
{mohrcircle.implement_update_sigmax_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_sigmay_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_tau_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2, SCALE_TAU)}
"""
updade_slider_pos = CustomJS(args=args_slider_pos, code=code_slider_pos)
args_slider_b = dict(source=source,
div=div_geo,
section=section,
support_r=support_r,
centroid=centroid,
neutral_axis=neutral_axis,
N_stress_diag=N_stress_diag,
axial_strain_diag=axial_strain_diag,
V_stress_diag=V_stress_diag,
M_stress_diag=M_stress_diag,
bending_strain_diag=bending_strain_diag,
sigma_stress_diag=sigma_stress_diag,
tau_stress_diag=tau_stress_diag,
Mohr_circle=Mohr_circle,
line_stress_state=line_stress_state,
points_stress_state=points_stress_state,
points_stress_state_theta=points_stress_state_theta,
line_stress_state_theta=line_stress_state_theta,
label_points_stress_state=label_points_stress_state,
label_points_stress_state_theta=label_points_stress_state_theta,
arc_theta_Mohr=arc_theta_Mohr,
label_theta_Mohr=label_theta_Mohr,
arc_theta_p_Mohr=arc_theta_p_Mohr,
label_theta_p_Mohr=label_theta_p_Mohr,
arrow_sigma_x1=arrows_stress_state[0],
arrow_sigma_x2=arrows_stress_state[1],
arrow_sigma_y1=arrows_stress_state[2],
arrow_sigma_y2=arrows_stress_state[3],
arrow_tau_x1=arrows_stress_state[4],
arrow_tau_x2=arrows_stress_state[5],
arrow_tau_y1=arrows_stress_state[6],
arrow_tau_y2=arrows_stress_state[7],
arrow_sigma_x1_theta=arrows_stress_state_theta[0],
arrow_sigma_x2_theta=arrows_stress_state_theta[1],
arrow_sigma_y1_theta=arrows_stress_state_theta[2],
arrow_sigma_y2_theta=arrows_stress_state_theta[3],
arrow_tau_x1_theta=arrows_stress_state_theta[4],
arrow_tau_x2_theta=arrows_stress_state_theta[5],
arrow_tau_y1_theta=arrows_stress_state_theta[6],
arrow_tau_y2_theta=arrows_stress_state_theta[7])
code_change_b = f"""
// retrieve data used
const db = source.data
const b = cb_obj.value // value of the slider
const h = db['h'][0]
const A = compute_area(b, h)
const Iy = compute_inertia_y(b, h)
const yG = db['yG'][0]
const N = db['N'][0]
const M = db['M'][0]
const V = db['V'][0]
const y_var = db['y_var'][0]
const theta_element = db['theta_element'][0]
const sigma_x0 = compute_total_sigma(compute_sigma_axial(N, A), compute_sigma_bending(y_var, M, Iy, yG))
const sigma_y0 = 0
const tau_0 = compute_total_tau(compute_tau_shear(V, compute_first_moment_of_area(y_var, b, h, yG), Iy, b))
const sigma_average = compute_sigma_average_mohr(sigma_x0, sigma_y0)
const r_circle = compute_radius_mohr(sigma_x0, sigma_y0, tau_0)
const theta_principal = compute_principal_theta_mohr(sigma_x0, sigma_y0, tau_0)
const theta = compute_theta_mohr(theta_element, theta_principal)
const new_state = compute_stress_state_mohr(sigma_average, r_circle, theta)
// apply the changes
db['b'][0] = b
db['A'][0] = A
db['Iy'][0] = Iy
db['Iz'][0] = compute_inertia_z(b, h)
db['y_n_axis'][0] = compute_neutral_axis(N, A, Iy, M, yG)
db['sigma_x0'][0] = sigma_x0
db['sigma_y0'][0] = sigma_y0
db['tau_0'][0] = tau_0
db['sigma_average'][0] = sigma_average
db['r_circle_mohr'][0] = r_circle
db['sigma_x'][0] = new_state[0]
db['sigma_y'][0] = new_state[1]
db['tau'][0] = new_state[2]
db['theta'][0] = theta
// update
update_div_geo(db, div)
update_section(db, section)
update_axial_stress_strain(db, N_stress_diag, axial_strain_diag)
update_bending_stress_strain(db, M_stress_diag, bending_strain_diag, centroid)
update_shear_stress(db, V_stress_diag)
update_total_stress(db, sigma_stress_diag, tau_stress_diag, neutral_axis)
// Mohr circle
update_circle_mohr(db, Mohr_circle, line_stress_state, points_stress_state, label_points_stress_state, line_stress_state_theta, points_stress_state_theta, label_points_stress_state_theta, arc_theta_Mohr, label_theta_Mohr, arc_theta_p_Mohr, label_theta_p_Mohr)
// stress state
update_sigmax_state(db, arrow_sigma_x1, arrow_sigma_x2)
update_sigmay_state(db, arrow_sigma_y1, arrow_sigma_y2)
update_tau_state(db, arrow_tau_x1, arrow_tau_x2, arrow_tau_y1, arrow_tau_y2)
// stress state (theta)
update_sigmax_state_theta(db, arrow_sigma_x1_theta, arrow_sigma_x2_theta)
update_sigmay_state_theta(db, arrow_sigma_y1_theta, arrow_sigma_y2_theta)
update_tau_state_theta(db, arrow_tau_x1_theta,arrow_tau_x2_theta, arrow_tau_y1_theta, arrow_tau_y2_theta)
// emit the changes
source.change.emit()
{beam_section.implement_update_div_geoJS()}
{beam_section.implement_update_sectionJS()}
{beam_section.implement_compute_areaJS()}
{beam_section.implement_compute_inertia_yJS()}
{beam_section.implement_compute_inertia_zJS()}
{stst.implement_compute_neutral_axisJS()}
{js.implement_update_axial_stress_strainJS(discr_stress_strain)}
{js.implement_update_bending_stress_strainJS(discr_stress_strain)}
{js.implement_update_shear_stressJS(discr_stress_strain)}
{js.implement_update_total_stressJS(discr_stress_strain)}
{js.implement_linspaceJS()}
{stst.implement_compute_epsilon_axialJS()}
{stst.implement_compute_epsilon_bendingJS()}
{stst.implement_compute_sigma_axialJS()}
{js.implement_update_stress_diagramJS()}
{js.implement_update_strain_diagramJS()}
{stst.implement_compute_sigma_bendingJS()}
{stst.implement_compute_total_sigmaJS()}
{stst.implement_compute_total_tauJS()}
{beam_section.implement_compute_first_moment_of_areaJS()}
{beam_section.implement_compute_first_moment_of_area_implicitJS()}
{stst.implement_compute_tau_shearJS()}
{beam_section.implement_compute_centroid_yJS()}
{stst.implement_compute_neutral_axisJS()}
{js.implement_arrow_growthJS()}
{mohrcircle.implement_compute_radius_mohrJS()}
{mohrcircle.implement_compute_stress_state_mohrJS()}
{mohrcircle.implement_compute_sigma_average_mohrJS()}
{mohrcircle.implement_compute_principal_theta_mohrJS()}
{mohrcircle.implement_compute_theta_mohrJS()}
{mohrcircle.implement_update_circle_mohrJS()}
{js.implement_update_arrowJS()}
{mohrcircle.implement_update_sigmax_stateJS(MAX_STRESS/2)}
{mohrcircle.implement_update_sigmay_stateJS(MAX_STRESS/2)}
{mohrcircle.implement_update_tau_stateJS(MAX_STRESS/2, SCALE_TAU)}
{mohrcircle.implement_update_sigmax_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_sigmay_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_tau_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2, SCALE_TAU)}
"""
update_b = CustomJS(args=args_slider_b, code=code_change_b)
args_slider_h = dict(source=source,
s_ss=source_section_scheme,
div=div_geo,
section=section,
support_r=support_r,
centroid=centroid,
neutral_axis=neutral_axis,
N_stress_diag=N_stress_diag,
axial_strain_diag=axial_strain_diag,
V_stress_diag=V_stress_diag,
M_stress_diag=M_stress_diag,
bending_strain_diag=bending_strain_diag,
sigma_stress_diag=sigma_stress_diag,
tau_stress_diag=tau_stress_diag,
slider_y=slider_y,
beam=beam,
Mohr_circle=Mohr_circle,
line_stress_state=line_stress_state,
points_stress_state=points_stress_state,
points_stress_state_theta=points_stress_state_theta,
line_stress_state_theta=line_stress_state_theta,
label_points_stress_state=label_points_stress_state,
label_points_stress_state_theta=label_points_stress_state_theta,
arc_theta_Mohr=arc_theta_Mohr,
label_theta_Mohr=label_theta_Mohr,
arc_theta_p_Mohr=arc_theta_p_Mohr,
label_theta_p_Mohr=label_theta_p_Mohr,
arrow_sigma_x1=arrows_stress_state[0],
arrow_sigma_x2=arrows_stress_state[1],
arrow_sigma_y1=arrows_stress_state[2],
arrow_sigma_y2=arrows_stress_state[3],
arrow_tau_x1=arrows_stress_state[4],
arrow_tau_x2=arrows_stress_state[5],
arrow_tau_y1=arrows_stress_state[6],
arrow_tau_y2=arrows_stress_state[7],
arrow_sigma_x1_theta=arrows_stress_state_theta[0],
arrow_sigma_x2_theta=arrows_stress_state_theta[1],
arrow_sigma_y1_theta=arrows_stress_state_theta[2],
arrow_sigma_y2_theta=arrows_stress_state_theta[3],
arrow_tau_x1_theta=arrows_stress_state_theta[4],
arrow_tau_x2_theta=arrows_stress_state_theta[5],
arrow_tau_y1_theta=arrows_stress_state_theta[6],
arrow_tau_y2_theta=arrows_stress_state_theta[7])
code_change_h = f"""
// solve sliders conflict
const db = source.data
const h = cb_obj.value // value of the slider
if (h < db['y_var'][0]) {{
db['y_var'][0] = h
}}
slider_y.end = h
if (h < slider_y.value) {{
slider_y.value = h
}}
// retrieve data used
const data_ss = s_ss.data
const b = db['b'][0]
const A = compute_area(b, h)
const Iy = compute_inertia_y(b, h)
const N = db['N'][0]
const V = db['V'][0]
const M = db['M'][0]
const yG = compute_centroid_y(h)
const y_var = db['y_var'][0]
const theta_element = db['theta_element'][0]
const sigma_x0 = compute_total_sigma(compute_sigma_axial(N, A), compute_sigma_bending(y_var, M, Iy, yG))
const sigma_y0 = 0
const tau_0 = compute_total_tau(compute_tau_shear(V, compute_first_moment_of_area(y_var, b, h, yG), Iy, b))
const sigma_average = compute_sigma_average_mohr(sigma_x0, sigma_y0)
const r_circle = compute_radius_mohr(sigma_x0, sigma_y0, tau_0)
const theta_principal = compute_principal_theta_mohr(sigma_x0, sigma_y0, tau_0)
const theta = compute_theta_mohr(theta_element, theta_principal)
const new_state = compute_stress_state_mohr(sigma_average, r_circle, theta)
// apply the changes
db['h'][0] = h
db['A'][0] = A
db['Iy'][0] = Iy
db['Iz'][0] = compute_inertia_z(b, h)
db['yG'][0] = yG
db['y_n_axis'][0] = compute_neutral_axis(N, A, Iy, M, yG)
beam.glyph.height = h // change the beam height
beam.glyph.y = h/2
data_ss['y'][1] = h // change the height of the section in the diagrams
db['sigma_x0'][0] = sigma_x0
db['sigma_y0'][0] = sigma_y0
db['tau_0'][0] = tau_0
db['sigma_average'][0] = sigma_average
db['r_circle_mohr'][0] = r_circle
db['sigma_x'][0] = new_state[0]
db['sigma_y'][0] = new_state[1]
db['tau'][0] = new_state[2]
db['theta'][0] = theta
// update
update_div_geo(db, div)
update_section(db, section)
update_axial_stress_strain(db, N_stress_diag, axial_strain_diag)
update_bending_stress_strain(db, M_stress_diag, bending_strain_diag, centroid)
update_shear_stress(db, V_stress_diag)
update_total_stress(db, sigma_stress_diag, tau_stress_diag, neutral_axis)
// Mohr circle
update_circle_mohr(db, Mohr_circle, line_stress_state, points_stress_state, label_points_stress_state, line_stress_state_theta, points_stress_state_theta, label_points_stress_state_theta, arc_theta_Mohr, label_theta_Mohr, arc_theta_p_Mohr, label_theta_p_Mohr)
// stress state
update_sigmax_state(db, arrow_sigma_x1, arrow_sigma_x2)
update_sigmay_state(db, arrow_sigma_y1, arrow_sigma_y2)
update_tau_state(db, arrow_tau_x1, arrow_tau_x2, arrow_tau_y1, arrow_tau_y2)
// stress state (theta)
update_sigmax_state_theta(db, arrow_sigma_x1_theta, arrow_sigma_x2_theta)
update_sigmay_state_theta(db, arrow_sigma_y1_theta, arrow_sigma_y2_theta)
update_tau_state_theta(db, arrow_tau_x1_theta,arrow_tau_x2_theta, arrow_tau_y1_theta, arrow_tau_y2_theta)
// emit the changes
source.change.emit()
s_ss.change.emit()
{beam_section.implement_update_div_geoJS()}
{beam_section.implement_update_sectionJS()}
{beam_section.implement_compute_areaJS()}
{beam_section.implement_compute_inertia_yJS()}
{beam_section.implement_compute_inertia_zJS()}
{beam_section.implement_compute_centroid_yJS()}
{stst.implement_compute_neutral_axisJS()}
{js.implement_update_axial_stress_strainJS(discr_stress_strain)}
{js.implement_update_bending_stress_strainJS(discr_stress_strain)}
{js.implement_update_shear_stressJS(discr_stress_strain)}
{js.implement_update_total_stressJS(discr_stress_strain)}
{js.implement_linspaceJS()}
{stst.implement_compute_epsilon_axialJS()}
{stst.implement_compute_epsilon_bendingJS()}
{stst.implement_compute_sigma_axialJS()}
{js.implement_update_stress_diagramJS()}
{js.implement_update_strain_diagramJS()}
{stst.implement_compute_sigma_bendingJS()}
{stst.implement_compute_total_sigmaJS()}
{stst.implement_compute_total_tauJS()}
{beam_section.implement_compute_first_moment_of_areaJS()}
{beam_section.implement_compute_first_moment_of_area_implicitJS()}
{stst.implement_compute_tau_shearJS()}
{js.implement_arrow_growthJS()}
{mohrcircle.implement_compute_radius_mohrJS()}
{mohrcircle.implement_compute_stress_state_mohrJS()}
{mohrcircle.implement_compute_sigma_average_mohrJS()}
{mohrcircle.implement_compute_principal_theta_mohrJS()}
{mohrcircle.implement_compute_theta_mohrJS()}
{mohrcircle.implement_update_circle_mohrJS()}
{js.implement_update_arrowJS()}
{mohrcircle.implement_update_sigmax_stateJS(MAX_STRESS/2)}
{mohrcircle.implement_update_sigmay_stateJS(MAX_STRESS/2)}
{mohrcircle.implement_update_tau_stateJS(MAX_STRESS/2, SCALE_TAU)}
{mohrcircle.implement_update_sigmax_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_sigmay_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_tau_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2, SCALE_TAU)}
"""
update_h = CustomJS(args=args_slider_h, code=code_change_h)
args_checkbox_P = dict(source=source,
s_M=source_M,
div_P=div_cb_P,
div_f=div_forces,
fP=scheme_axial_force,
fRx=scheme_Rx_l,
fRyl=scheme_Ry_l,
fRyr=scheme_Ry_r,
fN=scheme_N,
fV=scheme_V,
arr_head=scheme_M_head,
N_diag=N_diag,
neutral_axis=neutral_axis,
N_stress_diag=N_stress_diag,
axial_strain_diag=axial_strain_diag,
sigma_stress_diag=sigma_stress_diag,
tau_stress_diag=tau_stress_diag,
section_N=section_N,
section_V=section_V,
section_M_head=section_M_head,
s_section_M=source_section_M,
label_N_section=label_N_section,
label_V_section=label_V_section,
label_M_section=label_M_section,
Mohr_circle=Mohr_circle,
line_stress_state=line_stress_state,
points_stress_state=points_stress_state,
points_stress_state_theta=points_stress_state_theta,
line_stress_state_theta=line_stress_state_theta,
label_points_stress_state=label_points_stress_state,
label_points_stress_state_theta=label_points_stress_state_theta,
arc_theta_Mohr=arc_theta_Mohr,
label_theta_Mohr=label_theta_Mohr,
arc_theta_p_Mohr=arc_theta_p_Mohr,
label_theta_p_Mohr=label_theta_p_Mohr,
arrow_sigma_x1=arrows_stress_state[0],
arrow_sigma_x2=arrows_stress_state[1],
arrow_sigma_y1=arrows_stress_state[2],
arrow_sigma_y2=arrows_stress_state[3],
arrow_sigma_x1_theta=arrows_stress_state_theta[0],
arrow_sigma_x2_theta=arrows_stress_state_theta[1],
arrow_sigma_y1_theta=arrows_stress_state_theta[2],
arrow_sigma_y2_theta=arrows_stress_state_theta[3],
arrow_tau_x1_theta=arrows_stress_state_theta[4],
arrow_tau_x2_theta=arrows_stress_state_theta[5],
arrow_tau_y1_theta=arrows_stress_state_theta[6],
arrow_tau_y2_theta=arrows_stress_state_theta[7])
code_checkbox_P = f"""
// retrieve var from the object that uses callback
var f = cb_obj.active // checkbox P
if (f.length==0) f = [1]
const P = {P}*(1-f)
const db = source.data
const N = compute_N(P)
const M = db['M'][0]
const A = db['A'][0]
const Iy = db['Iy'][0]
const yG = db['yG'][0]
const y_var = db['y_var'][0]
const theta_element = db['theta_element'][0]
const sigma_x0 = compute_total_sigma(compute_sigma_axial(N, A), compute_sigma_bending(y_var, M, Iy, yG))
const sigma_y0 = 0
const tau_0 = db['tau_0'][0]
const sigma_average = compute_sigma_average_mohr(sigma_x0, sigma_y0)
const r_circle = compute_radius_mohr(sigma_x0, sigma_y0, tau_0)
const theta_principal = compute_principal_theta_mohr(sigma_x0, sigma_y0, tau_0)
const theta = compute_theta_mohr(theta_element, theta_principal)
const new_state = compute_stress_state_mohr(sigma_average, r_circle, theta)
// apply the changes
db['P'][0] = P
db['N'][0] = N
db['Rx'][0] = compute_Rx(db['P'][0])
db['sigma_x0'][0] = sigma_x0
db['sigma_y0'][0] = sigma_y0
db['sigma_average'][0] = sigma_average
db['r_circle_mohr'][0] = r_circle
db['sigma_x'][0] = new_state[0]
db['sigma_y'][0] = new_state[1]
db['tau'][0] = new_state[2]
db['theta'][0] = theta
// update
update_reactions(db, fRx, fRyl, fRyr)
update_external_forces(db, fP, div_P)
update_N_diagram(db, N_diag)
update_internal_forces(db, fN, fV, arr_head, s_M)
update_div_forces(db, div_f)
update_axial_stress_strain(db, N_stress_diag, axial_strain_diag)
update_total_stress(db, sigma_stress_diag, tau_stress_diag, neutral_axis)
update_NVM_section(db, section_N, section_V, section_M_head, s_section_M, label_N_section, label_V_section, label_M_section)
// Mohr circle
update_circle_mohr(db, Mohr_circle, line_stress_state, points_stress_state, label_points_stress_state, line_stress_state_theta, points_stress_state_theta, label_points_stress_state_theta, arc_theta_Mohr, label_theta_Mohr, arc_theta_p_Mohr, label_theta_p_Mohr)
// stress state
update_sigmax_state(db, arrow_sigma_x1, arrow_sigma_x2)
update_sigmay_state(db, arrow_sigma_y1, arrow_sigma_y2)
// stress state (theta)
update_sigmax_state_theta(db, arrow_sigma_x1_theta, arrow_sigma_x2_theta)
update_sigmay_state_theta(db, arrow_sigma_y1_theta, arrow_sigma_y2_theta)
update_tau_state_theta(db, arrow_tau_x1_theta,arrow_tau_x2_theta, arrow_tau_y1_theta, arrow_tau_y2_theta)
// emit the changes
source.change.emit()
// declare functions
{sb.implement_update_external_forcesJS()}
{sb.implement_update_reactionsJS()}
{sb.implement_compute_RxJS()}
{js.implement_update_arrowJS()}
{js.implement_arrow_alphaJS()}
{js.implement_update_NVM_diagramJS()}
{sb.implement_compute_NJS()}
{sb.implement_update_N_diagramJS(discr_NVM)}
{sb.implement_update_internal_forcesJS()}
{js.implement_update_curvedArrowJS()}
{js.implement_update_axial_stress_strainJS(discr_stress_strain)}
{js.implement_update_total_stressJS(discr_stress_strain)}
{js.implement_linspaceJS()}
{stst.implement_compute_epsilon_axialJS()}
{stst.implement_compute_sigma_axialJS()}
{js.implement_update_stress_diagramJS()}
{js.implement_update_strain_diagramJS()}
{stst.implement_compute_neutral_axisJS()}
{stst.implement_compute_sigma_bendingJS()}
{stst.implement_compute_total_sigmaJS()}
{sb.implement_update_div_forcesJS()}
{js.implement_update_NVM_sectionJS()}
{beam_section.implement_compute_first_moment_of_areaJS()}
{beam_section.implement_compute_first_moment_of_area_implicitJS()}
{stst.implement_compute_tau_shearJS()}
{stst.implement_compute_total_tauJS()}
{js.implement_arrow_growthJS()}
{mohrcircle.implement_compute_radius_mohrJS()}
{mohrcircle.implement_compute_stress_state_mohrJS()}
{mohrcircle.implement_compute_sigma_average_mohrJS()}
{mohrcircle.implement_compute_principal_theta_mohrJS()}
{mohrcircle.implement_compute_theta_mohrJS()}
{mohrcircle.implement_update_circle_mohrJS()}
{js.implement_update_arrowJS()}
{mohrcircle.implement_update_sigmax_stateJS(MAX_STRESS/2)}
{mohrcircle.implement_update_sigmay_stateJS(MAX_STRESS/2)}
{mohrcircle.implement_update_sigmax_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_sigmay_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_tau_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2, SCALE_TAU)}
"""
update_checkbox_P = CustomJS(args=args_checkbox_P, code=code_checkbox_P)
args_radiogroup_FBD = dict(source=source,
s_sb=source_scheme_beam,
s_q=source_scheme_q,
s_M=source_M,
div_P=div_cb_P,
fP=scheme_axial_force,
fRx=scheme_Rx_l,
fRyl=scheme_Ry_l,
fRyr=scheme_Ry_r,
fN=scheme_N,
fV=scheme_V,
arr_head=scheme_M_head,
tau_stress_diag=tau_stress_diag,
section_N=section_N,
section_V=section_V,
section_M_head=section_M_head,
s_section_M=source_section_M,
label_N_section=label_N_section,
label_V_section=label_V_section,
label_M_section=label_M_section)
code_radiogroup_FBD = f"""
// retrieve data
const db = source.data
const FBD = cb_obj.active
const data_sb = s_sb.data
const data_q = s_q.data
const pos = db['x'][0]
// apply the changes
db['FBD'][0] = FBD
// update
check_state(db)
update_internal_forces(db, fN, fV, arr_head, s_M)
update_scheme_position(db, data_sb, data_q)
update_reactions(db, fRx, fRyl, fRyr)
update_external_forces(db, fP, div_P)
update_NVM_section(db, section_N, section_V, section_M_head, s_section_M, label_N_section, label_V_section, label_M_section)
// emit the changes
source.change.emit()
s_sb.change.emit()
s_q.change.emit()
{models.implement_check_stateJS()}
{sb.implement_update_internal_forcesJS()}
{sb.implement_update_scheme_positionJS()}
{js.implement_update_curvedArrowJS()}
{js.implement_update_arrowJS()}
{sb.implement_update_reactionsJS()}
{sb.implement_update_external_forcesJS()}
{js.implement_arrow_alphaJS()}
{js.implement_update_NVM_sectionJS()}
{js.implement_arrow_growthJS()}
"""
update_radiogroup_FBD = CustomJS(args=args_radiogroup_FBD, code=code_radiogroup_FBD)
args_slider_q = dict(source=source,
s_q=source_scheme_q,
s_M=source_M,
div_f=div_forces,
div_P=div_cb_P,
fP=scheme_axial_force,
fRx=scheme_Rx_l,
fRyl=scheme_Ry_l,
fRyr=scheme_Ry_r,
fN=scheme_N,
fV=scheme_V,
arr_head=scheme_M_head,
V_diag=V_diag,
M_diag=M_diag,
centroid=centroid,
neutral_axis=neutral_axis,
V_stress_diag=V_stress_diag,
M_stress_diag=M_stress_diag,
bending_strain_diag=bending_strain_diag,
sigma_stress_diag=sigma_stress_diag,
tau_stress_diag=tau_stress_diag,
section_N=section_N,
section_V=section_V,
section_M_head=section_M_head,
s_section_M=source_section_M,
label_N_section=label_N_section,
label_V_section=label_V_section,
label_M_section=label_M_section,
Mohr_circle=Mohr_circle,
line_stress_state=line_stress_state,
points_stress_state=points_stress_state,
points_stress_state_theta=points_stress_state_theta,
line_stress_state_theta=line_stress_state_theta,
label_points_stress_state=label_points_stress_state,
label_points_stress_state_theta=label_points_stress_state_theta,
arc_theta_Mohr=arc_theta_Mohr,
label_theta_Mohr=label_theta_Mohr,
arc_theta_p_Mohr=arc_theta_p_Mohr,
label_theta_p_Mohr=label_theta_p_Mohr,
arrow_sigma_x1=arrows_stress_state[0],
arrow_sigma_x2=arrows_stress_state[1],
arrow_sigma_y1=arrows_stress_state[2],
arrow_sigma_y2=arrows_stress_state[3],
arrow_tau_x1=arrows_stress_state[4],
arrow_tau_x2=arrows_stress_state[5],
arrow_tau_y1=arrows_stress_state[6],
arrow_tau_y2=arrows_stress_state[7],
arrow_sigma_x1_theta=arrows_stress_state_theta[0],
arrow_sigma_x2_theta=arrows_stress_state_theta[1],
arrow_sigma_y1_theta=arrows_stress_state_theta[2],
arrow_sigma_y2_theta=arrows_stress_state_theta[3],
arrow_tau_x1_theta=arrows_stress_state_theta[4],
arrow_tau_x2_theta=arrows_stress_state_theta[5],
arrow_tau_y1_theta=arrows_stress_state_theta[6],
arrow_tau_y2_theta=arrows_stress_state_theta[7])
code_slider_q = f"""
// retrieve data
const db = source.data
const q = cb_obj.value
const pos = db['x'][0]
const L = db['L'][0]
const N = db['N'][0]
const V = compute_V(pos, q, L)
const M = compute_M(pos, q, L)
const y_var = db['y_var'][0]
const A = db['A'][0]
const b = db['b'][0]
const h = db['h'][0]
const yG = db['yG'][0]
const Iy = db['Iy'][0]
const theta_element = db['theta_element'][0]
const sigma_x0 = compute_total_sigma(compute_sigma_axial(N, A), compute_sigma_bending(y_var, M, Iy, yG))
const sigma_y0 = 0
const tau_0 = compute_total_tau(compute_tau_shear(V, compute_first_moment_of_area(y_var, b, h, yG), Iy, b))
const sigma_average = compute_sigma_average_mohr(sigma_x0, sigma_y0)
const r_circle = compute_radius_mohr(sigma_x0, sigma_y0, tau_0)
const theta_principal = compute_principal_theta_mohr(sigma_x0, sigma_y0, tau_0)
const theta = compute_theta_mohr(theta_element, theta_principal)
const new_state = compute_stress_state_mohr(sigma_average, r_circle, theta)
// update data
db['q'][0] = q
db['V'][0] = V
db['M'][0] = M
db['Ry_l'][0] = compute_Ry_l(q, L)
db['Ry_r'][0] = compute_Ry_r(q, L)
db['sigma_x0'][0] = sigma_x0
db['sigma_y0'][0] = sigma_y0
db['tau_0'][0] = tau_0
db['sigma_average'][0] = sigma_average
db['r_circle_mohr'][0] = r_circle
db['sigma_x'][0] = new_state[0]
db['sigma_y'][0] = new_state[1]
db['tau'][0] = new_state[2]
db['theta'][0] = theta
// update
update_u_load(db, s_q)
update_reactions(db, fRx, fRyl, fRyr)
update_external_forces(db, fP, div_P)
update_V_diagram(db, V_diag)
update_M_diagram(db, M_diag)
update_internal_forces(db, fN, fV, arr_head, s_M)
update_div_forces(db, div_f)
update_bending_stress_strain(db, M_stress_diag, bending_strain_diag, centroid)
update_shear_stress(db, V_stress_diag)
update_total_stress(db, sigma_stress_diag, tau_stress_diag, neutral_axis)
update_NVM_section(db, section_N, section_V, section_M_head, s_section_M, label_N_section, label_V_section, label_M_section)
// Mohr circle
update_circle_mohr(db, Mohr_circle, line_stress_state, points_stress_state, label_points_stress_state, line_stress_state_theta, points_stress_state_theta, label_points_stress_state_theta, arc_theta_Mohr, label_theta_Mohr, arc_theta_p_Mohr, label_theta_p_Mohr)
// stress state
update_sigmax_state(db, arrow_sigma_x1, arrow_sigma_x2)
update_sigmay_state(db, arrow_sigma_y1, arrow_sigma_y2)
update_tau_state(db, arrow_tau_x1, arrow_tau_x2, arrow_tau_y1, arrow_tau_y2)
// stress state (theta)
update_sigmax_state_theta(db, arrow_sigma_x1_theta, arrow_sigma_x2_theta)
update_sigmay_state_theta(db, arrow_sigma_y1_theta, arrow_sigma_y2_theta)
update_tau_state_theta(db, arrow_tau_x1_theta,arrow_tau_x2_theta, arrow_tau_y1_theta, arrow_tau_y2_theta)
// apply changes
source.change.emit()
// declare functions
{js.implement_update_arrowJS()}
{js.implement_linspaceJS()}
{js.implement_parabolaJS()}
{js.implement_arrow_alphaJS()}
{js.implement_update_arrowJS()}
{sb.implement_compute_VJS()}
{sb.implement_compute_MJS()}
{sb.implement_compute_Ry_lJS()}
{sb.implement_compute_Ry_rJS()}
{js.implement_update_NVM_diagramJS()}
{sb.implement_update_V_diagramJS(discr_NVM)}
{sb.implement_update_M_diagramJS(discr_NVM)}
{sb.implement_update_reactionsJS()}
{sb.implement_update_external_forcesJS()}
{sb.implement_update_u_loadJS(OFFSET_Q)}
{sb.implement_update_internal_forcesJS()}
{js.implement_update_curvedArrowJS()}
{js.implement_update_axial_stress_strainJS(discr_stress_strain)}
{js.implement_update_bending_stress_strainJS(discr_stress_strain)}
{js.implement_update_shear_stressJS(discr_stress_strain)}
{js.implement_update_total_stressJS(discr_stress_strain)}
{stst.implement_compute_epsilon_bendingJS()}
{stst.implement_compute_sigma_axialJS()}
{js.implement_update_stress_diagramJS()}
{js.implement_update_strain_diagramJS()}
{stst.implement_compute_neutral_axisJS()}
{beam_section.implement_compute_centroid_yJS()}
{stst.implement_compute_sigma_bendingJS()}
{stst.implement_compute_total_sigmaJS()}
{stst.implement_compute_total_tauJS()}
{beam_section.implement_compute_first_moment_of_areaJS()}
{beam_section.implement_compute_first_moment_of_area_implicitJS()}
{stst.implement_compute_tau_shearJS()}
{sb.implement_update_div_forcesJS()}
{js.implement_update_NVM_sectionJS()}
{js.implement_arrow_growthJS()}
{mohrcircle.implement_compute_radius_mohrJS()}
{mohrcircle.implement_compute_stress_state_mohrJS()}
{mohrcircle.implement_compute_sigma_average_mohrJS()}
{mohrcircle.implement_compute_principal_theta_mohrJS()}
{mohrcircle.implement_compute_theta_mohrJS()}
{mohrcircle.implement_update_circle_mohrJS()}
{js.implement_update_arrowJS()}
{mohrcircle.implement_update_sigmax_stateJS(MAX_STRESS/2)}
{mohrcircle.implement_update_sigmay_stateJS(MAX_STRESS/2)}
{mohrcircle.implement_update_tau_stateJS(MAX_STRESS/2, SCALE_TAU)}
{mohrcircle.implement_update_sigmax_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_sigmay_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_tau_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2, SCALE_TAU)}
"""
update_slider_q = CustomJS(args=args_slider_q, code=code_slider_q)
args_slider_theta = dict(source=source,
Mohr_circle=Mohr_circle,
line_stress_state=line_stress_state,
points_stress_state=points_stress_state,
line_stress_state_theta=line_stress_state_theta,
points_stress_state_theta=points_stress_state_theta,
label_points_stress_state=label_points_stress_state,
label_points_stress_state_theta=label_points_stress_state_theta,
stress_state_theta=stress_state_theta,
label_stress_state_theta=label_stress_state_theta,
arc_theta_element=arc_theta_element,
label_theta_element= label_theta_element,
arc_theta_Mohr=arc_theta_Mohr,
label_theta_Mohr=label_theta_Mohr,
arc_theta_p_Mohr=arc_theta_p_Mohr,
label_theta_p_Mohr=label_theta_p_Mohr,
rotating_axis=rotating_axis,
beam_position=beam_position,
arrow_sigma_x1_theta=arrows_stress_state_theta[0],
arrow_sigma_x2_theta=arrows_stress_state_theta[1],
arrow_sigma_y1_theta=arrows_stress_state_theta[2],
arrow_sigma_y2_theta=arrows_stress_state_theta[3],
arrow_tau_x1_theta=arrows_stress_state_theta[4],
arrow_tau_x2_theta=arrows_stress_state_theta[5],
arrow_tau_y1_theta=arrows_stress_state_theta[6],
arrow_tau_y2_theta=arrows_stress_state_theta[7])
code_slider_theta = f"""
// retrieve data
const db = source.data
const theta_element = cb_obj.value/180*Math.PI
const sigma_x0 = db['sigma_x0'][0]
const sigma_y0 = db['sigma_y0'][0]
const tau_0 = db['tau_0'][0]
const sigma_average = db['sigma_average'][0]
const r_circle = db['r_circle_mohr'][0]
const theta_principal = compute_principal_theta_mohr(sigma_x0, sigma_y0, tau_0)
const theta = compute_theta_mohr(theta_element, theta_principal)
const new_state = compute_stress_state_mohr(sigma_average, r_circle, theta)
// update data
db['sigma_x'][0] = new_state[0]
db['sigma_y'][0] = new_state[1]
db['tau'][0] = new_state[2]
db['theta_element'][0] = theta_element
db['theta'][0] = theta
// update
// square point:
beam_position.glyph.angle = theta_element
// stress state element
update_stress_state_elements(db, stress_state_theta, rotating_axis, label_stress_state_theta, arc_theta_element, label_theta_element)
// stress state (theta)
update_sigmax_state_theta(db, arrow_sigma_x1_theta, arrow_sigma_x2_theta)
update_sigmay_state_theta(db, arrow_sigma_y1_theta, arrow_sigma_y2_theta)
update_tau_state_theta(db, arrow_tau_x1_theta,arrow_tau_x2_theta, arrow_tau_y1_theta, arrow_tau_y2_theta)
// update Mohr circle
update_circle_mohr(db, Mohr_circle, line_stress_state, points_stress_state, label_points_stress_state, line_stress_state_theta, points_stress_state_theta, label_points_stress_state_theta, arc_theta_Mohr, label_theta_Mohr, arc_theta_p_Mohr, label_theta_p_Mohr)
// apply changes
source.change.emit()
// declare functions
{mohrcircle.implement_update_stress_state_elementsJS(MAX_STRESS, MAX_DIM_STRESS_STATE)}
{js.implement_arrow_growthJS()}
{mohrcircle.implement_compute_stress_state_mohrJS()}
{mohrcircle.implement_compute_principal_theta_mohrJS()}
{mohrcircle.implement_compute_theta_mohrJS()}
{mohrcircle.implement_update_circle_mohrJS()}
{js.implement_update_arrowJS()}
{mohrcircle.implement_update_sigmax_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_sigmay_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_tau_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2, SCALE_TAU)}
"""
update_slider_theta = CustomJS(args=args_slider_theta, code=code_slider_theta)
args_slider_y = dict(source=source,
Mohr_circle=Mohr_circle,
line_stress_state=line_stress_state,
points_stress_state=points_stress_state,
line_stress_state_theta=line_stress_state_theta,
points_stress_state_theta=points_stress_state_theta,
label_points_stress_state=label_points_stress_state,
label_points_stress_state_theta=label_points_stress_state_theta,
arc_theta_Mohr=arc_theta_Mohr,
label_theta_Mohr=label_theta_Mohr,
arc_theta_p_Mohr=arc_theta_p_Mohr,
label_theta_p_Mohr=label_theta_p_Mohr,
beam_position=beam_position,
arrow_sigma_x1=arrows_stress_state[0],
arrow_sigma_x2=arrows_stress_state[1],
arrow_sigma_y1=arrows_stress_state[2],
arrow_sigma_y2=arrows_stress_state[3],
arrow_tau_x1=arrows_stress_state[4],
arrow_tau_x2=arrows_stress_state[5],
arrow_tau_y1=arrows_stress_state[6],
arrow_tau_y2=arrows_stress_state[7],
arrow_sigma_x1_theta=arrows_stress_state_theta[0],
arrow_sigma_x2_theta=arrows_stress_state_theta[1],
arrow_sigma_y1_theta=arrows_stress_state_theta[2],
arrow_sigma_y2_theta=arrows_stress_state_theta[3],
arrow_tau_x1_theta=arrows_stress_state_theta[4],
arrow_tau_x2_theta=arrows_stress_state_theta[5],
arrow_tau_y1_theta=arrows_stress_state_theta[6],
arrow_tau_y2_theta=arrows_stress_state_theta[7])
code_slider_y = f"""
// retrieve data
const db = source.data
const y_var = cb_obj.value
const N = db['N'][0]
const V = db['V'][0]
const M = db['M'][0]
const A = db['A'][0]
const b = db['b'][0]
const h = db['h'][0]
const yG = db['yG'][0]
const Iy = db['Iy'][0]
const theta_element = db['theta_element'][0]
const sigma_x0 = compute_total_sigma(compute_sigma_axial(N, A), compute_sigma_bending(y_var, M, Iy, yG))
const sigma_y0 = 0
const tau_0 = compute_total_tau(compute_tau_shear(V, compute_first_moment_of_area(y_var, b, h, yG), Iy, b))
const sigma_average = compute_sigma_average_mohr(sigma_x0, sigma_y0)
const r_circle = compute_radius_mohr(sigma_x0, sigma_y0, tau_0)
const theta_principal = compute_principal_theta_mohr(sigma_x0, sigma_y0, tau_0)
const theta = compute_theta_mohr(theta_element, theta_principal)
const new_state = compute_stress_state_mohr(sigma_average, r_circle, theta)
// update data
db['y_var'][0] = y_var
db['sigma_x0'][0] = sigma_x0
db['sigma_y0'][0] = sigma_y0
db['tau_0'][0] = tau_0
db['sigma_average'][0] = sigma_average
db['r_circle_mohr'][0] = r_circle
db['sigma_x'][0] = new_state[0]
db['sigma_y'][0] = new_state[1]
db['tau'][0] = new_state[2]
db['theta'][0] = theta
// update
// square point:
beam_position.glyph.y = y_var
// update Mohr circle
update_circle_mohr(db, Mohr_circle, line_stress_state, points_stress_state, label_points_stress_state, line_stress_state_theta, points_stress_state_theta, label_points_stress_state_theta, arc_theta_Mohr, label_theta_Mohr, arc_theta_p_Mohr, label_theta_p_Mohr)
// stress state
update_sigmax_state(db, arrow_sigma_x1, arrow_sigma_x2)
update_sigmay_state(db, arrow_sigma_y1, arrow_sigma_y2)
update_tau_state(db, arrow_tau_x1, arrow_tau_x2, arrow_tau_y1, arrow_tau_y2)
// stress state (theta)
update_sigmax_state_theta(db, arrow_sigma_x1_theta, arrow_sigma_x2_theta)
update_sigmay_state_theta(db, arrow_sigma_y1_theta, arrow_sigma_y2_theta)
update_tau_state_theta(db, arrow_tau_x1_theta,arrow_tau_x2_theta, arrow_tau_y1_theta, arrow_tau_y2_theta)
// apply changes
source.change.emit()
// declare functions
{beam_section.implement_compute_first_moment_of_areaJS()}
{beam_section.implement_compute_first_moment_of_area_implicitJS()}
{stst.implement_compute_sigma_axialJS()}
{stst.implement_compute_sigma_bendingJS()}
{stst.implement_compute_tau_shearJS()}
{stst.implement_compute_total_sigmaJS()}
{stst.implement_compute_total_tauJS()}
{js.implement_arrow_growthJS()}
{mohrcircle.implement_compute_radius_mohrJS()}
{mohrcircle.implement_compute_stress_state_mohrJS()}
{mohrcircle.implement_compute_sigma_average_mohrJS()}
{mohrcircle.implement_compute_principal_theta_mohrJS()}
{mohrcircle.implement_compute_theta_mohrJS()}
{mohrcircle.implement_update_circle_mohrJS()}
{js.implement_update_arrowJS()}
{mohrcircle.implement_update_sigmax_stateJS(MAX_STRESS/2)}
{mohrcircle.implement_update_sigmay_stateJS(MAX_STRESS/2)}
{mohrcircle.implement_update_tau_stateJS(MAX_STRESS/2, SCALE_TAU)}
{mohrcircle.implement_update_sigmax_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_sigmay_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2)}
{mohrcircle.implement_update_tau_state_thetaJS(MAX_STRESS/2, MAX_STRESS*2, SCALE_TAU)}
"""
update_slider_y = CustomJS(args=args_slider_y, code=code_slider_y)
# apply the logics
slider_b.js_on_change('value', update_b)
slider_h.js_on_change('value', update_h)
slider_position.js_on_change('value', updade_slider_pos)
checkbox_P.js_on_click(update_checkbox_P)
radiogroup_FBD.js_on_click(update_radiogroup_FBD)
slider_q.js_on_change('value', update_slider_q)
slider_theta_element.js_on_change('value', update_slider_theta)
slider_y.js_on_change('value', update_slider_y)
########################################################
# Build the layout
########################################################
padding_layout = 10
layout1 = layout([
[column(row(column(fig_scheme,
row(fig_section, Spacer(width=padding_layout), column(Spacer(height=padding_layout),
slider_b,
slider_h,
# row(div_geo, div_forces),
slider_y,
slider_theta_element,
Spacer(height=padding_layout),
slider_position,
slider_q,
div_rg_FBD,
radiogroup_FBD,
div_cb_P,
checkbox_P))),
column(fig_beam,
Spacer(height=padding_layout),
fig_N,
fig_V,
fig_M)),
row(column(
row(fig_NM_section, fig_axial_strain, fig_stress_N, fig_bending_strain, fig_stress_M, fig_stress_sigma),
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),
))
),
column(fig_Mohr_circle, fig_stress_state)
],
])
show(layout1)

Event Timeline