def RunUtilities(self, sense='single'): # Get the pressure difference (Using an external utility) pUtil = UtilityRunner( argv=[self.pCmd, "-case", self.case_path, "-latestTime"], silent=True, logname="Pressure") pUtil.add("PressureDifference", "Pressure drop = (%f%) between inlet and outlet", idNr=1) pUtil.start() deltaP = UtilityRunner.get(pUtil, "PressureDifference")[0] tUtil = UtilityRunner( argv=[self.tCmd, "-case", self.case_path, "-latestTime"], silent=True, logname="Temperature") tUtil.add("TemperatureDifference", "Temperature drop = (%f%) between inlet and outlet", idNr=1) tUtil.start() deltaT = UtilityRunner.get(tUtil, "TemperatureDifference")[0] if sense == "multi": return float(deltaT), float(deltaP) else: return float(deltaT)
def execute(self, para, log): argv = [self.utility, ".", para['case']] + self.options.split() print_(" Executing and analyzing", " ".join(argv), end=" ") sys.stdout.flush() run = UtilityRunner(argv, silent=True, lam=Command.parallel, logname="_".join(argv)) run.add("data", self.regexp) run.start() data = run.analyzer.getData("data") result = None if data != None: result = [] for a in data: result.append(a) if result == None: print_("no data", end=" ") else: print_(result, end=" ") if run.runOK(): print_() else: print_("---> there was a problem") return run.runOK(), result
def RunUtilities(self, sense='single'): # Get the pressure difference (Using an external utility) pUtil = UtilityRunner( argv=[self.pCmd, "-case", self.case_path, "-latestTime"], silent=True, logname="Pressure") pUtil.add("PressureDifference", "Pressure drop = (%f%) between inlet and outlet", idNr=1) pUtil.start() deltaP = UtilityRunner.get(pUtil, "PressureDifference")[0] if sense == "multi": # Get the mass flow (Using an external utility) mUtil = UtilityRunner( argv=[self.mCmd, "-case", self.case_path, "-latestTime"], silent=True, logname="MassFlow") mUtil.add("mass", "Flux at outlet = (%f%)", idNr=1) mUtil.start() massFlow = UtilityRunner.get(mUtil, "mass")[0] return float(deltaP), float(massFlow) else: return float(deltaP)
def RunUtilities(): current = os.getcwd() solver1 = "icoUncoupledKinematicCustomInteractionFoam" # run parcelFoam for one timestep: mCalculated = UtilityRunner(argv=[solver1, "-case", current], silent=True, logname="ParticleEscape") print( "RunUtilities(x): icoUncoupledKinematicCustomInteractionFoam run for 1 timestep" ) mCalculated.add("massEscape", "- escape = outflow_top = (%f%)", idNr=1) mCalculated.add("massIntroduced", "- mass introduced = (%f%)", idNr=1) mCalculated.start() massEscape1 = UtilityRunner.get(mCalculated, "massEscape")[0] print("RunUtilities(): read massEscape to a number", str(massEscape1)) massIntro1 = UtilityRunner.get(mCalculated, "massIntroduced")[0] print("RunUtilities(): read massIntroduced to a number", str(massIntro1)) if ((platform == 'isambard_test') or (platform == 'isca_test')): subprocess.call(['rm', '-rf', current + '/0.011']) print("RunUtilities(): removed 0.011 directory") # remove redundant files subprocess.call([ 'pyFoamClearCase.py', current, '--after=0.01', '--processors-remove' ]) subprocess.call(['rm', '-rf', current + '/0']) print("RunUtilities(): removed processor directories and 0 directory") else: subprocess.call(['rm', '-rf', current + '/262.001']) print("RunUtilities(): removed 262.001 directory") # remove redundant files subprocess.call([ 'pyFoamClearCase.py', current, '--after=262', '--processors-remove' ]) subprocess.call(['rm', '-rf', current + '/0']) print("RunUtilities(): removed processor directories and 0 directory") with open(current + "/efficiency.txt", "a") as myfile_efficiency: myfile_efficiency.write( str((float(massIntro1) - float(massEscape1)) / float(massIntro1)) + '\n') print("RunUtilities(): written efficiency to a file")
def run(self): if self.opts.regexp == None: self.parser.error("Regular expression needed") cName = self.parser.casePath() run = UtilityRunner(argv=self.parser.getArgs(), silent=self.opts.silent, server=True) for i, r in enumerate(self.opts.regexp): name = self.opts.name if len(self.opts.regexp) > 1: name = "%s_%d" % (name, i) run.add(name, r) self.addToCaseLog(cName, "Starting") run.start() self.addToCaseLog(cName, "Ending") allData = run.data for i, r in enumerate(self.opts.regexp): name = self.opts.name if len(self.opts.regexp) > 1: name = "%s_%d" % (name, i) fn = path.join(run.getDirname(), name) data = run.analyzer.getData(name) allData["analyzed"][name] = data if data == None: print_(sys.argv[0] + ": No data found for expression", r) else: if self.opts.echo: fh = open(fn) print_(fh.read()) fh.close() else: print_(sys.argv[0] + ": Output written to file " + fn) self.setData(allData)
def run(self): if self.opts.regexp==None: self.parser.error("Regular expression needed") cName=self.parser.casePath() run=UtilityRunner(argv=self.parser.getArgs(), silent=self.opts.silent, server=True) for i,r in enumerate(self.opts.regexp): name=self.opts.name if len(self.opts.regexp)>1: name="%s_%d" % (name,i) run.add(name,r) self.addToCaseLog(cName,"Starting") run.start() self.addToCaseLog(cName,"Ending") allData=run.data for i,r in enumerate(self.opts.regexp): name=self.opts.name if len(self.opts.regexp)>1: name="%s_%d" % (name,i) fn=path.join(run.getDirname(),name) data=run.analyzer.getData(name) allData["analyzed"][name]=data if data==None: print sys.argv[0]+": No data found for expression",r else: if self.opts.echo: fh=open(fn) print fh.read() fh.close() else: print sys.argv[0]+": Output written to file "+fn self.setData(allData)
def RunUtilities(self, sense='multi'): # Get the pressure difference (Using an external utility) pUtil = UtilityRunner( argv=[self.pCmd, "-case", self.case_path, "-latestTime"], silent=True, logname="Pressure") pUtil.add("PressureDifference", "Total pressure drop = (%f%) between Inlet and Outlet1", idNr=1) pUtil.add("PressureDifference2", "Total pressure drop = (%f%) between Inlet and Outlet2", idNr=1) pUtil.start() deltaP = UtilityRunner.get(pUtil, "PressureDifference")[0] deltaP2 = UtilityRunner.get(pUtil, "PressureDifference2")[0] if sense == "multi": return float(deltaP), float(deltaP2) else: return max(np.abs(float(deltaP)), np.abs(float(deltaP2))),
def RunUtilities(self, sense='single'): lines = [] lines2 = [] if os.path.isdir(self.case_path + "10000"): N = 1000 else: N = 1 subprocess.call( ['pyFoamCopyLastToFirst.py', self.case_path, self.case_path]) subprocess.call([ 'pyFoamClearCase.py', self.case_path, '--processors-remove', '--keep-postprocessing' ]) # Get the pressure difference (Using an external utility) pUtil = UtilityRunner( argv=[self.pCmd, "-case", self.case_path, "-latestTime"], silent=True, logname="Pressure") pUtil.add("PressureDifference", "Pressure drop = (%f%) between inlet and outlet", idNr=1) pUtil.start() deltaP = UtilityRunner.get(pUtil, "PressureDifference")[0] if sense == "multi": # Get the mass flow (Using an external utility) mUtil = UtilityRunner( argv=[self.mCmd, "-case", self.case_path, "-latestTime"], silent=True, logname="MassFlow") mUtil.add("mass", "Flux at outlet = (%f%)", idNr=1) mUtil.start() massFlow = UtilityRunner.get(mUtil, "mass")[0] return -float(deltaP), -float(massFlow) else: return -float(deltaP)
def execute(self,para,log): argv=[self.utility,".",para['case']]+self.options.split() print_(" Executing and analyzing"," ".join(argv),end=" ") sys.stdout.flush() run=UtilityRunner(argv,silent=True,lam=Command.parallel,logname="_".join(argv)) run.add("data",self.regexp) run.start() data=run.analyzer.getData("data") result=None if data!=None: result=[] for a in data: result.append(a) if result==None: print_("no data",end=" ") else: print_(result,end=" ") if run.runOK(): print_() else: print_("---> there was a problem") return run.runOK(),result
print "Inlet velocity:", val sol.replaceBoundary("inlet", "(%f 0 0)" % (val)) # Run the solver run = ConvergenceRunner(BoundingLogAnalyzer(), argv=[solver, "-case", case], silent=True) run.start() print "Last Time = ", dire.getLast() # Get the pressure difference (Using an external utility) pUtil = UtilityRunner(argv=[pCmd, "-case", case], silent=True, logname="Pressure") pUtil.add("deltaP", "Pressure at .* Difference .*\] (.+)") pUtil.start() deltaP = pUtil.get("deltaP")[0] # Get the mass flow mUtil = UtilityRunner(argv=[mCmd, "-case", case, "-latestTime"], silent=True, logname="MassFlow") mUtil.add("mass", "Flux at (.+?) .*\] (.+)", idNr=1) mUtil.start() massFlow = mUtil.get("mass", ID="outlet")[0] # Archive the results dire.lastToArchive("vel=%g" % (val))
for i in range(nr+1): # Set the boundary condition at the inlet val=(maximum*i)/nr print "Inlet velocity:",val sol.replaceBoundary("inlet","(%f 0 0)" %(val)) # Run the solver run=ConvergenceRunner(BoundingLogAnalyzer(),argv=[solver,"-case",case],silent=True) run.start() print "Last Time = ",dire.getLast() # Get the pressure difference (Using an external utility) pUtil=UtilityRunner(argv=[pCmd,"-case",case],silent=True,logname="Pressure") pUtil.add("deltaP","Pressure at .* Difference .*\] (.+)") pUtil.start() deltaP=pUtil.get("deltaP")[0] # Get the mass flow mUtil=UtilityRunner(argv=[mCmd,"-case",case,"-latestTime"],silent=True,logname="MassFlow") mUtil.add("mass","Flux at (.+?) .*\] (.+)",idNr=1) mUtil.start() massFlow=mUtil.get("mass",ID="outlet")[0] # Archive the results dire.lastToArchive("vel=%g" % (val)) # Clear results