CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Community Contributions

[PyFoam] Parse log file while running.

Register Blogs Community New Posts Updated Threads Search

 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old   March 14, 2014, 17:18
Default Parse log file while running.
  #1
Member
 
Ripudaman Manchanda
Join Date: May 2013
Posts: 55
Rep Power: 13
ripudaman is on a distinguished road
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"))
Here is the logAnalyzer.py file that I use to parse the regular expressions in my created log file
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())
I apologize for any redundancy here since I do not fully understand the way pyFoam libraries are set and am not very familiar with the class system in python.

Any help here is appreciated.

Thank you.
Regards,
Ripu
ripudaman is offline   Reply With Quote

 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 19:17.