def save_file(beam_length, beam_type, load_positions, load_forces):
    print(
        "**************************************SAVE FILE******************************************"
    )
    while True:
        print("Where do you want to save this very file?\n")
        print("Now you are in this directory; \n  ", os.getcwd(), "\n")
        button = display_menu(save_menu_options)
        if button == 1:
            path = input(
                "Type the file location you want to save the file to\n>>")
        elif button == 2:
            path = os.getcwd()
        elif button == 3:
            break
        try:
            os.chdir(path)
            filename = input("Type a file name\n>>")
            np.savetxt(filename + ".csv",
                       merge(load_positions, load_forces, beam_length,
                             beam_type),
                       delimiter=',')
        except:
            print(
                "This very particular location is not found. Please type a valid directory.\n"
            )
            continue
        break
def choice1(beam_length, beam_type):
    #choice1 function displayes options regarding the beam and enables the  user to configure the beamlength and the beam support type.
    #Input: user input
    #Output: beamlength and support type (float & Integer, respectively)

    print(
        "*************************************CONFIGURE BEAM*******************************************"
    )
    while True:

        try:
            #checking beamlength is of float type
            beam_length = float(
                input("Please enter the length of the beam\n>>"))

        except:
            print("Unfortunately this is not a valid number\n")
            continue
        #checking if beamlength input is negative and giving feedback
        if beam_length < 0:
            print(
                "Please type a valid beam length because it seems like you typed in a negative number\n"
            )
            continue
        #displaying options for beam support type
        while True:
            print("Please choose the beam support type\n")

            button = display_menu(choice1_options)

            if button == 3: break  #ESCAPE option

            #checking the input is an integer and equal to 1 and 2
            try:
                beam_type = int(button)
            except:
                print("This is not a valid option.\n>>")
                continue
            if beam_type != 2 and beam_type != 1:
                print("This is not a valid option")
                continue
            break

        break
    return beam_length, beam_type
示例#3
0
def choice6(E, materials):
    #the choice 6 function changes the material constants for the beam and
    #hence changes the calculations according to different types of material.
    #Input: E, a number definite for each material; materials list
    #Output: The resulting number E according to the users choice

    #display the menu
    button = display_menu(materials)
    #assigning value to E
    if button == 1:
        E = 200 * (10**9)
    elif button == 2:
        E = 400 * (10**9)
    elif button == 3:
        E = 80 * (10**9)
    elif button == 4:
        E = 74 * (10**9)
    return E
def load(load_forces,load_positions,beam_length,beam_type):
    #the load function loads a file into the program. It splits the matrix of a saved file up and assign the certain values to 
    #load_forces,load_positions,beam_length and beam_type.
    #Input: User input
	path=os.getcwd()
	while True:
		#displaying directory
        print("Now you are in this directory; \n  ",os.getcwd(),"\n")
		#displaying menu
        button=display_menu(save_menu_options)
		if button==1:
        #redefining path
			path=input("Type the file location you want to load the file from\n>>")
		elif button==2:
        #staying with this directory
			path=os.getcwd()
		elif button==3:
        #printing content of current directory
			print(os.listdir(path) )
			continue
		elif button==4:
		#While loop is broken with QUIT option
			break
		while True:
			try:
				print("Q . Quit")
				filename=input("What is the name of the file?\n>>")
				if filename=="Q"or filename=="q":break #implementing quit option to go one submenu back
				
            #reading the file in and storing in variable df    
            df = pd.read_csv(path+"/"+filename, header=None)
				
            #assigning values
            beam_length=df[0][1]
				beam_type=df[0][0]	
				load_forces=df.loc[0,:]
				load_positions=df.loc[1,:]
				load_forces=load_forces.loc[1:][:]
				load_positions=load_positions.loc[1:][:]
				load_forces = np.array([float(x) for x in load_forces])
				load_positions = np.array([float(x) for x in load_positions])
示例#5
0
def load(load_forces, load_positions, beam_length, beam_type):
    path = os.getcwd()
    while True:
        print("Now you are in this directory; \n  ", os.getcwd(), "\n")
        button = display_menu(save_menu_options)
        if button == 1:
            path = input(
                "Type the file location you want to load the file from\n>>")
        elif button == 2:
            path = os.getcwd()
        elif button == 3:
            print(os.listdir(path))
            continue
        elif button == 4:
            break
        while True:
            try:
                print("Q . Quit")
                filename = input("What is the name of the file?\n>>")
                if filename == "Q" or filename == "q": break
                df = pd.read_csv(path + "/" + filename, header=None)
                beam_length = df[0][1]
                beam_type = df[0][0]
                load_forces = df.loc[0, :]
                load_positions = df.loc[1, :]
                load_forces = load_forces.loc[1:][:]
                load_positions = load_positions.loc[1:][:]
                load_forces = np.array([float(x) for x in load_forces])
                load_positions = np.array([float(x) for x in load_positions])
                if beam_type != 1 or beam_type != 2:
                    beam_type = 1
            except:
                print(
                    filename +
                    " file is not found please make sure the followings;\n* Make sure you are in the correct directory\n"
                    + "* Make sure you type the correct extension(.csv)\n")
                continue
            break
        break
    return load_forces, load_positions, beam_length, beam_type
def save_file(beam_length, beam_type, load_positions, load_forces):
    #save file saves the resulting matrix (see merge function) in a file.
    #Input:load postions, forces (array), beamtype(integer),beamlength (float)
    #Output: - saves the matrix to a file
    print(
        "**************************************SAVE FILE******************************************"
    )
    while True:
        print("Where do you want to save this very file?\n")
        print("Now you are in this directory; \n  ", os.getcwd(), "\n")

        #displaying menu
        button = display_menu(save_menu_options)

        #defining options
        if button == 1:
            #changing file location
            path = input(
                "Type the file location you want to save the file to\n>>")
        elif button == 2:
            #staying in current one
            path = os.getcwd()
        elif button == 3:
            #quit
            break
        try:
            #saving file
            os.chdir(path)
            filename = input("Type a file name\n>>")
            np.savetxt(filename + ".csv",
                       merge(load_positions, load_forces, beam_length,
                             beam_type),
                       delimiter=',')
        except:
            print(
                "This very particular location is not found. Please type a valid directory.\n"
            )
            continue
        break
beam_type=1
i = 0

#Printing the defaults
while True:
    clear_screen()
    print("*************************************MAIN MENU*******************************************")
    print("*  Length of the beam is ", beam_length)
    print("*  Type of the beam is", beamtype_array[beam_type-1],"\n\n")
    print("*****************************************************************************************")
     #checking loadpositions and forces according to beamlenght (see fct regular check)
    load_positions, load_forces=regular_check(load_positions, load_forces, beam_length)
    display_forces(load_positions,load_forces)
    
    #display menu to user and assing user's choice to variable choice(see fct display menu)
    choice=display_menu(main_menu)
    
    
    #changing beamlenght and support type and reassigning variables beam_lenght and support type
    if choice == 1:
        clear_screen()
        beam_length,beam_type = choice1(beam_length,beam_type)
        
    #changing forces and postions and reassigning variables load_forces and load_positions     
    elif choice == 2:
        clear_screen()
        load_positions, load_forces, i = choice2(load_positions, load_forces, conf_load_menu, i, beam_length)
        
    #saving loads, their forces, beam support type and length in a file 
    elif choice==3:
        clear_screen()
示例#8
0
def choice2(load_positions, load_forces, conf_load_menu, i, beam_length):
##choice2 function displayes options regarding the loads and enables the user to configure the amount of laods, their magnitude and their positions.
#Input: load_positions, load_forces, conf_load_menu, i, beam_length; user input
#Output: arrays load_positions, load_forces with stored values for magintude and positions of loads
        clear_screen()
        print("*************************************CONFIGURE LOADS*******************************************")
        #displaying actual forces and their postions to the user (if any)
        display_forces(load_positions, load_forces)
        
        #User Input
        choice= display_menu(conf_load_menu)
        esc=0
        
        #configuring the magnitudes of the loads
        if choice == 1:
            while (esc!="q" and esc!="Q"):
                print("Q . Quit\n")
                esc=input("The magnitude of the load?\n>>") #ESCAPE option
               
                #checking valid number input
                try:
                    load_forces[i] = float(esc)
                except:
                    load_forces[i]=0
                    print("This is not a valid input.(Type in a number!)\n")
                    continue
                if load_forces[i]<0:
                    print("Please type in a positive value!\nor")
                    load_forces[i]=0
                    continue
                
                #configuring the location of the loads
                while True:
                    print("Q . Quit\n")
                    esc=input("Location of the load?\n>>")
                    if esc=="q" or esc=="Q":
                        load_forces[i]=0
                        break#ESCAPE option
                        
                    #checking again for valid number inputs and making sure if escape button is hit to set force equal to zero too   
                    try:
                        load_positions[i] = float(esc)
                    except:
                        load_positions[i]=0
                        print("This is not a valid number. Please type a number!")
                        continue
                    if load_positions[i] < 0 or load_positions[i]> beam_length:
                        print("Please type a number between 0 and length of the beam(",beam_length," m)")
                        load_positions[i]=0
                        continue
                    break
                break
                
                
            #i is for keeping track of places of new forces and positions
            i = i + 1
        #removing all the loads    
        elif choice == 2:
            load_positions = np.zeros(100)
            load_forces = np.zeros(100)
            i=0
            print("Now you do not have any loads.")
        #removing one load at a certain position
        elif choice ==3:
            #giving feedback if there aren't any loads to remove
            if len(load_forces[load_forces!=0])==0:
                print("There is no force to be removed\n")
                continue
            
            button="Mike"
            print("Which one do you want to remove? These are the positions from left point.\n")
            
            #counting all elements and displaying them as list to choose from 
            while True:
                for counter,element in enumerate(load_forces):
                    if element!=0:
                        print(counter+1, " for the force at ", load_positions[counter],"meter position")
                print("Q Quit to main menu")#Escape option
                button=input(">>")
                if button=="q" or button=="Q":
                    break
                #checking user input
                try:
                    load_forces[int(button)-1]=0
                    load_positions[int(button)-1]=0
                except:
                    print("This value is either not an integer or an illegal input ")
                    continue
        elif choice==4:
            return load_positions, load_forces, i
        else:
            print("Please type a valid input.\n")
def choice2(load_positions, load_forces, conf_load_menu, i, beam_length):
    display_forces(load_positions, load_forces)
    choice = display_menu(conf_load_menu)
    esc = 0
    if choice == 1:
        while (esc != "q" and esc != "Q"):
            print("Press Q to quit\n")
            esc = input("The magnitude of the load?\n>>")
            try:
                load_forces[i] = float(esc)
            except:
                load_forces[i] = 0
                print("This is not a valid input.(Type in a number!)\n")
                continue
            if load_forces[i] < 0:
                print("Please type in a positive value!")
                load_forces[i] = 0
                continue
            while (esc != "q" and esc != "Q"):
                print("Press Q to quit\n")
                esc = input("Location of the load?\n>>")
                try:
                    load_positions[i] = float(esc)
                except:
                    load_positions[i] = 0
                    print("This is not a valid number. Please type a number!")
                    continue
                if load_positions[i] < 0 or load_positions[i] > beam_length:
                    print(
                        "Please type a number between 0 and length of the beam(",
                        beam_length, " m)")
                    load_positions[i] = 0
                    continue
                break
            break

        #i is for keeping track of places of new forces and positions
        i = i + 1
    elif choice == 2:
        load_positions = np.zeros(20)
        load_forces = np.zeros(20)
        print("Now you do not have any loads.")
    elif choice == 3:
        button = "mike"
        print(
            "Which one do you want to remove? These are the positions from left point.\n"
        )
        while True:
            for counter, element in enumerate(load_forces):
                if element != 0:
                    print(counter + 1, " for the force at ",
                          load_positions[counter], "meter position")
            print("Q Quit to main menu")
            button = input(">>")
            print("\n")
            if button == "q" or button == "Q":
                break
            try:
                load_forces[int(button) - 1] = 0
                load_positions[int(button) - 1] = 0
            except:
                print("This value either not an integer or ")
                continue

    return load_positions, load_forces, i