示例#1
0
 def _calc_mohr(self):
     mohr_circle = Stress_MohrCircle(self.σxx, self.σyy,self.σxy, self.σzz,self.σyz,self.σzx)
     if(self.angle2d!=None and self.ndims==2):
         mohr_circle.isAngle_stress = True
         mohr_circle.reqAngle_stress_2d = self.angle2d
     elif(self.ndims==3 and self.angle1!=None and self.angle2!=None):
         l,m,n= np.cos(np.deg2rad(self.angle1)), np.cos(np.deg2rad(self.angle2)), np.cos(np.deg2rad(self.angle3))
         mohr_circle.isAngle_stress = True
         l,m,n = round(l,3),round(m,3),round(n,3)
         mohr_circle.reqAngle_normal_3d = list([l,m,n])
     mohr_circle.ndims = self.ndims
     return mohr_circle.stress_execute()
示例#2
0
def tut2D_step5_window(screen, prev_win, windows):
    Big_font = game_font(60)
    Small_font = game_font(25)
    mid_font = game_font(40)
    # print(sigma_xx_tut.text, sigma_yy_tut.text, tau_xy_tut.text, angle_tut.text)
    head_text = Big_font.render("Tutorial 2-D Mode", 1, (0, 0, 0))
    mid_text = mid_font.render("STEP-5", 1, (0, 0, 0))
    screen.blit(head_text, (80, 70))
    screen.blit(mid_text, (80, 150))
    tut_text = [
        "Now, using the center and radius being ",
        "Thus the new line has its end-points on",
        "the circle. These endpoints denote the new",
        "(sigma_xx, -tau_xy) and (sigma_yy, tau_xy)", " ",
        "Thus you get the required values of stress",
        "at the required angle using Mohr's Circle!!!"
    ]
    count = 0
    for text in tut_text:
        text = Small_font.render(text, 1, (0, 0, 0))
        screen.blit(text, (70, 200 + count))
        count += 40
    backButton.draw(screen, (0, 0, 0))
    finishButton.draw(screen, (0, 0, 0))
    graphButton.draw(screen, (0, 0, 0))
    for event in pygame.event.get():
        pos = pygame.mouse.get_pos()
        if event.type == pygame.QUIT:
            global running
            running = False
        if event.type == pygame.MOUSEBUTTONDOWN:
            if backButton.isOver(pos):
                tut2D_step4_window_check.makeCurrent()
                tut2D_step5_window_check.endCurrent()
            if finishButton.isOver(pos):
                tut2D_final_window_check.makeCurrent()
                tut2D_step5_window_check.endCurrent()
            if graphButton.isOver(pos):
                req_mohr = Stress_MohrCircle(float(sigma_xx_tut.text),
                                             float(sigma_yy_tut.text),
                                             float(tau_xy_tut.text))
                # req_mohr.angle = float(angle_tut.text)
                req_mohr.ndims = 2
                # req_mohr.plot_angle2d()
                req_mohr.isAngle_stress = True
                req_mohr.reqAngle_stress_2d = float(angle_tut.text)
                req_mohr.isGraph = True
                req_mohr.stress_execute()
示例#3
0
def eval_window(screen, prev_win, windows):
    global userScore, show_graph, correct_answer, curr_question_type, quiz_question_type, user_concept_answer
    global sigma_xx, sigma_yy, sigma_zz, tau_xy, tau_yz, tau_zx, quest_nos, quest_index
    if curr_question_type != 'concept':
        mohr_2d = Stress_MohrCircle(σxx=sigma_xx,
                                    σyy=sigma_yy,
                                    σzz=sigma_zz,
                                    σxy=tau_xy,
                                    σyz=tau_yz,
                                    σzx=tau_zx)
        mohr_2d.ndims = 2
        mohr_3d = Stress_MohrCircle(σxx=sigma_xx,
                                    σyy=sigma_yy,
                                    σzz=sigma_zz,
                                    σxy=tau_xy,
                                    σyz=tau_yz,
                                    σzx=tau_zx)
        mohr_3d.ndims = 3
    x_button = nextButton
    if len(quiz_question_type) == 0:
        x_button = submitButton
    x_button.draw(screen, (0, 0, 0))

    Big_font = game_font(40)
    Small_font = game_font(20)
    if (curr_question_type != "concept"):
        graphButton.draw(screen, (0, 0, 0))
    isCorrect = False

    if show_graph == 0:
        if curr_question_type != 'concept':
            if curr_question_type == '2-D':
                mohr_2d.isGraph = False
                correct_answer = mohr_2d.stress_execute()
                correct_answer = correct_answer[0]

            elif curr_question_type == '3-D':
                mohr_2d.isGraph = False
                correct_answer = mohr_3d.stress_execute()
                correct_answer = correct_answer[0]

    try:
        if curr_question_type == "2-D":
            if correct_answer[0][0] < float(
                    C1_gen.text) + 0.5 and correct_answer[0][0] > float(
                        C1_gen.text) - 0.5:

                isCorrect = True
                if show_graph == 0:
                    userScore += 5
        elif curr_question_type == "3-D":
            user_answer = [[float(C1_gen.text)], [float(C2_gen.text)],
                           [float(C3_gen.text)]]
            counter = 0
            for k in user_answer:
                for l in correct_answer:
                    if k[0] < l[0] + 0.5 and k[0] > l[0] - 0.5:
                        counter += 1
                        break
            if counter == 3:
                isCorrect = True
                if show_graph == 0:
                    userScore += 5
        elif curr_question_type == 'concept':
            if (concept_quest[quest_nos[quest_index]][2] == user_concept_answer
                ):
                isCorrect = True
                if show_graph == 0:
                    userScore += 5
    except:
        pass
    show_graph += 1
    if (isCorrect):
        text = Big_font.render("CORRECT :)", 1, (0, 0, 0))
        screen.blit(text, (70, 250))
    else:
        text = Big_font.render("WRONG :(", 1, (0, 0, 0))
        screen.blit(text, (70, 250))

    if curr_question_type == 'concept':
        line_brk = 0
        exp_text = concept_quest[quest_nos[quest_index]][3]
        # print(exp_text)
        for exp in exp_text:
            exp = Small_font.render(exp, 1, (0, 0, 0))
            screen.blit(exp, (70, 300 + line_brk))
            line_brk += 20

    for event in pygame.event.get():
        pos = pygame.mouse.get_pos()
        if event.type == pygame.QUIT:
            global running
            running = False

        if event.type == pygame.MOUSEMOTION:
            if (curr_question_type != "concept"):
                if graphButton.isOver(pos):
                    graphButton.color = (255, 0, 0)
                else:
                    graphButton.color = (180, 0, 0)

            if x_button.isOver(pos):
                x_button.color = (255, 0, 0)
            else:
                x_button.color = (180, 0, 0)
        if event.type == pygame.MOUSEBUTTONDOWN:
            if graphButton.isOver(pos):
                if curr_question_type != 'concept':
                    if curr_question_type == '2-D':
                        mohr_2d.isGraph = True
                        mohr_2d.stress_execute()

                    elif curr_question_type == '3-D':
                        mohr_3d.isGraph = True
                        mohr_3d.stress_execute()

            if x_button.isOver(pos):
                if len(quiz_question_type) > 0:
                    # print(quiz_question_type[0])
                    show_graph = 0
                    if quiz_question_type[0] == '2-D':
                        sigma_xx = round(random.randint(-30, 30), 2)
                        sigma_yy = round(random.randint(-30, 30), 2)
                        tau_xy = round(random.randint(-30, 30), 2)
                        sigma_zz = 0
                        tau_yz = 0
                        tau_zx = 0
                        quiz_question_type = quiz_question_type[1:]
                        eval_window_check.endCurrent()
                        quizwindow_2d_check.makeCurrent()
                    elif quiz_question_type[0] == '3-D':
                        sigma_xx = round(random.randint(-30, 30), 2)
                        sigma_yy = round(random.randint(-30, 30), 2)
                        sigma_zz = round(random.randint(-30, 30), 2)
                        tau_xy = round(random.randint(-30, 30), 2)
                        tau_yz = round(random.randint(-30, 30), 2)
                        tau_zx = round(random.randint(-30, 30), 2)
                        quiz_question_type = quiz_question_type[1:]
                        eval_window_check.endCurrent()
                        quizwindow_3d_check.makeCurrent()
                    elif quiz_question_type[0] == 'concept':
                        user_concept_answer = -1
                        quiz_question_type = quiz_question_type[1:]
                        quest_nos.remove(quest_nos[quest_index])
                        print(quest_nos)
                        quest_index = random.randint(0, len(quest_nos) - 1)
                        eval_window_check.endCurrent()
                        quizwindow_concept_check.makeCurrent()
                else:
                    eval_window_check.endCurrent()
                    quiz_end_window_check.makeCurrent()
示例#4
0
def tut3D_stress_input_window(screen, prev_win, windows):
    global angle_check
    clock = pygame.time.Clock()
    input_boxes = {
        sigma_xx_tut: "sigma_xx",
        sigma_yy_tut: "sigma_yy",
        tau_xy_tut: "tau_xy",
        sigma_zz_tut: "sigma_zz",
        tau_yz_tut: "tau_yz",
        tau_zx_tut: "tau_zx",
        angle1_tut: "Angle x",
        angle2_tut: 'Angle y',
        angle3_tut: 'Angle z'
    }
    Small_font = game_font(20)
    head_text = Small_font.render("Tutorial 3-D Mode", 1, (0, 0, 0))

    for box in input_boxes.keys():
        box_text = Small_font.render(input_boxes[box] + ":", 1, (0, 0, 0))
        screen.blit(box_text, (box.x - 120, box.y))

    screen.blit(head_text, (360, 100))
    backButton.draw(screen, (0, 0, 0))
    enterButton.draw(screen, (0, 0, 0))
    for event in pygame.event.get():
        pos = pygame.mouse.get_pos()
        if event.type == pygame.QUIT:
            global running
            running = False
        if event.type == pygame.MOUSEBUTTONDOWN:
            if backButton.isOver(pos):
                tutorialwindow_check.makeCurrent()
                tut3D_stress_input_window_check.endCurrent()
            if enterButton.isOver(pos):
                mohrCircle_input = []
                try:
                    mohr_3d = Stress_MohrCircle(σxx=float(sigma_xx_tut.text),
                                                σyy=float(sigma_yy_tut.text),
                                                σzz=float(sigma_zz_tut.text),
                                                σxy=float(tau_xy_tut.text),
                                                σyz=float(tau_yz_tut.text),
                                                σzx=float(tau_zx_tut.text))
                    mohr_3d.ndims = 3
                    mohr_3d.isGraph = False
                    if (angle1_tut.text != '' and angle2_tut.text != ''):
                        angle_check = 1
                        mohr_3d.reqAngle_normal_3d = [
                            round(np.cos(np.deg2rad(float(angle1_tut.text))),
                                  3),
                            round(np.cos(np.deg2rad(float(angle2_tut.text))),
                                  3), 0
                        ]
                        mohr_3d.isAngle_stress = True
                    mohr_3d.stress_execute()
                    tut3D_stress_input_window_check.endCurrent()
                    tut3D_step1_window_check.makeCurrent()
                except Exception as e:
                    print(e)
                    tut3D_stress_input_window_check.endCurrent()
                    incompatible_input_window_check.makeCurrent()
            for box in input_boxes.keys():
                if box.render().collidepoint(event.pos):
                    print("click")
                    box.active = True
                else:
                    box.active = False
        box_text_input(event, input_boxes)

        if event.type == pygame.MOUSEMOTION:
            if backButton.isOver(pos):
                backButton.color = (255, 0, 0)
            else:
                backButton.color = (180, 0, 0)

    for box in input_boxes.keys():
        txt_surface = Small_font.render(box.text, True, box.color)
        width = max(200, txt_surface.get_width() + 10)
        box.render().w = width
        screen.blit(txt_surface, (box.x + 5, box.y + 5))
        pygame.draw.rect(screen, box.color, box.render(), 2)

    clock.tick(30)
示例#5
0
def tut3D_step7_window(screen, prev_win, windows):
    Big_font = game_font(60)
    Small_font = game_font(25)
    extra_small_font = game_font(18)
    mid_font = game_font(40)
    # print(sigma_xx_tut.text, sigma_yy_tut.text, tau_xy_tut.text, angle_tut.text)
    head_text = Big_font.render("Tutorial 3-D Mode", 1, (0, 0, 0))
    mid_text = mid_font.render("STEP-7", 1, (0, 0, 0))
    screen.blit(head_text, (80, 70))
    screen.blit(mid_text, (80, 150))
    l = np.cos(np.deg2rad(float(angle1_tut.text)))
    m = np.cos(np.deg2rad(float(angle2_tut.text)))
    n = np.sqrt(1 - l**2 - m**2)
    if (n == None):
        n = 0
    tut_text = [
        "To find the the value of stresses on plane",
        "whose normal's direction vector is (l,m,n)",
        "l = cos(" + str(angle1_tut.text) + ") = " + str(round(l, 3)),
        "m = cos(" + str(angle2_tut.text) + ") = " + str(round(m, 3)),
        "n = sqrt(1 - l^2 -m^2) =  " + str(round(n, 3)),
    ]
    tut2_text = [
        "use the following formula to obtain normal", "and shear stress : ",
        "sig_normal = l^2*sig_1+m^2*sig_2+n^2*sig_3",
        "sig_shear = l^2*sig_1^2 + m^2*sig_2^2 + n^2*sig_3^2 - sig_normal^2",
        "PLot the point (sig_normal, sig_shear)"
    ]
    count = 0
    for text in tut_text:
        text = Small_font.render(text, 1, (0, 0, 0))
        screen.blit(text, (70, 200 + count))
        count += 40
    count = 0
    for text in tut2_text:
        text = extra_small_font.render(text, 1, (0, 0, 0))
        screen.blit(text, (40, 400 + count))
        count += 25
    backButton.draw(screen, (0, 0, 0))
    graphButton.draw(screen, (0, 0, 0))
    finishButton.draw(screen, (0, 0, 0))
    for event in pygame.event.get():
        pos = pygame.mouse.get_pos()
        if event.type == pygame.QUIT:
            global running
            running = False
        if event.type == pygame.MOUSEBUTTONDOWN:
            if backButton.isOver(pos):
                tut3D_step6_window_check.makeCurrent()
                tut3D_step7_window_check.endCurrent()
            if finishButton.isOver(pos):
                tut3D_final_window_check.makeCurrent()
                tut3D_step7_window_check.endCurrent()
            if graphButton.isOver(pos):
                mohr_3d = Stress_MohrCircle(σxx=float(sigma_xx_tut.text),
                                            σyy=float(sigma_yy_tut.text),
                                            σzz=float(sigma_zz_tut.text),
                                            σxy=float(tau_xy_tut.text),
                                            σyz=float(tau_yz_tut.text),
                                            σzx=float(tau_zx_tut.text))
                mohr_3d.ndims = 3
                mohr_3d.isGraph = True
                if (angle1_tut.text != '' and angle2_tut.text != ''):
                    angle_check = 1
                    mohr_3d.reqAngle_normal_3d = [
                        round(np.cos(np.deg2rad(float(angle1_tut.text))), 3),
                        round(np.cos(np.deg2rad(float(angle2_tut.text))), 3), 0
                    ]
                    mohr_3d.isAngle_stress = True
                mohr_3d.stress_execute()
示例#6
0
def tut2D_stress_input_window(screen, prev_win, windows):
    global angle_check
    clock = pygame.time.Clock()
    input_boxes = {
        sigma_xx_tut: "sigma_xx",
        sigma_yy_tut: "sigma_yy",
        tau_xy_tut: "tau_xy",
        angle_tut: "angle"
    }
    Small_font = game_font(20)
    head_text = Small_font.render("Tutorial 2- D Mode", 1, (0, 0, 0))
    for box in input_boxes.keys():
        box_text = Small_font.render(input_boxes[box] + ":", 1, (0, 0, 0))
        screen.blit(box_text, (box.x - 120, box.y))
    screen.blit(head_text, (360, 100))
    backButton.draw(screen, (0, 0, 0))
    nextButton.draw(screen, (0, 0, 0))
    for event in pygame.event.get():
        pos = pygame.mouse.get_pos()
        if event.type == pygame.QUIT:
            global running
            running = False
        if event.type == pygame.MOUSEBUTTONDOWN:
            if backButton.isOver(pos):
                tutorialwindow_check.makeCurrent()
                tut2D_stress_input_window_check.endCurrent()
            if nextButton.isOver(pos):
                try:
                    mohr_2d = Stress_MohrCircle(σxx=float(sigma_xx_tut.text),
                                                σyy=float(sigma_yy_tut.text),
                                                σzz=0,
                                                σxy=float(tau_xy_tut.text),
                                                σyz=0,
                                                σzx=0)
                    mohr_2d.ndims = 2
                    mohr_2d.isGraph = False
                    if (angle_tut.text != ''):
                        mohr_2d.isAngle_stress = True
                        angle_check = 1
                        mohr_2d.reqAngle_stress_2d = float(angle_tut.text)
                    else:
                        angle_check = 0
                    mohr_2d.stress_execute()
                    tut2D_stress_input_window_check.endCurrent()
                    tut2D_step1_window_check.makeCurrent()
                except:
                    tut2D_stress_input_window_check.endCurrent()
                    incompatible_input_window_check.makeCurrent()
            for box in input_boxes.keys():
                if box.render().collidepoint(event.pos):
                    print("click")
                    box.active = True
                else:
                    box.active = False
        box_text_input(event, input_boxes)

        if event.type == pygame.MOUSEMOTION:
            if backButton.isOver(pos):
                backButton.color = (255, 0, 0)
            else:
                backButton.color = (180, 0, 0)

    for box in input_boxes.keys():
        txt_surface = Small_font.render(box.text, True, box.color)
        width = max(200, txt_surface.get_width() + 10)
        box.render().w = width
        screen.blit(txt_surface, (box.x + 5, box.y + 5))
        pygame.draw.rect(screen, box.color, box.render(), 2)

    clock.tick(30)
示例#7
0
def tut2D_step3_window(screen, prev_win, windows):
    global angle_check
    global sigma1, sigma2, curr_angle
    Big_font = game_font(60)
    Small_font = game_font(25)
    extra_small_font = game_font(15)
    mid_font = game_font(40)
    # print(sigma_xx_tut.text, sigma_yy_tut.text, tau_xy_tut.text, angle_tut.text)
    head_text = Big_font.render("Tutorial 2-D Mode", 1, (0, 0, 0))
    mid_text = mid_font.render("STEP-3", 1, (0, 0, 0))
    screen.blit(head_text, (80, 70))
    screen.blit(mid_text, (80, 150))
    tut_text = [
        "Now, using the center and radius being ",
        "the distance between the center and one ",
        "of the plotted points, draw a circle.",
        "Thus you get your Mohr's Circle",
        "The points where the circle cuts the X-axis",
        "are the principal stresses."
    ]
    count = 0
    for text in tut_text:
        text = Small_font.render(text, 1, (0, 0, 0))
        screen.blit(text, (70, 200 + count))
        count += 40
    backButton.draw(screen, (0, 0, 0))
    xButton = nextButton
    if angle_check == 0:
        xButton = finishButton
    xButton.draw(screen, (0, 0, 0))
    graphButton.draw(screen, (0, 0, 0))

    try:
        mohr_2d = Stress_MohrCircle(σxx=float(sigma_xx_tut.text),
                                    σyy=float(sigma_yy_tut.text),
                                    σzz=0,
                                    σxy=float(tau_xy_tut.text),
                                    σyz=0,
                                    σzx=0)
        mohr_2d.ndims = 2
        mohr_2d.isGraph = False
        if (angle_gen.text != ''):
            mohr_2d.isAngle_stress = True
            mohr_2d.reqAngle_stress_2d = float(angle_gen.text)
        _, sig, _, _, _, curr_angle = mohr_2d.stress_execute()
        sigma1, sigma2 = sig[0][0], sig[1][0]

        curr_angle = round(np.rad2deg(curr_angle), 2)
        answer_txt = "sigma_1 : " + str(sigma1) + ", sigma_2 : " + str(
            sigma2) + ", phi : " + str(curr_angle) + " deg"
        answer_txt = extra_small_font.render(answer_txt, 1, (0, 0, 0))
        screen.blit(answer_txt, (50, 480))
    except ValueError:
        # print(e)
        answer_txt = "sigma_1 :   sigma_2 :   phi"
        answer_txt = extra_small_font.render(answer_txt, 1, (0, 0, 0))
        screen.blit(answer_txt, (50, 480))
    for event in pygame.event.get():
        pos = pygame.mouse.get_pos()
        if event.type == pygame.QUIT:
            global running
            running = False
        if event.type == pygame.MOUSEBUTTONDOWN:
            if backButton.isOver(pos):
                tut2D_step2_window_check.makeCurrent()
                tut2D_step3_window_check.endCurrent()
            if xButton.isOver(pos):
                if xButton == nextButton:
                    tut2D_step3_window_check.endCurrent()
                    tut2D_step4_window_check.makeCurrent()
                else:
                    tut2D_step3_window_check.endCurrent()
                    tut2D_final_window_check.makeCurrent()
            if graphButton.isOver(pos):
                req_mohr = tut_Stress_MohrCircle(float(sigma_xx_tut.text),
                                                 float(sigma_yy_tut.text),
                                                 float(tau_xy_tut.text))
                req_mohr.ndims = 2
                req_mohr.plot_circle()