예제 #1
0
def make_particles(PD):
    '''Create test particle array'''
    
    particles = particle_data.particle_data(_PD['n_macro'], _PD['charge'], _PD['mass'], _PD['weight'])

    #Add r data - better to use linspace than arange
    particles.r = np.linspace(0.1*PD['R'],0.9*PD['R'],particles.np)
    particles.pr = -particles.mc * np.linspace(0.1, .5,particles.np)
    
    
    particles.ell = particles.weight*consts.electron_mass*consts.c*particles.r
    
    #Add z data 
    particles.z = np.linspace(0.1*PD['Z'],0.9*PD['Z'],particles.np) 
    particles.pz = particles.mc * np.linspace(0., 10., particles.np)

    return particles
예제 #2
0
def make_particles(PD):
    # instantiate particle data
    ptcl_data = particle_data.particle_data(PD['num_p'], PD['charge'],
                                            PD['mass'], PD['weight'])

    # Add r data - evenly distribute out to r = R
    ptcl_data.r = np.arange(0., PD['R'],
                            PD['R'] / PD['num_p']) + PD['R'] / PD['num_p']
    # Add pr and ell data - evenly distribute pr out to PR
    ptcl_data.pr = ptcl_data.mc * np.arange(0., PD['PR'],
                                            PD['PR'] / PD['num_p'])
    ptcl_data.ell = ptcl_data.r * ptcl_data.pr * .1

    # Add z data - evenly distribute out to z = Z/10.
    ptcl_data.z = np.linspace(
        0, _PD['Z'] / 10., _PD['num_p'])  #ptcl_data.z = np.zeros(PD['num_p'])
    ptcl_data.pz = ptcl_data.mc * np.arange(0., PD['Z'], PD['Z'] / PD['num_p'])

    return ptcl_data
예제 #3
0
def vary_rz_modes(mode_pair, PD, ns=1e2):
    '''
    Simulate ns number of steps of size ss using npart particles and a number of modes
    specified by mode_pair.

    Arguments:
        mode_pair (tuple): [n_r,n_z]
        PD (dict): dictionary of other fixed parameters
        ns (Optional[int]) : number of steps to run. Defaults to 100.

    Returns:
        timing (float): number of seconds/macroparticle/mode

    '''
    num_steps = ns
    PD['n_r'] = mode_pair[0]
    PD['n_z'] = mode_pair[1]
    num_modes = mode_pair[0] + mode_pair[1]
    PD['n_macro'] = PD['np_mode'] * num_modes
    num_particles = PD['n_macro']
    PD['weight'] = PD['n_e'] / PD['n_macro']

    # create fields, particles, integrator
    particles = particle_data.particle_data(PD['n_macro'], PD['charge'],
                                            PD['mass'], PD['weight'])
    fields = field_data.field_data(PD['Z'], PD['R'], PD['n_z'], PD['n_r'])
    create_init_conds(particles, fields, PD)

    my_integrator = integrator.integrator(PD['dt'], fields)

    step = 0

    #print "Running {} total modes and {} particles".format(num_modes, num_particles)

    #t0 = time.time()
    while step < num_steps:
        my_integrator.second_order_step(particles, fields)

        step = step + 1

    return
예제 #4
0
from rssympim.sympim_rz.data import particle_data, field_data
from rssympim.sympim_rz.integrators import integrator
import numpy as np

from matplotlib import pyplot as plt

import time


n_ptcls = 1000
n_r = 10
n_z = 10

ptcl_data = particle_data.particle_data(n_ptcls, 1., 1.3, 33.5)
fld_data  = field_data.field_data(5., 2., n_r, n_z)

fld_data.mode_coords = np.ones((n_r, n_z, 2))

ptcl_data.r  = np.ones(n_ptcls)
for idx in range(0, n_ptcls):
    ptcl_data.r[idx] *= idx*(4.)/n_ptcls + .01
ptcl_data.pr = ptcl_data.mc*np.arange(0.,.5,.5/n_ptcls)
ptcl_data.ell = ptcl_data.r*ptcl_data.pr*.1

ptcl_data.z = np.zeros(n_ptcls)
ptcl_data.pz = ptcl_data.mc*np.arange(0.,10.,10./n_ptcls)

dt = .1/np.amax(fld_data.omega)

my_integrator = integrator.integrator(dt, fld_data)
예제 #5
0
l_r = plasma_widths*2.*np.pi/k_p # cm
l_z = plasma_lengths*2.*np.pi/k_p # cm
volume = np.pi*l_r*l_r*l_z

# Domain parameters
n_electrons = n0*volume

# Simulation parameters
n_r_modes = plasma_widths*modes_per_r
n_z_modes = plasma_lengths*modes_per_z

n_macro_ptcls = ppm*n_r_modes*n_z_modes
macro_weight = n_electrons/n_macro_ptcls

# Create simulation objects
ptcl_data = particle_data.particle_data(n_macro_ptcls, charge, mass, macro_weight)
fld_data = field_data.field_data(l_z, l_r, n_z_modes, n_r_modes)

# Ten steps per fastest frequency
dt = 0.1*2*np.pi/np.amax(fld_data.omega)

# run for ten plasma periods
run_time = 50*dt #4.*np.pi/k_p

# Set the diagnostics
compute_energy = False

my_integrator = integrator.integrator(dt, fld_data.omega)

# Initial conditions
for ptcl_idx in range(0, n_macro_ptcls):
예제 #6
0
from rssympim.sympim_rz.data import field_data, particle_data
from rssympim.sympim_rz.integrators import integrator

import numpy as np

import timeit

n_ptcls = 40000
n_r = 40
n_z = 100
my_fields = field_data.field_data(1., 1., n_r, n_z)
my_ptcls = particle_data.particle_data(n_ptcls, 1., 1., 1.)

my_ptcls.r = np.ones(n_ptcls)
for idx in range(0, n_ptcls):
    my_ptcls.r[idx] *= idx * (4.) / n_ptcls + .01
my_ptcls.pr = -my_ptcls.mc * np.arange(0., .5, .5 / n_ptcls)
my_ptcls.ell = my_ptcls.r * my_ptcls.pr
my_ptcls.z = np.zeros(n_ptcls)
my_ptcls.pz = my_ptcls.mc * np.arange(0., 10., 10. / n_ptcls)

my_integrator = integrator.integrator(.01, my_fields.omega)

my_time = timeit.timeit('my_integrator.single_step(my_ptcls, my_fields)')

print my_time
예제 #7
0
#######################

# Import the particle and field initial conditions
ptcl_io = particle_io.particle_io('electrons')
fld_io = field_io.field_io('fields')

#
# Create the particle and field data classes
#

# particle data first
r, pr, z, pz, pl, weight, charge, mass = \
    ptcl_io.read_ptcls(particle_file)
n_macro = np.shape(r)[0]

electrons = particle_data.particle_data(n_macro, charge, mass, weight)
electrons.r = r
electrons.z = z

electrons.pr = pr
electrons.pz = pz

electrons.ell = pl

electrons.weight = weight

# field data second
n_modes_z, n_modes_r, L, R, P_omega, Q_omega, P_dc, Q_dc = \
    fld_io.read_field(fields_file)

fields = field_data.field_data(L, R, n_modes_z, n_modes_r)
예제 #8
0
ind = np.zeros(size)

for i in range(size):
    if i < n_left:
        inc += 1
    end[i] += n_ptcls_per_core * (i + 1)
    end[i] += inc
    if i + 1 < size:
        ind[i + 1] += n_ptcls_per_core * (i + 1)
        ind[i + 1] += inc

fld_data = field_data.field_data(length, radius, n_modes_z, n_modes_r)
ptcl_data = particle_data.particle_data(n_ptcls_per_core,
                                        charge,
                                        mass,
                                        macro_weight,
                                        n_total=n_macro_ptcls,
                                        end=end,
                                        ind=ind)

dtau = 0.1 * 2. * np.pi / np.max(fld_data.omega)

# Initial condition for a plasma wave

fld_data.omega_coords[0, 0,
                      0] = plasma_wave_amplitude * fld_data.mode_mass[0, 0]

# Initial conditions
#np.random.seed(0)
# uniform particle distribution in x, y, z
x = radius * np.random.rand(n_ptcls_per_core)