Merge /u/hjasak/foam-extend-3.1/ branch HrvojeJasak into nextRelease
[foam-extend-3.2.git] / bin / plotResCoupled.py
blob7050c7e51fb75db5ac0ad0c0a6f651e188f9de78
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 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]*)"
15 tUp = []
16 Ux = []
17 Uy = []
18 Uz = []
19 p = []
20 iUp = 0
22 tkomega = []
23 k = []
24 omega = []
25 ikomega = 0
27 #HJ take name of log file as script argument
28 pipefile=open(logfilename,'r')
29 lines = pipefile.readlines()
31 for line in lines:
32 matchUp=re.search(UpRegex,line)
33 if matchUp:
34 iUp = iUp + 1
35 tUp.append(iUp)
36 Ux.append(float(matchUp.group(2)))
37 Uy.append(float(matchUp.group(3)))
38 Uz.append(float(matchUp.group(4)))
39 p.append(float(matchUp.group(5)))
40 matchkomega=re.search(komegaRegex,line)
41 if matchkomega:
42 ikomega = ikomega + 1
43 tkomega.append(ikomega)
44 k.append(float(matchkomega.group(2)))
45 omega.append(float(matchkomega.group(3)))
47 outfile=open('residual.dat','w')
49 print 'hits = ', ikomega
51 #HJ need better way of combining lists
52 if ikomega > 0:
53 for index in range(0,ikomega):
54 outfile.write(str(tUp[index])+' '+str(Ux[index])+' '+str(Uy[index])+' '+str(Uz[index])+' '+str(p[index])+' '+str(k[index])+' '+str(omega[index])+'\n')
55 elif iUp > 0:
56 for index in range(0,iUp):
57 outfile.write(str(tUp[index])+' '+str(Ux[index])+' '+str(Uy[index])+' '+str(Uz[index])+' '+str(p[index])+'\n')
59 outfile.close()
61 # prepare plot
62 import pylab
63 pylab.xlabel('iteration')
64 pylab.ylabel('residual')
65 pylab.grid(True)
67 # plot in log scale
68 if iUp > 0:
69 pylab.semilogy(tUp,Ux,'-',label="Ux")
70 pylab.semilogy(tUp,Uy,'-',label="Uy")
71 pylab.semilogy(tUp,Uz,'-',label="Uz")
72 pylab.semilogy(tUp,p,'-',label="p")
74 if ikomega > 0:
75 pylab.semilogy(tkomega,k,'-',label="k")
76 pylab.semilogy(tkomega,omega,'-',label="omega")
78 pylab.legend()
79 pylab.show()