2 vis.py - GPUE: Split Operator based GPU solver for Nonlinear 3 Schrodinger Equation, Copyright (C) 2011-2018, Lee J. O'Riordan 4 <loriordan@gmail.com>, Tadhg Morgan, Neil Crowley. All rights reserved. 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions are 10 1. Redistributions of source code must retain the above copyright 11 notice, this list of conditions and the following disclaimer. 13 2. Redistributions in binary form must reproduce the above copyright 14 notice, this list of conditions and the following disclaimer in the 15 documentation and/or other materials provided with the distribution. 17 3. Neither the name of the copyright holder nor the names of its 18 contributors may be used to endorse or promote products derived from 19 this software without specific prior written permission. 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 24 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 27 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 from mpi4py
import MPI
36 from numpy
import genfromtxt
38 import matplotlib
as mpl
39 import matplotlib.tri
as tri
42 from scipy.spatial
import Voronoi, voronoi_plot_2d
45 from matplotlib.ticker
import ScalarFormatter
46 import matplotlib.pyplot
as plt
47 from matplotlib
import pyplot
as plt
48 import matplotlib.patheffects
as PathEffects
56 c = ConfigParser.ConfigParser()
58 c = ConfigParser.ConfigParser()
59 c.readfp(open(
r'Params.dat'))
65 xDim = int(c.getfloat(
'Params',
'xDim'))
66 yDim = int(c.getfloat(
'Params',
'yDim'))
67 gndMaxVal = int(c.getfloat(
'Params',
'gsteps'))
68 evMaxVal = int(c.getfloat(
'Params',
'esteps'))
69 incr = int(c.getfloat(
'Params',
'printSteps'))
70 sep = (c.getfloat(
'Params',
'dx'))
71 dx = (c.getfloat(
'Params',
'dx'))
72 dt = (c.getfloat(
'Params',
'dt'))
73 xMax = (c.getfloat(
'Params',
'xMax'))
74 yMax = (c.getfloat(
'Params',
'yMax'))
77 data = numpy.ndarray(shape=(xDim,yDim))
79 def image_gen_single(dataName, value, imgdpi,opmode, x_dat, cbarOn=True, plot_vtx=False):
80 real=open(dataName +
'_' + str(0)).read().splitlines()
81 img=open(dataName +
'i_' + str(0)).read().splitlines()
82 a1_r = numpy.asanyarray(real,dtype=
'f8')
83 a1_i = numpy.asanyarray(img,dtype=
'f8')
84 a1 = a1_r[:] + 1j*a1_i[:]
85 b1 = np.reshape(a1,(xDim,yDim))
87 if not os.path.exists(dataName+
"r_"+str(value)+
"_abspsi2.png"):
88 real=open(dataName +
'_' + str(value)).read().splitlines()
89 img=open(dataName +
'i_' + str(value)).read().splitlines()
90 a_r = numpy.asanyarray(real,dtype=
'f8')
91 a_i = numpy.asanyarray(img,dtype=
'f8')
92 a = a_r[:] + 1j*a_i[:]
93 b = np.transpose(np.reshape(a,(xDim,yDim)))
95 maxDensityVal=np.max(np.abs(a)**2)
99 vorts = np.loadtxt(
'vort_ord_' + str(value) +
'.csv', delimiter=
',', unpack=
True)
100 except Exception
as e:
101 print "Failed to load the required data file: %s"%e
102 print "Please run vort.py before plotting the density, if you wih to have correctly numbered vortices" 103 vorts = np.loadtxt(
'vort_arr_' + str(value), delimiter=
',', unpack=
True, skiprows=1)
106 if opmode & 0b100000 > 0:
107 nameStr = dataName+
"r_"+str(value)
109 fig, ax = plt.subplots()
110 f = plt.imshow( (abs(b)**2), cmap=
'hot', vmin=0, vmax=maxDensityVal, interpolation=
'none',)
113 plt.title(
't=' + tstr +
" s", fontsize=28)
116 tbar = fig.colorbar(f)
118 plt.gca().invert_yaxis()
121 zVort = zip(vorts[0,:],vorts[1,:], vorts[3,:])
123 zVort = zip(vorts[1,:], vorts[3,:], [0, 1, 2, 3])
124 for x, y, z
in zVort:
126 txt = plt.text(x, y, str(int(z)), color=
'#379696', fontsize=6, alpha=0.7)
127 txt.set_path_effects([PathEffects.withStroke(linewidth=1, foreground=
'#B9EA56')])
129 txt = plt.text(x, y, str(int(z)), color=
'#B9EA56', fontsize=6, alpha=0.7)
130 txt.set_path_effects([PathEffects.withStroke(linewidth=1, foreground=
'#379696')])
134 plt.savefig(dataName+
"r_"+str(value)+
"_abspsi2_num.png",dpi=imgdpi, bbox_inches=
'tight')
136 plt.savefig(dataName+
"r_"+str(value)+
"_abspsi2_nonum.png",dpi=imgdpi, bbox_inches=
'tight')
139 print "Saved figure: " + str(value) +
".png" 142 print "File(s) " + str(value) +
".png already exist." 144 if __name__ ==
'__main__':
146 cbarOn = sys.argv[1].lower() ==
'true' 147 plot_vtx = sys.argv[2].lower() ==
'true' 150 x_coord = np.loadtxt(
'x_0', unpack=
True)
152 comm = MPI.COMM_WORLD
155 print "Rank %d/%d initialised"%(rank,size-1)
157 arrG = np.array_split( xrange(0,gndMaxVal,incr), size)
158 arrE = np.array_split( xrange(0,evMaxVal,incr), size)
167 print "Processing data index=%d on rank=%d"%(i,rank)
172 except Exception
as e:
173 print "Unable to process wfc_0_ramp data index=%d on rank=%d"%(i,rank)
175 image_gen_single(
"wfc_0_const", i, 400, 0b100000, x_coord, cbarOn, plot_vtx)
176 except Exception
as e:
177 print "Unable to process wfc_0_const data index=%d on rank=%d"%(i,rank)
180 print "Processing data index=%d on rank=%d"%(i,rank)
184 print "Processed data index=%d on rank=%d"%(i,rank)
186 except Exception
as e:
187 print "Unable to process wfc_ev data index=%d on rank=%d"%(i,rank)
def image_gen_single(dataName, value, imgdpi, opmode, x_dat, cbarOn=True, plot_vtx=False)