From a863a5fc19d0aa3bce4a845c92a9ba84c4b9febf Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Wed, 29 Apr 2015 10:17:25 +0100 Subject: [PATCH] Feature: coupled solver residual scripts --- bin/plotForces.py | 62 +++++++++++++++++++++++++ bin/plotResCoupled.py | 79 ++++++++++++++++++++++++++++++++ bin/plotResidual.py | 103 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 244 insertions(+) create mode 100755 bin/plotForces.py create mode 100755 bin/plotResCoupled.py create mode 100755 bin/plotResidual.py diff --git a/bin/plotForces.py b/bin/plotForces.py new file mode 100755 index 000000000..910f367c1 --- /dev/null +++ b/bin/plotForces.py @@ -0,0 +1,62 @@ +#!/usr/bin/python + +import re +forceRegex=r"([0-9.Ee\-+]+)\s+\(+([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\)\s\(([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\s([0-9 .Ee\-+]+)\)+\s\(+([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\)\s\(([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\s([0-9.Ee\-+]+)\)+" +t = [] +fpx = []; fpy = []; fpz = [] +fvx = []; fvy = []; fvz = [] +mpx = []; mpy = []; mpz = [] +mvx = []; mvy = []; mvz = [] +pipefile=open('forces/0/forces.dat','r') +lines = pipefile.readlines() +for line in lines: + match=re.search(forceRegex,line) + if match: + t.append(float(match.group(1))) + fpx.append(float(match.group(2))) + fpy.append(float(match.group(3))) + fpz.append(float(match.group(4))) + fvx.append(float(match.group(5))) + fvy.append(float(match.group(6))) + fvz.append(float(match.group(7))) + mpx.append(float(match.group(8))) + mpy.append(float(match.group(9))) + mpz.append(float(match.group(10))) + mvx.append(float(match.group(11))) + mvy.append(float(match.group(12))) + mvz.append(float(match.group(13))) + + +# combine pressure and viscous forces and moments +fx = fpx +fy = fpy +fz = fpz + +mx = mpx +my = mpy +mz = mpz + +for i in range(1,len(t)): + fx[i] += fvx[i] + fy[i] += fvy[i] + fz[i] += fvz[i] + mx[i] += mvx[i] + my[i] += mvy[i] + mz[i] += mvz[i] + +# plot forces +import pylab +pylab.xlabel('iteration') +pylab.ylabel('force (N)') +pylab.grid(True) +# +pylab.plot(t,fx,'-',label="fx") +pylab.plot(t,fy,'-',label="fy") +pylab.plot(t,fz,'-',label="fz") + +#pylab.plot(t,mx,'-',label="mx") +#pylab.plot(t,my,'-',label="my") +#pylab.plot(t,mz,'-',label="mz") + +pylab.legend() +pylab.show() diff --git a/bin/plotResCoupled.py b/bin/plotResCoupled.py new file mode 100755 index 000000000..7050c7e51 --- /dev/null +++ b/bin/plotResCoupled.py @@ -0,0 +1,79 @@ +#!/usr/bin/python + +import sys +if len(sys.argv) != 2: + print 'script requires name of log file' + sys.exit() + +logfilename = sys.argv[1] +print 'Reading file', logfilename + +import re +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]*)" +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]*)" + +tUp = [] +Ux = [] +Uy = [] +Uz = [] +p = [] +iUp = 0 + +tkomega = [] +k = [] +omega = [] +ikomega = 0 + +#HJ take name of log file as script argument +pipefile=open(logfilename,'r') +lines = pipefile.readlines() + +for line in lines: + matchUp=re.search(UpRegex,line) + if matchUp: + iUp = iUp + 1 + tUp.append(iUp) + Ux.append(float(matchUp.group(2))) + Uy.append(float(matchUp.group(3))) + Uz.append(float(matchUp.group(4))) + p.append(float(matchUp.group(5))) + matchkomega=re.search(komegaRegex,line) + if matchkomega: + ikomega = ikomega + 1 + tkomega.append(ikomega) + k.append(float(matchkomega.group(2))) + omega.append(float(matchkomega.group(3))) + +outfile=open('residual.dat','w') + +print 'hits = ', ikomega + +#HJ need better way of combining lists +if ikomega > 0: + for index in range(0,ikomega): + outfile.write(str(tUp[index])+' '+str(Ux[index])+' '+str(Uy[index])+' '+str(Uz[index])+' '+str(p[index])+' '+str(k[index])+' '+str(omega[index])+'\n') +elif iUp > 0: + for index in range(0,iUp): + outfile.write(str(tUp[index])+' '+str(Ux[index])+' '+str(Uy[index])+' '+str(Uz[index])+' '+str(p[index])+'\n') + +outfile.close() + +# prepare plot +import pylab +pylab.xlabel('iteration') +pylab.ylabel('residual') +pylab.grid(True) + +# plot in log scale +if iUp > 0: + pylab.semilogy(tUp,Ux,'-',label="Ux") + pylab.semilogy(tUp,Uy,'-',label="Uy") + pylab.semilogy(tUp,Uz,'-',label="Uz") + pylab.semilogy(tUp,p,'-',label="p") + +if ikomega > 0: + pylab.semilogy(tkomega,k,'-',label="k") + pylab.semilogy(tkomega,omega,'-',label="omega") + +pylab.legend() +pylab.show() diff --git a/bin/plotResidual.py b/bin/plotResidual.py new file mode 100755 index 000000000..53d650415 --- /dev/null +++ b/bin/plotResidual.py @@ -0,0 +1,103 @@ +#!/usr/bin/python + +import sys +if len(sys.argv) != 2: + print 'script requires name of log file' + sys.exit() + +logfilename = sys.argv[1] +print 'Reading file', logfilename + +import re +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]*)" +kRegex=r"([A-Z,a-z]*):*.*Solving for k, Initial residual = ([0-9.Ee\-+]*), Final residual = ([0-9.Ee\-+]*), No Iterations ([0-9]*)" +omegaRegex=r"([A-Z,a-z]*):*.*Solving for omega, Initial residual = ([0-9.Ee\-+]*), Final residual = ([0-9.Ee\-+]*), No Iterations ([0-9]*)" +epsilonRegex=r"([A-Z,a-z]*):*.*Solving for epsilon, Initial residual = ([0-9.Ee\-+]*), Final residual = ([0-9.Ee\-+]*), No Iterations ([0-9]*)" + +tUp = [] +Ux = [] +Uy = [] +Uz = [] +p = [] +iUp = 0 + +tk = [] +k = [] +ik = 0 + +tomega = [] +omega = [] +iomega = 0 + +tepsilon = [] +epsilon = [] +iepsilon = 0 + +#HJ take name of log file as script argument +pipefile=open(logfilename,'r') +lines = pipefile.readlines() + +for line in lines: + matchUp=re.search(UpRegex,line) + if matchUp: + iUp = iUp + 1 + tUp.append(iUp) + Ux.append(float(matchUp.group(2))) + Uy.append(float(matchUp.group(3))) + Uz.append(float(matchUp.group(4))) + p.append(float(matchUp.group(5))) + matchk=re.search(kRegex,line) + if matchk: + ik = ik + 1 + tk.append(ik) + k.append(float(matchk.group(2))) + matchomega=re.search(omegaRegex,line) + if matchomega: + iomega = iomega + 1 + tomega.append(iomega) + omega.append(float(matchomega.group(2))) + matchepsilon=re.search(epsilonRegex,line) + if matchepsilon: + iepsilon = iepsilon + 1 + tepsilon.append(iepsilon) + epsilon.append(float(matchepsilon.group(2))) + +outfile=open('residual.dat','w') + +#HJ need better way of combining lists +if iomega > 0: + for index in range(0,iomega): + outfile.write(str(tUp[index])+' '+str(Ux[index])+' '+str(Uy[index])+' '+str(Uz[index])+' '+str(p[index])+' '+str(k[index])+' '+str(omega[index])+'\n') +elif iepsilon > 0: + for index in range(0,iepsilon): + outfile.write(str(tUp[index])+' '+str(Ux[index])+' '+str(Uy[index])+' '+str(Uz[index])+' '+str(p[index])+' '+str(k[index])+' '+str(epsilon[index])+'\n') +elif iUp > 0: + for index in range(0,iUp): + outfile.write(str(tUp[index])+' '+str(Ux[index])+' '+str(Uy[index])+' '+str(Uz[index])+' '+str(p[index])+'\n') + +outfile.close() + +# prepare plot +import pylab +pylab.xlabel('iteration') +pylab.ylabel('residual') +pylab.grid(True) + +# plot in log scale +if iUp > 0: + pylab.semilogy(tUp,Ux,'-',label="Ux") + pylab.semilogy(tUp,Uy,'-',label="Uy") + pylab.semilogy(tUp,Uz,'-',label="Uz") + pylab.semilogy(tUp,p,'-',label="p") + +if ik > 0: + pylab.semilogy(tk,k,'-',label="k") + +if iomega > 0: + pylab.semilogy(tomega,omega,'-',label="omega") + +if iepsilon > 0: + pylab.semilogy(tepsilon,epsilon,'-',label="epsilon") + +pylab.legend() +pylab.show()