Exemple #1
0
    def __init__(self, *file_names, do_print=False):
        Configuration.__init__(self, *file_names)

        #--------------------------------------------------
        # problem specific initializations
        if do_print:
            print("Initializing gyration setup...")

        #--------------------------------------------------
        # particle initialization

        #local variables just for easier/cleaner syntax
        c = self.cfl

        self.larmor = self.gamma * c**2
        self.beta = sqrt(1 - 1 / self.gamma**2.)
        self.vy = sqrt(self.gamma**2. - 1)
        self.vy = self.beta * self.gamma

        #plasma reaction & subsequent normalization
        self.omp = c / self.c_omp
        self.qe = -1

        #--------------------------------------------------
        # field initialization

        self.Nx = 1
        self.Ny = 1
        self.Nz = 1
        self.NxMesh = int(self.larmor * 2.2)
        self.NyMesh = int(self.larmor * 2.2)
        self.NzMesh = 1

        self.dx = 1.0
        self.dy = 1.0
        self.dz = 1.0

        self.x_start = np.floor(self.larmor * 0.1)

        print(self.larmor)
        print(self.NxMesh)
        print(self.x_start)

        #---------cold plasma-----------
        self.bphi = 90.0  #Bfield z angle (bphi=0  bz, bphi=90 -> x-y plane)
        self.btheta = 0.0  #Bfield x-y angle: btheta=0 -> parallel

        # set external magnetic field strength

        self.binit = 1.0
Exemple #2
0
def parse_input():

    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        '--conf',
                        dest='conf_filename',
                        default=None,
                        type=str,
                        help='Name of the configuration file (default: None)')

    parser.add_argument(
        '-l',
        '--lap',
        dest='lap',
        default=None,
        type=int,
        help='Specific lap to analyze (default: all that can be found)')

    parser.add_argument('-d',
                        '--dir',
                        dest='fdir',
                        default=None,
                        type=str,
                        help='Directory to analyze')

    parser.add_argument('-v',
                        '--var',
                        dest='var',
                        default=None,
                        type=str,
                        help='Variable to analyze')

    args = parser.parse_args()
    #args = parser.parse_known_args()

    if not (args.conf_filename == None):
        conf = Configuration(args.conf_filename)
        fdir = conf.outdir

    if not (args.fdir == None):
        fdir = args.fdir

        #look for conf file inside dir
        if args.conf_filename == None:
            print("looking for Conf file inside {}".format(args.fdir))
            print("TODO: not implemented")

    return conf, fdir, args
Exemple #3
0
    plt.rc('axes', labelsize=8)

    gs = plt.GridSpec(1, 2)
    gs.update(hspace=0.5)
    gs.update(wspace=0.07)

    axs = []
    axs.append(plt.subplot(gs[0]))
    axs.append(plt.subplot(gs[1]))

    # what to plot
    ispcs = 0
    vdir = "x"

    prefix = 'twostream/out/'
    conf = Configuration('config-twostream-relativistic.ini')

    #simulation box size
    xmin = 0.0
    ymin = 0.0
    xmax = conf.dx * conf.Nx * conf.NxMesh
    ymax = conf.dy * conf.Ny * conf.NyMesh

    # create panels from snapshots
    laps = range(0, 4001, 1000)
    for i, lap in enumerate(laps):
        print(lap)

        # check if this is top/bottom panel
        if i == 0:
            top = True
Exemple #4
0
    def __init__(self, *file_names, do_print=False):
        Configuration.__init__(self, *file_names)

        #-------------------------------------------------- 
        # problem specific initializations
        if do_print:
            print("Initializing shock setup...")
    
        #-------------------------------------------------- 
        # particle initialization

        #local variables just for easier/cleaner syntax
        me  = np.abs(self.me)
        mi  = np.abs(self.mi)
        c   = self.cfl
        ppc = self.ppc*2.0 #multiply x2 to account for 2 species/pair plasma

        # if gammas < 1, we interpret it as beta/c
        if self.gamma == 0:
            self.gamma = 1.0
            self.beta  = 0.0
        else:
            if(self.gamma < 1.):
                self.gamma = sqrt(1./(1.-self.gamma**2.)) 
            self.beta = sqrt(1.-1./self.gamma**2.)
        
	#plasma reaction & subsequent normalization
        omp=c/self.c_omp
        self.qe = -(omp**2.*self.gamma)/((ppc*.5)*(1.+me/mi)) 
        self.qi = -self.qe 

        me *= abs(self.qi)
        mi *= abs(self.qi)

        #temperatures
        self.delgam_e = self.delgam
        self.delgam_i = self.temp_ratio*self.delgam_e
        
        #--------------------------------------------------
        # printing 

        if do_print:
            print("init: Positron thermal spread: ", self.delgam_i)
            print("init: Electron thermal spread: ", self.delgam_e)

        sigmaeff = self.sigma #* temperature corrections
        if do_print:
            print("init: Alfven (outflow) three-velocity: ",sqrt(sigmaeff/(1.+sigmaeff)))
            print("init: Ion beta: ",     2.*self.delgam_i/(self.sigma*(mi/me+1.)/(mi/me)) )
            print("init: Electron beta: ",2.*self.delgam_e/(self.sigma*(mi/me+1.)) )

        #-------------------------------------------------- 
        # field initialization

        #---------cold plasma-----------
        # parse external magnetic field strength from sigma_ext
	#self.bz_ext = sqrt( (self.gamma-1.0)*.5*ppc*c**2*(mi+me)*self.sigma_ext)

	#determine initial magnetic field based on magnetization sigma which 
        #is magnetic energy density/ kinetic energy density
	#this definition works even for nonrelativistic flows. 
	#self.binit = sqrt((self.gamma)*ppc*.5*c**2.*(mi+me)*self.sigma)


        #----------hot plasma----------
        corrdelgam_qe = 1.0
        corrdelgam_sig = 1.0

        delgam_i = self.delgam_i
        delgam_e = self.delgam_e

        zeta=delgam_i/(0.24 + delgam_i)
        gad_i=1./3.*(5 - 1.21937*zeta + 0.18203*zeta**2 - 0.96583*zeta**3 + 2.32513*zeta**4 - 2.39332*zeta**5 + 1.07136*zeta**6)
        delgam_e=self.delgam*mi/me*self.temp_ratio 
        zeta=delgam_e/(0.24 + delgam_e)
        gad_e=1./3.*(5 - 1.21937*zeta + 0.18203*zeta**2 - 0.96583*zeta**3 + 2.32513*zeta**4 - 2.39332*zeta**5 + 1.07136*zeta**6)

        self.binit=1.*sqrt(ppc*.5*c**2.* \
                (mi*(1.+corrdelgam_sig*gad_i/(gad_i-1.)*self.delgam_i)+me*(1.+ \
                corrdelgam_sig*gad_e/(gad_e-1.)*self.delgam_e))*self.sigma)

        if do_print:
            print("init: sigma: ", self.sigma)
            print("init: B_guide: ", self.binit)


        #possibly moving piston wall
        if(self.wallgamma < 1.):
            self.wallgamma = sqrt(1./(1.-self.wallgamma**2.)) 
        self.beta = sqrt(1.-1./self.gamma**2.)


        #-------------------------------------------------- 
        # radiation drag, if any

        if "gammarad" in self.__dict__:
            if not(self.gammarad == 0.0):
                self.drag_amplitude = 0.1*self.binit/(self.gammarad**2.0)

                if do_print:
                    print("using radiation drag...")
                    print(" drag amplitude: {} with gamma_rad: {}".format(self.drag_amplitude, self.gammarad))
        else:
            self.gammarad = 0.0

        if "radtemp" in self.__dict__:
            if not(self.radtemp == 0.0):
                if do_print:
                    print("using radiation drag with temperature...")
                    print(" drag temperature: {}".format(self.radtemp))
        else:
            self.radtemp = 0.0
Exemple #5
0
    plt.rc('ytick', labelsize=8)
    plt.rc('axes', labelsize=8)

    gs = plt.GridSpec(1, 2)
    gs.update(hspace=0.5)
    gs.update(wspace=0.07)

    axs = []
    axs.append(plt.subplot(gs[0]))
    axs.append(plt.subplot(gs[1]))

    # what to plot
    ispcs = 0
    vdir = "x"
    prefix = "../projects/tests/"
    conf = Configuration(prefix + 'config-landau.ini')

    #simulation box size
    xmin = 0.0
    ymin = 0.0
    xmax = conf.dx * conf.Nx * conf.NxMesh
    ymax = conf.dy * conf.Ny * conf.NyMesh

    # create panels from snapshots
    laps = [0, 1, 2]
    for i, lap in enumerate(laps):

        # check if this is top/bottom panel
        if i == 0:
            top = True
        else:
Exemple #6
0
import numpy as np
import matplotlib.pyplot as plt
import h5py
import sys, os
import matplotlib.ticker as ticker
from scipy.stats import mstats
from scipy.optimize import curve_fit

from combine_files import combine_files, combine_tiles
from configSetup import Configuration

#--------------------------------------------------
# combine multiple files
fdir = 'weibel/out/'
conf = Configuration('config-weibel.ini')

print("files...")
ex = combine_files(fdir, "field", "ex", conf)
ey = combine_files(fdir, "field", "ey", conf)
ez = combine_files(fdir, "field", "ez", conf)
bx = combine_files(fdir, "field", "bx", conf)
by = combine_files(fdir, "field", "by", conf)
bz = combine_files(fdir, "field", "bz", conf)
rho = combine_files(fdir, "field", "rho", conf)
ekin = combine_files(fdir, "analysis", "edens", conf, isp=0)

#--------------------------------------------------
# read simulation data from file
print "Ex shape:", np.shape(ex)

#Read simulation values
Exemple #7
0
def flatten_spatial(arr):
    return arr.reshape(arr.shape[:-3] + (-1, )).T


read_files = True
read_runf = False

#--------------------------------------------------
# read simulation data from file
#fdir = 'twostream/out/'
fdir = 'twostream_kebne/ub2/'

if read_files:
    #conf = Configuration('config-twostream-relativistic.ini')
    conf = Configuration(fdir + 'config-ts2.ini')
    #--------------------------------------------------

    print("files...")
    ex_sparse = flatten_spatial(combine_files(fdir, "field", "ex", conf))
    #ey_sparse =  flatten_spatial( combine_files(fdir, "field",    "ey",   conf) )
    #ez_sparse =  flatten_spatial( combine_files(fdir, "field",    "ez",   conf) )
    #bx_sparse =  flatten_spatial( combine_files(fdir, "field",    "bx",   conf) )
    #by_sparse =  flatten_spatial( combine_files(fdir, "field",    "by",   conf) )
    #bz_sparse =  flatten_spatial( combine_files(fdir, "field",    "bz",   conf) )
    rh_sparse = flatten_spatial(combine_files(fdir, "field", "rho", conf))
    ed_sparse1 = flatten_spatial(
        combine_files(fdir, "analysis", "edens", conf, isp=0))
    ed_sparse2 = flatten_spatial(
        combine_files(fdir, "analysis", "edens", conf, isp=1))
    ed_sparse = ed_sparse1 + ed_sparse2
Exemple #8
0
        tile = f[dset][fvar][()]
        tile = np.reshape(tile, (NzMesh, NyMesh, NxMesh))

        for s in range(NzMesh):
            for r in range(NyMesh):
                for q in range(NxMesh):
                    arr[ii + q, jj + r, kk + s] = tile[s, r, q]

    return arr


##################################################

if __name__ == "__main__":

    conf = Configuration('../pic/config-weibel.ini')
    fdir = "../pic/weibel/out/"
    #fname = "field"
    #var = "ex"

    fname = "analysis"
    var = "mgamma"

    #arrs = combine_files(fdir, fname, var, conf)
    #arrs = combine_files(fdir, fname, var, conf, func=np.max)
    arrs = combine_files(fdir, fname, var, conf, isp=0)

    print(arrs)
    print(arrs.shape)
    print(len(arrs))
Exemple #9
0
    # Timer for profiling
    timer = Timer(["total", "init", "step", "io"])
    timer.start("total")
    timer.start("init")

    # parse command line arguments
    parser = argparse.ArgumentParser(
        description='Simple PIC-Maxwell simulations')
    parser.add_argument('--conf',
                        dest='conf_filename',
                        default=None,
                        help='Name of the configuration file (default: None)')
    args = parser.parse_args()
    if args.conf_filename == None:
        conf = Configuration('config-landau.ini')
    else:
        print("Reading configuration setup from ", args.conf_filename)
        conf = Configuration(args.conf_filename)

    #grid = plasma.Grid(conf.Nx, conf.Ny)
    grid = corgi.Grid(conf.Nx, conf.Ny, conf.Nz)

    xmin = 0.0
    xmax = conf.Nx * conf.NxMesh  #XXX scaled length
    ymin = 0.0
    ymax = conf.Ny * conf.NyMesh

    grid.set_grid_lims(xmin, xmax, ymin, ymax)

    #init.loadMpiRandomly(grid)
Exemple #10
0
    #axs.append( plt.subplot(gs[1]) )
    #axs.append( plt.subplot(gs[2]) )
    #axs.append( plt.subplot(gs[3]) )
    #axs.append( plt.subplot(gs[4]) )
    #axs.append( plt.subplot(gs[5]) )
    #axs.append( plt.subplot(gs[6]) )
    #axs.append( plt.subplot(gs[7]) )

    # Timer for profiling
    timer = Timer(["total", "init", "step", "io"])
    timer.start("total")
    timer.start("init")

    ##################################################
    #initialize grid
    conf = Configuration('config-landau.ini')
    #conf = Configuration('config-twostream.ini')
    #conf = Configuration('config-twostream-fast.ini')
    #conf = Configuration('config-bump-on-tail.ini')
    #conf = Configuration('config-twostream-relativistic.ini')
    #conf = Configuration('config-plasmaosc.ini')
    #conf = Configuration('config-dispersion.ini')

    grid = plasma.Grid(conf.Nx, conf.Ny)

    xmin = 0.0
    xmax = conf.dx * conf.Nx * conf.NxMesh
    ymin = 0.0
    ymax = conf.dy * conf.Ny * conf.NyMesh

    grid.set_grid_lims(xmin, xmax, ymin, ymax)
Exemple #11
0
    # Timer for profiling
    timer = Timer()
    timer.start("total")
    timer.start("init")

    timer.do_print = do_print


    # parse command line arguments
    parser = argparse.ArgumentParser(description='Simple PIC-Maxwell simulations')
    parser.add_argument('--conf', dest='conf_filename', default=None,
                       help='Name of the configuration file (default: None)')
    args = parser.parse_args()
    if args.conf_filename == None:
        conf = Configuration('gyration.ini', do_print=do_print) 
    else:
        if do_print:
            print("Reading configuration setup from ", args.conf_filename)
        conf = Configuration(args.conf_filename, do_print=do_print)


    grid = corgi.Grid(conf.Nx, conf.Ny, conf.Nz)

    xmin = 0.0
    xmax = conf.Nx*conf.NxMesh #XXX scaled length
    ymin = 0.0
    ymax = conf.Ny*conf.NyMesh
    grid.set_grid_lims(xmin, xmax, ymin, ymax)

    #init.loadMpiRandomly(grid)
Exemple #12
0
    axs.append( plt.subplot(gs[3]) )
    axs.append( plt.subplot(gs[4]) )
    axs.append( plt.subplot(gs[5]) )
    axs.append( plt.subplot(gs[6]) )
    axs.append( plt.subplot(gs[7]) )


    # Timer for profiling
    timer = Timer(["total", "init", "step", "io"])
    timer.start("total")
    timer.start("init")


    ################################################## 
    #initialize grid
    conf = Configuration('config-plasmaosc.ini') 
    #conf = Configuration('config-dispersion.ini') 

    grid = plasma.Grid(conf.Nx, conf.Ny)

    xmin = 0.0
    xmax = conf.dx*conf.Nx*conf.NxMesh
    ymin = 0.0
    ymax = conf.dy*conf.Ny*conf.NyMesh

    grid.set_grid_lims(xmin, xmax, ymin, ymax)


    #grid.initMpi()
    #loadMpiXStrides(grid)
Exemple #13
0
    plt.rc('font', family='serif', size=12)
    plt.rc('xtick')
    plt.rc('ytick')

    gs = plt.GridSpec(4, 1)
    gs.update(hspace=0.5)

    axs = []
    axs.append(plt.subplot(gs[0]))
    axs.append(plt.subplot(gs[1]))
    axs.append(plt.subplot(gs[2]))
    axs.append(plt.subplot(gs[3]))

    ##################################################
    #initialize node
    conf = Configuration('config.ini')

    node = plasma.Grid(conf.Nx, conf.Ny)
    node.setGridLims(conf.xmin, conf.xmax, conf.ymin, conf.ymax)

    #node.initMpi()
    #loadMpiXStrides(node)

    init.loadCells(node, conf)

    ##################################################
    # Path to be created
    if node.master:
        if not os.path.exists(conf.outdir):
            os.makedirs(conf.outdir)