x_eval, y_eval, cropped_potentials = t.crop_potentials(output, ydomain=None, xdomain=None)
coefficients = np.array([Vres, Vtrap, Vrg, Vcg, Vtg])
combined_potential = t.get_combined_potential(cropped_potentials, coefficients)
# Note: x_eval and y_eval are 1D arrays that contain the x and y coordinates at which the potentials are evaluated
# Units of x_eval and y_eval are um

CMS = anneal.CombinedModelSolver(x_eval * 1E-6, y_eval * 1E-6, -combined_potential.T,
                                 anneal.xy2r(res_electrons_x, res_electrons_y),
                                 spline_order_x=3, spline_order_y=3, smoothing=smoothing)

X_eval, Y_eval = np.meshgrid(x_eval * 1E-6, y_eval * 1E-6)

if 1:
    # Plot the resonator electron configuration
    fig1 = plt.figure(figsize=(12, 3))
    common.configure_axes(12)
    plt.pcolormesh(x_eval, y_eval, CMS.V(X_eval, Y_eval), cmap=plt.cm.Spectral_r, vmax=0.0, vmin=-0.75 * Vres)
    plt.pcolormesh((y_box + res_right_x + resonator_box_length / 2.) * 1E6, x_box * 1E6, RS.V(X_box, Y_box).T,
                   cmap=plt.cm.Spectral_r, vmax=0.0, vmin=-0.75 * Vres)
    plt.plot((y_init + res_right_x + resonator_box_length / 2.) * 1E6, x_init * 1E6, 'o', color='palegreen', alpha=0.5)
    plt.plot(res_electrons_x * 1E6, res_electrons_y * 1E6, 'o', color='deepskyblue', alpha=1.0)
    plt.xlabel("$x$ ($\mu$m)")
    plt.ylabel("$y$ ($\mu$m)")
    plt.title("Resonator configuration")
    plt.colorbar()
    plt.xlim(res_right_x * 1E6, (res_right_x + resonator_box_length) * 1E6)
    plt.ylim(-5, 5)


# Solve for the electron positions in the trap area!
ConvMon = anneal.ConvergenceMonitor(Uopt=CMS.Vtotal, grad_Uopt=CMS.grad_total, N=10,
Пример #2
0
def load_maxwell_data(df, do_plot=True, do_log=True, xlim=None, ylim=None, clim=None,
                       figsize=(6.,12.), plot_axes='xy', cmap=plt.cm.Spectral):
    """
    :param df: Path of the Maxwell data file (fld)
    :param do_plot: Use pcolormesh to plot the 3D data
    :param do_log: Plot the log10 of the array. Note that clim has to be adjusted accordingly
    :param xlim: Dafaults to None. May be any tuple.
    :param ylim: Defaults to None, May be any tuple.
    :param clim: Defaults to None, May be any tuple.
    :param figsize: Tuple of two floats, indicating the figure size for the plot (only if do_plot=True)
    :param plot_axes: May be any of the following: 'xy' (Default), 'xz' or 'yz'
    :return:
    """

    data = np.loadtxt(df, skiprows=2)
    x = data[:,0]
    y = data[:,1]
    z = data[:,2]
    magE = data[:,3]

    # Determine the shape of the array:
    if 'x' in plot_axes:
        for idx, X in enumerate(x):
            if X != x[0]:
                ysize=idx
                xsize=np.shape(magE)[0]/ysize
                break
    else:
        for idx, Y in enumerate(y):
            if Y != y[0]:
                ysize=idx
                xsize=np.shape(magE)[0]/ysize
                break

    # Cast the voltage data in an array:
    if plot_axes == 'xy':
        X = x.reshape((xsize, ysize))
        Y = y.reshape((xsize, ysize))
    if plot_axes == 'xz':
        X = x.reshape((xsize, ysize))
        Y = z.reshape((xsize, ysize))
    if plot_axes == 'yz':
        X = y.reshape((xsize, ysize))
        Y = z.reshape((xsize, ysize))

    E = magE.reshape((xsize, ysize))

    if do_plot:
        plt.figure(figsize=figsize)
        common.configure_axes(15)
        if do_log:
            plt.pcolormesh(X*1E6, Y*1E6, np.log10(E), cmap=cmap)
        else:
            plt.pcolormesh(X*1E6, Y*1E6, E, cmap=cmap)

        plt.colorbar()

        if clim is not None:
            plt.clim(clim)
        if xlim is None:
            plt.xlim([np.min(x)*1E6, np.max(x)*1E6]);
        else:
            plt.xlim(xlim)
        if ylim is None:
            plt.ylim([np.min(y)*1E6, np.max(y)*1E6]);
        else:
            plt.ylim(ylim)
        plt.xlabel('x ($\mu\mathrm{m}$)')
        plt.ylabel('y ($\mu\mathrm{m}$)')

    return X, Y, E
Пример #3
0
def z_from_fld(df, V=1.0, h=0.1E-3, d0=0.4E-6, xdomain=None, ydomain=None,
               plot_Efield=True, plot_surface=True, verbose=True, **kwargs):
    """
    Calculate the surface deformation from an fld file from Maxwell. This file should contain electric field
    data (Not E**2) and the contents can be scaled using the argument V.

    **kwargs may be any argument that can be passed into pcolormesh to adjust the surface plot.
    Of course this is only applicable if plot_surface=True. To change the color limits, use
    vmin=min_value and vmax=max_value.

    :param df: Maxwell datafile in fld format (exported from the field calculator).
    :param V: Applied voltage to the electrodes determines the electric field
    :param plot_Efield: Plot the E^2
    :param plot_surface: Plot the surface deformation.
    :return:
    """

    # Reset the constants and create the parameters for the model
    constants, parameters = reset_constants(verbose=False)
    parameters['h'] = h
    parameters['d0'] = d0

    # Load the data from the file
    X,Y,E0 = load_maxwell_data(df, do_plot=False)

    if verbose:
        print("Loaded data from FLD file...")

    # Cut the data for processing.
    xcut, ycut, Esquaredcut = select_domain(X, Y, V**2 * E0**2, xdomain=xdomain, ydomain=ydomain)

    # Plot, if necessary
    if plot_Efield:
        plt.figure(figsize=(12.,6.))
        common.configure_axes(13)
        plt.pcolormesh(xcut*1E6, ycut*1E6, np.log10(Esquaredcut), cmap=plt.cm.Spectral)
        plt.xlabel(r'x ($\mu$m)'); plt.xlim(min(xcut)*1E6, max(xcut)*1E6);
        plt.ylabel(r'y ($\mu$m)'); plt.ylim(min(ycut)*1E6, max(ycut)*1E6);
        plt.colorbar(); plt.title(r'$|E|^2$ for selected domain')

    parameters['w'] = xcut[-1] - xcut[0]
    parameters['l'] = ycut[-1] - ycut[0]

    if verbose:
        print_constants_parameters(constants, parameters)

    d = z_2D(xcut, ycut, constants, parameters, Esquared=Esquaredcut, verbose=verbose)

    # Plot surface profile, if necessary
    if plot_surface:
        fig2 = plt.figure(figsize=(12.,6.))
        common.configure_axes(13)
        plt.pcolormesh(xcut*1E6, ycut*1E6, (parameters['d0']-d)*1E9, **kwargs)
        plt.xlabel("x ($\mu$m)")
        plt.ylabel("y ($\mu$m)")
        plt.colorbar()
        plt.title("2D surface profile: $d_0 - d$, color in nm")
        plt.xlim(min(xcut)*1E6, max(xcut)*1E6);
        plt.ylim(min(ycut)*1E6, max(ycut)*1E6);

    return xcut, ycut, d
                                     os.path.join(master_path,
                                                  'all_electrodes.dxf'),
                                     'plot_options': {
                                         'color': 'black',
                                         'alpha': 0.6,
                                         'lw': 0.5
                                     }
                                 })

                plt.close('all')

            if twod_slice:
                electron_pos = electron_ri[::2] * 1E6

                fig = plt.figure(figsize=(7., 3.))
                common.configure_axes(13)
                plt.plot(x_plot * 1E6, CMS.V(x_plot, 0), '-', color='orange')
                plt.plot(electron_pos[electron_pos < 6],
                         CMS.V(electron_pos[electron_pos < 6] * 1E-6, 0) +
                         0.005,
                         'o',
                         color='cornflowerblue',
                         lw=2.0,
                         alpha=0.7,
                         mec='k',
                         mew=0.75)
                plt.xlabel("$x$ ($\mu$m)")
                plt.ylabel("Potential energy (eV)")
                plt.title("%s = %.2f V" %
                          (electrode_names[swept_electrode_idx],
                           coefficients[swept_electrode_idx]))