Exemple #1
0
    def __init__(self,
                 chamb,
                 Dh,
                 Dt_sc=None,
                 PyPICmode='FiniteDifferences_ShortleyWeller',
                 sparse_solver='scipy_slu',
                 f_telescope=None,
                 target_grid=None,
                 N_nodes_discard=None,
                 N_min_Dh_main=None):

        print 'Start space charge init.'

        if PyPICmode == 'FiniteDifferences_ShortleyWeller':
            import PyPIC.FiniteDifferences_ShortleyWeller_SquareGrid as PIC_FDSW
            self.PyPICobj = PIC_FDSW.FiniteDifferences_ShortleyWeller_SquareGrid(
                chamb=chamb, Dh=Dh, sparse_solver=sparse_solver)
            #To be replaced by a property to make it general (from PyPIC modules not having xn, yn)
            self.xn = self.PyPICobj.xn
            self.yn = self.PyPICobj.yn
        elif PyPICmode == 'ShortleyWeller_WithTelescopicGrids':
            import PyPIC.FiniteDifferences_ShortleyWeller_SquareGrid as PIC_FDSW
            PyPICmain = PIC_FDSW.FiniteDifferences_ShortleyWeller_SquareGrid(
                chamb=chamb, Dh=Dh, sparse_solver=sparse_solver)
            import PyPIC.MultiGrid as PIC_MG
            self.PyPICobj = PIC_MG.AddTelescopicGrids(
                pic_main=PyPICmain,
                f_telescope=f_telescope,
                target_grid=target_grid,
                N_nodes_discard=N_nodes_discard,
                N_min_Dh_main=N_min_Dh_main,
                sparse_solver=sparse_solver)
            self.xn = None  #not implemented in this mode (for now)
            self.yn = None  #not implemented in this mode (for now)

        elif PyPICmode == 'FiniteDifferences_Staircase':
            import PyPIC.FiniteDifferences_Staircase_SquareGrid as PIC_FDSQ
            self.PyPICobj = PIC_FDSQ.FiniteDifferences_Staircase_SquareGrid(
                chamb=chamb, Dh=Dh, sparse_solver=sparse_solver)
            #To be replaced by a property to make it general (from PyPIC modules not having xn, yn)
            self.xn = self.PyPICobj.xn
            self.yn = self.PyPICobj.yn
        elif PyPICmode == 'FFT_PEC_Boundary':
            if chamb.chamb_type != 'rect':
                raise ValueError(
                    '''PyPICmode = 'FFT_PEC_Boundary' can be used only if chamb_type = 'rect' '''
                )
            import PyPIC.FFT_PEC_Boundary_SquareGrid as PIC_FFT_PEC
            self.PyPICobj = PIC_FFT_PEC.FFT_PEC_Boundary_SquareGrid(
                x_aper=chamb.x_aper, y_aper=chamb.y_aper, Dh=Dh)
            #To be replaced by a property to make it general (from PyPIC modules not having xn, yn)
            self.xn = None  #not implemented in this mode (for now)
            self.yn = None  #not implemented in this mode (for now)
        elif PyPICmode == 'FFT_OpenBoundary':
            if chamb.chamb_type != 'rect':
                raise ValueError(
                    '''PyPICmode = 'FFT_OpenBoundary' can be used only if chamb_type = 'rect' '''
                )
            import PyPIC.FFT_OpenBoundary_SquareGrid as PIC_FFT_Open
            self.PyPICobj = PIC_FFT_Open.FFT_OpenBoundary_SquareGrid(
                x_aper=chamb.x_aper, y_aper=chamb.y_aper, Dh=Dh)
            #To be replaced by a property to make it general (from PyPIC modules not having xn, yn)
            self.xn = None  #not implemented in this mode (for now)
            self.yn = None  #not implemented in this mode (for now)
        else:
            raise ValueError('PyPICmode not racognized')

        self.Dh = self.PyPICobj.Dh
        self.xg = self.PyPICobj.xg
        self.Nxg = self.PyPICobj.Nxg
        self.bias_x = self.PyPICobj.bias_x
        self.yg = self.PyPICobj.yg
        self.Nyg = self.PyPICobj.Nyg
        self.bias_y = self.PyPICobj.bias_y

        self.Dt_sc = Dt_sc
        self.t_last_recom = 0.

        self.U_sc_eV_stp = 0.

        self.flag_decimate = (self.Dt_sc is not None)
        self.flag_recomputed_sc = False

        print 'Done space charge init.'
Exemple #2
0
chamber = poly.polyg_cham_geom_object({
    'Vx':
    na([x_aper, -x_aper, -x_aper, x_aper]),
    'Vy':
    na([y_aper, y_aper, -y_aper, -y_aper]),
    'x_sem_ellip_insc':
    0.99 * x_aper,
    'y_sem_ellip_insc':
    0.99 * y_aper
})

picFDSW = PIC_FDSW.FiniteDifferences_ShortleyWeller_SquareGrid(chamb=chamber,
                                                               Dh=Dh)
picFFTPEC = PIC_PEC_FFT.FFT_PEC_Boundary_SquareGrid(x_aper=chamber.x_aper,
                                                    y_aper=chamber.y_aper,
                                                    Dh=Dh,
                                                    fftlib='pyfftw')
picFFT = PIC_FFT.FFT_OpenBoundary_SquareGrid(x_aper=chamber.x_aper,
                                             y_aper=chamber.y_aper,
                                             Dh=Dh,
                                             fftlib='pyfftw')

picFDSW.scatter(x_part, y_part, nel_part)
picFFTPEC.scatter(x_part, y_part, nel_part)
picFFT.scatter(x_part, y_part, nel_part)

N_rep = 1000

import time
t_start_sw = time.mktime(time.localtime())
for _ in range(N_rep):
    def __init__(self, chamb, Dh, Dt_sc=None, PyPICmode='FiniteDifferences_ShortleyWeller' , sparse_solver='scipy_slu',
                 f_telescope=None, target_grid=None, N_nodes_discard=None, N_min_Dh_main=None, Dh_U_eV=None):

        print('Start space charge init.')

        if PyPICmode == 'FiniteDifferences_ShortleyWeller':
            import PyPIC.FiniteDifferences_ShortleyWeller_SquareGrid as PIC_FDSW
            self.PyPICobj = PIC_FDSW.FiniteDifferences_ShortleyWeller_SquareGrid(chamb=chamb, Dh=Dh, sparse_solver=sparse_solver)
            #To be replaced by a property to make it general (from PyPIC modules not having xn, yn)
            self.xn = self.PyPICobj.xn
            self.yn = self.PyPICobj.yn
        elif PyPICmode == 'ShortleyWeller_WithTelescopicGrids':
            import PyPIC.FiniteDifferences_ShortleyWeller_SquareGrid as PIC_FDSW
            PyPICmain = PIC_FDSW.FiniteDifferences_ShortleyWeller_SquareGrid(chamb=chamb, Dh=Dh, sparse_solver=sparse_solver)
            import PyPIC.MultiGrid as PIC_MG
            self.PyPICobj = PIC_MG.AddTelescopicGrids(pic_main=PyPICmain, f_telescope=f_telescope, target_grid=target_grid,
                                                      N_nodes_discard=N_nodes_discard, N_min_Dh_main=N_min_Dh_main, sparse_solver=sparse_solver)
            self.xn = None  # not implemented in this mode (for now)
            self.yn = None  # not implemented in this mode (for now)

        elif PyPICmode == 'FiniteDifferences_Staircase':
            import PyPIC.FiniteDifferences_Staircase_SquareGrid as PIC_FDSQ
            self.PyPICobj = PIC_FDSQ.FiniteDifferences_Staircase_SquareGrid(chamb=chamb, Dh=Dh, sparse_solver=sparse_solver)
            #To be replaced by a property to make it general (from PyPIC modules not having xn, yn)
            self.xn = self.PyPICobj.xn
            self.yn = self.PyPICobj.yn
        elif PyPICmode == 'FFT_PEC_Boundary':
            if chamb.chamb_type != 'rect':
                raise ValueError('''PyPICmode = 'FFT_PEC_Boundary' can be used only if chamb_type = 'rect' ''' )
            import PyPIC.FFT_PEC_Boundary_SquareGrid as PIC_FFT_PEC
            self.PyPICobj = PIC_FFT_PEC.FFT_PEC_Boundary_SquareGrid(x_aper=chamb.x_aper, y_aper=chamb.y_aper, Dh=Dh)
            #To be replaced by a property to make it general (from PyPIC modules not having xn, yn)
            self.xn = None  # not implemented in this mode (for now)
            self.yn = None  # not implemented in this mode (for now)
        elif PyPICmode == 'FFT_OpenBoundary':
            if chamb.chamb_type != 'rect':
                raise ValueError('''PyPICmode = 'FFT_OpenBoundary' can be used only if chamb_type = 'rect' ''' )
            import PyPIC.FFT_OpenBoundary as PIC_FFT_Open
            if len(np.atleast_1d(Dh)) == 2:
                self.PyPICobj = PIC_FFT_Open.FFT_OpenBoundary(x_aper=chamb.x_aper, y_aper=chamb.y_aper, dx=Dh[0], dy=Dh[1])
            else:
                self.PyPICobj = PIC_FFT_Open.FFT_OpenBoundary(x_aper=chamb.x_aper, y_aper=chamb.y_aper, Dh=Dh)

            #To be replaced by a property to make it general (from PyPIC modules not having xn, yn)
            self.xn = None  # not implemented in this mode (for now)
            self.yn = None  # not implemented in this mode (for now)
        else:
            raise ValueError('PyPICmode not recognized')

        self.Dh = self.PyPICobj.Dh
        self.xg = self.PyPICobj.xg
        self.Nxg = self.PyPICobj.Nxg
        self.bias_x = self.PyPICobj.bias_x
        self.yg = self.PyPICobj.yg
        self.Nyg = self.PyPICobj.Nyg
        self.bias_y = self.PyPICobj.bias_y

        self.Dt_sc = Dt_sc
        self.t_last_recom = 0.

        self.U_sc_eV_stp = 0.

        self.flag_decimate = (self.Dt_sc is not None)
        self.last_recomputation_check = False

        self.flag_em_tracking = False
        if Dh_U_eV is not None:
            self.evaluate_U_eV = True
            self.Dh_U_eV = Dh_U_eV
            self.xn_U_eV, self.yn_U_eV=np.meshgrid(
                    np.arange(-chamb.x_aper*1.01, chamb.x_aper*1.01, Dh_U_eV),
                    np.arange(-chamb.y_aper*1.01, chamb.y_aper*1.01, Dh_U_eV))

            self.xn_U_eV = self.xn_U_eV.T.flatten()
            self.yn_U_eV = self.yn_U_eV.T.flatten()
        else:
            self.evaluate_U_eV = False


        self.comm = None
        print('Done space charge init.')