FIX: Set CTEST_NIGTHLY_START_TIME in CTestConfig.cmake
[freefoam.git] / bin / freefoam-graphResUVWP.py.in
blobcae88979e4d2f9c33fb305b99b4269e43146af7b
1 #!@PYTHON_EXECUTABLE@
2 #-------------------------------------------------------------------------------
3 # ______ _ ____ __ __
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 #-------------------------------------------------------------------------------
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 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
26 # for more details.
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/>.
31 # Script
32 # freefoam-graphResUVWP
34 # Description
35 # The utility extracts the residuals of the velocity components 'U', 'V'
36 # and 'W' and the pressure 'p' at each time step and writes them to
37 # 'residualUVWP.dat' in TecPlot format.
38 #------------------------------------------------------------------------------
40 """Usage: freefoam@PY_SCRIPT_SUFFIX@ graphResUVWP [-h, -help] <logFile>
42 The utility extracts the residuals of the velocity components 'U', 'V' and 'W'
43 and the pressure 'p' at each time step and writes them to 'residualUVWP.dat' in
44 TecPlot format.
46 Options
47 -------
48 <logFile> The log file from which to extract the data.
49 -h, -help Display this help message.
51 """
53 import sys
54 import os.path
55 import re
56 # want to be future proof
57 sys.path.insert(0, '@FOAM_PYTHON_DIR@')
58 from FreeFOAM.compat import *
60 if len(sys.argv[1:]) != 1:
61 sys.stderr.write('Error: Require a log file as argument\n')
62 sys.stderr.write(__doc__+'\n')
63 sys.exit(1)
65 if sys.argv[1] == '-h' or sys.argv[1] == '-help':
66 print(__doc__)
67 sys.exit(0)
69 logFile = sys.argv[1]
70 if not os.path.isfile(logFile):
71 sys.stderr.write('Error: no such file')
72 sys.exit(1)
74 # parse the residuals from the log file
75 regex = re.compile(r'Solving for (?P<var>U[xyz]|p),\s+.*Initial residual\s+=\s+(?P<res>\S+),')
76 res = {}
77 for v in 'Ux Uy Uz p'.split():
78 res[v] = []
79 for l in open(logFile, 'rt'):
80 m = regex.search(l)
81 if m:
82 res[m.group('var')].append(float(m.group('res')))
84 # write file header
85 ngraphs = 0
86 for v in res.itervalues():
87 if len(v) > 0:
88 ngraphs += 1
89 outFile = open('residualUVWP.dat', 'wt')
90 outFile.write("""Solver Performance
91 number of iterations
92 residual
93 0 0
94 0 0
96 """%ngraphs)
98 # write data
99 for n, r in res.iteritems():
100 if len(r) > 0:
101 outFile.write("""%s
104 """%(n, len(r)))
105 for i, v in enumerate(r):
106 outFile.write('%d %g\n'%(i+1, v))
108 outFile.close()
110 # ------------------- vim: set sw=3 sts=3 ft=python et: ------------ end-of-file