def extractParaviewLineData(caseDir, varList, coords, calcDict, csvOutputVar, time): try: reader = ps.OpenFOAMReader(FileName=caseDir + '/case.foam') except: ps.Connect() reader = ps.OpenFOAMReader(FileName=caseDir + '/case.foam') try: reader.CellArrays = varList except: print("Variables {} were not found in results. Exiting ...".format( varList)) reader.MeshRegions = ['internalMesh'] if (time in reader.TimestepValues): reader.SMProxy.UpdatePipeline(time) reader.UpdatePipelineInformation() #view = ps.CreateRenderView() #view.ViewTime = time else: print("Time-directory {} does not exist. Exiting ...".format(time)) sys.exit(1) if (calcDict): calc = ps.Calculator(reader) calc.Function = calcDict["Function"] calc.ResultArrayName = calcDict["ResultArrayName"] plotLine = ps.PlotOverLine(Source="High Resolution Line Source") plotLine.Source.Resolution = 450 plotLine.Source.Point1 = coords[0] # [0.0, 0.0008, 0.0] plotLine.Source.Point2 = coords[1] # [0.59, 0.0008, 0.0] filePath = caseDir + "/tmp.csv" writer = ps.CreateWriter(filePath, plotLine) writer.WriteAllTimeSteps = False writer.UseScientificNotation = 1 #print("Writing file tmp.csv ... ") writer.UpdatePipeline() #print("Done!") ps.Delete(reader) ps.Delete(calc) #; ps.Delete(writer) ps.Delete(plotLine) reader = None del reader calc = None del calc plotLine = None del plotLine del writer if (np.mod((100. * time), 1) == 0): print("Disconnecting ... ") ps.Disconnect() # Clear memory occasionally. data = extractFromCSV("tmp.csv", csvOutputVar) return data
writeLog(parser, args) #==========================================================# strKey = args.strKey figName = args.figName fileAnim = args.fileAnim noAnimation = args.noAnim ylims = args.ylims varList = args.var fileNos, fileList = filesFromList("*" + strKey + "*") print(' The varList [-v, --var] option is over ridden at this point. ') print(' Reading coordinate values from file {} ...'.format(fileList[0])) coordList = ['arc_length', 'Points:0', 'Points:1', 'Points:2'] xv = extractFromCSV(fileList[0], coordList) s = xv[0].copy() # arc_length x = xv[1].copy() y = xv[2].copy() z = xv[3].copy() xv = None print(' Done.\n') # -------------------------------------------------------- # print(' Computing the mean velocity values ... ') varList = ['u', 'v', 'w'] Ux_mean = None Uy_mean = None Uz_mean = None
action="store_true", default=False) args = parser.parse_args() #==========================================================# #print type(args.var), args.var if (not args.filename): fileNos, fileList = filesFromList("*.csv") try: args.filename = fileList[0] except: sys.exit('Could not obtain a valid CSV file. Exiting ...') if (args.waveMode): varList = ["U:1", "U:2", "arc_length"] dat = extractFromCSV(args.filename, varList) Umag = np.sqrt(dat[0]**2 + dat[1]**2) xL = dat[2] waveAnalysis(Umag, xL) else: varList = args.var v_ref = args.ref print v_ref v = extractFromCSV(args.filename, varList)[0] print " " print sepStr print 'Analyzing {0} from file {1}.'.format(args.var[0], args.filename) print v_a = basicAnalysis(v, args.var[0], v_ref, 1)
xvar = args.xvar avar = args.appendv af = args.appendf nY = len(args.yvars) # Append the x- and a-variables into the variable list. varList.append(xvar) varList.append(avar) fileNos, fileList = filesFromList( "*"+strKey+"*" ) pfig = plt.figure(num=1, figsize=(12,10)) for fn in fileNos: dat = extractFromCSV( fileList[fn] , varList ) a = dat[-1]; x = dat[-2]; y = dat[:-2] dat = None for i in xrange(nY): astr ='_'+str(int(a[0]/100.)) y[i]+=(a*af) axLabels = ["{}(z)".format(varList[i]),"{} +x/100 [m/s]".format(varList[i]),"z [m]"] varLabel = varList[i]+astr pfig = addToPlot(pfig,y[i], x, varLabel, axLabels, False ) if(args.labels): pfig = userLabels( pfig ) plt.legend(loc=0) plt.grid(True) plt.show()