Beispiel #1
0
    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,
                                 start=-180,
                                 end=180,
                                 step=5)
AngleVector1Slider.on_change('value', changetheta1)
Beispiel #2
0
    [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,
                        end=5.0,
                        step=0.2,
                        width=400)
lam_input.on_change('value', change_lam)
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)

reset_button.on_click(reset)
line_button.on_click(change_line_visibility)



##################################
#           Build beam           #
##################################

# build the beam object
beam = NFR_beam()

# plot beam, supports and its labels in the main plot
beam.plot_all(plot_main)
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

# IMPORTANT NOTE: Only plot objects ONCE and then update them via the ColumnDataSources - otherwise the animation would slow down drastically
#                 if the object would be plotted completely at each callback

# global variables, that are not needed for direct plotting, can be created by dicts (or lists or other Python global scope objects)
# do not use the keyword global!
## 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(
        new)
    glob_initial_displacement_value.data = dict(
        initial_displacement_value=[initial_displacement_value])
                           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
radio_button_group = RadioButtonGroup(labels=["Item 1", "Item 2", "Item 3"],
                                      active=0,
                                      width=200)

##################################
###################################
# 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(
    column(row(Spacer(width=600), lang_button), description,
           row(plot, column(F1F2Location_slider))))
curdoc().title = "Couple moment"
# 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=',
                       value_unit='{N/mm}^{2}',
                       value=E_start_value,
                       start=60000,
                       end=260000,
                       step=20000,
                       width=250,
                       disabled=True)
nu_slider = LatexSlider(title='\\nu=',
                        value_unit='',
                        value=nu_start_value,
                        start=0,
        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])
        updateTargetArrow()

Beispiel #10
0
        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
        
    particleOne.update_velocity(newVelocityVectorOne[0],newVelocityVectorOne[1])
        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
description_filename = join(dirname(__file__), "description.html")
Beispiel #12
0
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}',
    value=0,
    start=0,
    end=10,
        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
    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)
        Force_select.disabled = True # disable selection during simulation run
########################


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,
    end=200,
    step=10,
    width=400)
            exec((s + '=' + strings[s][lang]).encode(encoding='utf-8'))
        else:
            exec(
                (s + '=\"' + strings[s][lang] + '\"').encode(encoding='utf-8'))


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

################################################################################

#Create Reset Button:
button = Button(label="Reset", button_type="success", width=50)

#Let program know what functions button calls when clicked:
weight_slide.on_change('value', fun_check1)
button.on_click(init)

#Initialization at the beginning:
init()

# add app description
description_filename = join(dirname(__file__), "description.html")
description = LatexDiv(text=open(description_filename).read(),
                       render_as_text=False,
                       width=app_width)

description1_filename = join(dirname(__file__), "description1.html")
description1 = LatexDiv(text=open(description1_filename).read(),
                        render_as_text=False,
                        width=app_width)
# ----------------------------------------------------------------- #

####################################
##        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,
    css_classes=["slider"])
B_slider.on_change(
    'value', slider_cb_fun_b)  # callback function is called when value changes

#Cable length stretch factor to compute the length of the cable from the distance between the supports
    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)

def change_D1(attr,old,new):
        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,
                                start=0.0,
                                end=360.0,
                                step=5)
            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)

# Set language
setDocumentLanguage(std_lang)