def graphFuncdDeck(L, Q, qArch, segs, H, anchOffProp, funcName, func): mn = 0. mx = 700. steps = 50 inc = (mx - mn)/steps d = mn ds = [] results = [] for i in range(steps): deck = fd.parabolicDeck(L, d) deckLen = sum(fd.getDeckLengths(deck, L, segs)) q = Q / deckLen anchOff = anchOffProp * d bridge = fd.fromDeck(deck, L, anchOff, H, q, qArch, segs) ds.append(d) results.append(func(bridge)) d += inc plt.plot(ds, results) plt.xlabel("Deck depth (d_deck) " + units['l']) plt.ylabel(funcName[0] + " " + funcName[1]) plt.title(funcName[0] + " as a function of d_deck") plt.show()
def graphFuncSegs(deck, L, q, qArch, H, anchOff, funcName, func): mn = 3 mx = 100 steps = 50 inc = (mx - mn)/steps segs = mn segss = [] results = [] for i in range(steps): bridge = fd.fromDeck(deck, L, anchOff, H, q, qArch, segs) segss.append(segs) results.append(func(bridge)) segs += inc plt.plot(segss, results) plt.xlabel("Number of segments") plt.ylabel(funcName[0] + " " + funcName[1]) plt.title(funcName[0] + " as a function of number of segments") plt.show()
def graphFuncAO(deck, L, q, qArch, segs, H, funcName, func): minAO = -90. maxAO = 400. steps = 50 inc = (maxAO - minAO)/steps anchOff = minAO anchOffs = [] results = [] for i in range(steps): bridge = fd.fromDeck(deck, L, anchOff, H, q, qArch, segs) anchOffs.append(anchOff) results.append(func(bridge)) anchOff += inc plt.plot(anchOffs, results) plt.xlabel("anchor offset " + units['l']) plt.ylabel(funcName[0] + " " + funcName[1]) plt.title(funcName[0] + " as a function of anchor offset") plt.show()
def graphFuncqArch(deck, L, q, segs, H, anchOff, funcName, func): mn = 0.01 mx = 0.25 steps = 50 inc = (mx - mn)/steps qArch = mn qs = [] results = [] for i in range(steps): bridge = fd.fromDeck(deck, L, anchOff, H, q, qArch, segs) qs.append(qArch) results.append(func(bridge)) qArch += inc plt.plot(qs, results) plt.xlabel("Self-weight of arch (q_arch) " + units['fpl']) plt.ylabel(funcName[0] + " " + funcName[1]) plt.title(funcName[0] + " as a function of q_arch") plt.show()
def graphFuncH(deck, L, q, qArch, segs, anchOff, funcName, func): minH = 5. maxH = 55. steps = 50 inc = (maxH - minH)/steps H = minH Hs = [] results = [] for i in range(steps): bridge = fd.fromDeck(deck, L, anchOff, H, q, qArch, segs) Hs.append(H) results.append(func(bridge)) H += inc plt.plot(Hs, results) plt.xlabel("horizontal force (H) " + units['f']) plt.ylabel(funcName[0] + " " + funcName[1]) plt.title(funcName[0] + " as a function of H") plt.show()
def graphFuncq(deck, L, qArch, segs, H, anchOff, funcName, func): mn = 0.05 mx = 0.55 steps = 50 inc = (mx - mn)/steps q = mn qs = [] results = [] for i in range(steps): bridge = fd.fromDeck(deck, L, anchOff, H, q, qArch, segs) qs.append(q) results.append(func(bridge)) q += inc plt.plot(qs, results) plt.xlabel("Load on deck (q) " + units['fpl']) plt.ylabel(funcName[0] + " " + funcName[1]) plt.title(funcName[0] + " as a function of q") plt.show()
def graphFunchDeck(L, d, q, qArch, segs, H, anchOff, funcName, func): mn = 0. mx = 500. steps = 50 inc = (mx - mn)/steps h = mn hs = [] results = [] for i in range(steps): deck = fd.parabolicDeck(L, d, h) bridge = fd.fromDeck(deck, L, anchOff, H, q, qArch, segs) hs.append(h) results.append(func(bridge)) h += inc plt.plot(hs, results) plt.xlabel("Deck height (h_deck) " + units['l']) plt.ylabel(funcName[0] + " " + funcName[1]) plt.title(funcName[0] + " as a function of h_deck") plt.show()
def optGlob(deck, L, q, qArch, segs, func, isArch=None, H=None, anchOff=None): try: step = 10. if H == None: if isArch: startHmin = 0. startHmax = q * 10000 else: startHmin = -q * 10000 startHmax = 0. minB = None minBVal = float('inf') minBH = None Hmin = startHmin Hmax = startHmax while step > 0.001: H = Hmin + step while H < Hmax: b = fromdeck.fromDeck(deck, L, anchOff, H, q, qArch, segs) if func(b) < minBVal: minBVal = func(b) minB = b minBH = H H += step Hmin = max(minBH - step, Hmin) Hmax = min(minBH + step, Hmax) step /= 10. if minBH <= startHmin + step * 10. \ or minBH >= startHmax - step * 10: print minBH print 'Exceeded Limit' return elif anchOff == None: dDeck = fromdeck.getDeckDepth(deck, L) startAOmin = -dDeck * 2 startAOmax = dDeck * 2 minB = None minBVal = float('inf') minBAO = None AOmin = startAOmin AOmax = startAOmax while step > 0.001: AO = AOmin + step while AO < AOmax: b = fromdeck.fromDeck(deck, L, AO, H, q, qArch, segs) if func(b) < minBVal: minBVal = func(b) minB = b minBAO = AO AO += step AOmin = max(minBAO - step, AOmin) AOmax = min(minBAO + step, AOmax) step /= 10. if minBAO <= startAOmin + step*10. \ or minBAO >= startAOmax - step*10: print minBAO print 'Exceeded Limit' return return minB except Exception as e: print e
def main(): # enter deck related attributes deckType = getString("Enter deck specification method", "parabolic", ["parabolic", "sinusoidal", "custom"]) objects = None if deckType == "parabolic": L = getReal("Enter deck length (L)", minimum=0.0001) d = getReal("Enter deck depth (d_deck)", minimum=0.) h = getReal("Enter deck height (h_deck)", 0.) deck = fd.parabolicDeck(L, d, h) segs = getInteger("Enter number of segments to approximate arch", minimum=2) elif deckType == "sinusoidal": L = getReal("Enter deck length (L)", minimum=0.0001) A = getReal("Enter deck amplitude (A)", minimum=0.) lmda = getReal("Enter deck wavelength (lambda)", L, minimum=0.0001) phi = getReal("Enter deck phase (phi)", 0., 0., 2 * math.pi) h = getReal("Enter deck height (h_deck)", 0.) deck = fd.sineDeck(L, A, lmda, phi, h) segs = getInteger("Enter number of segments to approximate arch", minimum=2) else: objects = rs.GetObjects("Select deck curve(s)", preselect=True, minimum_count=1) isValid = False for o in objects: end = rs.CurveEndPoint(o) start = rs.CurveStartPoint(o) if end.X < -0.0001 or start.X < -0.0001: isValid = False break elif abs(end.X) <= 0.0001: if abs(end.Y <= 0.0001) and abs(end.Z <= 0.0001): isValid = True break elif abs(start.X) <= 0.0001: if abs(start.Y <= 0.0001) and abs(start.Z <= 0.0001): isValid = True break if isValid == False: print "Deck must start at origin" exit() if len(objects) == 1: o = objects[0] deck = lambda x: rhinosgsm.ptToVect( rs.EvaluateCurve(o, rs.CurveClosestPoint(o, [x, 0., 0.]))) L = rs.CurveEndPoint(o).X - rs.CurveStartPoint(o).X segs = getInteger("Enter number of segments to approximate arch", minimum=2) else: deck = [rhinosgsm.ptToVect(rs.CurveStartPoint(objects[0]))] for o in objects: deck.append(rhinosgsm.ptToVect(rs.CurveEndPoint(o))) xEnd = lambda o: max( rs.CurveStartPoint(o).X, rs.CurveEndPoint(o).X) L = max(map(xEnd, objects)) segs = None # enter loads q = getReal("Enter load on deck (q)", minimum=0.0001) qArch = getReal("Enter self-weight of arch (q_arch)", minimum=0.0001) # choose whether or not to optimize isOpt = getString("Do you want to use an optimization function?", "yes", ["yes", "no"]) # produce optimized form if isOpt == "yes": var = getString("Enter the variable you want to change", strings=["H", "anchorOffset"]) if var == "H": sign = getString("Enter the sign of H", "positive", strings=["positive", "negative"]) if sign == "positive": isArch = True else: isArch = False anchOff = getReal("Enter anchor offset", 0.) H = None else: H = 0. while not H != 0.: H = getReal("Enter horizontal force (H)") if not H != 0.: print "H may not equal 0.0" anchOff = None isArch = None optParam = rs.ListBox(opt.optList(var == "H", var == "anchorOffset"), "Select optimization parameter", "Optimization Parameters") if optParam == "select arch height": hArch = getReal("Enter arch height", minimum=0.0001) else: hArch = None func = opt.optFunc(optParam, q, qArch, h=hArch) bridge = opt.optGlob(deck, L, q, qArch, segs, func, isArch, H, anchOff) if H == None: print "H =", bridge.getH() else: print "anchor offset =", bridge.getAnchOff() # produce non-optimized form else: H = 0. while not H != 0.: H = getReal("Enter horizontal force (H)") if not H != 0.: print "H may not equal 0.0" anchOff = getReal("Enter anchor offset", 0.) bridge = fd.fromDeck(deck, L, anchOff, H, q, qArch, segs) if segs == None: segs = len(objects) # draw bridge cables = getInteger("Enter number of cables to draw", segs - 1, 1, segs - 1) if objects != None: rs.DeleteObjects(objects) rhinobridge.drawBridge(bridge, cables)