extrem_val_label = LatexLabelSet(x='x', y='y', text='text', source=extrem_val_label_source, level='glyph')
plot_deform.add_layout(extrem_val_label)



###################################
#       Buttons and Sliders       #
###################################
radio_button_group = RadioButtonGroup(labels=["Point Load", "Constant Load", "Triangular Load", "Temperature"], active=initial_load, width=400)

radio_group_left  = RadioGroup(labels=["fixed", "sliding"], active=0, inline=True)
radio_group_right = RadioGroup(labels=["fixed", "sliding"], active=1, inline=True)
#radio_group_cross = RadioGroup(labels=["constant", "tapered"], active=0, inline=True) # cross-section not yet
radio_group_ampl  = RadioGroup(labels=["-1", "+1"], active=1, inline=True) # amplitude

load_position_slider  = LatexSlider(title="\\mathrm{Load \ Position:}", value_unit='\\frac{\\mathrm{L}}{\\mathrm{10}}', value=initial_load_position, start=xr_start, end=xr_end, step=1.0, width=400)

reset_button = Button(label="Reset", button_type="success", width=400)
line_button  = Button(label="Show line", button_type="success", width=400)


## call their corresponding callback functions

radio_button_group.on_change('active',change_load)

radio_group_left.on_change('active', change_left_support)
radio_group_right.on_change('active', change_right_support)
radio_group_ampl.on_change('active',change_amplitude)

load_position_slider.on_change('value', change_load_position)
    else:
        arrow_line.stream(dict(x1=[0], x2=[0], y1=[35 + disp], y2=[32 + disp]),
                          rollover=1)


## Create slider to choose mass
def change_mass(attr, old, new):
    [mass] = glob_mass.data["mass"]  #input/ouput -> class
    mass.changeMass(new)
    updateParameters()
    compute_amp_and_phase_angle()


mass_input = LatexSlider(title="\\text{Mass} \\left[ \\mathrm{kg} \\right]: ",
                         value=initial_mass_value,
                         start=0.5,
                         end=10.0,
                         step=0.5,
                         width=400)
mass_input.on_change('value', change_mass)


## Create slider to choose spring constant
def change_spring_constant(attr, old, new):
    [spring] = glob_spring.data["spring"]  # input/ouput -> class
    spring_old = spring.getSpringConstant
    spring.changeSpringConst(float(new))
    [initial_displacement_value
     ] = glob_initial_displacement_value.data["initial_displacement_value"]
    [initial_velocity_value
     ] = glob_initial_velocity_value.data["initial_velocity_value"]
    initial_displacement_value = initial_displacement_value * spring_old / float(
Beispiel #3
0
Reset_button.on_click(reset)


def change_mass(attr, old, new):
    [plot] = glob_fun_plot.data["fun"]  # input/
    glob_m.data = dict(val=[new])  #      /output
    TotEng = getTotEng()
    glob_TotEng.data = dict(val=[TotEng])  #      /output
    plot()


## Create slider to choose mass of blob
mass_input = LatexSlider(title="\\mathrm{Mass =}",
                         value_unit="[\\mathrm{kg}]",
                         value=5,
                         start=0.5,
                         end=10.0,
                         step=0.1,
                         width=200)
mass_input.on_change('value', change_mass)


def change_lam(attr, old, new):
    glob_lam.data = dict(val=[new])  #      /output


## Create slider to choose damper coefficient
lam_input = LatexSlider(title="\\mathrm{Damper\\ coefficient =}",
                        value_unit="[\\mathrm{Ns}/\\mathrm{m}]",
                        value=0.0,
                        start=0.0,
            exec(
                (s + '=\"' + strings[s][lang] + '\"').encode(encoding='utf-8'))


###################################
# Buttons and Sliders
###################################

# button to change language
lang_button = Button(label='Zu Deutsch wechseln', button_type="success")
lang_button.on_click(changeLanguage)

# Slider to change location of Forces F1 and F2
F1F2Location_slider = LatexSlider(title="\\text{Length } b =",
                                  value=10,
                                  start=1,
                                  end=20,
                                  step=1,
                                  value_unit="\\text{m}")
F1F2Location_slider.on_change('value', changeF1F2)

###################################
# Page Layout
###################################

#adding description from HTML file
description_filename = join(dirname(__file__), "description.html")
description = LatexDiv(text=open(description_filename).read(),
                       render_as_text=False,
                       width=880)

curdoc().add_root(
    radius=[10],
    start_angle=[0],
    end_angle=[0.5 * pi],
    line_dash="dashed",
    color="gray")  # TODO: check why the arc is plotted wrong -> aspect ratio
inclination_plot.toolbar.logo = None  # removes the bokeh logo
inclination_plot.match_aspect = True  # does not work, arc is still wrong; # with title it is better -> title counts to hight
# also: arc grows when using the ywheel_zoom

#alpha_input = Slider(title="alpha [°]", value=0.0, start=0.0, end=90.0, step=0.5, width=400) # build the slider (without LaTeX)
#alpha_input = LatexSlider(title="\\alpha [°]:", value=0.0, start=0.0, end=90.0, step=0.5, width=400) # build the slider (with LaTeX supported) # colons have to be written explicitly into the string
alpha_input = LatexSlider(
    title="\\alpha = ",
    value_unit="°",
    value=0.0,
    start=0.0,
    end=90.0,
    step=0.5,
    width=400
)  # build the slider (with LaTeX supported) # use the custom value_unit attribute if you use symbols
alpha_input.on_change(
    'value',
    change_alpha)  # callback function called when alpha is changed in slider

#---------------------------------------------------------------------#

#####################################
#    ping pong animation example    #
#####################################

# ping pong animation with changing color and a class
p.toolbar.logo = None

########################
#  slider definitions  #
########################


def change_mass(attr, old, new):
    mass = glob_vars['mass']  # input/output
    mass.changeMass(new)


## Create slider to choose mass of blob
mass_input = LatexSlider(title="\\text{Mass } \\left[ \mathrm{kg} \\right]: ",
                         value=initial_mass_value,
                         start=0.5,
                         end=10.0,
                         step=0.5,
                         width=400)
mass_input.on_change('value', change_mass)


def change_kappa(attr, old, new):
    spring = glob_vars['spring']  # input/output
    spring.changeSpringConst(new)


## Create slider to choose spring constant
kappa_input = LatexSlider(
    title="\\text{Spring stiffness } \\left[ \\frac{N}{m} \\right]: ",
    value=initial_kappa_value,
    start=0.0,
###################################
# or in general widgets
# you may also separate the definitions and calls depending on your setting

play_pause_button = Button(label="Play",
                           button_type="success",
                           width=button_width)
play_pause_button.on_click(play_pause)

# the attribute "value_unit" only exists in the costum LatexSlider class
# for a default bokeh slider use Slider
# use the css_classes to reference this object in /templates/styles.css
example_slider = LatexSlider(title="\\text{example}=",
                             value_unit="\\frac{Sv}{m \\cdot kg}",
                             value=initial_value,
                             start=start_value,
                             end=end_value,
                             step=0.5,
                             width=400,
                             css_classes=["slider"])
example_slider.on_change(
    'value', slider_cb_fun)  # callback function is called when value changes

# radio button: round and only one active selection per group allowed
# active=0 to select the the first button by default
# inline=True to place the buttons horizontally
radio_group_01 = RadioGroup(labels=["1", "2"], active=0, inline=True)
radio_group_02 = RadioGroup(labels=["3", "4"])
radio_group_01.on_change("active", radio_cb_fun)
radio_group_02.on_change("active", radio_cb_fun_2)

# radio button group: buttons that are merged next to each other, only one active selection per group allowed
                           text='label_text',
                           source=source,
                           level='glyph',
                           x_offset=-10,
                           y_offset=-10)
    figure.add_layout(visual)

###################################
# Buttons and Sliders
###################################

# sliders to choose force applied to x- and y-axis
Fx_slider = LatexSlider(title='R_x=',
                        value_unit='{kN}',
                        value=0,
                        start=-0.5,
                        end=0.5,
                        step=0.10,
                        width=300)
Fy_slider = LatexSlider(title='R_y=',
                        value_unit='{kN}',
                        value=0,
                        start=-0.5,
                        end=0.5,
                        step=0.10,
                        width=300)
Fx_slider.on_change('value', cb_change_load)
Fy_slider.on_change('value', cb_change_load)

# sliders to choose material parameters
E_slider = LatexSlider(title='E=',

def change_mass(attr, old, new):
    mass.changeMass(new)
    if (t == 0):
        InitialFloor(
        )  # update position of static equilibrium for the new mass
    update_current_ratio()
    update_amplification_function()
    update_phase_angle()


## Create slider to choose mass of blob
mass_input = LatexSlider(title="\\text{Mass} \\left[ \\mathrm{kg} \\right]: ",
                         value=5,
                         start=0.3,
                         end=10.0,
                         step=0.1,
                         width=400)
mass_input.on_change('value', change_mass)


def change_kappa(attr, old, new):
    spring.changeSpringConst(new)
    if (t == 0):
        InitialFloor(
        )  # update position of static equilibrium for the new mass
    update_current_ratio()
    update_amplification_function()
    update_phase_angle()

Beispiel #10
0
    
    if velocityMagnitude == 0:
        # Create some default velocity vector
        newVelocityVectorOne = np.array([0.1,0.0])
        # Update respective Magnitude slider
        ballOneVelocityMagSlider.value = 0.1
    else:
        newVelocityVectorOne = velocityMagnitude * np.array([
                                                            np.cos(np.deg2rad(angle)),
                                                            np.sin(np.deg2rad(angle))
                                                        ])
        
    particleOne.update_velocity(newVelocityVectorOne[0], newVelocityVectorOne[1])
    
ballOneVelocityDirSlider = LatexSlider(
                                  title="\\text{Green Ball Velocity Direction [deg]:} ",
                                  value=dirOne , start=0, end=360, step=1.0, width=slider_width
                                 )
ballOneVelocityDirSlider.on_change('value',update_ballOne_VelocityDir)

##################### Creating velocity magnitude slider ######################
def update_ballOne_VelocityMag(attr,old,new):
    magnitude = new
    velocityMagnitude = particleOne.get_velocity_magnitude()
    if velocityMagnitude == 0.0:
        # Create some default velocity vector
        newVelocityVectorOne = np.array([0.1,0.0])
    else:
        newVelocityVectorOne = particleOne.velocity
        newVelocityVectorOne *= 1/velocityMagnitude                        
        newVelocityVectorOne *= magnitude
        
    for s in strings:
        if 'checkFlag' in strings[s]:
            flag = flags.data[strings[s]['checkFlag']][0]
            exec( (s + '=\"' + strings[s][flag][lang] + '\"').encode(encoding='utf-8') )
        elif 'isCode' in strings[s] and strings[s]['isCode']:
            exec( (s + '=' + strings[s][lang]).encode(encoding='utf-8') )
        else:
            exec( (s + '=\"' + strings[s][lang] + '\"').encode(encoding='utf-8') )



###################################
# Buttons and Sliders
###################################

slider_angle = LatexSlider(title='\\text{Inclination of ladder:}', value_unit='^{\\circ}', value=0.0, start=0.0, end=90, step=90/20)
slider_angle.on_change('value',slider_func)

button_structural_system = Button(label="Show/Hide structural system", button_type="success", width=300)
button_structural_system.on_click(show_structural_system)

lang_button = Button(label='Zu Deutsch wechseln', button_type="success")
lang_button.on_click(changeLanguage)



###################################
# Page Layout
###################################

# add app description text
Beispiel #12
0
    fig.ygrid.visible = False
    fig.toolbar.logo = None


turn_off_grid(figure1)
turn_off_grid(figure2)
turn_off_grid(figure3)

###################################
# Buttons and Sliders
###################################

### Create  sliders to change Normal and Tangential Forces
Normal_X_slider = LatexSlider(title="\\sigma_x=",
                              value_unit='\\frac{\\mathrm{N}}{\\mathrm{mm}^2}',
                              value=0,
                              start=-10,
                              end=10,
                              step=0.5)
Normal_X_slider.on_change('value', NormalForceX_init)

Normal_Z_slider = LatexSlider(title="\\sigma_z=",
                              value_unit='\\frac{\\mathrm{N}}{\\mathrm{mm}^2}',
                              value=0,
                              start=-10,
                              end=10,
                              step=0.5)
Normal_Z_slider.on_change('value', NormalForceZ_init)

Tangential_XZ_slider = LatexSlider(
    title="\\tau_{xz}=",
    value_unit='\\frac{\\mathrm{N}}{\\mathrm{mm}^2}',
        update_3d_plot()
        freq_coordinates_source.data = dict(x = [slider_frequency.value, slider_frequency.value], y = [disp_freq.y_range.start, disp_freq.y_range.end])
        switch_button.label = "⇦  Change Input Parameters"


#################################
##          USER INPUT         ##
#################################

# selection for beam type
system_select = Select(title="Type of Beam:", value="Pinned-Pinned Beam", width=300,
                                 options=["Pinned-Pinned Beam", "Fixed-Fixed Beam", "Fixed-Pinned Beam", "Fixed-Free Beam"])
system_select.on_change('value', change_selection)

# slider for location of the load
slider_location_load = LatexSlider(title="\\text{Location of the Load} \\left[ \\mathrm{m} \\right]: ", value_unit="\\mathrm{L}", value=length_left/L,
                                   start=0, end=1, step=.01, width=423, bar_color = c_orange)
slider_location_load.on_change('value',change_location_load)

# slider for location of the frequency analysis
slider_location_freq = LatexSlider(title="\\text{Location of the Frequency Analysis} \\left[ \\mathrm{m} \\right]: ", value_unit="\\mathrm{L}", 
                                   value=lfa/L, start=0, end=1, step=.01, width=423, bar_color = c_green)
slider_location_freq.on_change('value',change_location_freq)

# slider for damping coefficient
slider_damping = LatexSlider(title="\\text{Loss Modulus } \\eta: ", value=damping, start=0.01, end=0.4, step=.01, width=423) 
slider_damping.on_change('value',change_damping)

# slider for excitation frequency ratio
slider_frequency = LatexSlider(title="\\text{Excitation Frequency Ratio } r=\\frac{\\Omega}{\\omega_1}: ", value=r, 
                               start=0.04, end=10, step=0.04, width=215, bar_color = c_blue) 
slider_frequency.on_change('value',change_frequency_ratio)
Beispiel #14
0
    mass.moveTo((0,10+disp))
    spring.draw(SRS_Coord(-2,.75),SRS_Coord(-2,8+disp))
    damper.draw(SRS_Coord(2,.75),SRS_Coord(2,8+disp))
    Bottom_Line.data=dict(x=[-2,2],y=[8+disp, 8+disp])
    Linking_Line.data=dict(x=[0,0],y=[8+disp, 10+disp])
    if force_value > 0:
        arrow_line.stream(dict(x1=[0],x2=[0],y1=[15+disp],y2=[12+disp]), rollover=1)
    else:
        arrow_line.stream(dict(x1=[0],x2=[0],y1=[35+disp],y2=[32+disp]), rollover=1)


## Create slider to choose damping coefficient
def change_damping_coefficient(attr,old,new):
    glob_vars["damper"].changeDamperCoeff(float(new*2*sqrt(initial_spring_constant_value*glob_vars["mass_value"])))
    updateParameters()
damping_coefficient_input = LatexSlider(title="\\text{Damping coefficient} \\left[ \\frac{\\mathrm{Ns}}{\mathrm{m}} \\right]:", value=initial_damping_ratio, callback_policy="mouseup", start=0.0, end=1, step=0.05,width=550)
damping_coefficient_input.on_change('value',change_damping_coefficient)

## Create slider to choose the frequency ratio
def change_frequency_ratio(attr,old,new):
    if (not glob_vars["Active"]):
        glob_vars["TimePeriodRatio"] = new #      /output
        updateParameters()
frequency_ratio_input = LatexSlider(title="\\text{Impulse duration to natural period ratio:}", value=glob_vars["TimePeriodRatio"], start=0.1, end=3.0, step=0.1,width=550)
frequency_ratio_input.on_change('value',change_frequency_ratio)

def play_pause():
    [callback_id] = glob_callback_id.data["callback_id"]
    if play_pause_button.label == "Play":
        play_pause_button.label = "Pause" # change label
        callback_id = curdoc().add_periodic_callback(evolve,dt*1000)
Beispiel #15
0
    glob_theta1.data = dict(val=[radians(new)])  #      /output
    updateVector1()
    updateResultant()


#changing theta2
def changetheta2(attr, old, new):
    glob_theta2.data = dict(val=[radians(new)])  #      /output
    updateVector2()
    updateResultant()


## Create slider to choose force applied
Vector1Slider = LatexSlider(title="|V1|=",
                            value=95.0,
                            start=0,
                            end=100,
                            step=5)
Vector1Slider.on_change('value', changeVector1)
Vector2Slider = LatexSlider(title="|V2|=",
                            value=100.0,
                            start=0.0,
                            end=100.0,
                            step=5)
Vector2Slider.on_change('value', changeVector2)

AngleVector1Slider = LatexSlider(title='\\alpha_{V1}=',
                                 value_unit='^{\\circ}',
                                 value=60.0,
                                 start=0.0,
                                 end=360.0,
    [theta] = glob_theta.data["val"]  # input/output
    # if it has been modified during the simulation
    # move back == deactivated (does not exist in bokeh)
    if (Active and theta != radians(new)):
        angle_slider.value = old
    else:
        # else update angle and update images
        glob_theta.data = dict(val=[radians(new)])
        rotateCannon(radians(30 - new))
        updateTargetArrow()


# angle increment is large to prevent lag
angle_slider = LatexSlider(
    title="\\text{Angle \u0398} \\left[ \\mathrm{°} \\right]: ",
    value=30,
    start=0,
    end=65,
    step=5)
angle_slider.on_change('value', changeTheta)


def changeSpeed(attr, old, new):
    [Active] = glob_active.data["Active"]  # input/
    [speed] = glob_speed.data["val"]  # input/output
    # if it has been modified during the simulation
    # move back == deactivated (does not exist in bokeh)
    if (Active and speed != new):
        speed_slider.value = old
    else:
        # else update speed and directional arrow
        glob_speed.data = dict(val=[new])
Beispiel #17
0
#changing theta2
def changetheta2(attr, old, new):
    glob_theta2.data = dict(val=[radians(new)])  #      /output
    updateVector2()
    updateSub()
    updateSum()
    updateLine()
    updatevalues()
    updateMul()
    updateDiv()


Vector1Slider = LatexSlider(title="|Z1|=",
                            value=Vector1,
                            start=0,
                            end=10.0,
                            step=0.2)

Vector1Slider.on_change('value', changeVector1)
Vector2Slider = LatexSlider(title="|Z2|=",
                            value=Vector2,
                            start=0.0,
                            end=10.0,
                            step=0.2)

Vector2Slider.on_change('value', changeVector2)

AngleVector1Slider = LatexSlider(title='\\alpha_{Z1}=',
                                 value_unit='^{\\circ}',
                                 value=theta1 / pi * 180,
        lW = [3]  # line width
        #self.arrow.data = dict(xS = xS, xE = xE , yS = yS, yE = yE, lW = lW)
        self.arrow.stream(dict(xS=xS, xE=xE, yS=yS, yE=yE, lW=lW), rollover=1)

    def fun_labels(self, force_label="F"):
        '''Member Function: Creates labels of force arrows'''
        x = [self.pts.data['x'][-1] + .6, self.xstart - .7]
        y = [self.h + zstart + 2, 0]
        name = [force_label, "\\mathrm{" + self.name + "}"]
        self.labels.data = dict(x=x, y=y, name=name)


weight_slide = LatexSlider(
    title=
    "\\mathrm{Force \ Ratio \ }\\frac{\\mathrm{F}}{\\mathrm{F_{crit,2}}}\\mathrm{:}",
    value=0,
    start=0,
    end=f_end,
    step=step,
    width=450)  #slider created to change weight on columns


def drange(start, stop, step):
    '''Function created to provide float range'''
    r = start
    while r < stop:
        yield r
        r += step


col1 = Column("Free-Fixed", L, 0.25 * fcrit_2)  #beam: "Free-Fixed" Column
col2 = Column("Pinned-Pinned", L, fcrit_2)  #beam: "Pinned-Pinned" Column
        'yL':
        [(0, -25 + H + 0.5 * (np.sin(theta_total2) * 150 * T2 / (T1 + T2)))]
    })


# ----------------------------------------------------------------- #

####################################
##        SLIDERS & BUTTONS       ##
####################################
#Sliders
#Vertical Distance between the supports
H_slider = LatexSlider(title="\\text{Vertical distance between supports (H)}=",
                       value_unit="\\text{m}",
                       value=H,
                       start=H_min,
                       end=H_max,
                       step=1.0,
                       width=400,
                       css_classes=["slider"])
H_slider.on_change(
    'value', slider_cb_fun)  # callback function is called when value changes

#Horizontal Distance between the supports
B_slider = LatexSlider(
    title="\\text{Horizontal distance between supports (B)}=",
    value_unit="\\text{m}",
    value=B,
    start=B_min,
    end=B_max,
    step=1.0,
    width=400,
    m2_label_source.data=dict(x=[-3], y=[h2-2], t=['m'])
    m1_index_label_source.data=dict(x=[0.6], y=[h1-2.8], t=['1'])
    m2_index_label_source.data=dict(x=[-2.4], y=[h2-2.3], t=['2'])


def change_mass_ratio(attr,old,new):
    global M, accOld
    Update_system()
    Update_current_state()
    topMass.changeMass(new*m1)
    M = np.array([[mainMass.mass,0.],
                  [0., topMass.mass]])
    accOld = inv(M).dot(F0-K.dot(dispOld)-C.dot(velOld))

## Create slider to choose mass of upper mass
mass_ratio_input = LatexSlider(title="\\text{Mass Ratio } \mu = \\frac{m_2}{m_1} = ", value=m2/m1, start=0.01, end=0.20, step=0.01, width=450)
mass_ratio_input.on_change('value',change_mass_ratio)

def change_tuning(attr,old,new):
    global K, accOld
    Update_system()
    Update_current_state()
    spring.changeSpringConst(new*new*k1*mass_ratio_input.value)
    K = np.array([[baseSpring.kappa+spring.kappa,-spring.kappa],
                 [-spring.kappa,                 spring.kappa]])
    accOld = inv(M).dot(F0-K.dot(dispOld)-C.dot(velOld))

## Create slider to choose spring constant
tuning_input = LatexSlider(title="\\text{TMD Tuning } \kappa = \\frac{\omega_2}{\omega_1} = \sqrt{\\frac{k_2 \cdot m_1}{k_1 \cdot m_2}} = ", value=sqrt(k2*m1/(k1*m2)), start=0.7, end=1.3, step=0.01, width=450)
tuning_input.on_change('value',change_tuning)
                (s + '=\"' + strings[s][lang] + '\"').encode(encoding='utf-8'))

    [Active] = glob_active.data["Active"]
    if Active:
        show_button.label = strings["show_button.label"]['on'][lang]
    else:
        show_button.label = strings["show_button.label"]['off'][lang]


###################################
# Buttons and Sliders
###################################

AngleVector1Slider = LatexSlider(title='\\theta=',
                                 value_unit='^{\\circ}',
                                 value=45.0,
                                 start=0.0,
                                 end=360.0,
                                 step=5)
AngleVector1Slider.on_change('value', changeTheta1)

LineVector1Slider = LatexSlider(title="\\text {Direction 1: } \\alpha_1=",
                                value_unit='^{\\circ}',
                                value=90.0,
                                start=0.0,
                                end=360.0,
                                step=5)
LineVector1Slider.on_change('value', changeTheta1Line1)

LineVector2Slider = LatexSlider(title="\\text {Direction 2: } \\alpha_2=",
                                value_unit='^{\\circ}',
                                value=0.0,
    for s in strings:
        if 'checkFlag' in strings[s]:
            flag = flags.data[strings[s]['checkFlag']][0]
            exec((s + '=\"' + strings[s][flag][lang] +
                  '\"').encode(encoding='utf-8'))
        elif 'isCode' in strings[s] and strings[s]['isCode']:
            exec((s + '=' + strings[s][lang]).encode(encoding='utf-8'))
        else:
            exec(
                (s + '=\"' + strings[s][lang] + '\"').encode(encoding='utf-8'))


# Slider to change location of Forces F1 and F2
F1F2Location_slider = LatexSlider(value=20,
                                  start=1,
                                  end=39,
                                  step=1,
                                  value_unit="\\text{m}")
F1F2Location_slider.on_change('value', changeLength)

# Toggle button to show forces
show_button = Toggle(button_type="success")
show_button.on_click(changeShow)

lang_button = Button(button_type="success")
lang_button.on_click(changeLanguage)

# Description from HTML file
description_filename = join(dirname(__file__), "description.html")
description = LatexDiv(render_as_text=False, width=880)