示例#1
0
def time_particlescalars():
    import postpic as pp
    import timeit
    pp.chooseCode('dummy')
    dr1 = pp.readDump(0.01e6, dimensions=3)
    dr2 = pp.readDump(1.0e6, dimensions=3)
    ms1 = pp.MultiSpecies(dr1, 'electron')
    ms2 = pp.MultiSpecies(dr2, 'electron')
    testexprs = [
        'x', 'x + y + z', 'gamma', 'beta', 'angle_xy', 'angle_xaxis',
        'sqrt(x**2 + y**2 + z**2)', 'r_xyz',
        '(gamma > 1.5) & (angle_xaxis < 0.2) & (r_xyz < 2)'
    ]
    print('')
    print(
        'calculation times for n million particles, averaged over 3 calculations each...'
    )
    headformat = ' {:2s}  | {:6s} | {:6s} | {:s}'
    print(headformat.format('n', ' t', ' t/n', 'per particle quantity'))
    print(headformat.format('', ' ms', 'ms/mio', ''))

    def timeexpr(expr, ms):
        t = timeit.Timer(lambda: ms(expr))
        tc = t.timeit(number=3) / 3.0
        npartmio = len(ms) / 1e6
        print('{:4.2f} | {:6.2f} | {:6.2f} | "{}"'.format(
            npartmio, tc * 1e3, (tc * 1e3) / npartmio, expr))

    for expr in testexprs:
        for ms in (ms1, ms2):
            timeexpr(expr, ms)
示例#2
0
def time_particleidsort():
    import postpic as pp
    import numpy as np
    from timeit import default_timer as timer
    pp.chooseCode('dummy')
    dr = pp.readDump(1e6, dimensions=3)
    ms = pp.MultiSpecies(dr, 'electron')

    def timeid(ms, ids):
        t0 = timer()
        ms2 = ms.compress(ids)
        tf = timer()
        print('npart = {:.1e}, fraction_taken ={:6.2f}%, time ={:6.2f}ms' \
              .format(len(ms), len(ms2)/len(ms)*100, (tf-t0)*1e3))

    print('')
    print('time to take a fraction of the particles by their ids')
    timeid(ms, np.arange(100))
    timeid(ms, np.arange(len(ms) / 20))
    timeid(ms, np.arange(len(ms)))
示例#3
0
def time_particleidfilter():
    import postpic as pp
    import numpy as np
    from timeit import default_timer as timer
    pp.chooseCode('dummy')
    dr = pp.readDump(1e6, dimensions=3)
    ms = pp.MultiSpecies(dr, 'electron')

    def timefilter(ms, expr):
        t0 = timer()
        ms2 = ms.filter(expr)
        tf = timer()
        print('npart = {:.1e}, fraction_taken = {:6.2f}%, time = {:6.2f}ms, expr: "{}"' \
              .format(len(ms), len(ms2)/len(ms)*100, (tf-t0)*1e3, expr))

    print('')
    print('time to filter to a fraction of the particles by expression')
    timefilter(ms, 'x > 0')
    timefilter(ms, 'gamma > 1.5')
    timefilter(ms, '(gamma > 1.5) & (angle_xaxis < 0.2) & (r_xyz < 2)')
示例#4
0
 def setUp(self):
     pp.chooseCode('dummy')
     self.dr = pp.readDump(10000)
     self.p = pp.MultiSpecies(self.dr, 'electron')
#################
##  postpic define ###

import postpic as pp

print pp.__version__  # postpic version

pp.chooseCode('epoch')
dr = pp.readDump('Data/0020.sdf')
print(dr)
# the dumpreader knwos all the information of the simulation
print('The simulations was running on {} spatial dimensions.'.format(
    dr.simdimensions()))

# if needed, postpic can be bypassed and the underlying datastructure (sdf in this case)
# can be accessed directly via keys
print(dr.keys())
print dr['Header']

print(dr.listSpecies()
      )  # the multispecies Object is used to access particle data
ms = pp.MultiSpecies(dr, 'electron')
# ms is representing the species "Electrons"
print(ms)

x = ms('x')
print(len(x))

# you can look at  for a list of predefined values
#print pp.particle_scalars