# to the boundary of the resonator. We add half of the box length and move it to the right side of the trap area box.
res_right_x = np.max(x_eval)
res_electrons_x += resonator_box_length / 2. + res_right_x - 1.5E-6

print("Switching to greater trap area...")
t = trap_analysis.TrapSolver()
c = trap_analysis.get_constants()

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=0.01)

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

if 0:
    # Plot the resonator electron configuration
    fig1 = plt.figure(figsize=(9.5, 2.5))
    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)")
# to the boundary of the resonator. We add half of the box length and move it to the right side of the trap area box.
res_right_x = np.max(x_eval)
res_electrons_x += resonator_box_length / 2. + res_right_x - 1.5E-6

print("Switching to greater trap area...")
t = trap_analysis.TrapSolver()
c = trap_analysis.get_constants()

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)")
Пример #3
0
def coordinate_transformation(r):
    x, y = anneal.r2xy(r)
    y_new = EP.map_y_into_domain(y)
    r_new = anneal.xy2r(x, y_new)
    return r_new
Пример #4
0
    if res['status'] > 0:
        cprint(
            "WARNING: Step %d (Vres = %.2f V) did not converge!" % (k, Vres),
            "red")

    # This maps the electron positions within the simulation domain
    res['x'] = coordinate_transformation(res['x'])

    if len(annealing_steps) > 0:
        res = EP.perturb_and_solve(EP.Vtotal, len(annealing_steps),
                                   annealing_steps[0], res,
                                   **minimizer_options)
        res['x'] = coordinate_transformation(res['x'])

    resonator_ns_area = anneal.get_electron_density_by_area(
        anneal.xy2r(res['x'][::2], res['x'][1::2]))
    resonator_ns_pos = anneal.get_electron_density_by_position(
        anneal.xy2r(res['x'][::2], res['x'][1::2]))
    print(
        "Electron density on resonator = %.2e (by area) or %.2e (by position)"
        % (resonator_ns_area, resonator_ns_pos))

    PP = anneal.PostProcess(save_path=conv_mon_save_path,
                            res_pinw=res_pinw * 1E6,
                            edge_gapw=edge_gapw * 1E6,
                            center_gapw=center_gapw * 1E6,
                            box_length=box_length * 1E6)
    PP.save_snapshot(res['x'],
                     xext=x_box,
                     yext=y_box,
                     Uext=EP.V,
Пример #5
0
                              'callback': None}

    # We save the initial Jacobian of the system for purposes.
    initial_jacobian = CMS.grad_total(electron_initial_positions)
    res = minimize(CMS.Vtotal, electron_initial_positions, **trap_minimizer_options)

    while res['status'] > 0:
        # Try removing unbounded electrons and restart the minimization
        if remove_unbound_electrons:
            # Remove any electrons that are to the left of the trap
            best_x, best_y = anneal.r2xy(res['x'])
            idxs = np.where(np.logical_and(best_x > remove_bounds[0], best_x < remove_bounds[1]))[0]
            best_x = np.delete(best_x, idxs)
            best_y = np.delete(best_y, idxs)
            # Use the solution from the current time step as the initial condition for the next timestep!
            electron_initial_positions = anneal.xy2r(best_x, best_y)
            if len(best_x) < len(res['x'][::2]):
                print("%d/%d unbounded electrons removed. %d electrons remain." % (np.int(len(res['x'][::2]) - len(best_x)), len(res['x'][::2]), len(best_x)))
            res = minimize(CMS.Vtotal, electron_initial_positions, **trap_minimizer_options)
        else:
            best_x, best_y = anneal.r2xy(res['x'])
            idxs = np.union1d(np.where(best_x < -2E-6)[0], np.where(np.abs(best_y) > 2E-6)[0])
            if len(idxs) > 0:
                print("Following electrons are outside the simulation domain")
                for i in idxs:
                    print("(x,y) = (%.3f, %.3f) um"%(best_x[i]*1E6, best_y[i]*1E6))
            # To skip the infinite while loop.
            break

    if res['status'] > 0:
        cprint("WARNING: Initial minimization for Trap did not converge!", "red")
# Note: x_eval and y_eval are 2D arrays that contain the x and y coordinates at which the potentials are evaluated

conv_mon_save_path = os.path.join(save_path, sub_dir, "Figures")

print("Switching to greater trap area...")
t = trap_analysis.TrapSolver()
c = trap_analysis.get_constants()

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([], []),
                                 spline_order_x=3, spline_order_y=3, smoothing=0.01)

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


VBG_mat = np.zeros((len(y_eval), len(x_eval)))
for j, X in enumerate(x_eval * 1E-6):
    VBG_mat[:, j] = CMS.Vbg(X * np.ones(len(y_eval)), y_eval * 1E-6)


# Solve for the electron positions in the trap area!
ConvMon = anneal.ConvergenceMonitor(Uopt=CMS.Vtotal, grad_Uopt=CMS.grad_total, N=10,
                                    Uext=CMS.V,
                                    xext=xeval * 1E-6, yext=yeval * 1E-6, verbose=False, eps=epsilon,
                                    save_path=conv_mon_save_path)
t.get_electron_frequency([fr[0], -fr[1] / 1E6], [ferr[0], -ferr[1] / 1E6])

# Rectangle
if N_cols * N_rows != N_electrons:
    raise ValueError("N_cols and N_rows are not compatible with N_electrons")
else:
    y_separation = 1.25E-6
    x_separation = 1.0E-6
    y0 = -15E-6
    ys = np.linspace(y0, y0 + N_cols * y_separation, N_cols)
    yinit = np.tile(np.array(ys), N_rows)
    xs = np.linspace(-(N_rows - 1) / 2. * x_separation,
                     +(N_rows - 1) / 2. * x_separation, N_rows)
    xinit = np.repeat(xs, N_cols)

electron_initial_positions = anneal.xy2r(xinit, yinit)

x_box = np.linspace(-3E-6, 3E-6, 501)
y_box = np.linspace(-box_length / 2, box_length / 2, 11)
X_box, Y_box = np.meshgrid(x_box, y_box)


def coordinate_transformation(r):
    x, y = anneal.r2xy(r)
    y_new = EP.map_y_into_domain(y)
    r_new = anneal.xy2r(x, y_new)
    return r_new


# This is where the actual solving starts...
os.mkdir(os.path.join(save_path, sub_dir))