|
[Sponsors] |
March 14, 2014, 17:18 |
Parse log file while running.
|
#1 |
Member
Ripudaman Manchanda
Join Date: May 2013
Posts: 55
Rep Power: 13 |
Hi,
I am relatively inexperienced in pyFoam. I am using bits and pieces of information that I have gathered from the various pyFoam talks and presentations over the years. I am having a problem in being able to run a case, generate a specific log file and read the log file for a regExp to modify the output on the screen all in one go. I am able to do all this but I am having to run the solver twice. I want to find a way to do this without having to run the solver twice. Also another tips on this will be very useful. Here is the snippet of code that I am using Code:
run=AnalyzedRunner(Analyzer(),silent=True,argv=["convergeFracWidthFoam","-case",work.name],logname='CFWF') run.start() CONVERGED=LogAnalyzer("CONVERGED") analyzer=LogAnalyzerApplication(CONVERGED) analyzer.run(path.join(target,"CFWF.logfile")) Code:
import re,sys from PyFoam.LogAnalysis.FoamLogAnalyzer import FoamLogAnalyzer from PyFoam.LogAnalysis.LogAnalyzerApplication import LogAnalyzerApplication from PyFoam.LogAnalysis.LogLineAnalyzer import LogLineAnalyzer from PyFoam.LogAnalysis.BoundingLogAnalyzer import BoundingLogAnalyzer class LogAnalyzer(FoamLogAnalyzer): def __init__(self,name): super(LogAnalyzer,self).__init__() self.addAnalyzer(name,LineAnalyzer()) def obtainWidth(self,name): return self.getAnalyzer(name).obtainWidth() def obtainHaltRatio(self,name): return self.getAnalyzer(name).obtainHaltRatio() class LineAnalyzer(LogLineAnalyzer): def __init__(self): LogLineAnalyzer.__init__(self) self.told="" self.exp1=re.compile("^(.+): Solving for (.+), Initial residual = (.+), Final residual = (.+), No Iterations (.+)$") self.exp2=re.compile("Previous Fracture Width = (.+) Current Fracture Width = (.+)$") self.exp3=re.compile("Current Halt Ratio = (.+) Desired Halt Ratio = (.+)$") self.currentwidth=0 self.haltratio=1 def doAnalysis(self,line): m=self.exp1.match(line) if m!=None: name=m.group(2) resid=m.group(3) iters=m.group(5) time=self.getTime() if time!=self.told: self.told=time print "\n t = %3g: " % ( float(time) ), print "%3s: %3e %5s: %1g" % (name,float(resid),"NIter",float(iters)), #sys.stdout.flush() m=self.exp2.match(line) if m!=None: previous=m.group(1) current=m.group(2) print "\t %5s: %6e" % ("FracWidth",float(current)), self.currentwidth=float(current) sys.stdout.flush() m=self.exp3.match(line) if m!=None: current=m.group(1) target=m.group(2) self.haltratio=float(current) def obtainWidth(self): return self.currentwidth def obtainHaltRatio(self): return self.haltratio class Analyzer(BoundingLogAnalyzer): def __init__(self): BoundingLogAnalyzer.__init__(self) self.addAnalyzer("Analyzer",LineAnalyzer()) Any help here is appreciated. Thank you. Regards, Ripu |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
OpenFoam "Permission denied" and "command not found" problems. | iyidaniel@yahoo.co.uk | OpenFOAM Running, Solving & CFD | 11 | January 2, 2018 06:47 |
[OpenFOAM.org] Error creating ParaView-4.1.0 OpenFOAM 2.3.0 | tlcoons | OpenFOAM Installation | 13 | April 20, 2016 17:34 |
[foam-extend.org] problem when installing foam-extend-1.6 | Thomas pan | OpenFOAM Installation | 7 | September 9, 2015 21:53 |
[OpenFOAM.org] Compile OF 2.3 on Mac OS X .... the patch | gschaider | OpenFOAM Installation | 225 | August 25, 2015 19:43 |
[swak4Foam] Error bulding swak4Foam | sfigato | OpenFOAM Community Contributions | 18 | August 22, 2013 12:41 |