import math, csv, sys, time, os, glob, copy from multiprocessing import Process, Pipe from math import sqrt from random import randint from itertools import repeat import argparse MPH_PER_MPS = 2.2369362920544 DEG_PER_ROTATION = 360 SEC_PER_MINUTE = 60 RPM_TO_DEGPERSEC = DEG_PER_ROTATION/SEC_PER_MINUTE FT_PER_METER = 3.280824 #Feet in a Meter PI = math.acos(-1) parser = argparse.ArgumentParser(description='Save our windmills by saving our birds.') parser.add_argument('--inputFileName', default='Variables.csv', help='Indentifies the input parameters file name (usually a .csv file)') parser.add_argument('--outputDirectoryName', default="Diagnostics",help='Indentifies the directory where the output is to be written (usually multiple files and a summary .csv file)') commandLineArguments = vars(parser.parse_args()) print "Input File Name = ", commandLineArguments['inputFileName'] print "OutputDirectory = ", commandLineArguments['outputDirectoryName'] def DetermineInputFileName(): return os.path.abspath(commandLineArguments['inputFileName']) def OutputDirectoryPath(): if commandLineArguments['outputDirectoryName'] == None: inputFileName = DetermineInputFileName() elements = os.path.split(inputFileName) return elements[0] else: inputFileName = DetermineInputFileName() elements = os.path.split(inputFileName) return os.path.join(elements[0],commandLineArguments['outputDirectoryName']) def fullOutputFileName( stemName, shortName ): outputDirectory = OutputDirectoryPath() if not os.path.exists(os.path.join(outputDirectory, stemName)): os.makedirs(os.path.join(outputDirectory, stemName)) print os.path.join(outputDirectory, stemName), "created" return os.path.join(outputDirectory, stemName, shortName) DATE = time.strftime("%d.%B.%Y.at.%I.%M.%S(%p)") FLDR = fullOutputFileName("TestsOn."+DATE, "") #BUILDBEFOREMULTIPROCESS if not os.path.exists(OutputDirectoryPath()): os.makedirs(OutputDirectoryPath()) Neighbors = os.path.split(sys.argv[0])[0] #Reading A CSV File To Get Inputs print DetermineInputFileName() InFile = open(DetermineInputFileName(),'r') Info = csv.reader(InFile,delimiter=',',skipinitialspace=True) Cnsts = {} for line in Info: if line: print line Key = line[0] Length = len(line) if Length>2: Value = [] for pt in range(1,Length): ref = pt-1 Value.append(float(line[pt])) Cnsts[Key] = Value else: Value = line[1] try: Value = float(Value) except: Value = line[1] Cnsts[Key] = Value InFile.close() # Uncomment to Print List of Inputs # Alph = Cnsts.copy() # for x in sorted(Alph): # print x,"-\t",Alph.get(x) #Keys: Cnsts[Key] #BldSpdInt(RPM) BldThck(%c) BrdLngth(m) BrdLngthRng(m) #BrdName(str) BrdSpdInt(mps) BrdWdth(m) BrdWdthRng(m) #ChrdLngth(m) DegStepSize(deg) HighBldSpd(RPM) HighBrdSpd(mps) #LowBldSpd(RPM) LowBrdSpd(mps) NumOfBirds(#) NumOfBlds(#) #RotorDia(m) ThckLoc(%c) if str(type(Cnsts["DegStepSize"])) == "": Cnsts["DegStepSize"] = [Cnsts["DegStepSize"]] Cnsts["NumOfBirds"] = [Cnsts["NumOfBirds"]] if len(Cnsts["DegStepSize"]) != len(Cnsts["NumOfBirds"]): print "UnBalanced Test Conditions, Must Provide a Number of Birds and Degree Step Size" else: NumOfTests = len(Cnsts["DegStepSize"])*(1+int(Cnsts["Wiggle"])) Meters = ["m","M","meters","Meters","METERS"] Feet = ["ft","Ft","FT","feet","Feet","FEET"] Inches = ["in.","In.","IN","inches","Inches","INCHES","inch","Inch","INCH"] Mps = ["MPS","Mps","mps","m/s","M/S","Meters/Sec","meters/sec","Meters/Second","meters/second"] Mph = ["MPH","Mph","mph","m/hr","M/HR","Miles/Hour","miles/hour","Miles/Hr","miles/hr"] Fps = ["FPS","Fps","fps","ft/s","f/s","FT/S","F/S","Feet/Sec","Ft/Sec","feet/sec","ft/sec", "Feet/Second","Ft/Second","feet/second","ft/second",] RPM = ["RPM","rpm","Rot/S","rot/s","Rot/Sec","Rot/Second","rot/sec","ROT/SECOND","rot/second"] Chrd = ["%c","%C","%ofC","% of C","%ofc","% of c","%ofChord","%ofchord", "% of Chord","% of chord","%Chord","%chord","%CHORD","%OFCHORD"] BrdWdth = [[]for b in range(3)] BrdLngth = [[]for b in range(3)] BrdWdthft = [[]for b in range(3)] BrdLngthft = [[]for b in range(3)] untchck = 0 for x in range(len(Meters)): if Cnsts["BrdSzeUnit"] == Meters[x]: for size in range(len(Cnsts["BrdWdth"])): BrdWdth[size] = Cnsts["BrdWdth"][size] BrdLngth[size] = Cnsts["BrdLngth"][size] BrdWdthft[size] = FT_PER_METER* BrdWdth[size] BrdLngthft[size] = FT_PER_METER* BrdLngth[size] untchck += 1 if Cnsts["BldSzeUnit"] == Meters[x]: ChrdLngthM = Cnsts["ChrdLngth"] RotorDiaM = Cnsts["RotorDia"] HubDiaM = Cnsts["HubDia"] untchck +=1 for x in range(len(Inches)): if Cnsts["BrdSzeUnit"] == Inches[x]: for size in range(len(Cnsts["BrdWdth"])): BrdWdthft[size] = Cnsts["BrdWdth"][size]/12 BrdLngthft[size] = Cnsts["BrdLngth"][size]/12 BrdWdth[size] = BrdWdthft[size]/(12*FT_PER_METER) BrdLngth[size] = BrdLngthft[size]/(12*FT_PER_METER) untchck += 1 if Cnsts["BldSzeUnit"] == Inches[x]: ChrdLngthM = Cnsts["ChrdLngth"]/(12*FT_PER_METER) RotorDiaM = Cnsts["RotorDia"] /(12*FT_PER_METER) HubDiaM = Cnsts["HubDia"] /(12*FT_PER_METER) untchck +=1 for x in range(len(Feet)): if Cnsts["BrdSzeUnit"] == Feet[x]: for size in range(len(Cnsts["BrdWdth"])): BrdWdthft[size] = Cnsts["BrdWdth"][size] BrdLngthft[size] = Cnsts["BrdLngth"][size] BrdWdth[size] = BrdWdthft[size]/FT_PER_METER BrdLngth[size] = BrdLngthft[size]/FT_PER_METER untchck += 1 if Cnsts["BldSzeUnit"] == Feet[x]: ChrdLngthM = Cnsts["ChrdLngth"]/FT_PER_METER RotorDiaM = Cnsts["RotorDia"] /FT_PER_METER HubDiaM = Cnsts["HubDia"] /FT_PER_METER untchck +=1 for x in range(len(Mps)): if Cnsts["BrdSpdUnit"] == Mps[x]: LowBrdSpdMPS = Cnsts["LowBrdSpd"] HighBrdSpdMPS = Cnsts["HighBrdSpd"] BrdSpdIntMPS = Cnsts["BrdSpdInt"] untchck +=1 if Cnsts["BldSpdUnit"] == Mps[x]: Circum = PI*RotorDiaM HighBldSpdRPM = 60*Cnsts["HighBldSpd"]/Circum LowBldSpdRPM = 60*Cnsts["LowBldSpd"]/Circum BldSpdIntRPM = 60*Cnsts["BldSpdInt"]/Circum untchck +=1 for x in range(len(Mph)): if Cnsts["BrdSpdUnit"] == Mph[x]: LowBrdSpdMPS = Cnsts["LowBrdSpd"] / MPH_PER_MPS HighBrdSpdMPS = Cnsts["HighBrdSpd"] / MPH_PER_MPS BrdSpdIntMPS = Cnsts["BrdSpdInt"] / MPH_PER_MPS untchck +=1 if Cnsts["BldSpdUnit"] == Mph[x]: Circum = PI*RotorDiaM #should be in meters HighBldSpdRPM = 60*Cnsts["HighBldSpd"]/(MPH_PER_MPS*Circum) LowBldSpdRPM = 60*Cnsts["LowBldSpd"] /(MPH_PER_MPS*Circum) BldSpdIntRPM = 60*Cnsts["BldSpdInt"] /(MPH_PER_MPS*Circum) untchck +=1 for x in range(len(Fps)): if Cnsts["BrdSpdUnit"] == Fps[x]: LowBrdSpdMPS = Cnsts["LowBrdSpd"] / FT_PER_METER HighBrdSpdMPS = Cnsts["HighBrdSpd"] / FT_PER_METER BrdSpdIntMPS = Cnsts["BrdSpdInt"] / FT_PER_METER untchck +=1 if Cnsts["BldSpdUnit"] == Fps[x]: Circum = PI*RotorDiaM #should be in meters HighBldSpdRPM = 60*Cnsts["HighBldSpd"]/(FT_PER_METER*Circum) LowBldSpdRPM = 60*Cnsts["LowBldSpd"] /(FT_PER_METER*Circum) BldSpdIntRPM = 60*Cnsts["BldSpdInt"] /(FT_PER_METER*Circum) untchck +=1 for x in range(len(RPM)): if Cnsts["BldSpdUnit"] == RPM[x]: HighBldSpdRPM = Cnsts["HighBldSpd"] LowBldSpdRPM = Cnsts["LowBldSpd"] BldSpdIntRPM = Cnsts["BldSpdInt"] untchck +=1 for x in range(len(Chrd)): if Cnsts["ThcknssUnit"] == Chrd[x]: BldThckPerc = Cnsts["BldThck"] ThckLocPerc = Cnsts["ThckLoc"] untchck +=1 for x in range(len(Meters)): if Cnsts["ThcknssUnit"] == Meters[x]: BldThckPerc = Cnsts["BldThck"]/ChrdLngthM ThckLocPerc = Cnsts["ThckLoc"]/ChrdLngthM untchck +=1 for x in range(len(Inches)): if Cnsts["ThcknssUnit"] == Inches[x]: BldThckPerc = Cnsts["BldThck"]/(12*FT_PER_METER*ChrdLngthM) ThckLocPerc = Cnsts["ThckLoc"]/(12*FT_PER_METER*ChrdLngthM) untchck +=1 for x in range(len(Feet)): if Cnsts["ThcknssUnit"] == Feet[x]: BldThckPerc = Cnsts["BldThck"]/(FT_PER_METER*ChrdLngthM) ThckLocPerc = Cnsts["ThckLoc"]/(FT_PER_METER*ChrdLngthM) untchck +=1 if untchck != 5: print "INCORRECT UNIT SYNTAX, ",untchck," unit checks" #Reading A CSV File To Get Inputs print DetermineInputFileName() InFile = open(DetermineInputFileName(),'r') Info = csv.reader(InFile,delimiter=',',skipinitialspace=True) Cnsts = {} for line in Info: if line: print line Key = line[0] Length = len(line) if Length>2: Value = [] for pt in range(1,Length): ref = pt-1 Value.append(float(line[pt])) Cnsts[Key] = Value else: Value = line[1] try: Value = float(Value) except: Value = line[1] Cnsts[Key] = Value InFile.close() # Uncomment to Print List of Inputs # Alph = Cnsts.copy() # for x in sorted(Alph): # print x,"-\t",Alph.get(x) #Keys: Cnsts[Key] #BldSpdInt(RPM) BldThck(%c) BrdLngth(m) BrdLngthRng(m) #BrdName(str) BrdSpdInt(mps) BrdWdth(m) BrdWdthRng(m) #ChrdLngth(m) DegStepSize(deg) HighBldSpd(RPM) HighBrdSpd(mps) #LowBldSpd(RPM) LowBrdSpd(mps) NumOfBirds(#) NumOfBlds(#) #RotorDia(m) ThckLoc(%c) if str(type(Cnsts["DegStepSize"])) == "": Cnsts["DegStepSize"] = [Cnsts["DegStepSize"]] Cnsts["NumOfBirds"] = [Cnsts["NumOfBirds"]] if len(Cnsts["DegStepSize"]) != len(Cnsts["NumOfBirds"]): print "UnBalanced Test Conditions, Must Provide a Number of Birds and Degree Step Size" else: NumOfTests = len(Cnsts["DegStepSize"])*(1+int(Cnsts["Wiggle"])) Meters = ["m","M","meters","Meters","METERS"] Feet = ["ft","Ft","FT","feet","Feet","FEET"] Inches = ["in.","In.","IN","inches","Inches","INCHES","inch","Inch","INCH"] Mps = ["MPS","Mps","mps","m/s","M/S","Meters/Sec","meters/sec","Meters/Second","meters/second"] Mph = ["MPH","Mph","mph","m/hr","M/HR","Miles/Hour","miles/hour","Miles/Hr","miles/hr"] Fps = ["FPS","Fps","fps","ft/s","f/s","FT/S","F/S","Feet/Sec","Ft/Sec","feet/sec","ft/sec", "Feet/Second","Ft/Second","feet/second","ft/second",] RPM = ["RPM","rpm","Rot/S","rot/s","Rot/Sec","Rot/Second","rot/sec","ROT/SECOND","rot/second"] Chrd = ["%c","%C","%ofC","% of C","%ofc","% of c","%ofChord","%ofchord", "% of Chord","% of chord","%Chord","%chord","%CHORD","%OFCHORD"] BrdWdth = [[]for b in range(3)] BrdLngth = [[]for b in range(3)] BrdWdthft = [[]for b in range(3)] BrdLngthft = [[]for b in range(3)] untchck = 0 for x in range(len(Meters)): if Cnsts["BrdSzeUnit"] == Meters[x]: for size in range(len(Cnsts["BrdWdth"])): BrdWdth[size] = Cnsts["BrdWdth"][size] BrdLngth[size] = Cnsts["BrdLngth"][size] BrdWdthft[size] = FT_PER_METER* BrdWdth[size] BrdLngthft[size] = FT_PER_METER* BrdLngth[size] untchck += 1 if Cnsts["BldSzeUnit"] == Meters[x]: ChrdLngthM = Cnsts["ChrdLngth"] RotorDiaM = Cnsts["RotorDia"] HubDiaM = Cnsts["HubDia"] untchck +=1 for x in range(len(Inches)): if Cnsts["BrdSzeUnit"] == Inches[x]: for size in range(len(Cnsts["BrdWdth"])): BrdWdthft[size] = Cnsts["BrdWdth"][size]/12 BrdLngthft[size] = Cnsts["BrdLngth"][size]/12 BrdWdth[size] = BrdWdthft[size]/(12*FT_PER_METER) BrdLngth[size] = BrdLngthft[size]/(12*FT_PER_METER) untchck += 1 if Cnsts["BldSzeUnit"] == Inches[x]: ChrdLngthM = Cnsts["ChrdLngth"]/(12*FT_PER_METER) RotorDiaM = Cnsts["RotorDia"] /(12*FT_PER_METER) HubDiaM = Cnsts["HubDia"] /(12*FT_PER_METER) untchck +=1 for x in range(len(Feet)): if Cnsts["BrdSzeUnit"] == Feet[x]: for size in range(len(Cnsts["BrdWdth"])): BrdWdthft[size] = Cnsts["BrdWdth"][size] BrdLngthft[size] = Cnsts["BrdLngth"][size] BrdWdth[size] = BrdWdthft[size]/FT_PER_METER BrdLngth[size] = BrdLngthft[size]/FT_PER_METER untchck += 1 if Cnsts["BldSzeUnit"] == Feet[x]: ChrdLngthM = Cnsts["ChrdLngth"]/FT_PER_METER RotorDiaM = Cnsts["RotorDia"] /FT_PER_METER HubDiaM = Cnsts["HubDia"] /FT_PER_METER untchck +=1 for x in range(len(Mps)): if Cnsts["BrdSpdUnit"] == Mps[x]: LowBrdSpdMPS = Cnsts["LowBrdSpd"] HighBrdSpdMPS = Cnsts["HighBrdSpd"] BrdSpdIntMPS = Cnsts["BrdSpdInt"] untchck +=1 if Cnsts["BldSpdUnit"] == Mps[x]: Circum = PI*RotorDiaM HighBldSpdRPM = 60*Cnsts["HighBldSpd"]/Circum LowBldSpdRPM = 60*Cnsts["LowBldSpd"]/Circum BldSpdIntRPM = 60*Cnsts["BldSpdInt"]/Circum untchck +=1 for x in range(len(Mph)): if Cnsts["BrdSpdUnit"] == Mph[x]: LowBrdSpdMPS = Cnsts["LowBrdSpd"] / MPH_PER_MPS HighBrdSpdMPS = Cnsts["HighBrdSpd"] / MPH_PER_MPS BrdSpdIntMPS = Cnsts["BrdSpdInt"] / MPH_PER_MPS untchck +=1 if Cnsts["BldSpdUnit"] == Mph[x]: Circum = PI*RotorDiaM #should be in meters HighBldSpdRPM = 60*Cnsts["HighBldSpd"]/(MPH_PER_MPS*Circum) LowBldSpdRPM = 60*Cnsts["LowBldSpd"] /(MPH_PER_MPS*Circum) BldSpdIntRPM = 60*Cnsts["BldSpdInt"] /(MPH_PER_MPS*Circum) untchck +=1 for x in range(len(Fps)): if Cnsts["BrdSpdUnit"] == Fps[x]: LowBrdSpdMPS = Cnsts["LowBrdSpd"] / FT_PER_METER HighBrdSpdMPS = Cnsts["HighBrdSpd"] / FT_PER_METER BrdSpdIntMPS = Cnsts["BrdSpdInt"] / FT_PER_METER untchck +=1 if Cnsts["BldSpdUnit"] == Fps[x]: Circum = PI*RotorDiaM #should be in meters HighBldSpdRPM = 60*Cnsts["HighBldSpd"]/(FT_PER_METER*Circum) LowBldSpdRPM = 60*Cnsts["LowBldSpd"] /(FT_PER_METER*Circum) BldSpdIntRPM = 60*Cnsts["BldSpdInt"] /(FT_PER_METER*Circum) untchck +=1 for x in range(len(RPM)): if Cnsts["BldSpdUnit"] == RPM[x]: HighBldSpdRPM = Cnsts["HighBldSpd"] LowBldSpdRPM = Cnsts["LowBldSpd"] BldSpdIntRPM = Cnsts["BldSpdInt"] untchck +=1 for x in range(len(Chrd)): if Cnsts["ThcknssUnit"] == Chrd[x]: BldThckPerc = Cnsts["BldThck"] ThckLocPerc = Cnsts["ThckLoc"] untchck +=1 for x in range(len(Meters)): if Cnsts["ThcknssUnit"] == Meters[x]: BldThckPerc = Cnsts["BldThck"]/ChrdLngthM ThckLocPerc = Cnsts["ThckLoc"]/ChrdLngthM untchck +=1 for x in range(len(Inches)): if Cnsts["ThcknssUnit"] == Inches[x]: BldThckPerc = Cnsts["BldThck"]/(12*FT_PER_METER*ChrdLngthM) ThckLocPerc = Cnsts["ThckLoc"]/(12*FT_PER_METER*ChrdLngthM) untchck +=1 for x in range(len(Feet)): if Cnsts["ThcknssUnit"] == Feet[x]: BldThckPerc = Cnsts["BldThck"]/(FT_PER_METER*ChrdLngthM) ThckLocPerc = Cnsts["ThckLoc"]/(FT_PER_METER*ChrdLngthM) untchck +=1 if untchck != 5: print "INCORRECT UNIT SYNTAX, ",untchck," unit checks" def Outline(): global bldspdrange, brdspdrange, BirdSizes, CountA, CountB, DPM, DPMDICT, DPMSet bldspdrange = [] brdspdrange = [] DPMDICT = {} DPM = [] BirdSizes = len(Cnsts["BrdLngth"]) COUNT = 0 CountA = int(1+((HighBldSpdRPM-LowBldSpdRPM)/BldSpdIntRPM)) CountB = int(1+((HighBrdSpdMPS-LowBrdSpdMPS)/BrdSpdIntMPS)) for i in range(CountA): bldspdrange.append(RPM_TO_DEGPERSEC \ *(LowBldSpdRPM+i*BldSpdIntRPM)) #in Deg/Sec for i in range(CountB): brdspdrange.append(LowBrdSpdMPS+i*BrdSpdIntMPS) #in mps print "\nBird Speed Range:",brdspdrange,"Meters/Second" print "Blade Speed Range:",bldspdrange,"Degrees/Second" print "\nTesting:",CountA,"Blade Speeds, and",CountB,"Bird Speeds" for test in range(len(Cnsts["DegStepSize"])): #Different Resolutions CountC = int(1+((360/Cnsts["NumOfBlds"])/Cnsts["DegStepSize"][test])) CountD = int(1+Cnsts["NumOfBirds"][test]) COUNT = COUNT + CountA*CountB*CountC*CountD*Cnsts["NumOfBlds"] print "\nFor Test",test print "{0:d} Bird Sizes".format(BirdSizes) print "Degree Step Size = ",Cnsts["DegStepSize"][test] print "Number of Bird Rows =", CountC,"per cycle" print "Number of Birds Per Row=", CountD,"\n" if Cnsts["Wiggle"] > 0: print "Executed with random variation to Degree Step Size ",Cnsts["Wiggle"]," times\n" print "Total Number of Comparisons to Test = ",COUNT,"\n" for a in range(CountA): for b in range(CountB): KEY = [] degpermet = float(bldspdrange[a])/float(brdspdrange[b]) KEY.append("[{0:.4} deg/s + ".format(bldspdrange[a])) KEY.append("{0:.3} mps]".format(brdspdrange[b])) KEY = "".join(KEY) DPMDICT[KEY] = degpermet DPM.append(degpermet) print "Key:",KEY," / Value:",degpermet DPMSet = set(DPM) DPMSet = list(DPMSet) DPMSet.sort() print len(DPM)-len(DPMSet), "Duplicate Ratios Eliminated" print "Testing a total of:",len(DPMSet),"Values for Degrees per Meter" print "Degrees Per Meter To Test: \n", DPMSet print "" def GO (INPUTS): BirdSize = INPUTS[0] BrdWdth = INPUTS[1] BrdLngth = INPUTS[2] Path = INPUTS[3] Centers = INPUTS[4] test = INPUTS[5] dpmIndex = INPUTS[6] coordOUT = INPUTS[7] FlNm = ["brdsze"+str(BirdSize)] FlNm.append(".dpm{0:.0f}".format(Path.Deg_Per_M)) FlNm.append(".tst"+str(test)+".txt") FlNm = fullOutputFileName("TestsOn."+DATE, "".join(FlNm)) print FlNm Fl = open(FlNm,'w') start = time.time() MinAccept = max(BrdLngth,BrdWdth,ChrdLngthM) if BirdSize == 2: SIZE = "Large" elif BirdSize == 1: SIZE = "Average" elif BirdSize == 0: SIZE = "Small" FLOCK = Flock(Centers,BrdWdth,BrdLngth) [Hit,Tot] = BladePath.Test(Path,FLOCK,MinAccept,coordOUT) Result = (Hit/Tot)*100 end = time.time() TotTime = end - start pairs = [] for k,v in DPMDICT.iteritems(): if v == DPMSet[dpmIndex]: pairs.append(k) pairs = "".join(pairs) Fl.write(SIZE+" "+Cnsts["BrdName"]+"\n[Width - "+"{0:.2f}".format(BrdWdth)) Fl.write("m] [Length - {0:.2f}m]\n".format(BrdLngth)) Fl.write("[Test#{0:d}".format(test)) Fl.write("] [Degrees Per Meter:{0:.0f}]".format(DPMSet[dpmIndex])) Fl.write("\nWhich Includes Trials:") Fl.write(pairs) Fl.write("\n[Hits - {0:.0f}]".format(Hit)+" [NoHits - {0:.0f}]".format(Tot-Hit)) Fl.write("[Total - {0:.0f}] [%Hits - ".format(Tot)) Fl.write("{0:.3f}%]\n".format(Result)) Fl.write("Time to Solution : {0:.2f}".format(end-start)) Fl.write(" seconds, at {0:.2f} seconds per trial".format((TotTime)/(Tot))) Fl.close() return Result def PresentResults(Results): runnum = 0 FILE = os.path.join(os.path.split(OutputDirectoryPath())[0]+"/"+Cnsts["BrdName"]+"000.csv") while os.access(FILE,os.F_OK): runnum += 1 if runnum < 10: FILE = os.path.join(os.path.split(OutputDirectoryPath())[0]+"/"+Cnsts["BrdName"]+'00'+str(runnum)+".csv") elif runnum < 100: FILE = os.path.join(os.path.split(OutputDirectoryPath())[0]+"/"+Cnsts["BrdName"]+'0'+str(runnum)+".csv") else: FILE = os.path.join(os.path.split(OutputDirectoryPath())[0]+"/"+Cnsts["BrdName"]+str(runnum)+".csv") csv.register_dialect('std',delimiter=" ",quoting=csv.QUOTE_NONE,escapechar=' ', lineterminator='',strict=True,skipinitialspace=True) out = csv.writer(open(FILE,"w"),'std') out.writerow(["Turbine Name,"+Cnsts["TurbName"]+"\n"]) out.writerow(["Rotor Diameter,"+str(Cnsts["RotorDia"])+","+Cnsts["BldSzeUnit"]+"\n"]) out.writerow(["Center Post Diameter,"+str(Cnsts["HubDia"])+","+Cnsts["BldSzeUnit"]+"\n"]) out.writerow(["Blade Chord Length,"+str(Cnsts["ChrdLngth"])+","+Cnsts["BldSzeUnit"]+"\n"]) out.writerow(["Blade Thickness,"+str(Cnsts["BldThck"])+","+Cnsts["ThcknssUnit"]+"\n"]) out.writerow(["Thickness Location,"+str(Cnsts["ThckLoc"])+","+Cnsts["ThcknssUnit"]+"\n\n"]) for BirdSize in range(int(BirdSizes)): if BirdSize == 0: SIZE = "Small" if BirdSize == 1: SIZE = "Average" if BirdSize == 2 : SIZE = "Large" brdnam = [""] brdnam.append(SIZE) brdnam.append(" ") brdnam.append(Cnsts["BrdName"]) brdnam = "".join(brdnam) out.writerow([brdnam+","]) wdth = [""] lngth = [""] wdth.append("Wingspan : ") wdth.append("{0:.3} ".format(Cnsts["BrdWdth"][BirdSize])) wdth.append(Cnsts["BrdSzeUnit"]) lngth.append("Body Length : ") lngth.append("{0:.3} ".format(Cnsts["BrdLngth"][BirdSize])) lngth.append(Cnsts["BrdSzeUnit"]) wdth = "".join(wdth) lngth = "".join(lngth) for test in range(len(Cnsts["DegStepSize"])): out.writerow(["Test#",test+1,"@",str(Cnsts["DegStepSize"][test]),"Degree Step,"]) for i in range(CountA+2): out.writerow(",") if Cnsts["Wiggle"] > 0 : for w in range(int(Cnsts["Wiggle"])): out.writerow(["Test#",test+1,"@ [90%-105%] DegStep,"]) for i in range(CountA+2): out.writerow(",") out.writerow(["\n"+lngth+","]) for test in range(int(NumOfTests)): out.writerow(["Blade Speeds (",Cnsts["BldSpdUnit"],"), --->,"]) for i in range(CountA): out.writerow([str(Cnsts["LowBldSpd"]+i*Cnsts["BldSpdInt"])+","]) out.writerow(",") out.writerow(["\n"+wdth]) for test in range(NumOfTests): out.writerow([",Bird Speeds (",Cnsts["BrdSpdUnit"],")"]) for i in range(CountA+2): out.writerow(",") out.writerow(["\nResults in %,"]) for brd in range(CountB): #Different Bird Speeds for test in range(int(NumOfTests)): #Different Resolutions out.writerow([str(Cnsts["LowBrdSpd"]+brd*Cnsts["BrdSpdInt"])+",,"]) for bld in bldspdrange: #Different Blade Speeds DpM = bld/brdspdrange[brd] dpmIndex = DPMSet.index(DpM) out.writerow(["{:,.2f},".format(Results[BirdSize][test][dpmIndex])]) out.writerow(",") out.writerow("\n,") out.writerow("\n") def Main(): Outline() cycles = 3 START = time.time() ProgLoc = os.path.join(OutputDirectoryPath()+"/Progress.txt") if os.access(ProgLoc,os.F_OK): os.remove(ProgLoc) ProgFl = open(ProgLoc,'w') ProgFl.write("0\n") ProgFl.close() Prog = float(0) ProgInt = 0.01 o = Cnsts["OutVal"] TotalTests = float(len(DPMSet)*NumOfTests) Results = [[[0 for x in range(len(DPMSet))]for x in range(int(NumOfTests))]for x in range(BirdSizes)] P = [[[]for d in range(len(DPMSet))]for t in range(int(NumOfTests))] B = [[[]for d in range(len(DPMSet))]for t in range(int(NumOfTests))] Wiggle = [[0 for d in range(len(DPMSet))] for t in range(int(Cnsts["Wiggle"]+1))] arg1 = [[] for d in range(len(DPMSet))] arg2 = [[] for d in range(len(DPMSet))] arg3 = [[] for d in range(len(DPMSet))] arg4 = [[] for d in range(len(DPMSet))] arg5 = [[] for d in range(len(DPMSet))] arg6 = [[] for d in range(len(DPMSet))] for dpm in DPMSet: #Different Ratios dpmIndex = DPMSet.index(dpm) for test in range(int(len(Cnsts["DegStepSize"]))): for w in range(int(1 + Cnsts["Wiggle"])): N = int((1 + Cnsts["Wiggle"])*test + w) if w == 0 : Wiggle[w][dpmIndex] = 1 else: Wiggle[w][dpmIndex] = float(randint(900,1050))/1000 P[N][dpmIndex] = BladePath(dpm,Wiggle[w][dpmIndex]*Cnsts["DegStepSize"][test],cycles) B[N][dpmIndex] = Centers(dpm,Wiggle[w][dpmIndex]*Cnsts["DegStepSize"][test],cycles,Cnsts["NumOfBirds"][test]) for BirdSize in range(int(BirdSizes)): for w in range(int(NumOfTests)): arg1[dpmIndex].append(BirdSize) arg2[dpmIndex].append(BrdWdth[BirdSize]) arg3[dpmIndex].append(BrdLngth[BirdSize]) arg4[dpmIndex].append(P[w][dpmIndex]) arg5[dpmIndex].append(B[w][dpmIndex]) arg6[dpmIndex].append(w) for dpm in DPMSet: #Different Ratios Inc = False dpmIndex = DPMSet.index(dpm) TestNumber = float(dpmIndex*NumOfTests) ProgCurr = float(TestNumber/TotalTests) while ProgCurr >= Prog+ProgInt: Prog += ProgInt Inc = True if Inc: ProgFl = open(ProgLoc,'a') ProgFl.write(str(Prog)+"\n") ProgFl.close() args = zip(arg1[dpmIndex],arg2[dpmIndex],arg3[dpmIndex],arg4[dpmIndex],arg5[dpmIndex],arg6[dpmIndex],repeat(dpmIndex),repeat(o)) for a in args: Results[a[0]][a[5]][a[6]] = GO(a) ProgFl = open(ProgLoc,'a') ProgFl.write("1\n") ProgFl.close() END = time.time() print "Total Time: {0:.2f} seconds".format(END-START) print Results PresentResults(Results) Main()