Example #1
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,
                     figsize=(4, 6),
                     common=common,
                     title="Vres = %.2f V" % Vres,
                     clim=(-0.75 * max(resVs), 0))

    f.create_dataset("step_%04d/electron_final_coordinates" % k, data=res['x'])
    f.create_dataset("step_%04d/electron_initial_coordinates" % k,
                     data=electron_initial_positions)
    f.create_dataset("step_%04d/solution_converged" % k,
Example #2
0
        plt.plot(x_eval[x_eval < 6], CMS.V(x_eval[x_eval < 6]*1E-6, 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')
        plt.xlabel("$x$ ($\mu$m)")
        plt.ylabel("Potential energy (eV)")
        plt.title("%s = %.2f V" % (electrode_names[SweepIdx], coefficients[SweepIdx]))
        plt.ylim(-0.7, -0.55)

        if save:
            common.save_figure(fig, save_path=os.path.join(save_path, sub_dir, "2D slice"))

        plt.close(fig)

    def magE(x, y):
        return np.log10(np.sqrt(CMS.dVdx(x, y)**2 + CMS.dVdy(x, y)**2))

    PP = anneal.PostProcess(save_path=conv_mon_save_path)
    x_plot = np.arange(-2E-6, +6E-6, dx)
    y_plot = y_eval*1E-6 #[np.logical_and(y_eval > -1, y_eval < 1)]*1E-6
    PP.save_snapshot(best_res['x'], xext=x_plot, yext=y_plot, Uext=magE,
                     figsize=(6.5, 3.), common=common, title="Gradient at %s = %.3f V" % (electrode_names[SweepIdx], coefficients[SweepIdx]),
                     clim=(1.5, 6.0),
                     draw_resonator_pins=False,
                     draw_from_dxf={'filename' : os.path.join(master_path, 'all_electrodes.dxf'),
                                    'plot_options' : {'color' : 'black', 'alpha' : 0.6, 'lw' : 0.5}})

    f = h5py.File(os.path.join(os.path.join(save_path, sub_dir), "Results.h5"), "a")
    #f.create_dataset("step_%04d/x_during_simulation" % k, data=ConvMon.curr_xk)
    #|f.create_dataset("step_%04d/jac_during_simulation" % k, data=ConvMon.jac)
    f.create_dataset("step_%04d/initial_jacobian" % k, data=initial_jacobian)
    f.create_dataset("step_%04d/final_jacobian" % k, data=best_res['jac'])
    f.create_dataset("step_%04d/electron_initial_coordinates" % k, data=electron_initial_positions)
        if "step" in step:
            valid_solution = f[step + "/solution_converged"][()]
            electron_ri = f[step + "/electron_final_coordinates"][()]
            if not (valid_solution):
                electron_ri = np.zeros(len(electron_ri))

            if k == 0:
                Ri = electron_ri
            else:
                Ri = np.vstack((Ri, electron_ri))

            k += 1

post_process = anneal.PostProcess(save_path=os.path.join(data_path, "Figures"),
                                  res_pinw=0.9,
                                  edge_gapw=0.5,
                                  center_gapw=0.7,
                                  box_length=box_length * 1E6)

convergence_monitor = anneal.ConvergenceMonitor(None,
                                                None,
                                                None,
                                                Uext=None,
                                                xext=None,
                                                yext=None,
                                                verbose=True,
                                                eps=1E-12,
                                                save_path=os.path.join(
                                                    data_path, "Figures"),
                                                figsize=(12., 3.),
                                                coordinate_transformation=None)
    for step in tqdm(f.keys()):
        if "step" in step:
            coefficients = [Vres, Vtrap, Vresguard, Vtrapguard]
            potentials = [
                potential_res, potential_trap, potential_resguard,
                potential_trapguard
            ]
            coefficients[swept_electrode_idx] = swept_electrode[k]

            for i, c in enumerate(coefficients):
                if i == 0:
                    potential_data = c * potentials[i]
                else:
                    potential_data += c * potentials[i]

            PP = anneal.PostProcess(
                save_path=os.path.join(data_path, "Figures"))

            valid_solution = f[step + "/solution_converged"][()]
            electron_ri = f[step + "/electron_final_coordinates"][()]

            print(np.shape(x[0, :]), np.shape(y[:, 0]),
                  np.shape(potential_data.T))

            CMS = anneal.TrapAreaSolver(x[0, :],
                                        y[:, 0],
                                        potential_data.T,
                                        spline_order_x=3,
                                        spline_order_y=3,
                                        smoothing=0.00,
                                        include_screening=include_screening,
                                        screening_length=screening_length)