Backported surfaceTracking solvers and tutorials (vanilla OF 3.0.1)
[foam-extend-4.0.git] / bin / plotResidual.py
blob22149b34e7d9ab402780e60317166f24b864f082
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 kRegex=r"([A-Z,a-z]*):*.*Solving for k, Initial residual = ([0-9.Ee\-+]*), Final residual = ([0-9.Ee\-+]*), No Iterations ([0-9]*)"
14 omegaRegex=r"([A-Z,a-z]*):*.*Solving for omega, Initial residual = ([0-9.Ee\-+]*), Final residual = ([0-9.Ee\-+]*), No Iterations ([0-9]*)"
15 epsilonRegex=r"([A-Z,a-z]*):*.*Solving for epsilon, Initial residual = ([0-9.Ee\-+]*), Final residual = ([0-9.Ee\-+]*), No Iterations ([0-9]*)"
17 tUp = []
18 Ux = []
19 Uy = []
20 Uz = []
21 p = []
22 iUp = 0
24 tk = []
25 k = []
26 ik = 0
28 tomega = []
29 omega = []
30 iomega = 0
32 tepsilon = []
33 epsilon = []
34 iepsilon = 0
36 #HJ take name of log file as script argument
37 pipefile=open(logfilename,'r')
38 lines = pipefile.readlines()
40 for line in lines:
41 matchUp=re.search(UpRegex,line)
42 if matchUp:
43 iUp = iUp + 1
44 tUp.append(iUp)
45 Ux.append(float(matchUp.group(2)))
46 Uy.append(float(matchUp.group(3)))
47 Uz.append(float(matchUp.group(4)))
48 p.append(float(matchUp.group(5)))
49 matchk=re.search(kRegex,line)
50 if matchk:
51 ik = ik + 1
52 tk.append(ik)
53 k.append(float(matchk.group(2)))
54 matchomega=re.search(omegaRegex,line)
55 if matchomega:
56 iomega = iomega + 1
57 tomega.append(iomega)
58 omega.append(float(matchomega.group(2)))
59 matchepsilon=re.search(epsilonRegex,line)
60 if matchepsilon:
61 iepsilon = iepsilon + 1
62 tepsilon.append(iepsilon)
63 epsilon.append(float(matchepsilon.group(2)))
65 outfile=open('residual.dat','w')
67 if iomega > 0:
68 for data in zip(tUp,Ux,Uy,Uz,p,k,omega):
69 outfile.write(' '.join([str(d) for d in data])+'\n')
70 elif iepsilon > 0:
71 for data in zip(tUp,Ux,Uy,Uz,p,k,epsilon):
72 outfile.write(' '.join([str(d) for d in data])+'\n')
73 elif iUp > 0:
74 for data in zip(tUp,Ux,Uy,Uz,p):
75 outfile.write(' '.join([str(d) for d in data])+'\n')
77 outfile.close()
79 # prepare plot
80 import pylab
81 pylab.xlabel('iteration')
82 pylab.ylabel('residual')
83 pylab.grid(True)
85 # plot in log scale
86 if iUp > 0:
87 pylab.semilogy(tUp,Ux,'-',label="Ux")
88 pylab.semilogy(tUp,Uy,'-',label="Uy")
89 pylab.semilogy(tUp,Uz,'-',label="Uz")
90 pylab.semilogy(tUp,p,'-',label="p")
92 if ik > 0:
93 pylab.semilogy(tk,k,'-',label="k")
95 if iomega > 0:
96 pylab.semilogy(tomega,omega,'-',label="omega")
98 if iepsilon > 0:
99 pylab.semilogy(tepsilon,epsilon,'-',label="epsilon")
101 pylab.legend()
102 pylab.show()