Example #1
0
def stack(arr, num_periods=1):
    # returns an array that is stacked `num_periods` times along y.  For plotting many periods of the accelerator unit cell.
    arr_orig = get_value(arr).copy()
    arr_big = get_value(arr).copy()
    for i in range(num_periods):
        arr_big = np.hstack([arr_big, arr_orig])
    return arr_big
Example #2
0
         })


def stack(arr, num_periods=1):
    # returns an array that is stacked `num_periods` times along y.  For plotting many periods of the accelerator unit cell.
    arr_orig = get_value(arr).copy()
    arr_big = get_value(arr).copy()
    for i in range(num_periods):
        arr_big = np.hstack([arr_big, arr_orig])
    return arr_big


num_periods = 4

# plot the final permittivity
eps_disp = imarr(stack(get_value(F.eps_r), num_periods=num_periods))

plt.imshow(np.real(eps_disp), cmap='nipy_spectral')
plt.colorbar()
plt.show()

# plot the accelerating fields
fields = F.solve(source)

[Ex, Ey, Hz] = [get_value(f) for f in fields]

plt.imshow(imarr(np.real(stack(Ey, num_periods=num_periods))) / E0,
           cmap='RdBu')
plt.title('E_y / E0 (<-)')
plt.xlabel('y')
plt.ylabel('x')