Пример #1
0
def example_unterlagen_visu(curr_doc: CurrentDoc):
    q = Symbol('q')
    l = Symbol('l')
    start_knot = Knot.Knot(0, 0.5, 2, ElSupEnum.SUPPORT_ROLLER_END.value, 0, [0, 0, 0], [0, 0, 0])
    middle_knot1 = Knot.Knot(1, 2.5, 2, ElSupEnum.JOINT.value, 0, [0, 0, 0], [0, 0, 0])
    middle_knot2 = Knot.Knot(2, 2.5, 1, ElSupEnum.THROUGH_ELEMENT.value, 0, [0, 0, 0], [0, 0, - 2 * q * l**2])
    end_knot = Knot.Knot(3, 4.5, 1, ElSupEnum.SUPPORT_CLAMPED.value, 0)
    lineload = [0, q]
    temp_prop = TempProps.TempProps(0, 0, 0)
    knot_list = []
    elementlist = []
    l0 = gc.knot_dist(start_knot, middle_knot1)
    l1 = gc.knot_dist(middle_knot1, middle_knot2)
    l2 = gc.knot_dist(middle_knot2, end_knot)
    ele = ElementCalculation(0, start_knot, middle_knot1, l0 * l, lineload, temp_prop, Symbol('EI'), float('inf'), Symbol('h'))
    elementlist.append(ele)
    knot_list.append([start_knot, middle_knot1])
    ele = ElementCalculation(1, middle_knot1, middle_knot2, l1 * l, [0, 0], temp_prop, float('inf'), float('inf'), Symbol('h'))
    elementlist.append(ele)
    knot_list.append([middle_knot1, middle_knot2])
    ele = ElementCalculation(2, middle_knot2, end_knot, l2 * l, [0, 0], temp_prop, Symbol('EI'), float('inf'), Symbol('h'))
    elementlist.append(ele)
    knot_list.append([middle_knot2, end_knot])
    start_knot.add_coupled_el(0)
    middle_knot1.add_coupled_el([0, 1])
    middle_knot2.add_coupled_el([1, 2])
    end_knot.add_coupled_el(2)

    # VIS STRUCTURE
    testbox.vis_structure_from_input(curr_doc, knot_list, elementlist)
Пример #2
0
def final_structure_software_lab(curr_doc: CurrentDoc):
    f = Symbol('F')
    k = Symbol('k')
    start_knot = Knot.Knot(0, 1, 3, ElSupEnum.SUPPORT_CLAMPED.value, 0)
    middle_knot = Knot.Knot(1, 2, 3, ElSupEnum.JOINT.value, 0, [0, 0, 0], [0, f, 0])
    end_knot = Knot.Knot(2, 3, 2, ElSupEnum.SUPPORT_ROLLER_END.value, 0, [0, 0, k])
    q = Symbol('q')
    l = Symbol('l')
    h = Symbol('h')
    x = Symbol('x')
    at = Symbol('at')
    ei = Symbol('EI')
    line_load_0 = [0, q * x]
    temp_load_0 = TempProps.TempProps(0, 0, 0)
    knot_list = []
    elementlist = []

    # ELEMENT 0
    l0 = gc.knot_dist(start_knot, middle_knot) * l
    ele0 = ElementCalculation(0, start_knot, middle_knot, l0, line_load_0, temp_load_0, ei=ei, ea=float('inf'), h=h)
    elementlist.append(ele0)
    knot_list.append([start_knot, middle_knot])

    # ELEMENT 1
    line_load_1 = [0, 0]
    temp_load_1 = TempProps.TempProps(0, Symbol('dT'), at)
    l1 = gc.knot_dist(middle_knot, end_knot) * l
    ele1 = ElementCalculation(1, middle_knot, end_knot, l1, line_load_1, temp_load_1, ei=ei, ea=float('inf'), h=h)
    elementlist.append(ele1)
    knot_list.append([middle_knot, end_knot])

    # VIS STRUCTURE
    testbox.vis_structure_from_input(curr_doc, knot_list, elementlist)
def get_func_from_user(knot1, knot2, func_type=""):
    test_str = "(a + 2*s)**5"
    s = Symbol('s')
    if func_type == "":
        func_type = input(
            "Choose between function of type: constant [c], linear [l], arbitrary [a]"
        )
    if func_type.lower() == "c":
        # TODO function needs to be set correctly to the knots
        c_0 = input("Height of function: ")
        res, mes = check_float_input(c_0)
        if math.isnan(res):
            func = symbbox.get_symbol_from_string(str(c_0))
            return func
        else:
            func = (res + s * 0)
            return func
    if func_type.lower() == "l":
        if knot1 == knot2:
            print("Knot1 & Knot2 are the same. No line load created.")
            return 0
        y0 = check_float_input(input("Start force: "))
        y1 = check_float_input(input("End force: "))
        # TODO check if y0 and y1 are symbols or number values. Get it correctly
        x0 = 0
        x1 = gc.knot_dist(knot1, knot2)
def calc_xy(symb_func, symb_to_plot_over, l_val, start_knot, end_knot):
    """
    Calculate the x- and y-coordinates for the plot
    :param symb_func: function that needs to be plotted
    :param symb_to_plot_over: running variable from 0 to 1, type(symb_to_plot_over) == type(sympy.Symbol())
    :param l_val: Defines length of the complete element
    :param start_knot: start knot for the function
    :param end_knot: end knot of the function
    """
    if symb_func is None:
        return None, None, False
    free_symbs = symb_func.free_symbols
    len_el = gc.knot_dist(start_knot, end_knot)
    prec_plot = 50

    x_length = float(symbbox.remove_free_symbols(l_val, None))
    x_vals = np.linspace(0, x_length, round(prec_plot * len_el))
    symb_func = symbbox.remove_free_symbols(symb_func, symb_to_plot_over)
    if symb_func == 0:
        return None, None, False
    if symb_to_plot_over in free_symbs and symb_to_plot_over in symb_func.free_symbols:
        # evaluate function from zero to one with symb_to_plot_over
        func_lambdified = lambdify(symb_to_plot_over, symb_func, "numpy")
        y_vals = func_lambdified(x_vals)
    elif symb_to_plot_over in free_symbs and symb_to_plot_over not in symb_func.free_symbols:
        print(
            'function can not be displayed correctly. e.g : f(x)=1+x*(M-F*l) -> f(x)=1+x*(0)'
        )
        y_vals = np.full(len(x_vals), float(symb_func))
    else:
        y_vals = np.full(len(x_vals), float(symb_func))
    return x_vals, y_vals, True
Пример #5
0
def extract_line_load(ds_nodedep, indice, node_list):
    knot_1, knot_2 = get_related_knots_for_elements(ds_nodedep, indice,
                                                    node_list)
    ll_local = ds_nodedep.data["ll_local"][indice]
    ll_x_n = ds_nodedep.data["ll_x_n"][indice]
    ll_y_q = ds_nodedep.data["ll_y_q"][indice]
    angle = ds_nodedep.data["angle"][indice]

    len_symb = Symbol('x')
    x_2 = gc.knot_dist(knot_1, knot_2)
    n, q = calc_line_load(ll_local, ll_x_n, ll_y_q, 0, x_2, len_symb, angle)
    return [n, q]
Пример #6
0
def single_beam_lineload_visu(curr_doc: CurrentDoc):
    start_knot = Knot.Knot(0, 1, 1, ElSupEnum.SUPPORT_FIXED_END.value, 0, [0, 0, 0], [0, 0, 0])
    end_knot = Knot.Knot(1, 3, 1, ElSupEnum.SUPPORT_ROLLER_END.value,  0, [0, 0, 0], [0, 0, 0])
    q = Symbol('p')
    l = gc.knot_dist(start_knot, end_knot) * Symbol('l')
    lineload = [0, q]
    temp_prop = TempProps.TempProps(0, 0, 0)
    knot_list = [[start_knot, end_knot]]
    elementlist = []
    ele = ElementCalculation(0, start_knot, end_knot, l, lineload, temp_prop, Symbol('EI'), float('inf'), Symbol('h'))
    start_knot.add_coupled_el(0)
    end_knot.add_coupled_el(0)
    elementlist.append(ele)
    testbox.vis_structure_from_input(curr_doc, knot_list, elementlist)
Пример #7
0
def vis_all_possible_nodedep_ele(curr_doc: CurrentDoc):
    # Visualises: beam, lineload, spring, spring_support, spring_moment, temp_prop
    f = Symbol('f')
    start_knot = Knot.Knot(0, 1.2, 1.7, ElSupEnum.SUPPORT_FIXED_END.value, k=[0, 0, 0], pointload=[0, 0, 0], angleSupport=-30)
    middle_knot = Knot.Knot(1, 2, 1, ElSupEnum.THROUGH_ELEMENT.value, k=[0, 0, 0], pointload=[0, 2*f, f])
    end_knot = Knot.Knot(2, 3, 1, ElSupEnum.SUPPORT_ROLLER_END.value, k=[0, 0, 0], pointload=[0, 0, 0], angleSupport=0)
    q = Symbol('q')
    n = Symbol('n')
    l = Symbol('l')
    l1 = gc.knot_dist(start_knot, middle_knot) * l
    l2 = gc.knot_dist(middle_knot, end_knot) * l
    k = Symbol('k')
    ei = Symbol('EI')
    ea = Symbol('EA')
    h = Symbol('h')
    lineload = [0.5 * n * l, q]
    temp_prop = TempProps.TempProps(0, 0, 0)
    knot_list = []
    elementlist = []
    # BEAM
    ele = ElementCalculation(0, start_knot, middle_knot, l1, lineload, temp_prop, ei=ei, ea=ea, h=h)
    elementlist.append(ele)
    knot_list.append([start_knot, middle_knot])

    # SPRING
    ele = ElementCalculation(1, middle_knot, end_knot, l2, [0, 0, 0], temp_prop, ei=ei, ea=ea, h=h, k_spring=k)
    elementlist.append(ele)
    knot_list.append([middle_knot, end_knot])

    # SPRING SUPPORT
    spring_sup = Knot.Knot(4, 2, 2, ElSupEnum.FREE_END.value, k=[2*k, 0, 0], pointload=[0, 0, 0], angleSupport=-90)
    spring_mom = Knot.Knot(5, 4, 2, ElSupEnum.FREE_END.value, k=[0, 0, 3*k], pointload=[0, 0, 0], angleSupport=0)
    temp_prop = TempProps.TempProps(10, 0, 0)
    ele = ElementCalculation(2, spring_sup, spring_mom, l1, [0, 0, 0], temp_prop, ei=ei, ea=ea, h=h)
    elementlist.append(ele)
    knot_list.append([spring_sup, spring_mom])
    testbox.vis_structure_from_input(curr_doc, knot_list, elementlist)
def plot_characteristic_vals(curr_doc: CurrentDoc,
                             plot,
                             func,
                             symb_to_plot_over,
                             l_val,
                             start_knot,
                             end_knot,
                             x_vals,
                             y_vals,
                             multipl_factor,
                             plot_list,
                             mirror_y_values=False,
                             line_color="#f46d43"):
    """
    Calculates all characteristic values for a given function and visualises them
    Visibility of Start/ end values is by default 1
    Visibility of Extrema and zero crossing is by default 0
    :param plot: plot the values need to be added to
    :param func: func the values are based on
    :param symb_to_plot_over: the running variable
    :param l_val: length variable of the element
    :param x_vals: array of all x values of the function
    :param y_vals: array of all y_values rotated to the end configuration
    :param multipl_factor: scaling of y coordinates
    :param plot_list: collects all elements that exist in this plot (needed to delete everything)
    :param mirror_y_values: If True, changes the sign of the text value
    :return:
    """
    if func is None or x_vals is None or y_vals is None:
        return

    sign = 1
    if mirror_y_values:
        sign = -1

    func_without_free_symbs = symbbox.remove_free_symbols(
        func, symb_to_plot_over)
    len_symbol = next(iter(l_val.free_symbols))
    kn_dist = gc.knot_dist(start_knot, end_knot)
    rel_tol = 1e-1
    abs_tol = 1e-1

    # BOUNDARY VALUES
    expr = round_expression(func.subs(symb_to_plot_over, 0), 2, 6)
    start_text = symbbox.get_str_from_func(sign * expr)
    x_point_start = x_vals[1]
    y_point_start = y_vals[1]
    start_bound_name = "bound_start_" + prhlp.get_id_from_knots(
        start_knot, end_knot)
    plot_bound_val(curr_doc, x_point_start, y_point_start, start_text, plot,
                   start_bound_name, line_color, rel_tol, abs_tol)
    plot_list.append(start_bound_name)

    expr = round_expression(func.subs(symb_to_plot_over, l_val), 2, 6)
    end_text = symbbox.get_str_from_func(sign * expr)
    x_point_end = x_vals[-2]
    y_point_end = y_vals[-2]
    end_bound_name = "bound_end_" + prhlp.get_id_from_knots(
        start_knot, end_knot)
    plot_bound_val(curr_doc, x_point_end, y_point_end, end_text, plot,
                   end_bound_name, line_color, rel_tol, abs_tol)
    plot_list.append(end_bound_name)

    # EXTREMA VALUES
    if not func_is_const(func, symb_to_plot_over):
        # print("EXTREME VALUES")
        diff_func_without_symbs = diff(func_without_free_symbs,
                                       symb_to_plot_over)
        roots = gc.get_real_roots(diff_func_without_symbs, symb_to_plot_over,
                                  kn_dist)
        i = 0
        for root in roots:
            if 0 < root < kn_dist:
                expr = round_expression(
                    func.subs(symb_to_plot_over, root * len_symbol), 2, 6)
                diff_text = symbbox.get_str_from_func(sign * expr)
                x_point = x_vals[0] + float(root)
                y_point = float(
                    func_without_free_symbs.subs(
                        symb_to_plot_over, root)) * multipl_factor + y_vals[0]
                x_point, y_point = gc.rotate_x_y_values(
                    x_point, y_point, start_knot, end_knot)
                # print_charac_val_to_console(diff_text, x_point, y_point)
                if plot in curr_doc.plot_data.char_vals_dict:
                    points_to_check = curr_doc.plot_data.char_vals_dict[plot]
                    # if gc.is_close_position(x_point, y_point, points_to_check, rel_tol, abs_tol):
                    #     continue
                diff_name = "extreme_val_" + prhlp.get_id_from_knots(
                    start_knot, end_knot) + str(i)
                plot.text([x_point], [y_point], [" " + str(diff_text)],
                          text_color=line_color,
                          text_font_size='1.3em',
                          text_align='left',
                          text_alpha=0,
                          name=diff_name)
                add_el_to_dict(curr_doc.plot_data.char_vals_dict, plot,
                               LinePlot.PointCol(x_point, y_point))
                add_el_to_dict(curr_doc.plot_data.extreme_vals_dict, plot,
                               diff_name)
                plot_list.append(diff_name)

                ex_cross_name = "cross_ex_" + prhlp.get_id_from_knots(
                    start_knot, end_knot) + str(i)
                plot.cross([x_point], [y_point],
                           angle=1 / m.sqrt(2),
                           size=15,
                           color=line_color,
                           line_width=3,
                           line_alpha=0,
                           name=ex_cross_name)
                add_el_to_dict(curr_doc.plot_data.extreme_vals_cross_dict,
                               plot, ex_cross_name)
                plot_list.append(ex_cross_name)
                i += 1

    # ZERO CROSSING VALUES
    i = 0
    if not func_is_const(func, symb_to_plot_over):
        roots = gc.get_real_roots(func_without_free_symbs, symb_to_plot_over,
                                  kn_dist)
        for root in roots:
            if 0 < root < kn_dist:
                zero_cross_text = symbbox.get_str_from_func(round(root, 2) *
                                                            len_symbol,
                                                            round_func=True)
                x_point = x_vals[0] + root
                y_point = y_vals[0] + 0
                x_point, y_point = gc.rotate_x_y_values(
                    x_point, y_point, start_knot, end_knot)
                # print_charac_val_to_console(zero_cross_text, x_point, y_point)
                if plot in curr_doc.plot_data.char_vals_dict:
                    points_to_check = curr_doc.plot_data.char_vals_dict[plot]
                    # if gc.is_close_position(x_point, y_point, points_to_check, rel_tol, abs_tol):
                    #     continue
                zero_cross_name = "zero_cross_val_" + prhlp.get_id_from_knots(
                    start_knot, end_knot) + str(i)
                plot.text([x_point], [y_point],
                          ["(" + str(zero_cross_text) + ", 0)"],
                          text_color=line_color,
                          text_font_size='1.3em',
                          text_align='left',
                          text_alpha=0,
                          name=zero_cross_name)
                add_el_to_dict(curr_doc.plot_data.char_vals_dict, plot,
                               LinePlot.PointCol(x_point, y_point))
                add_el_to_dict(curr_doc.plot_data.zero_cross_dict, plot,
                               zero_cross_name)
                plot_list.append(zero_cross_name)

                zero_cross_cross_name = "cross_zero_cross_" + prhlp.get_id_from_knots(
                    start_knot, end_knot) + str(i)
                plot.cross([x_point], [y_point],
                           angle=1 / m.sqrt(2),
                           size=15,
                           color=line_color,
                           line_width=3,
                           line_alpha=0,
                           name=zero_cross_cross_name)
                add_el_to_dict(curr_doc.plot_data.zero_cross_cross_dict, plot,
                               zero_cross_cross_name)
                plot_list.append(zero_cross_cross_name)
                i += 1
def plot_symbolic_func(plot,
                       symb_func,
                       symb_to_plot_over,
                       l_val,
                       start_knot,
                       end_knot,
                       xy_data,
                       y_reference,
                       plot_list,
                       line_color="#f46d43",
                       line_width=4):
    """
    Gets a symbolic function and plots it for a running symbol from 0 to 1 and moves it to the position between two knots
    :param plot: plot to print the function to
    :param symb_func: function that needs to be plotted
    :param symb_to_plot_over: running variable from 0 to 1, type(symb_to_plot_over) == type(sympy.Symbol())
    :param l_val: Defines length of the complete element
    :param start_knot: start knot for the function
    :param end_knot: end knot of the function
    :param xy_data: x- and y-coordinates for the plot
    :param y_reference: the maximum value of the plot series (e.g. Normal force), which will be scaled to y_max
    :param plot_list: collects all elements that exist in this plot (needed to delete everything)
    """
    y_max = 1  # the maximum y value for the plot (e.g. if y_max=1, no y value in the plot will be greater than 1)
    if symb_func is None:
        return None, None, 0
    len_el = gc.knot_dist(start_knot, end_knot)
    prec_plot = 50
    tol = 1e-15

    # Plot a zero in the middle of the structure, if function is zero
    if symb_func == 0:
        x_val = start_knot.x_ + (end_knot.x_ - start_knot.x_) / 2
        y_val = start_knot.y_ + (end_knot.y_ - start_knot.y_) / 2
        name = str(start_knot.id) + str(end_knot.id) + str(time.time())
        plot.text([x_val], [y_val], ["0"],
                  text_color=line_color,
                  name=name,
                  text_font_size='4em',
                  text_align='center',
                  text_alpha=1,
                  text_baseline='middle')
        plot_list.append(name)
        return None, None, 0

    x_vals, y_vals = xy_data[0], xy_data[1]
    if y_vals is None:
        return None, None, 0

    # Rotate, translate and scale function to beam to plot over
    y_vals, multipl_factor = scale_y_values(y_vals, y_reference, y_max)
    x_vals = np.linspace(start_knot.x_, start_knot.x_ + len_el,
                         round(prec_plot * len_el))
    y_vals += start_knot.y_
    x_vals, y_vals = gc.rotate_x_y_values(x_vals, y_vals, start_knot, end_knot,
                                          tol)

    x_vals = np.concatenate([[start_knot.x_], x_vals, [end_knot.x_]])
    y_vals = np.concatenate([[start_knot.y_], y_vals, [end_knot.y_]])
    name = str(start_knot.id) + str(end_knot.id) + str(time.time())
    plot.line(x_vals,
              y_vals,
              line_color=line_color,
              line_width=line_width,
              line_alpha=0.6,
              name=name)
    plot_list.append(name)

    return x_vals, y_vals, multipl_factor
Пример #10
0
 def length_nr_(self):
     return knot_dist(self.start_knot, self.end_knot)