Beispiel #1
0
    def __init__(self, ID, masses, massSupports, trusses, trussLength, base,
                 frequency, modeShape):
        S3S_Structure.__init__(self, masses, massSupports, trusses,
                               trussLength, base)
        self.id = ID
        self.frequency = frequency
        self.modeShape = modeShape
        self.maxModeShape = np.array([0, 0, 0])  # 0 is a default value
        self.locationInERS = ColumnDataSource(data=dict(
            x=[0], y=[0]))  # with default values
        self.participationFactor = 0  # 0 is a default value

        self.multiplier_text = LatexDiv(
            text=" $\\displaystyle\\frac{\\beta S_a(T) }{ \\omega^2} =" +
            str(0) + "$",
            width=240,
            height=20)
        self.frequency_text = LatexDiv(text="""<b>Natural Frequency =</b> """,
                                       width=240,
                                       height=20)
       y='y',
       line_dash='dashed',
       source=V1parallel_line_source,
       color="black")
p.title.text_font_size = "20pt"

p.add_layout(Vector1_glyph)
p.add_layout(LO1_label_glyph)
p.add_layout(LO2_label_glyph)
p.add_layout(Vector2_glyph)
p.add_layout(VectorResultant_glyph)
p.add_layout(V_label_glyph)
p.add_layout(V1_label_glyph)
p.add_layout(V2_label_glyph)
p.add_layout(Resultant_values_glyph)
value_plot = LatexDiv(text="", render_as_text=False, width=300)

my_line = p.line(x='x',
                 y='y',
                 line_dash='dashed',
                 source=Line_source,
                 color='#0065BD',
                 line_width=3)
my_line = p.line(x='x',
                 y='y',
                 line_dash='dashed',
                 source=Line2_source,
                 color='#0065BD',
                 line_width=3)

p.toolbar.logo = None
mass = TA_CircularMass(8, 2, 2, 0.8, 0.5)
spring = TA_Spring((0, .3), (0, 1.5), 1, 1, 50, 0.25)
damper = TA_Dashpot((4, .3), (4, 1.5), 0.5, 1.5)
mass.plot(figure_name)
spring.plot(figure_name)
damper.plot(figure_name)

# for other real application classes browse through existing apps

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

description_filename = join(dirname(__file__), "description.html")
description = LatexDiv(text=open(description_filename).read(),
                       render_as_text=False,
                       width=1000)

# to keep track of the final page layout it is suggested to more or less use the same layout in your curdoc code
# add additional spacers to move your objects to the desired locations
curdoc().add_root(
    column(
        description,
        row(
            figure_name, Spacer(width=100),
            column(play_pause_button, example_slider, radio_group_01,
                   radio_group_02, radio_button_group)), surface))
curdoc().title = split(dirname(__file__))[-1].replace('_', ' ').replace(
    '-', ' '
)  # get path of parent directory and only use the name of the Parent Directory for the tab name. Replace underscores '_' and minuses '-' with blanks ' '
import sys, inspect
currentdir = dirname(abspath(inspect.getfile(inspect.currentframe())))
parentdir = join(dirname(currentdir), "shared/")
sys.path.insert(0, parentdir)
from latex_support import LatexDiv, LatexLabelSet, LatexSlider
# ----------------------------------------------------------------- #

###################################################
##           APP THEORETICAL DESCRIPTION         ##
###################################################

#Theoretical description of the app in Latex
description_filename1 = join(dirname(__file__),
                             "description1.html")  #Part I of the description
description1 = LatexDiv(text=open(description_filename1).read(),
                        render_as_text=False,
                        width=1000)

description_filename2 = join(dirname(__file__),
                             "description2.html")  #Part II of the description
description2 = LatexDiv(text=open(description_filename2).read(),
                        render_as_text=False,
                        width=1000)

description_filename3 = join(dirname(__file__),
                             "description3.html")  #Part III of the description
description3 = LatexDiv(text=open(description_filename3).read(),
                        render_as_text=False,
                        width=1000)

#Figures_static
heavy_comp_button = Button(
    label="start intensive computation",
    button_type="success",
    width=150,
    height=80
)  # also add a height to avoid resizing when the loading sign is displayed # in general buttons can stay with their default height
heavy_comp_button.on_click(
    start_work
)  # callback to apply the layout changes and start the computational work

# loading the html which provides the style definition of the loading symbol
# this can of course also be done where the other descriptions are loaded, however we keep important code together in each example section
description_filename_loading = join(dirname(__file__),
                                    "description_loading.html")
description_loading = LatexDiv(text=open(description_filename_loading).read(),
                               render_as_text=False,
                               width=div_width)

# create the div container which holds the loading sign
loading_sign = Div(
    text="<div class=\"lds-dual-ring\"></div>", width=650, visible=False
)  # initially visible is false since it only should be seen during calculations

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

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

#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)

################################################################################
####Output section
################################################################################
#Output to the browser:
curdoc().add_root(
    column(
        row(Spacer(width=600), lang_button), description1,
        column(
    def __init__(self, Vis, Plotter):
        # setup random by selecting a seed (so that numbers are truly random)
        seed()
        # save car viewer
        self.Vis = Vis
        # save graph plotter
        self.Plotter = Plotter
        # choose a random velocity, e.g. between 0.5 and 10 (steps of 0.5)
        self.v = self._init_random_velocity()
        # tell the car viewer about this choice
        self.Vis.setV(self.v)

        ## set up interactions
        # input for v0 or v(s)
        self.Vs = TextInput(value=str(self.v),
                            title="Initial Velocity",
                            width=300)
        self.Vs.on_change('value', self.set_v)
        # choice of v0 or v(s) method
        self.VMethod = Select(
            title="",
            value="Initial Velocity",
            options=["Initial Velocity", "Distance-dependent Velocity"],
            width=300)
        self.VMethod.on_change('value', self.switch_model)
        # get user value for acceleration
        self.UserAcceleration = TextInput(value="",
                                          title="Acceleration :",
                                          width=300)
        self.UserAcceleration.on_change('value', self.check_acceleration)
        # button which runs the simulation
        self.startSim = Button(label="Start",
                               button_type="success",
                               width=100,
                               disabled=True)
        self.startSim.on_click(self.Start)
        # reset button
        self.reset_button = Button(label="Reset",
                                   button_type="success",
                                   width=100)
        self.reset_button.on_click(self.Reset)
        # selection for exact time and distance dependent formulas
        self.eq_selection = Select(title="",
                                   value="Select an equation",
                                   width=300,
                                   options=[
                                       "Select an equation",
                                       "s(t) - time dependent distance",
                                       "v(t) - time dependent velocity",
                                       "t(s) - distance dependent time",
                                       "v(s) - distance dependent velocity"
                                   ])
        self.eq_selection.on_change('value', self.show_equation)
        # write equations into a invisible div
        self.eq_st = LatexDiv(text="$$ s(t) = \\frac{1}{2} a_0 t^2 + v_0 t $$",
                              visible=False)
        self.eq_vt = LatexDiv(text="$$ v(t) = \\frac{1}{2} a_0 t + v_0 $$",
                              visible=False)
        self.eq_ts = LatexDiv(
            text=
            "$$ t(s) = \\frac{2s}{v(s)+v_0} = \\frac{2s}{\\sqrt{2as + v_0^2}+v_0} $$",
            visible=False)
        self.eq_vs = LatexDiv(text="$$ v(s) = \\sqrt{2as + v_0^2} $$",
                              visible=False)
        self.equations = {
            "st": self.eq_st,
            "vt": self.eq_vt,
            "ts": self.eq_ts,
            "vs": self.eq_vs
        }
        # user input for t(s) to be tested against simulation
        self.UserTs = TextInput(value="", title="t(s) = ", width=200)
        self.UserTs.on_change('value', self.check_function_inputs)
        # user input for v(s) (or a(s)) to be tested against simulation
        self.UserVs = TextInput(value="", title="v(s) = ", width=200)
        self.UserVs.on_change('value', self.check_function_inputs)
        # button to plot t(s) and v(s)/a(s) over simulation data
        self.TestEqs = Button(label="Check equations",
                              button_type="success",
                              width=150)
        self.TestEqs.on_click(self.plot_attempt)
        # warning widget
        self.warning_widget = Div(text="",
                                  render_as_text=False,
                                  style={
                                      'color': 'red',
                                      'font_size': '200%'
                                  },
                                  width=300)
        self.warning_widget_equ = Div(text="",
                                      render_as_text=False,
                                      style={
                                          'color': 'red',
                                          'font_size': '200%'
                                      },
                                      width=300)

        # mathematical operation buttons for user input
        self.math_group_map = {0: self.Vs, 1: self.UserTs, 2: self.UserVs}
        num_math_usr_button_groups = len(self.math_group_map)
        self.math_usr_buttons = dict(sqrts=[], quads=[])
        for i in range(0, num_math_usr_button_groups):
            tmp_tag = "math_group_" + str(i)
            self.math_usr_buttons["sqrts"].append(
                Button(label=bl_sqrt,
                       button_type="success",
                       width=math_button_width,
                       tags=[tmp_tag]))
            self.math_usr_buttons["quads"].append(
                Button(label=bl_quad,
                       button_type="success",
                       width=math_button_width,
                       tags=[tmp_tag]))
            self.math_usr_buttons["sqrts"][i].on_click(self.add_math_op)
            self.math_usr_buttons["quads"][i].on_click(self.add_math_op)

        # define a callback map for easy removal and reset of callbacks to widgets
        self.callback_map = {
            self.Vs: self.set_v,
            self.UserTs: self.check_function_inputs,
            self.UserVs: self.check_function_inputs
        }

        # initialise initial time, displacement and acceleration
        self.t = 0
        self.s = 0
        self.a = 0
        # remember which model is being used
        self.model_type = "init_v"  # "init_v" and "distance_v"

        # save the callback id to run the simulations
        self.callback_id = None

        # save layout
        self.Layout = column(
            self.VMethod,
            row(self.math_usr_buttons["sqrts"][0],
                self.math_usr_buttons["quads"][0]),
            self.Vs, self.UserAcceleration,
            row(self.startSim, self.warning_widget), self.reset_button,
            self.eq_selection, self.eq_st, self.eq_vt, self.eq_ts, self.eq_vs,
            row(self.math_usr_buttons["sqrts"][1],
                self.math_usr_buttons["quads"][1]), self.UserTs,
            row(self.math_usr_buttons["sqrts"][2],
                self.math_usr_buttons["quads"][2]), self.UserVs,
            row(self.TestEqs, self.warning_widget_equ))
Beispiel #8
0
        y_t = [0.1]
        layout.children[1] = row(column(Spacer(height=10), material_select, rubber_description, row(Spacer(width=75), play_pause_button), 
                             row(Spacer(width=75), reset_button)), column(p), column(Spacer(height=89), column(plot)))
    if new == "CFRP" or new == "Steel":
        A_source.data = dict(x=x_A, y=y_A)
        A3_label_source.data = dict(x=x_A3, y=y_A3, A=["A"])
    R_m_source.data = dict(x=x_R_m, y=y_R_m)
    R3_label_source.data = dict(x=x_R3, y=y_R3, R=["R"])
    m_label_source.data = dict(x=x_m, y=y_m, m=["m"])
    A_t_source.data = dict(x=x_A_t, y=y_A_t)
    A4_label_source.data = dict(x=x_A4, y=y_A4, A=["A"])
    t_label_source.data = dict(x=x_t, y=y_t, t=["t"])

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

## add coefficient description
steel_filename = join(dirname(__file__), "steel_description.html")
steel_description = LatexDiv(text=open(steel_filename).read(), render_as_text=False, width=250)
cfrp_filename = join(dirname(__file__), "cfrp_description.html")
cfrp_description = LatexDiv(text=open(cfrp_filename).read(), render_as_text=False, width=250)
rubber_filename = join(dirname(__file__), "rubber_description.html")
rubber_description = LatexDiv(text=open(rubber_filename).read(), render_as_text=False, width=250)

## initial values
def init():
    i = [1]
    dx = [0]
    dL = [0]
    x_mounting = [1, 4, 4, 3, 2, 1]
                               text='name',
                               text_font_size="15pt",
                               level='glyph',
                               source=F2_source)

plot.add_layout(F1_arrow_glyph)
plot.add_layout(F2_arrow_glyph)
plot.add_layout(F1_label_glyph)
plot.add_layout(F2_label_glyph)
plot.add_layout(dist)
plot.add_layout(dist_label)
plot.add_layout(length)
plot.add_layout(length_label)

# Div to show force and distance values
value_plot = LatexDiv(text="", render_as_text=False, width=300)


def setValueText(F1, F2):
    value_plot.text = "$$\\begin{aligned} F_1&=" + "{:4.1f}".format(
        F1) + "\\,\\mathrm{N}\\\\ F_2&=" + "{:4.1f}".format(
            F2) + "\\,\\mathrm{N} \\end{aligned}$$"


def changeLength(attr, old, new):
    tmp = (l_beam - new) / new
    F1_new = (F_total * tmp) / (1 + tmp)
    F2_new = F_total - F1_new
    F1_source.patch({"yS": [(0, F1_new)]})
    F2_source.patch({"yS": [(0, F2_new)]})
    dist_source.patch({'xE': [(0, new)], 'xL': [(0, new / 2.0 - 0.3)]})