|
[Sponsors] |
March 14, 2014, 18: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 |
|
March 19, 2014, 18:57 |
|
#2 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Basically (but you seem to have guessed so far) the division of tasks is: the LineAnalyzer looks at one line at a time and reacts to it. The Analyzer collects LineAnalyzer and feeds all of them the same lines. The AnalyzedRunner executes the solver and hands each line of the output to the Analyzer. What is important is that if you want to access data the Analyzer might have is to create the analyzer as a separate variable, pass the variable to the runner. After the Analyzer has the data. You've just got to ask for it
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
March 20, 2014, 00:51 |
|
#3 |
Member
Ripudaman Manchanda
Join Date: May 2013
Posts: 55
Rep Power: 13 |
Thank you for your response Bernhard. I have seen the presentation you suggested and have incorporated parts of it in my code. However, I did not fully understand the implementation in the presentation. I think I need to spend some time understanding the nuances of the code written in the presentation. The algorithmic guide you provide in the steps of execution should help in aiding my understanding.
I hope a more careful re-look at what is going on will help. Is there any way I can access the code explained in the slides in one file? That would help tremendously. For example, where can I find AbscheideAnalyzer.py? Thanks again. Ripu |
|
March 20, 2014, 14:27 |
|
#4 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
I only glanced at your code and I think the necessary change is what I described in the last post: create an Analyzer-object. Pass that to the Runner. Afterwards query the Analyzer-object. Basically you've got everything there. Only the order does not fit
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
March 30, 2014, 23:41 |
|
#5 |
Member
Ripudaman Manchanda
Join Date: May 2013
Posts: 55
Rep Power: 13 |
You were absolutely right. The rearrangement of the statements and following the logic you recommended solved my problem. Thank you very much. Now my code will run in half the time
|
|
|
|
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 07:47 |
[OpenFOAM.org] Error creating ParaView-4.1.0 OpenFOAM 2.3.0 | tlcoons | OpenFOAM Installation | 13 | April 20, 2016 18:34 |
[foam-extend.org] problem when installing foam-extend-1.6 | Thomas pan | OpenFOAM Installation | 7 | September 9, 2015 22:53 |
[OpenFOAM.org] Compile OF 2.3 on Mac OS X .... the patch | gschaider | OpenFOAM Installation | 225 | August 25, 2015 20:43 |
[swak4Foam] Error bulding swak4Foam | sfigato | OpenFOAM Community Contributions | 18 | August 22, 2013 13:41 |