GPUE  v1.0
GPU Gross-Pitaevskii Equation numerical solver for Bose-Einstein condensates
en.py
Go to the documentation of this file.
1 '''
2 en.py - GPUE: Split Operator based GPU solver for Nonlinear
3 Schrodinger Equation, Copyright (C) 2011-2015, 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 CPUs = os.environ['SLURM_JOB_CPUS_PER_NODE']
35 print "Number of cores: " + str(CPUs)
36 from numpy import genfromtxt
37 import math as m
38 import matplotlib as mpl
39 import numpy as np
40 import scipy as sp
41 import numpy.matlib
42 mpl.use('Agg')
43 import ConfigParser
44 import random as r
45 from decimal import *
46 
47 getcontext().prec = 4
48 c = ConfigParser.ConfigParser()
49 getcontext().prec = 4
50 c = ConfigParser.ConfigParser()
51 c.readfp(open(r'Params.dat'))
52 
53 xDim = int(c.getfloat('Params','xDim'))
54 yDim = int(c.getfloat('Params','yDim'))
55 gndMaxVal = int(c.getfloat('Params','gsteps'))
56 evMaxVal = int(c.getfloat('Params','esteps'))
57 incr = int(c.getfloat('Params','print_out'))
58 sep = (c.getfloat('Params','dx'))
59 dx = (c.getfloat('Params','dx'))
60 dy = (c.getfloat('Params','dx'))
61 dt = (c.getfloat('Params','dt'))
62 xMax = (c.getfloat('Params','xMax'))
63 yMax = (c.getfloat('Params','yMax'))
64 num_vort = 0#int(c.getfloat('Params','Num_vort'))
65 
66 data = numpy.ndarray(shape=(xDim,yDim))
67 K = np.reshape(np.array(open('K_0').read().splitlines(),dtype='f8'),(xDim,yDim))
68 V = np.reshape(np.array(open('V_0').read().splitlines(),dtype='f8'),(xDim,yDim))
69 X = np.array(open('x_0').read().splitlines(),dtype='f8')
70 Y = np.array(open('y_0').read().splitlines(),dtype='f8')
71 XM,YM = np.meshgrid(X,Y)
72 R = (XM**2+YM**2)
73 macheps = 7./3. - 4./3. - 1. #http://rstudio-pubs-static.s3.amazonaws.com/13303_daf1916bee714161ac78d3318de808a9.html
74 Q = (XM**2-YM**2)
75 
76 def expectValueR(dataName,i,Val):
77  real=open(dataName + '_' + str(i)).read().splitlines()
78  img=open(dataName + 'i_' + str(i)).read().splitlines()
79  a_r = np.array(real,dtype='f8') #64-bit double
80  a_i = np.array(img,dtype='f8') #64-bit double
81  wfcr = np.reshape(a_r[:] + 1j*a_i[:],(xDim,yDim))
82  return np.real(np.trapz(np.trapz(np.conj(wfcr)*Val*wfcr))*dx*dy)
83 
84 def energy_total(dataName,i):
85  real=open(dataName + '_' + str(i)).read().splitlines()
86  img=open(dataName + 'i_' + str(i)).read().splitlines()
87  a_r = np.array(real,dtype='f8') #64-bit double
88  a_i = np.array(img,dtype='f8') #64-bit double
89  wfcr = np.reshape(a_r[:] + 1j*a_i[:],(xDim,yDim))
90  wfcp = np.array(np.fft.fft2(wfcr))
91  wfcr_c = np.conj(wfcr)
92 
93  E1 = np.fft.ifft2(K*wfcp)
94  E2 = V*wfcr
95 
96  E_k = np.trapz(np.trapz(wfcr_c*E1))*dx*dy
97  E_vi = np.trapz(np.trapz(wfcr_c*E2))*dx*dy
98  return np.real(E_k + E_vi)
99 
100 #for ii in range(0,gndMaxVal,incr):
101 # print "E(t={} s)={}".format(ii*dt,energy_total('wfc_0_const',ii))
102 
103 for ii in range(0,evMaxVal,incr):
104 # print "E(t={} s)={}".format(ii*dt,energy_total('wfc_ev',ii))
105  #print "R(t={} s)={}".format(ii*dt,rad('wfc_ev',ii))
106  print "{},{}".format(ii*dt,expectValueR('wfc_ev',ii,R))
107 
def expectValueR(dataName, i, Val)
Definition: en.py:76
def energy_total(dataName, i)
Definition: en.py:84