2 #-------------------------------------------------------------------------------
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
13 # Gerber van der Graaf <gerber_graaf@users.sf.net>
14 #-------------------------------------------------------------------------------
16 # This file is part of FreeFOAM.
18 # FreeFOAM is free software: you can redistribute it and/or modify it
19 # under the terms of the GNU General Public License as published by the
20 # Free Software Foundation, either version 3 of the License, or (at your
21 # option) any later version.
23 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
24 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 # You should have received a copy of the GNU General Public License
29 # along with FreeFOAM. If not, see <http://www.gnu.org/licenses/>.
32 # freefoam-solverSweeps
35 # Extracts statistics from a log file
37 #------------------------------------------------------------------------------
39 """Usage: freefoam@PY_SCRIPT_SUFFIX@ solverSweeps [-h, -help] [<log>]
41 This utility script extracts solver statistics from a log file and prints them
42 to the screen. The extracted quantities are:
43 - execution time of the first iteration
44 - overall execution time
45 - the number of iterations
46 - the first iteration number
47 - the last iteration number
48 - the number of solver sweeps for the velocity and pressure fields
52 -h, -help Print this help message
53 <log> Analyze this log file. If this is -, read log from standard input.
54 If not specified, the name of the file (NOT the data) is read from
63 # want to be future proof
64 sys
.path
.insert(0, '@FOAM_PYTHON_DIR@')
65 from FreeFOAM
.compat
import *
72 if a
== '-h' or a
== '-help':
80 sys
.stderr
.write('Error: unknown option "%s"\n'%a
)
81 sys
.stderr
.write(__doc__
+'\n')
89 sys
.stderr
.write('Name of log file [log] : ')
90 logName
= sys
.stdin
.readline().strip()
91 if os
.path
.isfile(logName
):
92 logFile
= open(logName
, 'rt')
94 sys
.stderr
.write('Error: No such file "%s"\n'%logName
)
106 progRegex
= re
.compile(r
'^Exec\s+: (?P<program>\S+)')
107 execTimeRegex
= re
.compile(r
'^ExecutionTime\s*=.*')
108 timeRegex
= re
.compile(r
'^Time\s*=.*')
109 pRegex
= re
.compile(r
'.*Solving for p,.*\s+(?P<niter>\d+)$')
110 URegex
= re
.compile(r
'.*Solving for U.,.*\s+(?P<niter>\d+)$')
114 m
= progRegex
.match(l
)
116 program
= m
.group('program')
118 if execTimeRegex
.match(l
):
121 if timeRegex
.match(l
):
126 pIter
+= int(m
.group('niter'))
130 UIter
+= int(m
.group('niter'))
133 print('\nProgram: %s'%program
)
136 print(' 1st iter : %s'%runTime
[0])
137 print(' overall : %s'%runTime
[-1])
139 print('\nSimulation:')
140 print(' steps: %d'%len(time
))
141 print(' from : %s'%time
[0])
142 print(' to : %s'%time
[-1])
144 print('\nSolver sweeps:')
145 print(' p : %d'%pIter
)
146 print(' U(U0,U1,U2) : %d'%UIter
)
148 # ------------------- vim: set sw=3 sts=3 ft=python et: ------------ end-of-file