In [1]:
import numpy as np
import pycuda.gpuarray as gpuarray
from pycuda.tools import make_default_context
import matplotlib as matplotlib
import pylab as plt

#-------------------------------------------------------------------------------------
from pywignercuda_path import SetPyWignerCUDA_Path
SetPyWignerCUDA_Path()
from GPU_Dirac2D import *

In [2]:
%matplotlib inline

In [3]:
class DefinePotential_Dirac2D( GPU_Dirac2D ):
    def __init__ (self):
        #....................Defining the geometry.....................................    
        gridDIM_X = 2*256
        gridDIM_Y = 2*256
        
        X_amplitude =16
        Y_amplitude =16
        
        dt = 0.01

        timeSteps =  1000
        skipFrames =  100
        #...................Defining the kinematic-dynamical constants.................
        self.mass = 1.
        self.c = 1.
        #...................Defining the potential and initial state parameters........
        hBar = 1
        #self.a = 2.
        #self.r = 5.

        self.px = 2.
        self.py = 0.
        
        
        self.energy = np.sqrt( (self.mass*self.c)**2 +  self.px**2 + self.py**2  )
        #Q = 1./(  self.mass + self.energy )
        #...................Defining the potential.....................................
       
        self.Potential_0_String = '0.'
        
        self.Potential_1_String = '0.'
        
        self.Potential_2_String = '0.'
        
        self.Potential_3_String = '0.'
        
        #..................Defining the output directory/file .........................
        self.fileName =  '/home/rcabrera/DATA/Dirac2D/Free.hdf5'

        #..............................................................................	

        amplitude = (X_amplitude,Y_amplitude)
        gridDIM   = (gridDIM_X,gridDIM_Y)

        #method = 'Hybrid'
        #method = 'Bandrauk'

        GPU_Dirac2D.__init__( self,gridDIM, amplitude ,dt,timeSteps, skipFrames = skipFrames,frameSaveMode='Spinor')

        
    def Set_Initial_Condition (self):

        def gaussian(x,y):
            return np.exp( - ( x**2 + y**2)/4. )
        
        self.Psi_init = self.Spinor_Particle_SpinUp(  (self.px,self.py) , gaussian )
        #self.Psi_init = self.Spinor_Particle_SpinDown( (self.px,self.py) , gaussian )
        #self.Psi_init = self.Spinor_AntiParticle_SpinUp(  (self.px,self.py) , gaussian )
        #self.Psi_init = self.Spinor_AntiParticle_SpinDown(  (self.px,self.py) , gaussian )
        
        norm = self.Norm( self.Psi_init )
        
        self.Psi_init /= norm

In [4]:
instance = DefinePotential_Dirac2D()

instance.Set_Initial_Condition()

#instance_Dirac3D.FilterElectrons(1)

print '                                      '
print ' dx = ', instance.dX

Psi_end = instance.Run ()


                                      
 dx =  0.0625
--------------------------------------------
              Dirac Propagator 2D           
--------------------------------------------
  save Mode  =   Spinor
                                                               
number of steps  =   1000  dt =  0.01
dX =  0.0625 dY =  0.0625
dPx =  0.196349540849 dPy =  0.196349540849
                                                               
  
 progress  0 %
 progress  9 %
 progress  19 %
 progress  29 %
 progress  39 %
 progress  49 %
 progress  59 %
 progress  69 %
 progress  79 %
 progress  89 %
 progress  99 %
 computational time  =  62.8656210899

In [5]:
Rho_end = instance.Density_From_Spinor(instance.Psi_end)

In [6]:
Rho_end.shape


Out[6]:
(512, 512)

In [7]:
def PlotDensity( Psi ):
    global_max =  0.12       #  Maximum value used to select the color range
    global_min =  -0.01

    Rho = instance.Density_From_Spinor(Psi)
    Rho = fftpack.fftshift( Rho )

    x1_min = -instance.X_amplitude
    x1_max = instance.X_amplitude - instance.dX

    p1_min = -instance.Y_amplitude
    p1_max = instance.Y_amplitude - instance.dY

    print ' max Rho =  ', np.max(Rho)
    #print ' min Rho =  ', np.min(Rho)
    print ' normalization = ', np.sum( Rho )*instance.dX*instance.dY

    zero_position =  abs( global_min) / (abs( global_max) + abs(global_min)) 
    wigner_cdict = {'red' 	: 	((0., 0., 0.),
                                (zero_position, 1., 1.), 
                                (1., 1., 1.)),
                        'green' :	((0., 0., 0.),
                                (zero_position, 1., 1.),
                                (1., 0., 0.)),
                        'blue'	:	((0., 1., 1.),
                                (zero_position, 1., 1.),
                                (1., 0., 0.)) }
    wigner_cmap = matplotlib.colors.LinearSegmentedColormap('wigner_colormap', wigner_cdict, 512)

    fig, ax = plt.subplots(figsize=(20, 7))

    cax = ax.imshow( Rho \
        ,origin='lower',interpolation='nearest',\
        extent=[x1_min, x1_max, p1_min, p1_max], vmin= global_min, vmax=global_max, cmap=wigner_cmap)

In [8]:
PlotDensity( instance.Psi_init )
PlotDensity( instance.load_Spinor(100)  )
PlotDensity( instance.load_Spinor(200)  )
PlotDensity( instance.load_Spinor(500)  )


 max Rho =   0.159154943092
 normalization =  1.0
 max Rho =   0.143444352973
 normalization =  1.0
 max Rho =   0.136933562156
 normalization =  1.0
 max Rho =   0.0986866702133
 normalization =  1.0

In [9]:
PlotDensity( instance.Psi_end );


 max Rho =   0.0567341212126
 normalization =  1.0

In [9]:


In [10]:
axis_font = {'size':'24'}


fig, ax = plt.subplots(figsize=(20, 7))

ax.plot( instance.timeRange ,  np.gradient(instance.X_average , instance.dt)  , 'g',
        label= '$\\frac{dx^1}{dt} $')

ax.plot( instance.timeRange ,  instance.Alpha1_average ,'r--' ,label='$c \\alpha^1$')

ax.set_xlabel(r'$t$',**axis_font)

ax.legend(bbox_to_anchor=(1.05, 0.5), loc=1, prop={'size':22})


Out[10]:
<matplotlib.legend.Legend at 0x7f59f6d87050>

In [11]:
axis_font = {'size':'24'}


fig, ax = plt.subplots(figsize=(20, 7))

ax.plot( instance.timeRange ,  np.gradient(instance.Y_average , instance.dt)   , 'g',
        label= '$\\frac{dx^2}{dt} $')

ax.plot( instance.timeRange ,  instance.Alpha2_average ,'r--' ,label='$c \\alpha^2$')

ax.set_xlabel(r'$t$',**axis_font)

ax.legend(bbox_to_anchor=(1.05, 0.5), loc=1, prop={'size':22})


Out[11]:
<matplotlib.legend.Legend at 0x7f59ed12a650>

In [12]:
axis_font = {'size':'24'}


fig, ax = plt.subplots(figsize=(20, 7))

ax.plot( instance.timeRange ,  instance.Beta_average  , 'g',
        label= '$\\langle\\gamma^0\\rangle $')

ax.set_xlabel(r'$t$',**axis_font)

ax.legend(bbox_to_anchor=(1.05, 0.5), loc=1, prop={'size':22})


Out[12]:
<matplotlib.legend.Legend at 0x7f59f6bc9cd0>

In [13]:
axis_font = {'size':'24'}


fig, ax = plt.subplots(figsize=(20, 7))


ax.plot( instance.timeRange ,  instance.Potential_0_average + instance.KEnergy_average, 'b-',
        label= '$ K + A_0 $')

ax.set_ylim(-0.,2.5)

ax.set_xlabel(r'$t$',**axis_font)

ax.legend(bbox_to_anchor=(1.05, 0.5), loc=1, prop={'size':22})


Out[13]:
<matplotlib.legend.Legend at 0x7f59ed0b6750>

In [14]:
axis_font = {'size':'24'}


fig, ax = plt.subplots(figsize=(20, 7))


ax.plot( instance.X_average ,  instance.Y_average , 'r-')

#ax.set_ylim(-8,5)
#ax.set_xlim(-3,3)

ax.set_xlabel(r'$x$',**axis_font)
ax.set_ylabel(r'$y$',**axis_font)

#ax.legend(bbox_to_anchor=(1.05, 0.9), loc=1, prop={'size':22})


Out[14]:
<matplotlib.text.Text at 0x7f59f6a72a50>

In [15]:
Psi_end_filtered = instance.FilterElectrons(-1, instance.Psi_end)


  
  	Filter Electron routine 
  

In [16]:
PlotDensity( 4*Psi_end_filtered )


 max Rho =   0.0350519575777
 normalization =  1.00991638882

In [16]: