def overlstp(): curdir = os.getcwd() #CHANGE TO DIR WITH OVERLST.I (2 LEVELS UP) for i in range(0,2): os.chdir(GetParentDir(os.getcwd())) print(" Aerodata has not been updated since last run, " + "'running 'overlst -p'") #UPDATE RUN DATA WITH OVERLST -P out = cmd('overlst -p') print('OVERLST -P OUTPUT:\n\n' + out) #RETURN TO RUN DIR os.chdir(curdir)
def TrimLog(ext, iter): """Trim an OVERFLOW log file (a.ext) after the specified iteration. (different for a.animate, time based)""" #LOG FILE TO TRIM #add if ext='animate', get dt from difference in times in file, calc time, might need exponential notation filename = 'a.' + ext #RENAME OLD LOG FILE cmd('mv ' + filename + ' a.tmp') ifile = open('a.tmp', 'r') lines = ifile.readlines() nextlines = lines[1:] ofile = open(filename, 'w') for line, nextline in zip(lines, nextlines): #FIND FIRST ITER AFTER GIVEN ITER if nextline.find(' ' + str(iter + 1)) != -1: #(added a space in front to differentiate from random occurances) if ext != 'fomoco': #a.fomoco has an extra line to not write ofile.write(line) #BREAK OUT OF FUNCTION TO TRIM ALL REMAINING ITERATIONS cmd('rm a.tmp') return ofile.write(line)
def ReadQinfo(dir=None, names=None, keys=None): """Read latest qfile for freestream data dir --> path to directory to run in (default current) names --> list of strings to search for in file and return value after = keys --> list of dict keys for each parameter in names """ #Default is to run in current directory1 if dir == None: dir = os.getcwd() if names == None or keys == None: #DEFAULT PARAMETERS TO READ param = { 'fsmach' : 'M' , #Freestream Mach Number 'alpha' : 'alpha' , #OVERFLOW Angle of Attack (deg) 're_inf' : 'Re' , #Reynolds Number (per grid unit) 'gammainf' : 'gamma' , #Freestream Specific Heat Ratio (N.D.) 'beta' : 'beta' , #OVERFLOW Sideslip (deg) 'tinf' : 'T' , #Freestream Static Temperature (Rankine) 'grid units' : 'Lref' , #Reference Length for grid units (in) 'a_inf' : 'a' , #Freestream Speed of Sound (ft/s) 'v_inf' : 'V' , #Freestream Velocity (ft/s) 'rho_inf' : 'rho' , #Freestream Density (slug/ft^3) 'p_inf' : 'P' , #Freestream Static Pressure (psf) 'q_inf' : 'q' , #Freestream Dynamic Pressure (psf) } else: #USER SPECIFIED PARAMETERS TO READ params = {} for name, key in zip(names, keys): param[name] = key #FIRST, CHECK FOR Q SAVE FILES qfile = None for f in ['q.save', 'q.restart']: path = '{}/{}'.format(dir, f) if os.path.isfile(path): qfile = path #IF NO SAVE FILES, GET OUTPUT OF QINFO SCRIPT FOR LATEST Q FILE #NOTE: BROKEN FOR NOW if qfile == None: files = glob.glob(dir + 'q.[0-9]*') iters = [] for file in files: iters.append(re.search(r'q\.([0-9]*)', file).group(1)) if iters == []: #in case it doesnt return q.xxxx files qfile = 'q.save' else: qfile = 'q.' + str(max(iters)) #CALL QINFO output = cmd('qinfo {}'.format(qfile) ) output = output.splitlines() # print(output) #READ INDIVIDUAL FREESTREAM PARAMETERS #Free Stream Parameter Dictionary fs= {} # Read each line of the file for line in output: for name, key in param.items(): if re.search(name,line) != None: fs[key] = float(NoWhitespace(FindBetween(line, '='))) return fs
def main(istart=None, rundir=None, dyn=False, nfomo=10, dt=1, it0=0): """ rundir --> path to run directory (default current directory) istart --> iteration at which run will start dyn --> if dynamics = True, manage sixdof files (a.sixdof, a.animate) dt --> DTPHYS used in runs (assumed constant, fix later) it0 --> time where dynamics started """ #CHANGE TO RUN DIRECTORY if rundir == None: rundir = os.getcwd() ogdir = os.getcwd() os.chdir(rundir) print('\nTrimming \'' + rundir + '\' to iter=' + str(istart)) #################################################################### ### REMOVE FILES ################################################### #################################################################### print(' Removing extra run files') #DELETE CURRENT SAVE FILES cmd('rm *.save *.restart *.tmp') #DELETE OVERFLOW RUN FILES cmd('rm RUNNING STOP END') #DELETE PREVIOUSLY CALCULATED AERO DATA cmd('rm -r aerodata/') #DELETE SOLUTIONS AFTER START ITER if istart != None: heads = ['x', 'q', 'x.y0', 'q.y0', 'x.surf', 'q.surf', 'a.[0-9][0-9]'] if dyn == True: heads.extend(['sixdof', 'animate']) for head in heads: iters = GetIters(head) if iters == []: print(' No ' + head + '. files!') else: deliters = [str(i) for i in iters if i > istart] for deliter in deliters: cmd('rm ' + head + '.' + deliter) #################################################################### ### TRIM LOG FILES ################################################# #################################################################### if istart != None and istart != 0: print(' Trimming log files') logs = ['resid', 'turb', 'rpmin', 'fomoco'] if dyn == True: logs.extend(['sixdof', 'animate']) for log in logs: print(' a.' + log) #TRIM FILE if log == 'animate': #A.ANIMATE SORTED BY NON-DIM TIME #start time is timestep times iterations passed since time reset tstart = dt * (istart - it0) #Format as in a.animate tstart = '%.7E'%(tstart) #Just do it manually, i dont trust this tstart = '0.xxx0000E+03' TrimLog(log, tstart) elif log == 'fomoco': #fomoco save every 10 for this case******************************************* TrimLog(log, istart+nfomo-1) else: TrimLog(log, istart) if istart == 0: #DELETE LOG FILES FOR CLEAN START cmd('rm a.*') #################################################################### ### MAKE SAVE FILES ################################################ #################################################################### if istart != None and istart != 0: print(' Copying save files') saves = ['x', 'q'] if dyn == True: saves.extend(['sixdof', ]) for save in saves: print(' ' + save + '.save') #COPY SAVE FILES FOR START ITER TO .SAVE FILES cmd('cp ' + save + '.' + str(istart) + ' ' + save + '.save') #RETURN TO ORIGINAL DIRECTORY os.chdir(ogdir)
def Delete(filename): """Delete a given file""" cmd("rm {}".format(filename))
def main(sourcedir, sourcefile, savedir, saveheader, moving=0, incr=1, imin=0, imax=-1 ): """ imin --> minimum iteration above which files will be written incr --> iteration interval to write files at """ # ogdir = os.getcwd() # os.chdir(savedir) MakeOutputDir(savedir) #link in source file if not os.path.isfile('{}/{}'.format(savedir, sourcefile)): # cmd('ln -s {}/{} {}'.format(sourcedir, sourcefile, sourcefile)) cmd('ln -s {}/{} {}/{}'.format(sourcedir, sourcefile, savedir, sourcefile)) #GET GRID/FILE DIMENSIONS f = FortranFile('{}/{}'.format(savedir, sourcefile), 'r') dims = f.read_ints('uint32')[2:6] #Number of iterations, Number of points in each direction, number of parameters, needed to read whole file nj, nk, nl, nq = dims #FORMATS IN BC201 FILE bc201formats = [ ('ints', '<i4', (1,7)), #IGRID,ISTEP,NJ,NK,NL,NQ,NQC ('tvr', 'float64'), #TVREF ('dtr', 'float64'), #DTVREF ('xyz', 'float64', (3,nj,nk,nl)), #XYZ points ('q', 'float64', (nq,nj,nk,nl)), #Q variables (nq variables, njXnkXnl values for each) ('iblank', 'int32', (nj,nk,nl)), #IBLANK status of each grid point ] ######################### #Save pressure coeff history at certian locations #! I want to write out a subset through time (every iteration!) ports = [8,13,30,45] out = open(savedir+"/cp_history.dat","w") out.write("ITER") for p in ports: out.write(" {}_x {}_cp".format(p,p)) out.write("\n") ############################# #RESTART FILE AND READ EACH RECORD f = FortranFile('{}/{}'.format(savedir, sourcefile), 'r') keep_reading = True irecord = -1 while (keep_reading is True): irecord += 1 #READ CURRENT RECORD b = f.read_record(bc201formats) #GET CURRENT ITERATION istep = b['ints'][0][0][1] # print(istep) #DONT WRITE UNDESIRED FILES (SKIP) #only write files at specified interval if (istep % incr != 0): continue #Don't write files below start iter if (istep < imin): continue #Stop reading when max desired iteration is reached if istep > imax - incr: keep_reading = False #WRITE GRID POINTS TO PLOT3D FORMATTED FILE if moving: #Grid is moving, write to file at each iteration savename = '{}/{}.x.{}'.format(savedir, saveheader, istep) WriteGrid(savename, b, nj, nk, nl) elif irecord == 0: #Grid is stationary, write to file only once savename = '{}/{}.x'.format(savedir, saveheader) WriteGrid(savename, b, nj, nk, nl) #CALCULATE CP FOR EACH POINT cps = np.zeros((nj,nk,nl)) # print(cps.shape) for j in range(nj): for k in range(nk): for l in range(nl): #print(j,k,l,b['q'].shape) q = np.zeros(nq) for iq in range(nq): q[iq] = b['q'][0][iq][j][k][l] #print(q) u = q[1] / q[0] v = q[2] / q[0] w = q[3] / q[0] v2 = (u*u + v*v + w*w) dp = 0.5 * q[0] * v2 # Dynamic Pressure dpinf = 0.5 * 1.0 * 0.107**2.0 # DP_oo 0.107=Mach p = (q[5] - 1.0)*(q[4] - dp) cp = (p - 1.0/1.4)/dpinf # 1.4 = gamma_oo cps[j][k][l] = cp #WRITE CP TO PLOT3D FILE # #If horizontal line, the pressure at the gap behind the ramp is at this location to use a reference pressure # vent_cp = cps[45][0][0] #get biggest pressure aft of gap to use as reference pressure vent_cps = [] for j in range(15): vent_cps.append(cps[49+j][0][0]) vent_cp = max(vent_cps) ofile = open('{}/cp.{}.{}'.format(savedir, saveheader, istep), 'w') #write header line with grid dimensions ofile.write('X Y Z cp cp_ref\n') #for the three dimensions, x,y,z... for j in range(nj): for k in range(nk): for l in range(nl): for x in range(3): ofile.write( ' {}'.format(b['xyz'][0][x][j][k][l]) ) ofile.write( ' {}'.format(cps[j][k][l]) ) #if horizontal line, also write gap cp for reference ofile.write( ' {}'.format(vent_cp)) ofile.write( '\n') # ofile.close() ##################### #Save pressure coeff history at certian locations out.write("{:10d}".format(istep)) for p in ports: out.write(" {:12g} {:12g}".format(b['xyz'][0][0][p][0][0],cps[p][0][0])) out.write("\n")