Beispiel #1
0
def main():
    howMany = getNum("Enter a number between 10 and 20: ", 10, 20,
                     float("inf"), True)
    list = randomNumber(howMany)
    n = getNum("Enter a number between 0 and 100: ", 0, 100, float("inf"),
               True)
    largerThan(list, n)
Beispiel #2
0
def main():
    turns = 0
    currentPlayer = "O"
    board = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
    gameOver = False
    count = 0
    while (not gameOver):
        drawBoard(board)
        currentPlayer = switchPlayer(currentPlayer)
        turns += 1
        choice = getNum("Player " + currentPlayer + ",", 1, len(board),
                        float("inf"), True)
        while (board[choice - 1] == "X" or board[choice - 1] == "O"):
            choice = getNum("That spot is taken, try again:", 1, len(board),
                            float("inf"), True)
        board[choice - 1] = currentPlayer
        # <<<<<<< HEAD
        # <<<<<<< HEAD
        gameOver = checkWinner(board, currentPlayer, turns)
        # =======
        count += 1
        gameOver = checkWinner(board, currentPlayer, turns)
        if (count == 9):
            gameOver = True
            drawBoard(board)
            print("It's a tie folks!")

# >>>>>>> 9c7d0a222af0e4d6332910c5e46674cec20bdf9d
# =======
        gameOver = checkWinner(board, currentPlayer, turns)
    def makePrimitive(self):
        while True:
            primName = input("Name of STL file: ")
            foundName = False
            for k in range(len(self.primitives)):
                if primName == self.primitives[k].name:
                    print("Error: Name must be unique")
                    foundName = True
                    break
            if not foundName:
                break
        while True:
            axis = input("Select axis for primitive (x or y or z): ")
            if axis in ['x', 'y', 'z']:
                break
            else:
                print("bad input")
        matType = int(hp.getNum("Material Type: "))
        walLocation = hp.getNum("Location of primitivie: ")

        myPrim = primOb(name=primName,
                        matType=matType,
                        xyzPlane=axis,
                        value=walLocation)

        self.primitives.append(myPrim)

        return
def main():
  # STEP 1: Prompt the user for a number between 10 and 20. Assign the user's response to a variable called howMany.    
    howMany = getNum("Please enter a number between 10 and 20", 10, 20, float("inf"), True, "Invalid number.")
    # STEP 2: Call a randomNumbers function, passing the howMany variable as an argument. Assign the result to a variable called list.
    list = randomNumbers(howMany)
    # STEP 7: Prompt the user for a number between 0 and 100. Assign the user's response to a variable called n.
    n = getNum("Please enter a number between 0 and 100", 0, 100, float("inf"), True, "Invalid number.")
     # STEP 8: Call a largerThan function, passing the list and n variables as arguments.
    largerThan(list, n)
Beispiel #5
0
def main():
    currentPlayer = "O"
    board = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
    gameOver = False
    while (not gameOver):
        drawBoard(board)
        currentPlayer = switchPlayer(currentPlayer)
        choice = getNum("Pick a spot:", 1, len(board), float("inf"), True)
        while (board[choice - 1] == "X" or board[choice - 1] == "O"):
            choice = getNum("That spot is taken, try again:", 1, len(board),
                            float("inf"), True)
        board[choice - 1] = currentPlayer
        gameOver = checkWinner(board, currentPlayer)
def getRainfallData():
	result = [] 
	months = ["March", "April", "May", "June"]
	for i in range(len(months)):
		question = "Enter " + months[i] + "'s rainfall total: "
		result.append(getNum(question, 0.0, 100.0))
	return result
Beispiel #7
0
    def setMaterialProps(self):
        hp.clear()
        while True:
            print("Set Material Properties")
            print("1: Number of Materials")
            print("2: Contact Model")
            print("3: Bond Model")
            print("4: Material Properties")
            print("0: Back")

            opt = input("Option to use: ")
            hp.clear()
            if opt == "1":
                self.numMaterials = int(hp.getNum("Number of Materials: "))
                hp.clear()
            elif opt == "2":
                self.contactModel["p2p"] = self.getContactModel()
                hp.clear()
            elif opt == "3":
                self.bondModel = "gran"
                hp.clear()
            elif opt == "4":
                self.getMaterialProps()
                hp.clear()
            elif opt == "0":
                hp.clear()
                return
Beispiel #8
0
def pocketPicker(pocket=0):  # 1, 2           # 5 vvv
    pocket = getNum("",
                    0,
                    36,
                    float("inf"),
                    convertToInt=True,
                    invalidMsg="That is not a Roulette pocket number.")
    if (pocket == 0):  # 3
        print("Pocket", pocket, "is Green.")
    elif (1 <= pocket <= 10):
        if ((pocket % 2) == 0):
            print("Pocket", pocket, "is Black.")
        else:
            print("Pocket", pocket, "is Red.")
    elif (11 <= pocket <= 18):
        if ((pocket % 2) == 0):
            print("Pocket", pocket, "is Red.")
        else:
            print("Pocket", pocket, "is Black.")
    elif (19 <= pocket <= 28):
        if ((pocket % 2) == 0):
            print("Pocket", pocket, "is Black.")
        else:
            print("Pocket", pocket, "is Red.")
    elif (29 <= pocket <= 36):
        if ((pocket % 2) == 0):
            print("Pocket", pocket, "is Red.")
        else:
            print("Pocket", pocket, "is Black.")
    else:
        print(pocket, "is not a valid pocket number.")
Beispiel #9
0
def getRainfallData():
    result = []
    months = ["April", "May", "June", "July"]
    for month in months:
        question = "Enter " + month + "'s rainfall total:"
        result.append(getNum(question, 0.0, 100.0))
    return result
Beispiel #10
0
 def getVelocityOptions(self, fact):
     hp.clear()
     while True:
         print("Velocity Type")
         print("1: Constant")
         opt = input("Select Velocity Type: ")
         hp.clear()
         if opt == '1':
             self.factories[fact].factoryOptions['vel'][0] = 'constant'
             vx = hp.getNum("Velocity in x direction: ")
             vy = hp.getNum("Velocity in y direction: ")
             vz = hp.getNum("Velocity in z direction: ")
             self.factories[fact].factoryOptions['vel'][1] = [vx, vy, vz]
             return
         else:
             print("Bad Input")
     return
Beispiel #11
0
def main():
    board = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
    currentPlayer = "O"
    gameOver = False
    turnCount = 0
    while not gameOver:
        drawBoard(board)
        currentPlayer = switchPlayer(currentPlayer)
        choice = getNum("Pick a box: ", 1, 9, float("inf"), True)
        while board[choice - 1] == "X" or board[choice - 1] == "O":
            choice = getNum("Enter a number: ", 1, 9, float("inf"), True)
        board[choice - 1] = currentPlayer
        gameOver = checkWinner(board, currentPlayer)
        turnCount += 1
        if turnCount == 9 and gameOver != True:
            print('It\'s a tie')
            break
Beispiel #12
0
 def setRunTime(self):
     if self.dt < 0:
         input(
             "You must set the time step before setting the runtime\nPress enter to return."
         )
         return
     simTime = hp.getNum("How long will the simulation run: ")
     simSteps = np.ceil(simTime / self.dt)
     self.numSteps = simSteps
def main():
    currentPlayer = "O"
    board = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
    gameOver = False
    count = 0
    while(not gameOver):
        drawBoard(board)
        currentPlayer = switchPlayer(currentPlayer)
        choice = getNum("Pick a spot:", 1, len(board), float("inf"), True)
        while (board[choice-1] == "X" or board[choice-1] == "O"):
            choice = getNum("That spot is taken, try again:", 1, len(board), float("inf"), True)
        board[choice - 1] = currentPlayer
        count += 1
        gameOver = checkWinner(board,currentPlayer)
        if(count == 9):
            gameOver = True
            drawBoard(board)
            print("It's a tie folks!")
    def updateGeom(self):
        numStlFiles = len(self.stlFiles)
        if numStlFiles == 0:
            print("No Files to Update...")
            return
        while True:
            print("Available STLs to Update:")
            for k in range(len(self.stlFiles)):
                print(str(k + 1) + ": " + self.stlFiles[k].name)
            print("")
            print("0: Go Back")
            opt = input("Option to use: ")
            hp.clear()
            if opt == "0":
                return
            try:
                opt = int(opt)
            except:
                print("Option must be an integer...")
                continue
            if opt > numStlFiles:
                print("Bad Option")
                continue
            break

        oldVal = self.stlFiles[opt - 1].orgScale
        while True:
            scale = hp.getNum("Scaling to use for file (Was " + str(oldVal) +
                              "): ")
            if scale < 0.0:
                print("scale must be greater than 0.0...")
            else:
                break

        oldVal = self.stlFiles[opt - 1].orgMove
        mx = hp.getNum("Move Geom in x (Was " + str(oldVal[0]) + "): ")
        my = hp.getNum("Move Geom in y (Was " + str(oldVal[1]) + "): ")
        mz = hp.getNum("Move Geom in z (Was " + str(oldVal[2]) + "): ")

        oldVal = self.stlFiles[opt - 1].orgRotate
        rx = hp.getNum("Rotate Geom in x (Was " + str(oldVal[0]) + "): ")
        ry = hp.getNum("Rotate Geom in y (Was " + str(oldVal[1]) + "): ")
        rz = hp.getNum("Rotate Geom in z (Was " + str(oldVal[2]) + "): ")
        rv = hp.getNum("Rotate Geom by (Deg) (Was " + str(oldVal[3]) + "): ")

        newSTL = stlOb(name=self.stlFiles[opt - 1].name,
                       stlMesh=self.stlFiles[opt - 1].orgMesh,
                       move=(mx, my, mz),
                       rotate=(rx, ry, rz, rv),
                       scale=scale,
                       fileLocation=self.stlFiles[opt - 1].fileLocation,
                       stlObject=self.stlFiles[opt - 1].stlObject)
        self.stlFiles[opt - 1] = newSTL
        hp.clear()
Beispiel #15
0
 def setAtomStyle(self):
     hp.clear()
     while True:
         print("Select Atom Style From List")
         print("1: Granular")
         print("2: Granular Bond")
         opt = input("Option to use: ")
         if opt == "1":
             self.atomType = "granular"
             self.numBondTypes = -1
             self.maxBondsPerAtom = -1
             # hp.clear()
             break
         elif opt == "2":
             self.numBondTypes = hp.getNum("Number of Bond Types: ")
             self.maxBondsPerAtom = hp.getNum("Max Bonds Per Atom: ")
             self.atomType = "hybrid granular bond/gran"
             # hp.clear()
             break
         else:
             print("Bad Option...")
     hp.clear()
Beispiel #16
0
    def getRollingProps(self, rollMod):
        if rollMod == -1:
            return
        numAtomTypes = self.numMaterials
        rollMod = rollMod[rollMod.find(" "):].strip()

        if len(rollMod) == 0:
            return

        self.rollingProps["coefficientRollingFriction"] = []
        for k1 in range(numAtomTypes):
            for k2 in range(k1, numAtomTypes):
                curStr = "Coef Rolling Friction Between Type %i and %i: " % (
                    k1 + 1, k2 + 1)
                self.rollingProps["coefficientRollingFriction"].append(
                    hp.getNum(curStr))
        if rollMod == "cdt" or rollMod == "epsd2":
            pass
        elif rollMod == "cdt_jkr":
            self.rollingProps["adhesionHysteresis"] = []
            for k1 in range(numAtomTypes):
                for k2 in range(k1, numAtomTypes):
                    curStr = "Coef Adhesion Hysteresis Between Type %i and %i: " % (
                        k1 + 1, k2 + 1)
                    self.rollingProps["adhesionHysteresis"].append(
                        hp.getNum(curStr))
        elif rollMod == "epsd" or rollMod == "epsd3":
            self.rollingProps["coefficientRollingViscousDamping"] = []
            for k1 in range(numAtomTypes):
                for k2 in range(k1, numAtomTypes):
                    curStr = "Coef Rolling Damping Between Type %i and %i: " % (
                        k1 + 1, k2 + 1)
                    self.rollingProps[
                        "coefficientRollingViscousDamping"].append(
                            hp.getNum(curStr))
            if rollMod == "epsd3":
                curStr = "Coef Rolling Stiffness: "
                self.rollingProps["coeffRollingStiffness"] = hp.getNum(curStr)
    def makeSTL(self):
        # Get filename
        fileName = hp.getFileName(['stl', 'STL'], "Path to STL file:")
        while True:
            stlName = input("Name of STL file: ")
            foundName = False
            for k in range(len(self.stlFiles)):
                if stlName == self.stlFiles[k].name:
                    print("Error: Name must be unique")
                    foundName = True
                    break
            if not foundName:
                break

        while True:
            scale = hp.getNum("Scaling to use for file: ")
            if scale < 0.0:
                print("scale must be greater than 0.0...")
            break
        mx = hp.getNum("Move Geom in x: ")
        my = hp.getNum("Move Geom in y: ")
        mz = hp.getNum("Move Geom in z: ")

        rx = hp.getNum("Rotate Geom in x: ")
        ry = hp.getNum("Rotate Geom in y: ")
        rz = hp.getNum("Rotate Geom in z: ")
        rv = hp.getNum("Rotate Geom by (Deg): ")

        matType = int(hp.getNum("Material Type: "))

        if rv == 0:
            rx = 0.0
            ry = 0.0
            rz = 1.0

        self.addSTL(fileName=fileName,
                    scale=scale,
                    move=(mx, my, mz),
                    rotate=(rx, ry, rz, rv),
                    name=stlName,
                    matType=matType)
        hp.clear()
Beispiel #18
0
    def getCohesionProps(self, cohesionMod):
        if cohesionMod == -1:
            return
        numAtomTypes = self.numMaterials
        cohesionMod = cohesionMod[cohesionMod.find(" "):].strip()

        if len(cohesionMod) == 0:
            return

        if cohesionMod == "easo/capillary/viscous" or cohesionMod == "washino/capillary/viscous":
            curStr = "Min Seperation Distance Ratio (Recommended = 1.01): "
            self.cohesionProps["minSeparationDistanceRatio"] = hp.getNum(
                curStr)

            curStr = "Max Seperation Distance Ratio (Recommended = 1.1): "
            self.cohesionProps["maxSeparationDistanceRatio"] = hp.getNum(
                curStr)

            curStr = "Initial Surface Liquid Content (%): "
            self.cohesionProps["surfaceLiquidContentInitial"] = hp.getNum(
                curStr)

            curStr = "Surface Tension (N/m): "
            self.cohesionProps["surfaceTension"] = hp.getNum(curStr)

            curStr = "Fluid Viscosity (Pascal-Second): "
            self.cohesionProps["fluidViscosity"] = hp.getNum(curStr)

            for k in range(numAtomTypes):
                curStr = "Contact Angle Between Type %i and Fluid: " % (k + 1)
                self.cohesionProps["contactAngle"].append(hp.getNum(curStr))

            if cohesionMod == "":
                for k in range(numAtomTypes):
                    curStr = "Max Liquid Content of Type %i (0.0 to turn off): " % (
                        k + 1)
                    self.cohesionProps["maxLiquidContent"].append(
                        hp.getNum(curStr))

        elif cohesionMod == "sjkr" or cohesionMod == "sjkr2":
            for k1 in range(numAtomTypes):
                for k2 in range(k1, numAtomTypes):
                    curStr = "Cohesion Energy Density Between Type %i and %i: " % (
                        k1 + 1, k2 + 1)
                    self.cohesionProps["cohesionEnergyDensity"].append(
                        hp.getNum(curStr))
Beispiel #19
0
 def setSimBoundaries(self):
     hp.clear()
     while True:
         print("Select Boundary Info")
         print("1: Boundary Types")
         print("2: Boundary Size")
         print("3: Gravity")
         print("0: Go Back")
         opt = input("Option to use: ")
         hp.clear()
         if opt == "1":
             print("Boundaries can be (f)ixed or (p)eriodic")
             self.boundaries["x"][2] = getBoundaryType("Boundary Type X: ")
             self.boundaries["y"][2] = getBoundaryType("Boundary Type Y: ")
             self.boundaries["z"][2] = getBoundaryType("Boundary Type Z: ")
             hp.clear()
         elif opt == "2":
             self.boundaries["x"][0] = hp.getNum("Min X Boundary: ")
             self.boundaries["x"][1] = hp.getNum("Max X Boundary: ")
             self.boundaries["y"][0] = hp.getNum("Min Y Boundary: ")
             self.boundaries["y"][1] = hp.getNum("Max Y Boundary: ")
             self.boundaries["z"][0] = hp.getNum("Min Z Boundary: ")
             self.boundaries["z"][1] = hp.getNum("Max Z Boundary: ")
             hp.clear()
         elif opt == "3":
             self.gravity[0] = hp.getNum("Set Gravity Magnitude: ")
             print("Gravity Direction")
             self.gravity[1] = hp.getNum("X - Direction: ")
             self.gravity[2] = hp.getNum("Y - Direction: ")
             self.gravity[3] = hp.getNum("Z - Direction: ")
             hp.clear()
         elif opt == "0":
             hp.clear()
             return
         else:
             print("Bad Input...")
Beispiel #20
0
 def getTargetTypeOptions(self, fact):
     hp.clear()
     while True:
         print("Insertion Types")
         print("1: Volume Fraction")
         opt = input("Select Insertion Type: ")
         hp.clear()
         if opt == '1':
             self.factories[fact].factoryOptions['targetType'][
                 0] = 'volumefraction_region'
             self.factories[fact].factoryOptions['targetType'][
                 1] = hp.getNum("volume fraction target: ")
         else:
             print("Bad Input")
     return
Beispiel #21
0
 def deleteFactory(self):
     numFactories = len(self.factories)
     if numFactories == 0:
         print("You have no factories to delete... Returning")
         return
     hp.clear()
     while True:
         print("Which factory would you like to delete?")
         for k in range(numFactories):
             print("%i: %s" % (k + 1, self.factories[k].name))
         opt = hp.getNum("Factory to delete: ")
         hp.clear()
         if opt < 1 or numFactories < opt:
             print("Bad Input")
         else:
             break
Beispiel #22
0
 def defineTemplate(self):
     hp.clear()
     while True:
         numAtoms = int(hp.getNum("Number of spheres in template: "))
         if numAtoms < 1:
             print("Error: Must have at least one sphere in template")
         else:
             break
     mol = molecule()
     mol.name = input("Name of Particle: ")
     mol.density = hp.getNum("Density of Particle: ")
     mol.type = int(hp.getNum("Material Type of Particle: "))
     for k in range(numAtoms):
         print("Sphere ", k+1)
         x = hp.getNum("x pos: ")
         y = hp.getNum("y pos: ")
         z = hp.getNum("z pos: ")
         r = hp.getNum("Radius of sphere: ")
         mol.atom.append([x,y,z,r])
     self.template.append(mol)
     hp.clear()
Beispiel #23
0
    def getFactoryType(self):
        print("Select Factory Shape")
        print("1: Box")
        print("2: Cylinder")
        opt = input("Option to use: ")
        hp.clear()
        if opt == '1':
            f = factory(input("Factory Name: "))
            f.shape = box_factory()
            f.shape.dimmensions[0] = hp.getNum("Box xMin: ")
            f.shape.dimmensions[1] = hp.getNum("Box xMax: ")
            f.shape.dimmensions[2] = hp.getNum("Box yMin: ")
            f.shape.dimmensions[3] = hp.getNum("Box yMax: ")
            f.shape.dimmensions[4] = hp.getNum("Box zMin: ")
            f.shape.dimmensions[5] = hp.getNum("Box zMax: ")

        elif opt == '2':
            f = factory(input("Factory Name: "))
            f.shape = cylinder_factory()
            while True:
                opt = input("Which axis is the cylinder along: ")
                if not opt in ['x', 'y', 'z']:
                    print(
                        "Bad Option: Cylinder can only be in the x or y or z direction"
                    )
                else:
                    break
            f.shape.axis = opt
            f.shape.x1 = hp.getNum("x1 Position: ")
            f.shape.x2 = hp.getNum("x2 Position: ")
            f.shape.h1 = hp.getNum("Cylinder Start Height: ")
            f.shape.h2 = hp.getNum("Cylinder End Height: ")
            f.shape.radius = hp.getNum("Cylinder Radius: ")
            f.shape.height = hp.getNum("Cylinder Height: ")

        else:
            print("Bad Input")

        self.factories.append(f)

        return
Beispiel #24
0
    def setFactoryOptions(self):
        numFactories = len(self.factories)
        if numFactories == 0:
            print("You have no factories created... Returning")
            return
        hp.clear()
        while True:
            print("Which factory would you like to edit?")
            for k in range(numFactories):
                print("%i: %s" % (k + 1, self.factories[k].name))
            opt = int(hp.getNum("Factory to edit: "))
            hp.clear()
            if opt < 1 or numFactories < opt:
                print("Bad Input")
            else:
                break
        keys = list(self.factories[opt - 1].factoryOptions.keys())
        while True:
            print("Which options would you like to edit?")
            k = 1
            for key in keys:
                print("%i: %s" % (k, key))
                k += 1
            key_opt = int(hp.getNum("Option to edit: "))
            hp.clear()
            if key_opt < 1 or len(keys) < key_opt:
                print("Bad Input")
            else:
                break

        if keys[key_opt - 1] == 'maxattempt':
            self.factories[opt-1].factoryOptions['maxattempt'] = \
            int(hp.getNum("New value for %s (%i) " % ('maxattempt', self.factories[opt-1].factoryOptions['maxattempt'])))
        elif keys[key_opt - 1] == 'insert_every':
            if self.factories[opt -
                              1].factoryOptions['insert_every'] == 'once':
                oldVal = 0
            else:
                oldVal = int(self.factories[opt -
                                            1].factoryOptions['insert_every'])
            newVal = int(
                hp.getNum("New value for %s (%i) " % ('insert_every', oldVal)))
            if newVal == 0:
                self.factories[opt - 1].factoryOptions['insert_every'] = 'once'
            else:
                self.factories[opt -
                               1].factoryOptions['insert_every'] = str(newVal)
        elif keys[key_opt - 1] == 'overlapcheck':
            self.factories[opt-1].factoryOptions['overlapcheck'] = \
            hp.getYesNo("New value for %s (%s) " % ('overlapcheck', self.factories[opt-1].factoryOptions['overlapcheck']))
        elif keys[key_opt - 1] == 'orientation':
            self.getOrientationOptions(opt - 1)
        elif keys[key_opt - 1] == 'all_in':
            self.factories[opt-1].factoryOptions['all_in'] = \
            hp.getYesNo("New value for %s (%s) " % ('all_in', self.factories[opt-1].factoryOptions['all_in']))
        elif keys[key_opt - 1] == 'vel':
            self.getVelocityOptions(opt - 1)
        elif keys[key_opt - 1] == 'targetType':
            self.getTargetTypeOptions(opt - 1)
        elif keys[key_opt - 1] == 'ntry_mc':
            self.factories[opt-1].factoryOptions['ntry_mc'] = \
            int(hp.getNum("New value for %s (%i) " % ('ntry_mc', self.factories[opt-1].factoryOptions['ntry_mc'])))
        elif keys[key_opt - 1] == 'check_dist_from_subdomain_border':
            self.factories[opt-1].factoryOptions['check_dist_from_subdomain_border'] = \
            hp.getYesNo("New value for %s (%s) " % ('check_dist_from_subdomain_border', self.factories[opt-1].factoryOptions['check_dist_from_subdomain_border']))

        return
from helpers import getNum


def shipping_charges(weightofPackage):
    if weightofPackage < 0.1:
        print("Sorry bad input")
    elif weightofPackage <= 2:
        shippingCharges = weightofPackage * 1.50
        print("This is the charges for shipping: $", shippingCharges)
    elif weightofPackage > 2 and weightofPackage <= 6:
        shippingCharges = weightofPackage * 3
        print("This is the charges for shipping: $", shippingCharges)
    elif weightofPackage > 6 and weightofPackage <= 10:
        shippingCharges = weightofPackage * 4
        print("This is the charges for shipping: $", shippingCharges)
    else:
        shippingCharges = weightofPackage * 4.75
        print("This is the charges for shipping: $", shippingCharges)


userWeight = getNum("What is the weight of the package?", 0.1, 150, 3, False,
                    "Invalid weight")
shipping_charges(userWeight)
def main():
  howMany = getNum("Enter a number between 10 and 20: " ,10,20)
  list = randomNumbers(howMany)
  n = getNum("Enter a number between 0 and 100: ",0,100)
  largerThan(list,n)
def main():
    howMany = getNum("How many random numbers?", 10, 20, float("inf"), True)
    list = randomNumber(howMany)
    n = getNum("Enter smallest desired number.", 0, 100, float("inf"), True)
    largerThan(list, n)
Beispiel #28
0
    def getContactProps(self, contactMod):
        if contactMod == -1:
            return
        numAtomTypes = self.numMaterials
        contactMod = contactMod[contactMod.find(" "):].strip()

        if len(contactMod) == 0:
            return

        self.contactProps["youngsModulus"] = []
        for k in range(numAtomTypes):
            curStr = "Contact Young's Modulus for Type %i: " % (k + 1)
            self.contactProps["youngsModulus"].append(hp.getNum(curStr))

        self.contactProps["poissonsRatio"] = []
        for k in range(numAtomTypes):
            curStr = "Contact Poisson's Ratio for Type %i: " % (k + 1)
            self.contactProps["poissonsRatio"].append(hp.getNum(curStr))

        self.contactProps["coefRestitution"] = []
        for k1 in range(numAtomTypes):
            for k2 in range(k1, numAtomTypes):
                curStr = "Coefficient of Restitution Between Types %i and %i: " % (
                    k1 + 1, k2 + 1)
                self.contactProps["coefRestitution"].append(hp.getNum(curStr))

        self.contactProps["coefFriction"] = []
        for k1 in range(numAtomTypes):
            for k2 in range(k1, numAtomTypes):
                curStr = "Coefficient of Friction Between Types %i and %i: " % (
                    k1 + 1, k2 + 1)
                self.contactProps["coefFriction"].append(hp.getNum(curStr))

        if contactMod[:contactMod.find(" ")].strip(
        ) == "hooke" or contactMod[:contactMod.find(" ")].strip(
        ) == "hooke/stiffness":
            curStr = "Characteristic Velocity: "
            self.contactProps["characteristicVelocity"] = hp.getNum(curStr)

        if contactMod[:contactMod.find(" ")].strip(
        ) == "hertz/stiffness" or contactMod[:contactMod.find(" ")].strip(
        ) == "hooke/stiffness":
            self.contactProps["kn"] = []
            self.contactProps["kt"] = []
            self.contactProps["gamman"] = []
            self.contactProps["gammat"] = []
            for k1 in range(numAtomTypes):
                for k2 in range(k1, numAtomTypes):
                    curStr = "Normal Stiffness Between Types %i and %i: " % (
                        k1 + 1, k2 + 1)
                    self.contactProps["kn"].append(hp.getNum(curStr))
            for k1 in range(numAtomTypes):
                for k2 in range(k1, numAtomTypes):
                    curStr = "Tangential Stiffness Between Types %i and %i: " % (
                        k1 + 1, k2 + 1)
                    self.contactProps["kt"].append(hp.getNum(curStr))
            for k1 in range(numAtomTypes):
                for k2 in range(k1, numAtomTypes):
                    curStr = "Normal Damping Between Types %i and %i: " % (
                        k1 + 1, k2 + 1)
                    self.contactProps["gamman"].append(hp.getNum(curStr))
            for k1 in range(numAtomTypes):
                for k2 in range(k1, numAtomTypes):
                    curStr = "Tangential Damping Between Types %i and %i: " % (
                        k1 + 1, k2 + 1)
                    self.contactProps["gammat"].append(hp.getNum(curStr))

        if contactMod[:contactMod.find(" ")].strip() == 'jkr':
            self.contactProps["coefAdhesion"] = []
            for k1 in range(numAtomTypes):
                for k2 in range(k1, numAtomTypes):
                    curStr = "Coefficient of Adhesion Between Types %i and %i: " % (
                        k1 + 1, k2 + 1)
                    self.contactProps["coefAdhesion"].append(hp.getNum(curStr))
            self.contactProps["jkrResolution"] = hp.getNum(
                "Reselution in JKR interpolation table (1.0e-4): ")
Beispiel #29
0
    def timeStep(self, sp, ap):
        # Get atom props
        numTemplates = len(ap.template)
        minR = None
        minDensity = None
        for k in range(numTemplates):
            curTemp = ap.template[k]
            curDensity = curTemp.density
            if minDensity is None or curDensity < minDensity:
                minDensity = curDensity
            for atom in curTemp.atom:
                curR = atom[-1]
                if minR is None or curR < minR:
                    minR = curR
        # Get material properties
        maxY = None
        maxG = None
        maxP = None
        for k in range(sp.numMaterials):
            Y = sp.contactProps['youngsModulus'][k]
            if maxY is None or Y > maxY:
                maxY = Y
            P = sp.contactProps['poissonsRatio'][k]
            if maxP is None or P > maxP:
                maxP = P
            G = Y / (2.0 * (1.0 + P))
            if maxG is None or G > maxG:
                maxG = G

        # Calculate Rayleigh Time
        dt_ray = np.pi * minR * np.sqrt(
            minDensity / maxG) / (0.1631 * maxP + 0.8766)
        self.dt_ray = dt_ray

        while True:
            print("Set time step of simulation")
            print("Rayleigh Time:", dt_ray)
            print("1: Set time step")
            print("2: Set percentage of rayleigh time")
            print("0: Go Back")
            opt = input("Option to use: ")
            hp.clear()
            if opt == "2":
                while True:
                    per = hp.getNum("Percentage of Rayleigh Time: ")
                    if 0.0 < per and per < 1.0:
                        self.dt = per * dt_ray
                        return
                    else:
                        print("The value entered must be between 0.0 and 1.0")
            elif opt == "1":
                while True:
                    dt = hp.getNum("Set Time Step: ")
                    if dt > 0.0:
                        self.dt = dt
                        return
                    else:
                        print("The timestep must be greater than 0")
            elif opt == "0":
                return
            else:
                hp.clear()
                print("Bad Input")
        return
Beispiel #30
0
    def setParticleDistribution(self, atomProps):
        if len(atomProps.template) == 0:
            print("No Atoms Defined: You must create atom templates first...")
            return
        if len(self.factories) == 0:
            print("No factories built yet...")
            return
        numFactories = len(self.factories)
        while True:
            print(
                "Which factory would you like to set particle distribution for?"
            )
            for k in range(numFactories):
                print("%i: %s" % (k + 1, self.factories[k].name))
            opt = int(hp.getNum("Factory to edit: "))
            hp.clear()
            if opt < 1 or numFactories < opt:
                print("Bad Input")
            else:
                break
        factOpt = opt
        while True:
            print("Set Particle Probabilities")
            print("1: Manually")
            print("2: By Distribution")
            opt = input(" Select Type: ")
            hp.clear()
            if opt == '1':
                insertPers = list()
                sumPers = 0.0
                for k in range(len(atomProps.template)):
                    while True:
                        curStr = "Percentage for atom %s:" % (
                            atomProps.template[k].name)
                        per = hp.getNum(curStr)
                        if per < 0 or 1 < per:
                            print("Atom Percentage must be between 0 and 1")
                        else:
                            sumPers += per
                            insertPers.append(per)
                            break
                for per in insertPers:
                    per /= sumPers

                self.factories[factOpt - 1].atom_distribution = insertPers

                return
            elif opt == '2':
                input(
                    "This is not currently available... Press enter to return:"
                )
                return
                for k in range(len(atomProps.template)):
                    while True:
                        print("Choose Distribution")
                        print("1: Guassian")
                        print("2: Uniform")
                        opt = input("Select Type: ")
                        hp.clear
                        if opt == '1':
                            return
                        elif opt == '2':
                            return
                        else:
                            print("Bad Input")
                    return
            else:
                print("Bad Input")