|
| 1 | +import numpy as np |
| 2 | +import pylab as pl |
| 3 | +from scipy.constants import e as qe |
| 4 | +import mystyle as ms |
| 5 | + |
| 6 | +# build chamber |
| 7 | +x_aper = 2e-2; y_aper=1e-2 |
| 8 | +import geom_impact_ellip as ell |
| 9 | +chamber = ell.ellip_cham_geom_object(x_aper = x_aper, y_aper = y_aper) |
| 10 | + |
| 11 | +#build particle distribution |
| 12 | +from scipy import randn |
| 13 | +N_part = 10000; sigmax=.5e-3; sigmay=1e-3 |
| 14 | +x_mp = sigmax*randn(N_part); |
| 15 | +y_mp = sigmay*randn(N_part); |
| 16 | +nel_mp = x_mp*0.+1. |
| 17 | + |
| 18 | +#build probes |
| 19 | +N_probes = 100 |
| 20 | +n_sigma_probes = 1. |
| 21 | +theta_probes = np.linspace(0, 2*np.pi, N_probes) |
| 22 | +x_probes = n_sigma_probes*sigmax*np.cos(theta_probes) |
| 23 | +y_probes = n_sigma_probes*sigmay*np.sin(theta_probes) |
| 24 | + |
| 25 | +# build pics |
| 26 | +pic_list = [] |
| 27 | + |
| 28 | +# Finite Difference Shortley-Weller |
| 29 | +Dh=1e-3 |
| 30 | +import FiniteDifferences_ShortleyWeller_SquareGrid as PIC_FDSW |
| 31 | +pic_list.append(PIC_FDSW.FiniteDifferences_ShortleyWeller_SquareGrid(chamb = chamber, Dh = Dh, sparse_solver = 'PyKLU')) |
| 32 | + |
| 33 | +# Finite Difference Staircase |
| 34 | +Dh=1e-3 |
| 35 | +import FiniteDifferences_Staircase_SquareGrid as PIC_FDSC |
| 36 | +pic_list.append(PIC_FDSC.FiniteDifferences_Staircase_SquareGrid(chamb = chamber, Dh = Dh, sparse_solver = 'PyKLU')) |
| 37 | + |
| 38 | +# Multi grid |
| 39 | +Sx_target = 5*sigmax |
| 40 | +Sy_target = 5*sigmay |
| 41 | +Dh_target = 0.1*min([sigmax, sigmay]) |
| 42 | +Dh_single = .5e-3 |
| 43 | +pic_singlegrid = PIC_FDSW.FiniteDifferences_ShortleyWeller_SquareGrid(chamb = chamber, Dh = Dh_single, sparse_solver = 'PyKLU') |
| 44 | +from MultiGrid import AddTelescopicGrids |
| 45 | +pic_list.append(AddTelescopicGrids(pic_main = pic_singlegrid, f_telescope = 0.3, |
| 46 | + target_grid = {'x_min_target':-Sx_target/2., 'x_max_target':Sx_target/2.,'y_min_target':-Sy_target/2.,'y_max_target':Sy_target/2.,'Dh_target':Dh_target}, |
| 47 | + N_nodes_discard = 3., N_min_Dh_main = 10, sparse_solver='PyKLU')) |
| 48 | + |
| 49 | +# test: |
| 50 | + |
| 51 | +pl.close('all') |
| 52 | +ms.mystyle_arial(fontsz = 14) |
| 53 | + |
| 54 | +for i_pic, pic in enumerate(pic_list): |
| 55 | + |
| 56 | + # standard solve and gather |
| 57 | + pic.scatter(x_mp, y_mp, nel_mp, charge = qe) |
| 58 | + pic.solve() |
| 59 | + Ex_probes, Ey_probes = pic.gather(x_probes, y_probes) |
| 60 | + |
| 61 | + # build state list |
| 62 | + fact_states = np.linspace(1.5, 2., 4) |
| 63 | + N_states = len(fact_states) |
| 64 | + |
| 65 | + list_states = [] |
| 66 | + for _ in fact_states: |
| 67 | + list_states.append(pic.get_state_object()) |
| 68 | + |
| 69 | + for i_state, state in enumerate(list_states): |
| 70 | + state.scatter(x_mp, y_mp, nel_mp*fact_states[i_state], charge = qe) |
| 71 | + |
| 72 | + # solve states |
| 73 | + pic.solve_states(list_states) |
| 74 | + |
| 75 | + # gather and plot |
| 76 | + pl.figure(1+i_pic, figsize=(10, 6)).patch.set_facecolor('w') |
| 77 | + sp1 = pl.subplot(2,1,1) |
| 78 | + pl.plot(theta_probes, Ex_probes) |
| 79 | + sp2 = pl.subplot(2,1,2) |
| 80 | + pl.plot(theta_probes, Ey_probes) |
| 81 | + |
| 82 | + for i_state, state in enumerate(list_states): |
| 83 | + colorcurr = ms.colorprog(i_state, N_states) |
| 84 | + Ex_prb_state, Ey_prb_state = state.gather(x_probes, y_probes) |
| 85 | + pl.subplot(2,1,1) |
| 86 | + pl.plot(theta_probes, Ex_prb_state, '.', color=colorcurr, label = 'State %d'%i_state) |
| 87 | + pl.plot(theta_probes, Ex_probes*fact_states[i_state], '-', color=colorcurr, label = 'Ref. %d'%i_state) |
| 88 | + pl.xlabel('theta [deg]') |
| 89 | + pl.ylabel('Ex [V/m]') |
| 90 | + pl.subplot(2,1,2) |
| 91 | + pl.plot(theta_probes, Ey_prb_state, '.', color=colorcurr, label = 'State %d'%i_state) |
| 92 | + pl.plot(theta_probes, Ey_probes*fact_states[i_state], '-', color=colorcurr, label = 'Ref. %d'%i_state) |
| 93 | + pl.xlabel('theta [deg]') |
| 94 | + pl.ylabel('Ey [V/m]') |
| 95 | + #check single state case |
| 96 | + fact_single_state = 2.5 |
| 97 | + single_state = pic.get_state_object() |
| 98 | + single_state.scatter(x_mp, y_mp, nel_mp*fact_single_state, charge = qe) |
| 99 | + pic.solve_states(single_state) |
| 100 | + Ex_prb_single_state, Ey_prb_single_state = single_state.gather(x_probes, y_probes) |
| 101 | + colorcurr = 'black' |
| 102 | + pl.subplot(2,1,1) |
| 103 | + pl.plot(theta_probes, Ex_prb_single_state, '.', color=colorcurr, label = 'Single state') |
| 104 | + pl.plot(theta_probes, Ex_probes*fact_single_state, '-', color=colorcurr, label = 'Single ref.') |
| 105 | + pl.subplot(2,1,2) |
| 106 | + pl.plot(theta_probes, Ey_prb_single_state, '.', color=colorcurr, label = 'Single state') |
| 107 | + pl.plot(theta_probes, Ey_probes*fact_single_state, '-', color=colorcurr, label = 'Single ref.') |
| 108 | + |
| 109 | + sp1.ticklabel_format(style='sci', scilimits=(0,0),axis='x') |
| 110 | + sp1.ticklabel_format(style='sci', scilimits=(0,0),axis='y') |
| 111 | + sp1.legend(loc='center left', bbox_to_anchor=(1, 0.)) |
| 112 | + sp2.ticklabel_format(style='sci', scilimits=(0,0),axis='x') |
| 113 | + sp2.ticklabel_format(style='sci', scilimits=(0,0),axis='y') |
| 114 | + pl.subplots_adjust(left = .10, right = .77, bottom = .13,top = .90, hspace = .40) |
| 115 | + pl.suptitle(str(pic.__class__).replace('<','').replace('>','').split('.')[-1].replace("'", '')) |
| 116 | + |
| 117 | +pl.show() |
0 commit comments