Forward compatibility: flex
[foam-extend-3.2.git] / bin / plotResCoupled.py
blobff88c79b43f2bfc1248eea35f4bf42ec08ecc17f
1 #!/usr/bin/python
3 import sys
4 if len(sys.argv) != 2:
5 print 'script requires name of log file'
6 sys.exit()
8 logfilename = sys.argv[1]
9 print 'Reading file', logfilename
11 import re
12 UpRegex=r"([A-Z,a-z]*):*.*Solving for Up, Initial residual = \(([0-9.Ee\-+]*)\s([0-9.Ee\-+]*)\s([0-9.Ee\-+]*)\s([0-9.Ee\-+]*)\), Final residual = \(([0-9.Ee\-+]*)\s([0-9.Ee\-+]*)\s([0-9.Ee\-+]*)\s([0-9.Ee\-+]*)\), No Iterations ([0-9]*)"
13 kepsilonRegex=r"([A-Z,a-z]*):*.*Solving for kEpsilon, Initial residual = \(([0-9.Ee\-+]*)\s([0-9.Ee\-+]*)\), Final residual = \(([0-9.Ee\-+]*)\s([0-9.Ee\-+]*)\), No Iterations ([0-9]*)"
14 komegaRegex=r"([A-Z,a-z]*):*.*Solving for kOmega, Initial residual = \(([0-9.Ee\-+]*)\s([0-9.Ee\-+]*)\), Final residual = \(([0-9.Ee\-+]*)\s([0-9.Ee\-+]*)\), No Iterations ([0-9]*)"
16 tUp = []
17 Ux = []
18 Uy = []
19 Uz = []
20 p = []
21 iUp = 0
23 tkomega = []
24 k = []
25 omega = []
26 ikomega = 0
28 tkepsilon = []
29 k = []
30 epsilon = []
31 ikepsilon = 0
33 #HJ take name of log file as script argument
34 pipefile=open(logfilename,'r')
35 lines = pipefile.readlines()
37 for line in lines:
38 matchUp=re.search(UpRegex,line)
39 if matchUp:
40 iUp = iUp + 1
41 tUp.append(iUp)
42 Ux.append(float(matchUp.group(2)))
43 Uy.append(float(matchUp.group(3)))
44 Uz.append(float(matchUp.group(4)))
45 p.append(float(matchUp.group(5)))
46 matchkepsilon=re.search(kepsilonRegex,line)
47 if matchkepsilon:
48 ikepsilon = ikepsilon + 1
49 tkepsilon.append(ikepsilon)
50 k.append(float(matchkepsilon.group(2)))
51 epsilon.append(float(matchkepsilon.group(3)))
52 matchkomega=re.search(komegaRegex,line)
53 if matchkomega:
54 ikomega = ikomega + 1
55 tkomega.append(ikomega)
56 k.append(float(matchkomega.group(2)))
57 omega.append(float(matchkomega.group(3)))
59 outfile=open('residual.dat','w')
61 if ikomega > 0:
62 for data in zip(tUp,Ux,Uy,Uz,p,k,omega):
63 outfile.write(' '.join([str(d) for d in data])+'\n')
64 elif ikepsilon > 0:
65 for data in zip(tUp,Ux,Uy,Uz,p,k,epsilon):
66 outfile.write(' '.join([str(d) for d in data])+'\n')
67 elif iUp > 0:
68 for data in zip(tUp,Ux,Uy,Uz,p):
69 outfile.write(' '.join([str(d) for d in data])+'\n')
71 outfile.close()
73 # prepare plot
74 import pylab
75 pylab.xlabel('iteration')
76 pylab.ylabel('residual')
77 pylab.grid(True)
79 # plot in log scale
80 if iUp > 0:
81 pylab.semilogy(tUp,Ux,'-',label="Ux")
82 pylab.semilogy(tUp,Uy,'-',label="Uy")
83 pylab.semilogy(tUp,Uz,'-',label="Uz")
84 pylab.semilogy(tUp,p,'-',label="p")
86 if ikepsilon > 0:
87 pylab.semilogy(tkepsilon,k,'-',label="k")
88 pylab.semilogy(tkepsilon,epsilon,'-',label="epsilon")
90 if ikomega > 0:
91 pylab.semilogy(tkomega,k,'-',label="k")
92 pylab.semilogy(tkomega,omega,'-',label="omega")
94 pylab.legend()
95 pylab.show()