FIX: Bogus includes found with consistency checks
[freefoam.git] / bin / freefoam-graphResUVWP.py.in
blob55238aa81d2a8d8b836ca143ac1713446e4db5f1
1 #!@PYTHON_EXECUTABLE@
2 #-------------------------------------------------------------------------------
3 # ______ _ ____ __ __
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2011 Michael Wild <themiwi@users.sf.net>
13 # Gerber van der Graaf <gerber_graaf@users.sf.net>
14 #-------------------------------------------------------------------------------
15 # License
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 2 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
26 # for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with FreeFOAM; if not, write to the Free Software Foundation,
30 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 # Script
33 # freefoam-graphResUVWP
35 # Description
36 # The utility extracts the residuals of the velocity components 'U', 'V'
37 # and 'W' and the pressure 'p' at each time step and writes them to
38 # 'residualUVWP.dat' in TecPlot format.
39 #------------------------------------------------------------------------------
41 """Usage: freefoam@PY_SCRIPT_SUFFIX@ graphResUVWP [-h, -help] <logFile>
43 The utility extracts the residuals of the velocity components 'U', 'V' and 'W'
44 and the pressure 'p' at each time step and writes them to 'residualUVWP.dat' in
45 TecPlot format.
47 Options
48 -------
49 <logFile> The log file from which to extract the data.
50 -h, -help Display this help message.
52 """
54 # want to be future proof
55 from FreeFOAM.compat import *
57 import sys
58 import os.path
59 import re
61 if len(sys.argv[1:]) != 1:
62 sys.stderr.write('Error: Require a log file as argument\n')
63 sys.stderr.write(__doc__+'\n')
64 sys.exit(1)
66 if sys.argv[1] == '-h' or sys.argv[1] == '-help':
67 print(__doc__)
68 sys.exit(0)
70 logFile = sys.argv[1]
71 if not os.path.isfile(logFile):
72 sys.stderr.write('Error: no such file')
73 sys.exit(1)
75 # parse the residuals from the log file
76 regex = re.compile(r'Solving for (?P<var>U[xyz]|p),\s+.*Initial residual\s+=\s+(?P<res>\S+),')
77 res = {}
78 for v in 'Ux Uy Uz p'.split():
79 res[v] = []
80 for l in open(logFile, 'rt'):
81 m = regex.search(l)
82 if m:
83 res[m.group('var')].append(float(m.group('res')))
85 # write file header
86 ngraphs = 0
87 for v in res.itervalues():
88 if len(v) > 0:
89 ngraphs += 1
90 outFile = open('residualUVWP.dat', 'wt')
91 outFile.write("""Solver Performance
92 number of iterations
93 residual
94 0 0
95 0 0
97 """%ngraphs)
99 # write data
100 for n, r in res.iteritems():
101 if len(r) > 0:
102 outFile.write("""%s
105 """%(n, len(r)))
106 for i, v in enumerate(r):
107 outFile.write('%d %g\n'%(i+1, v))
109 outFile.close()
111 # ------------------- vim: set sw=3 sts=3 ft=python et: ------------ end-of-file