GPUE  v1.0
GPU Gross-Pitaevskii Equation numerical solver for Bose-Einstein condensates
mpi_vis.py
Go to the documentation of this file.
1 '''
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.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
8 met:
9 
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 
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.
16 
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.
20 
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.
32 '''
33 import os
34 from mpi4py import MPI
35 CPUs = 1#os.environ['SLURM_JOB_CPUS_PER_NODE']
36 from numpy import genfromtxt
37 import math as m
38 import matplotlib as mpl
39 import matplotlib.tri as tri
40 import numpy as np
41 import scipy as sp
42 from scipy.spatial import Voronoi, voronoi_plot_2d
43 import numpy.matlib
44 mpl.use('Agg')
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
49 import ConfigParser
50 import random as r
51 from decimal import *
52 import stats
53 import hist3d
54 
55 getcontext().prec = 4
56 c = ConfigParser.ConfigParser()
57 getcontext().prec = 4
58 c = ConfigParser.ConfigParser()
59 c.readfp(open(r'Params.dat'))
60 
61 #Default value for wavefunction density max; modified by initially loaded wavefunction set,
62 # and used for all subsequent plotting.
63 maxDensityVal=5e7
64 
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'))
75 num_vort = 0#int(c.getfloat('Params','Num_vort'))
76 
77 data = numpy.ndarray(shape=(xDim,yDim))
78 
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') #128-bit complex
83  a1_i = numpy.asanyarray(img,dtype='f8') #128-bit complex
84  a1 = a1_r[:] + 1j*a1_i[:]
85  b1 = np.reshape(a1,(xDim,yDim))
86 
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') #128-bit complex
91  a_i = numpy.asanyarray(img,dtype='f8') #128-bit complex
92  a = a_r[:] + 1j*a_i[:]
93  b = np.transpose(np.reshape(a,(xDim,yDim))) #Transpose to match matlab plots
94  if value=0:
95  maxDensityVal=np.max(np.abs(a)**2)
96  startBit = 0x00
97 
98  try:
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)
104  startBit=0x01
105 
106  if opmode & 0b100000 > 0:
107  nameStr = dataName+"r_"+str(value)
108 
109  fig, ax = plt.subplots()
110  f = plt.imshow( (abs(b)**2), cmap='hot', vmin=0, vmax=maxDensityVal, interpolation='none',)
111  #extent=[-xMax, xMax, -xMax, xMax])
112  tstr = str(value*dt)
113  plt.title('t=' + tstr + " s", fontsize=28)
114 
115  if cbarOn==True:
116  tbar = fig.colorbar(f)
117 
118  plt.gca().invert_yaxis()
119  if plot_vtx==True:
120  if startBit==0x00:
121  zVort = zip(vorts[0,:],vorts[1,:], vorts[3,:])
122  else:
123  zVort = zip(vorts[1,:], vorts[3,:], [0, 1, 2, 3])
124  for x, y, z in zVort:
125  if z==0:
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')])
128  else:
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')])
131  plt.axis('equal')
132  plt.axis('off')
133  if plot_vtx==True:
134  plt.savefig(dataName+"r_"+str(value)+"_abspsi2_num.png",dpi=imgdpi, bbox_inches='tight')
135  else:
136  plt.savefig(dataName+"r_"+str(value)+"_abspsi2_nonum.png",dpi=imgdpi, bbox_inches='tight')
137  plt.close()
138 
139  print "Saved figure: " + str(value) + ".png"
140  plt.close()
141  else:
142  print "File(s) " + str(value) +".png already exist."
143 
144 if __name__ == '__main__':
145  import sys
146  cbarOn = sys.argv[1].lower() == 'true'
147  plot_vtx = sys.argv[2].lower() == 'true'
148  gndImgList=[]
149  evImgList=[]
150  x_coord = np.loadtxt('x_0', unpack=True)
151 
152  comm = MPI.COMM_WORLD
153  size = comm.size
154  rank = comm.rank
155  print "Rank %d/%d initialised"%(rank,size-1)
156 
157  arrG = np.array_split( xrange(0,gndMaxVal,incr), size)
158  arrE = np.array_split( xrange(0,evMaxVal,incr), size)
159 
160  for i in arrG[rank]:
161  gndImgList.append(i)
162  for i in arrE[rank]:
163  evImgList.append(i)
164 
165  while gndImgList:
166 
167  print "Processing data index=%d on rank=%d"%(i,rank)
168  i=gndImgList.pop()
169 
170  try:
171  image_gen_single("wfc_0_ramp", i, 400, 0b100000, x_coord, cbarOn, plot_vtx)
172  except Exception as e:
173  print "Unable to process wfc_0_ramp data index=%d on rank=%d"%(i,rank)
174  try:
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)
178 
179  while evImgList:
180  print "Processing data index=%d on rank=%d"%(i,rank)
181  i=evImgList.pop()
182  try:
183  image_gen_single("wfc_ev", i, 400, 0b100000, x_coord, cbarOn, plot_vtx)
184  print "Processed data index=%d on rank=%d"%(i,rank)
185 
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)
Definition: mpi_vis.py:79